PDA

View Full Version : Selecting a region by drawing a rectangle.


washington
03-10-2009, 04:09 AM
Hi,

I posted a similar question a few days ago, but nobody replied. I'm hoping that a new thread with a more descriptive title will help.

Basically, I'm trying to implement a 'real time strategy' type selection tool over many canvases that are contained within vboxes. I want the user to be able to draw a rectangle over those canvases (using a mouse), and the relevant information to be passed to some kind of function which will process the data.

Does anyone have any idea how this might be done? or have any links to tutorials that might be of help? I would really really appreciate any assistance. Thank you.

rawmantick
03-10-2009, 11:43 AM
On mouse down remember the initial position.

On mouse move just draw the rectangle after having cleared the previous one.

On mouse up get the current mouse position and construct the rectangle along with the initial position.

Once you have a selection rect and a rect of a selectable item - you can check if they intersect easily.

Well... that's for rectangular items...

Peter Cowling
03-10-2009, 01:39 PM
Hi,

I posted a similar question a few days ago, but nobody replied. I'm hoping that a new thread with a more descriptive title will help.



A more descriptive description would be good :), specifically:


I want the user to be able to draw a rectangle over those canvases (using a mouse), and the relevant information to be passed to some kind of function which will process the data.


The sort of information contained in the canvases is relevant to the approach you need adopt. So is it images or text etc? Or is it unknown in advance?

And what will happen to the processed data?

washington
03-11-2009, 05:09 AM
Thanks for your replies. Really appreciate it.

Essentially, the rectangle will be drawn over objects that are extensions of a canvas. The information I need from them is essentially their location within the box that contains them, so the x and y values of the rectangle should be enough I believe.

Any more advice/suggestions would be welcome. Thanks again for your help :)