MaxGUI System

BlitzMax Forums/BlitzMax Programming/MaxGUI System

Black Hydra(Posted 2006) [#1]
I'm working on a program that will need to use a lot of MaxGUI gadgets and I am having trouble developing a system to manage them all.

When I worked with Blitz3D, the way I would handle the interface is to have each gadget have a Tag$ field. Then when I checked for events I would just reference the objects by tag like so:

ButtonClicked$ = GetEvent()

If ButtonClicked$ = "mainheader_one"

...

MaxGUI seems to use a system whereby the object itself is returned instead of a tag or handle (From EventSource())

This would be fine, except as you can see in my example above I used a constant (the "mainheader_one" bit) to reference what button was clicked. Now seeing as I must either reference the object itself (which I can't provide a constant for) or a handle which is not constant, I am forced to use a variable to store the gadget like:

If EventSource() = MyGadget:TGadget
...

Seeing as my program may very well use hundreds of gadgets, having to store hundreds of global variables seems to be a rather unelegant solution to the problem. I have looked through the module source files and have been unable to find a field that:

1) Is a string (so I can reference it like EventSource.x$ = "MyGadgetName")
2) All gadgets have the field (i.e. not just windows or buttons)
3) Remains constant throughout program operation

In all of the MaxGUI examples the gadgets are all referenced by a variable storing the object. Clearly this would become unwieldly if you were to have several hundered gadgets (and therefore several hundred unique variables). I have proposed a simple tag system to reference individual gadgets, but if anyone else has made use of a program which utilized a different system, I'd be interested to hear it as well.

Any help would be greatly appreciated.


Dreamora(Posted 2006) [#2]
You have to store those 100 gadgets somewhere anyway or they might be cleaned by the GC if they aren't referenced anywhere anymore like all other objects.

But for a clean event handling system, you better use eventhook which gives you the ability to handle all the stuff in a far better structured way.

I can advice this thread for information on the "how to do it": http://www.blitzbasic.com/Community/posts.php?topic=56480


Black Hydra(Posted 2006) [#3]
Well, of course I have to store them to keep them from being collected in the garbage run, but storing them in one list instead of one hundred individually named variables is preferable. I'll take a look at that event handling system, to see what you mean.


Black Hydra(Posted 2006) [#4]
Okay, I've looked through the fields for Type TGadget.

So far the only string I can see is Text$. Context:Object is not a string but being a generic object, couldn't it support be sent a string and then String(MyGadget.Context) could be used to recover its tag.

My problem is that I have no idea what the object Context is used for so stealing it so I can use it as a tag identifier for my objects may not be wise.

I'd add my own field with a tag$ parameter, but I'm not sure whether that would create a lot more problems.

Unfortunately I don't see much alternative between those two choices. The only other alternative would be to:

a) Set up a bunch of global variables which would be fairly ugly.
b) Create a shell type such as Widget, that would store both a gadget and tag parameter. Then when I use the EventSource() function I could use a GetWidgetByTag(tag$) function to find the widget with the tag to see if they match. While this would work, it would seem to be fairly wasteful with processing resources looping through every widget to find one with the corresponding tag.

Any ideas, I think my narrow focus may be causing me to ignore an easier solution...


Dreamora(Posted 2006) [#5]
btw: there would be a different approach to use your string naming:

You could check out TMap. this would allow you to link a string and an object which you then could use for checking.