Jump to content
  • Advertisement
Sign in to follow this  
d000hg

Message handling in custom GUI

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing a custom GUI and am a little confused as to passing messages/notifications between child&parent items. Currently I capture mouse messages and sent them to my GUIManager. I have the concept of some messages (Button-up events and mouse-move) requiring a focus window, so if there is a focus window the message is passed directly to that item's HandleEvent() method, otherwise it is ignored. For messages which don't require a focus window, the GUIManager finds a registered window which overlaps the mouse position, and calls its HandleEvent() method. GUIItems can have child items, so the basic implementation of HandleEvent is to see if a child item overlaps with the mouse position and if so pass the event to that item. A custom item like a button or scroll-list overrides this to actually do something based on the event. If I have a dialog-type item with a button, then clicking on the button triggers Dialog.HandleEvent(), which in turn calls Button.HandleEvent(). This should do basic stuff like make the button 'push down', but it's the dialog which wants to know about the button being clicked. So what is a good mechanism to manage this? Should the item which actually handles the mouse event then notify the parent of this, and how? Sorry if I didn't describe this too well. I already have some basic functionity going, but I want to create more complex objects in a way which is flexible to use and doesn't require loads of code to be duplicated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
What I do in my GUI is I have a pointer to an event handler in each widget. That event handler contains and receives/dispatches messages that are pooled into it by the aforementioned widgets. So, in an event that dialog' button has been pressed, for a custom dialog I'd look up int messages list whether or not the button was pressed and whether that button IS a child of that dialog. If all those requirements are met, I know that the button is the right one and handle the action that is assigned on click of that button within the dialog.

That's about it. Good luck.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!