New topic: Can you ADD a "MOUSE" Event to a GROUP2D Object
<http://forums.realsoftware.com/viewtopic.php?t=30657> Page 1 of 1 [ 7 posts ] Previous topic | Next topic Author Message IMIXMMM Post subject: Can you ADD a "MOUSE" Event to a GROUP2D ObjectPosted: Sun Oct 25, 2009 10:35 pm Joined: Thu Oct 26, 2006 4:49 am Posts: 35 HI, Q1) If I have a canvas area and create some objects in that area using GROUP2D Object, is it possible to add my own events like MOUSE CLICK, MOUSE DRAG etc, so can easily manipulate the Object? Q2) If I create GROUPED objects, Can I also give them a NAME/ID ( i.e Property ) so I can refer to them later? Thanks Dave M Top sbeach Post subject: Re: Can you ADD a "MOUSE" Event to a GROUP2D ObjectPosted: Sun Oct 25, 2009 10:51 pm Joined: Wed May 10, 2006 1:27 pm Posts: 23 IMIXMMM wrote:Q1) If I have a canvas area and create some objects in that area using GROUP2D Object, is it possible to add my own events like MOUSE CLICK, MOUSE DRAG etc, so can easily manipulate the Object? The canvas already has mouse events, so I assume you mean you want MouseDown/MouseUp/MouseDrag events for the Object2D or Group2D objects correct? If so you'd have to create them via the MouseDown/MouseUp/MouseDrag events (respectively) in the canvas itself. An elegant solution would be to subclass the Canvas control, add arrays of object2d and group2d to store these within the canvas (see answer 2), and create new MouseDown/MouseUp/MouseDrag events that pass arrays of the Object2D items that were clicked. IMIXMMM wrote:Q2) If I create GROUPED objects, Can I also give them a NAME/ID ( i.e Property ) so I can refer to them later? You could, again, subclass the Object2D and Group2D classes to add name and id properties. However to prevent the objects from being destroyed you would need to be storing the objects somewhere where they would remain in scope (a property within a module for example)- and by doing this, you would already have the means to access the objects again (ie through the property in the module). _________________ -Sean Top IMIXMMM Post subject: Re: Can you ADD a "MOUSE" Event to a GROUP2D ObjectPosted: Mon Oct 26, 2009 12:33 am Joined: Thu Oct 26, 2006 4:49 am Posts: 35 Hi Sbeach, Thanks for the reply, So, ARE the "MOUSE EVENT's" is passed from the CANVAS to the OBJECT Directly? Or do I still have to SCAN ALL my OBJECTS to see if its in the Current range of X,Y mouse values? This is what I am trying to avoid. thanks Dave M Top sbeach Post subject: Re: Can you ADD a "MOUSE" Event to a GROUP2D ObjectPosted: Mon Oct 26, 2009 12:39 am Joined: Wed May 10, 2006 1:27 pm Posts: 23 IMIXMMM wrote:So, ARE the "MOUSE EVENT's" is passed from the CANVAS to the OBJECT Directly? Or do I still have to SCAN ALL my OBJECTS to see if its in the Current range of X,Y mouse values? There is no relationship between canvas and object, so you would have to scan all your objects to determine if they fall within the xyz range of the mouse event. While it seems daunting, it's completely possible. _________________ -Sean Top IMIXMMM Post subject: Re: Can you ADD a "MOUSE" Event to a GROUP2D ObjectPosted: Mon Oct 26, 2009 12:52 am Joined: Thu Oct 26, 2006 4:49 am Posts: 35 Thanks sbeach, So I need to keep track of my OBJECTS ( at least the top level of the group ) With each object I could have the following properties saved in an array? X, Y, Width,Height, Name/ID, Object Type 2) Have code to scan the X,Y area to see if any objects are within range 3) Let the object decide within range decide what to do? So, I don't see any point in adding the mouse events to the objects, so long as I keep track of the objects? thanks Dave M Top sbeach Post subject: Re: Can you ADD a "MOUSE" Event to a GROUP2D ObjectPosted: Mon Oct 26, 2009 1:05 am Joined: Wed May 10, 2006 1:27 pm Posts: 23 IMIXMMM wrote:With each object I could have the following properties saved in an array? X, Y, Width,Height, Name/ID, Object Type 2) Have code to scan the X,Y area to see if any objects are within range 3) Let the object decide within range decide what to do? Yup, you could go about it a number of different ways: Make a class that contains a generic Object2D object and the properties you want, then make an array of this in a subclass of CanvasUse introspection to pull object data out of a Object2D array and then use the variables within it to determine clicks.Take each subclass of Object2D and subclass it further, making arrays of each, and check them all.If youre only using a few objects (because this is slower), create an offscreen image buffer, redraw each object into that buffer then sample the pixel data at x and y to see if the object exists in this location. #4 is the slowest but easiest to implement, how you go about it depends a lot on your situation and the program's needs. _________________ -Sean Top IMIXMMM Post subject: Re: Can you ADD a "MOUSE" Event to a GROUP2D ObjectPosted: Mon Oct 26, 2009 1:19 am Joined: Thu Oct 26, 2006 4:49 am Posts: 35 Thanks sbeach, Ok, there are some things I need to look at, but.. Q1) If I add a grouped object to the canvas, how to you then refer to that object after that? i.e where does the object go?? I need an object ref Dave M Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 7 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
