Jump to content
  • Advertisement
Sign in to follow this  
sofakng

How you start a GUI? (do you keep track of client state or something?)

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

How do you start programming a GUI? (whats the idea behind it) I'm thinking that I need a bunch of images to start with (each button, each menu box, etc). Then, I need to keep track of the client state. In other words, when the user clicks on the screen I need to know which state (or menu) they are in so I can compare x,y coordinates with the location of the buttons. For example, When the client is in state CL_MAIN_MENU and they click the mouse between (50, 100) and (150, 150) I will interpret that as the user clicking on a button. However, if the user is in state CL_PLAYING_GAME then a click at that same position won't do anything. It seems like I'll need objects for each button containing the bounding boxes, etc. Am I thinking about this correctly?

Share this post


Link to post
Share on other sites
Advertisement
This would be one way to go about designing a GUI, albeit a very simple one. More advanced and flexible methods might involve GUI objects that store their own position and dimensions(/bounding boxes), hierarchically and with a manager that keeps track of z-order. Thus when a click event is generated, the manager finds the first object whose bounding box surrounds the click coordinates, starting at the top of the z-order. The manager then passes that object the click event, and the object passes it on to its children if appropriate or handles it otherwise.

This is only a part of it, and doesn't cover things such as messaging, how to broadcast events, or a number of other things.

-Twilight Dragon

EDIT: Hm. The above poster's name is remarkably similar to mine. Weird.

Share this post


Link to post
Share on other sites
I use a GameState enumerator that has several menus in it as well as the "GAMEPLAY" state. I check this and draw the appropiate objects and whatnot.

If you are designing your own GUI the hard part will be coming up with a nice system that can manage menus, buttons, drop downs and all that good stuff for you.

Good luck mate,
John

Share this post


Link to post
Share on other sites
If you are using the windows API then windows takes care of all that logic. For instance, if you put a button on the screen somewhere, and a user clicks it, then a WM_COMMAND message is sent to the parents window procedure. Along with this message comes the Child Window ID stored in wParam, the Notification code also stored in wParam, and the Child Window Handle.

Java has a much simpler GUI system which takes care of even more logic. All you have to do in java is add an anonymous inner class listener to the GUI component.

So basically, you could use a predefined window which has all that functionality. You can customize it by setting it to look like an image.

To find out the state of the game all you would have to do would be have the windows respond to the message by doing some tests.

Share this post


Link to post
Share on other sites
Do I need to program the logic of each GUI object?

For example, a drop-down box. When the user clicks on it the box changes and displays a new box containing three (or whatever) items. If the clicks off of the box the drop-down resets.

Do I need to program all of that or can I use the existing Windows objects and simply change the look and feel of them?

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!