Jump to content
  • Advertisement
Sign in to follow this  
Mantear

GUI issue: how to link widgets

This topic is 4326 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

Greetings, I'm playing around with making a GUI in OpenGL, in part to have something to use but mainly to learn more about OpenGL and C++. I'm at the point where I have functional "widgets" (menu bars, dialog boxes, buttons, etc). I'm now at the point where I need to link these widgets to elements within my program. For buttons it's not that tricky. When creating a button, simply link a value to that button (perhaps even a function pointer) that will know to call a specific funtion when the button is pressed. However, I run into trouble when I want to have the statistics of an object. Let's say one of my dialog boxes contains the statistics of 3D renderable object. If the user moves the object, I want the GUI to know about it and update the statistics (coordinates, rotation, etc). Also, if the user enters a coordinate/rotation/whatever into the GUI, I want it to update the object. What's going to be the most flexible was of linking the GUI to the object? The GUI is going to have to have the smarts about the object (and all other elements that the GUI can control) and the object is going to have to have the smarts about the GUI (either directly, or through some 3rd party manager) so that they can update each other. However, I really don't want the 3D object to have to know much about the GUI other than it needs to be updated when something changes. And I don't want the GUI to have to know the specifics about the 3D object, otherwise it'll need to know the specifics of every element it touches. I'm looking for a generic interface that'll work with all the elements in my program, something that'll work for the renderer, 3D objects, etc. Any ideas? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
It sounds like you're asking for a design pattern. The Observer Pattern is appropriate. Provide an interface where any object can subscribe and react to GUI events. You can use the same pattern if you want the GUI to know when some object's properties have changed.

In some cases you'll want a proxy, rather than the GUI and the objects directly interacting. For example:
Quote:
Also, if the user enters a coordinate/rotation/whatever into the GUI, I want it to update the object.

For this you can have some InputHandler class, which subscribes to the GUI events (like a button being pushed). When this happens, it would query the GUI to find the coordinates, then update the object.

Share this post


Link to post
Share on other sites
The info you linked to is a bit too advanced/abstract for me to really understand. Could you provide some more concrete information with perhaps an example of how the GUI could talk to an object and vice-versa? I was thinking of having some sort of a registry object, where both the GUI and the objects can check to see if the registry has been updated and parameters need to be refreshed.

I forgot to mention before, I'm using C++.

Share this post


Link to post
Share on other sites
The GUI system I'm currently developing models Java's 1.1 event model. It is working out very well and would highly recommend doing something similiar. It seperates control code from handler code by requiring that you "subscribe" to a particular listener type. The listener derived class reacts to events passed from the controls.

http://java.sun.com/j2se/1.3/docs/guide/awt/designspec/events.html

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!