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 › A LEFT mouse click with SHIFT key Problem
Page Index Toggle Pages: 1
A LEFT mouse click with SHIFT key Problem (Read 1324 times)
A LEFT mouse click with SHIFT key Problem
Nov 12th, 2009, 8:32pm
 
So I have a program where I am displaying a treemap (see Ben Fry's Visualizing Data book) of some hierarchical data.  To make a long story short, I have the program opening and zooming further into the hierarchy of the treemap with a LEFT mouse click and zooming out and closing the children of the treemap with a RIGHT mouse click. I am now using the RIGHT click for something else, so I now want that RIGHT click to become a SHIFT and LEFT click to zoom out.

Here is a part of the code that controls this function:
[td]  
boolean mousePressed()
 {
   if (mouseInside())
   {
     if (mouseButton == LEFT)
     {
       parent.zoomIn();
       return true;
     }
     else if (mouseButton == RIGHT)
     {
       if (parent == zoomItem)
       {
         parent.zoomOut();
       }
       else
       {
         parent.hideContents();
       }
       return true;
     }
   }
 return false;
 }
}
[/td]

I tried replacing the else if statement with this:
else if (mouseButton == LEFT && (keyPressed == true && key == CODED && keyCode == SHIFT))

It doesn't work.  It doesn't zoom out at all.  I was wondering if it was because it as a boolean mousePressed?  I got a small program to work with a void mousePressed:
[td]
color fillVal = color(126);

void draw() {
 fill(fillVal);
 rect(25, 25, 50, 50);
}

void mousePressed(){
 if (keyPressed && key == CODED && keyCode == SHIFT && mouseButton == LEFT){
     fillVal = 255;
   } else if (keyPressed && key == CODED && keyCode == CONTROL && mouseButton == LEFT) {
     fillVal = 0;
   }
 } else {
   fillVal = 126;
 }
}
[/td]

Could anyone might see where I am going wrong? Thanks for the help.
Re: A LEFT mouse click with SHIFT key Problem
Reply #1 - Nov 12th, 2009, 10:09pm
 
what i prefere is zooming in and out by right clicking and then move the mouse up for zooming in and move the mouse down for zooming out.
All you have to do is get the mouse position on mouseClicked and then zoom the difference between the prev and actuall mouseY coodinate ( or map the value to whatever you want)
Re: A LEFT mouse click with SHIFT key Problem
Reply #2 - Nov 13th, 2009, 4:54am
 
Look at your logic (as you describe it):
if (mouseButton == LEFT)
// Do Stuff
else if (mouseButton == LEFT && (keyPressed == true && key == CODED && keyCode == SHIFT))
// Do something else

You will never go into the else if, because when mouseButton == LEFT, you just go in the first statement, never in the second.
Put the key tests into the if (mouseButton == LEFT) condition.
Re: A LEFT mouse click with SHIFT key Problem
Reply #3 - Nov 15th, 2009, 3:00pm
 
Thanks a lot for your help!  You were right in that I had to check the keyPressed in the first if statement.  A simple "if (mousePressed == LEFT && keyPessed == false)" was the piece I was missing.  Works great now!

Thanks
Page Index Toggle Pages: 1