// experiment with mouse moving a button in MAUI // copyright 2008 Les Hall // This software is protected by the GNU General Public License // set up the view panel 400 => int x_max; 400 => int y_max; 1280 => int screen_width; 960 => int screen_height; MAUI_View mouse_view; mouse_view.size (x_max, y_max); mouse_view.position (screen_width/2 - x_max/2, screen_height/2 - y_max/2); mouse_view.name ("Experiment with moving buttons"); mouse_view.display (); // create the button 200 => int x_pos; 200 => int y_pos; 60 => int button_size; MAUI_Button mouse_button; mouse_button.toggleType (); mouse_button.size (button_size, button_size); mouse_button.position (x_pos - button_size/2, y_pos - button_size/2); mouse_button.name (""); mouse_view.addElement (mouse_button); // create a dummy button MAUI_Button mouse_button2; mouse_button2.toggleType (); mouse_button2.size (x_max, button_size); mouse_button2.position (0, 0); mouse_button2.name ("Click and drag the square button"); mouse_view.addElement (mouse_button2); SinOsc sinosc => JCRev jcrev => dac; jcrev.mix (0.1); 0 => int device; Hid hid; HidMsg hidmsg; if (!hid.openMouse (device)) me.exit(); 0 =>int move_mouse; // infinite time loop while (true) { // wait on event hid => now; // loop over messages while (hid.recv (hidmsg)) { if (hidmsg.isButtonDown()) { 1 => move_mouse; } if (hidmsg.isButtonUp ()) { 0 => move_mouse; } if( hidmsg.isMouseMotion() ) { if (move_mouse) { // add the mouse movement to x and y positions hidmsg.deltaX +=> x_pos; hidmsg.deltaY +=> y_pos; // check lower limit on x if (x_pos < 0) { 0 => x_pos; } // check upper limit on x if (x_pos > x_max - button_size) { x_max - button_size => x_pos; } // check lower limit on y if (y_pos < button_size) { button_size => y_pos; } // check upper limit on y if (y_pos > y_max - button_size) { y_max - button_size => y_pos; } // move the button mouse_button.position (x_pos, y_pos); mouse_view.addElement (mouse_button); // adjust frequency and amplitude of sound source sinosc.freq (500 * x_pos / (x_max $ float)); sinosc.gain (1 - y_pos / (y_max $ float)); // delay to let system catch up 0.1::ms => now; } } } }