]> gitweb.factorcode.org Git - factor.git/commitdiff
game.input.demos.joysticks: Add to demos and wrap buttons.
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 6 Feb 2021 02:31:58 +0000 (20:31 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 6 Feb 2021 02:31:58 +0000 (20:31 -0600)
On joysticks with 128 buttons the UI was extending across several
monitors. Instead we make a grid of buttons 32 wide which people
without joysticks with more than 32 buttons will never see.

extra/game/input/demos/joysticks/joysticks.factor
extra/game/input/demos/joysticks/tags.txt
extra/game/input/demos/key-caps/tags.txt

index fdf910dfae8fc4d660f9d655b2474c60a78abd4c..854f27881d9451943fb41721bc92a4748fb481f7 100644 (file)
@@ -1,8 +1,8 @@
-USING: ui ui.gadgets sequences kernel arrays math colors
-colors.constants ui.render ui.pens.polygon ui.pens.solid math.vectors
-accessors fry ui.gadgets.packs game.input ui.gadgets.labels
-ui.gadgets.borders timers calendar locals strings ui.gadgets.buttons
-combinators math.parser assocs threads ;
+USING: accessors arrays assocs calendar colors.constants
+combinators game.input grouping kernel math math.parser
+math.vectors sequences threads timers ui ui.gadgets
+ui.gadgets.borders ui.gadgets.buttons ui.gadgets.labels
+ui.gadgets.packs ui.pens.polygon ui.pens.solid ;
 IN: game.input.demos.joysticks
 
 CONSTANT: SIZE { 151 151 }
@@ -87,13 +87,23 @@ TUPLE: joystick-demo-gadget < pack axis raxis controller buttons timer ;
 : add-raxis-gadget ( gadget shelf -- gadget shelf )
     <axis-gadget> [ >>raxis ] [ add-gadget-with-border ] bi-curry bi* ;
 
-:: (add-button-gadgets) ( gadget shelf -- )
-    gadget controller>> read-controller buttons>> length <iota> [
-        number>string [ drop ] <border-button>
-        shelf over add-gadget drop
-    ] map gadget buttons<< ;
+: button-pref-dim ( n -- dim )
+    number>string [ drop ] <border-button> pref-dim ;
 
-: add-button-gadgets ( gadget shelf -- gadget shelf )
+:: (add-button-gadgets) ( gadget pile -- )
+    gadget controller>> read-controller buttons>>
+    dup length button-pref-dim :> pref-dim
+    length <iota> [
+        number>string [ drop ] <border-button>
+        pref-dim >>pref-dim
+    ] map :> buttons
+    buttons gadget buttons<<
+    buttons 32 group [
+        [ <shelf> ] dip [ add-gadget ] each
+        pile swap add-gadget drop
+    ] each ;
+
+: add-button-gadgets ( gadget pile -- gadget pile )
     [ (add-button-gadgets) ] 2keep ;
 
 : <joystick-demo-gadget> ( controller -- gadget )
@@ -101,7 +111,7 @@ TUPLE: joystick-demo-gadget < pack axis raxis controller buttons timer ;
     { 0 1 } >>orientation
     swap add-controller-label
     <shelf> add-axis-gadget add-raxis-gadget add-gadget
-    <shelf> add-button-gadgets add-gadget ;
+    <pile> add-button-gadgets add-gadget ;
 
 : update-buttons ( buttons button-states -- )
     [ >>selected? drop ] 2each ;
index 84d4140a708087ed366b2c57729dee056dbc0149..214a7b666bdd6650bf4ef4dd784154e86d20561e 100644 (file)
@@ -1 +1,2 @@
 games
+demos
index cb5fc203e1106f97cf94182f5ead210d99aa803f..214a7b666bdd6650bf4ef4dd784154e86d20561e 100644 (file)
@@ -1 +1,2 @@
+games
 demos