architekt
01-11-2002, 12:42 AM
I'm in the process of designing some GUI widgets that I need specifically for my game. Some of the features I'm implementing are texture mapped widgets, and alpha blending among the non mundane. My main question though is in regards to event handling. One way I thought of how to do things was to have the user (most likely only me) register callback functions for each event they were interested in processing. A pointer to their function would then be stored and called when the proper event is triggered. But in terms of triggering the event...the first way to implement it that came to mind to me was something like this:
In the OpenGL mouse handling code, check for, e.g., a left mouse button down event. For each widget on screen, call their left mouse button down event, passing in the mouse coordinates. If the mouse coordinates lie within the bounds of the widget, then that event has been triggered, and the user's callback code gets executed and returns the value of that callback. The process is much the same for every other callback.
Now, it works, but I was wondering if there was a way to make this way simpler. Ideally, it would be cool if when a widget or dialog box was on the screen, if the dialog box (which contains all the widgets) could take over proecssing the mouse input, and keyboard input in the case of the edit box. By taking over the input, I could in the class have it check for the proper events and call teh right methods, instead of having the user get so involved in the process. Then, after the events have been processed, it could relay the event message or propogate it in some say so that just in case the user didn't want to lose total control of their input abilities when dialog boxes are on the screen, they could still receive the input notifications.
Just conceptually speaking (I'm not asking for source code), is there a way to at least get close to what I'm trying to achieve, or is the way I'm currently approaching it "as good as it gets"? Perhaps there's a better method altogether. Thanks for your help, I greatly appreciate it.
One last note, I know how to do it in DirectX: I can use have the user pass in a pointer to the input device (roughly speaking) from which I can automagically poll the mouse. Is there a similar way?
In the OpenGL mouse handling code, check for, e.g., a left mouse button down event. For each widget on screen, call their left mouse button down event, passing in the mouse coordinates. If the mouse coordinates lie within the bounds of the widget, then that event has been triggered, and the user's callback code gets executed and returns the value of that callback. The process is much the same for every other callback.
Now, it works, but I was wondering if there was a way to make this way simpler. Ideally, it would be cool if when a widget or dialog box was on the screen, if the dialog box (which contains all the widgets) could take over proecssing the mouse input, and keyboard input in the case of the edit box. By taking over the input, I could in the class have it check for the proper events and call teh right methods, instead of having the user get so involved in the process. Then, after the events have been processed, it could relay the event message or propogate it in some say so that just in case the user didn't want to lose total control of their input abilities when dialog boxes are on the screen, they could still receive the input notifications.
Just conceptually speaking (I'm not asking for source code), is there a way to at least get close to what I'm trying to achieve, or is the way I'm currently approaching it "as good as it gets"? Perhaps there's a better method altogether. Thanks for your help, I greatly appreciate it.
One last note, I know how to do it in DirectX: I can use have the user pass in a pointer to the input device (roughly speaking) from which I can automagically poll the mouse. Is there a similar way?