Mouse events and event source
BlitzMax Forums/MaxGUI Module/Mouse events and event source
| ||
hello everyone - I'm creating a map editor for a future game and I plan to create a bunch of panels that will have graphics loaded into them. From what I read from the tutorials, you can use a flag to turn the panels into buttons. So for events like event_mousedown, how do I find out which panel I'm clicking on? I looked at the eventsource and eventsourcehandle, which seems to return the actual object and the object id but I can't figure out how to find out which specific panel it is referring to or is there a better way? Thanks in advance for any help. |
| ||
See code below: Click into the panels to change it's color. |
| ||
Ah ok, I didn't realize that last parameter, the title, was the unique identifier, thanks! |
| ||
Oh, the title is not important, it is the Local BorderPanel4:TGadget which is checked here: Case BorderPanel4 and if the event source is from that panel the function is triggered. |
| ||
Yes I see that now, I know what I was doing wrong. I had the control as a local variable in another file but now it's working and I understand, thanks again. |
| ||
JSP. that's the other question I wanted to ask - Is there a way to add a custom field to an object? For example, borderPanel1.myfield = 1 Or should I just use a type? |
| ||
Yes, there are two ways to add your own stuff. First you can add an 'object' via SetGadgetExtra() and get it via GadgetExtra(), that should be the preferred method. Second you can use YourGadget.Context=object to store an 'object' , this was before we got the GadgetExtra the only method. It does not have a getter and setter method and is also internally used by textfields when they use a textfilter, but apart from that still very useful. When I say 'object' it means you can NOT store a number as int or float, but types and strings so for your example it would look like: SetGadgetExtra(borderPanel1,"1") to set the number 1 as string Number = Int( GadgetExtra(borderPanel1) ) or borderPanel1.Context = "1" Number = Int( borderPanel1.Context ) be aware that you need to check if there is a Context or GadgetExtra before doing something with it as the result could be null (object does not exist) if not present! |