1 /* class to display wiimote data as a gui */
4 classvar <>xposScreen=0, <>yposScreen=20;
6 var <>w, <>wiimote, <watcher;
12 ^super.new.w_(w).wiimote_(wiimote).init;
17 var ncview, rmview, clview;
18 counter = counter + 1;
20 // xsize = 64 + ((2*44 + 2)*2) + 2;
23 // ysize = (10+1) * 34 + 2;
26 // labelColor = Color.white.alpha_(0.4);
28 w = GUI.window.new("WiiMote Control", Rect(xposScreen, yposScreen, xsize + 10, ysize)).front;
29 //w.view.background_(Color.black);
30 w.view.decorator = FlowLayout(Rect(4, 4, w.bounds.width, w.bounds.height), 2@2, 2@2);
34 // unclutter the windows on the screen:
35 yposScreen = yposScreen + 160;
36 if ( yposScreen > 700,
37 { yposScreen = 20; xposScreen = xposScreen + xsize + 10;
38 if ( xposScreen > 900,
42 GUI.staticText.new(w, Rect(0, 0, xsize - 2, 20)).string_("WiiMote" + wiimote.id + wiimote.address )
44 //.background_(labelColor);
46 rmview = GUI.compositeView.new( w, Rect( 5, 30, 205, 130 ));
47 rm = WiiRemoteGUI.new( rmview, wiimote, 0 ); //30 );
49 ncview = GUI.compositeView.new( w, Rect( 5, 160, 205, 105 ));
50 nc = WiiNunchukGUI.new( ncview, wiimote, 0 ); // 160 );
52 watcher = SkipJack.new( { this.updateVals }, 0.1, { w.isClosed }, (\wiimote_gui_ ++ counter));
60 if ( wiimote.ext_type == 1, {
68 if ( GUI.scheme.id == \swing,
78 if ( GUI.scheme.id == \swing,
90 var <buttons, <sliders, <led, <rumble;
91 var <onColor, <offColor;
93 *new{ |w,wiimote,offset|
94 ^super.new.wiimote_(wiimote).w_(w).init( offset );
99 xpos = 5; ypos = offset+5;
101 onColor = Color.yellow;
102 offColor = Color.white;
104 buttons = Array.fill( 11, 0 );
106 [ "A", "B", "1", "2", "-", "home", "+" ].do{ |it,i|
109 if ( it == "home", { size = 45 } );
110 buttons[i] = GUI.staticText.new( w, Rect( xpos, ypos, size, 20 ) ).string_( it ).background_(onColor).align_( 0 );
111 xpos = xpos + size + 5;
117 buttons[9] = GUI.staticText.new( w, Rect( xpos, ypos+25, 20, 20 ) ).string_( "<-" ).background_(onColor).align_( 0 );
119 buttons[7] = GUI.staticText.new( w, Rect( xpos, ypos, 20, 20 ) ).string_( "^" ).background_(onColor).align_( 0 );
120 buttons[8] = GUI.staticText.new( w, Rect( xpos, ypos+50, 20, 20 ) ).string_( "v" ).background_(onColor).align_( 0 );
122 buttons[10] = GUI.staticText.new( w, Rect( xpos, ypos+25, 20, 20 ) ).string_( "->" ).background_(onColor).align_( 0 );
126 sliders = wiimote.remote_motion.collect{ |it,i|
128 GUI.slider.new( w, Rect( xpos-25, ypos, 20, 70 ) );
131 sliders = sliders.add( GUI.slider.new( w, Rect( xpos, ypos, 20, 70 ) ) );
136 led = wiimote.remote_led.collect{ |it,i|
138 GUI.button.new( w, Rect( xpos-25, ypos, 20, 20 ) )
139 .states_( [ [ "X", Color.black, Color.yellow ],["O", Color.yellow, Color.black ] ] )
140 .action_( { |but| wiimote.setLEDState( i, but.value ) } );
143 rumble = GUI.button.new( w, Rect( xpos, ypos, 70, 20 ) )
144 .states_( [ [ "rumble", Color.black, Color.yellow ],["RUMBLING", Color.yellow, Color.black ] ] )
145 .action_( { |but| wiimote.rumble( but.value ) } );
149 led.do{ |it,i| it.value = wiimote.remote_led[i] };
150 //rumble.value = wiimote.rumble;
151 wiimote.remote_motion.do{ |it,i| sliders[i].value = it };
152 //sliders[3].value = wiimote.remote_motion[3]/3;
153 sliders[4].value = wiimote.battery;
154 wiimote.remote_buttons.do{ |it,i|
157 buttons[i].background = onColor;
159 buttons[i].background = offColor;
168 var <buttons, <sliders, <slider2d;
169 var <onColor, <offColor;
171 *new{ |w,wiimote,offset|
172 ^super.new.wiimote_(wiimote).w_(w).init( offset );
177 xpos = 5; ypos = offset+5;
179 onColor = Color.yellow;
180 offColor = Color.white;
182 buttons = Array.fill( 2, 0 );
184 [ "Z", "C" ].do{ |it,i|
185 buttons[i] = GUI.staticText.new( w, Rect( xpos, ypos, 20, 20 ) ).string_( it ).background_(onColor).align_( 0 );
192 sliders = wiimote.nunchuk_motion.collect{ |it,i|
194 GUI.slider.new( w, Rect( xpos-25, ypos, 20, 70 ) );
197 slider2d = GUI.slider2D.new( w, Rect( xpos, ypos, 70, 70 ) );
202 //rumble.value = wiimote.rumble;
203 wiimote.nunchuk_motion.do{ |it,i| sliders[i].value = it };
204 wiimote.nunchuk_buttons.do{ |it,i|
207 buttons[i].background = onColor;
209 buttons[i].background = offColor;
212 slider2d.setXY( wiimote.nunchuk_stick[0], wiimote.nunchuk_stick[1] );