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 › newbie mouse over question
Page Index Toggle Pages: 1
newbie mouse over question (Read 335 times)
newbie mouse over question
Feb 23rd, 2009, 4:39pm
 
I'm trying to write a script which first randomly places several rects  with type on top of them (using a random(x, y)). I then want the user to be able to drag any rectangle-and-word pair, but only when the mouse is down AND it is over a rectangle.

Obviously I don't want every box to track the mouse, and I only want drag to function on the box the mouse is over on mouseClick.

Any thoughts on how to set this up? It's pretty easy to do if you only have one box drawn, but if there are several, I'm a little lost.

Re: newbie mouse over question
Reply #1 - Feb 23rd, 2009, 8:36pm
 
You need to keep track of the position and size of each rectangle.  Then on mouse click, loop through each rectangle and see if the mouse is inside each rect to determine which rect has been selected.

Additionally, if you are doing a click-drag operation, you might want to use mousePressed() instead of mouseClick().
Re: newbie mouse over question
Reply #2 - Feb 24th, 2009, 7:34am
 
I made some code to manage handles when I started to code Processing. Perhaps I would do it a bit differently now, I don't know. Anyway, you can take a look:

http://philho.pastebin.com/f16ac1b09 -- Handles (demo)
http://philho.pastebin.com/f19f2cace -- Handle (class)

Note that I had to manage the dragged state at the collection of handles level, to avoid dragging several handles at once.
Page Index Toggle Pages: 1