We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Mouse Over issue
Page Index Toggle Pages: 1
Mouse Over issue (Read 1153 times)
Mouse Over issue
May 6th, 2010, 8:55am
 
Hi,

I'm checking to see if the mouse is over a rectangle. If it is, then it should make the box blue. Here is the code of that class, note that I do get a mouse clicked response.

 final int BLUETOOTH_TEST_BUTTON_X = 100;
 final int BLUETOOTH_TEST_BUTTON_Y = 100;
 
 final int STANDARD_BUTTON_WIDTH = 80;
 final int STANDARD_BUTTON_HEIGHT = 40;
 final int STANDARD_BUTTON_COLOR = 255; //Standard button color is white
 final Color MOUSE_OVER_BUTTON_COLOR = Color.green;
 
 boolean testButtonMouseOver = false;
 
 
 //Checks to see if the Test button is clicked, if so it will send a signal via
 //Bluetooth to turn on the LED test button
 void checkTestButtonClick()
 {
   //println("Button Click Tested!");
   
   if (mouseX > BLUETOOTH_TEST_BUTTON_X && mouseX < BLUETOOTH_TEST_BUTTON_X + STANDARD_BUTTON_WIDTH &&
   mouseY > BLUETOOTH_TEST_BUTTON_Y && mouseY <  BLUETOOTH_TEST_BUTTON_Y + STANDARD_BUTTON_HEIGHT)
   {
     println("Test Button CLicked!");
     
     myPort.write('A'); // Sends 'A' char to on board computer to be processed and interpreted
   }
 }
 
 void checkTestButtonMouseOver()
 {
 if (mouseX > BLUETOOTH_TEST_BUTTON_X && mouseX < BLUETOOTH_TEST_BUTTON_X + STANDARD_BUTTON_WIDTH &&
   mouseY > BLUETOOTH_TEST_BUTTON_Y && mouseY <  BLUETOOTH_TEST_BUTTON_Y + STANDARD_BUTTON_HEIGHT)
   {
     println("Test Button Mouse Over!");
     testButtonMouseOver = true;
   }
 }
 
 
 void draw() //Draws all things related to bluetooth
 {
   if (testButtonMouseOver)
   {
     fill(0, 102, 153);
   }
   
    rect(BLUETOOTH_TEST_BUTTON_X, BLUETOOTH_TEST_BUTTON_Y, STANDARD_BUTTON_WIDTH, STANDARD_BUTTON_HEIGHT); //Draw Bluetooth Test button
    //fill(STANDARD_BUTTON_COLOR); //Fill button
   
 }

Both the draw() and the checkTestButtonMouseOver() are called from the same place, and the checkTestButtonMouseOver() is called 1st.

Why is the box not changing color?
Re: Mouse Over issue
Reply #1 - May 6th, 2010, 9:32am
 
brennonW wrote on May 6th, 2010, 8:55am:
Both the draw() and the checkTestButtonMouseOver() are called from the same place, and the checkTestButtonMouseOver() is called 1st.

Why is the box not changing color



Hard to say without a bit more context...  Where are you calling these methods from
Re: Mouse Over issue
Reply #2 - May 7th, 2010, 10:20am
 
These are called from:

void drawBluetooth()
{
 
 bt.checkTestButtonMouseOver();
 bt.draw();
}

which in turn is called from setup().
Re: Mouse Over issue
Reply #3 - May 7th, 2010, 12:05pm
 
In setup(), mouseX/Y are always zero...
Re: Mouse Over issue
Reply #4 - May 8th, 2010, 2:27am
 
And setup() is only called once: when your sketch starts.  Try moving drawBluetooth() into the main draw() loop...
Page Index Toggle Pages: 1