Sign in to follow this  
ProgrammerZ

Programming a GUI (C++, DirectX)

Recommended Posts

ProgrammerZ    180
Hey guys. I've been thinking of programming a GUI (UI, whatever) for my game, and I had a couple design questions. I was intending to have a GUI manager class that would own all the widgets. Classes such as buttons, checkboxes, etc. would be derived from the widget class, and more specific types of buttons, checkboxes, etc. would be derived from those. However, I was wondering how I would, for instance, program some sort of standard-size button for general use. Would it be a good idea to pass some constant (or read from a file) value to the widget constructor, or to use some other method? Also, I wasn't sure how I would implement widget states. For example, a button would have mouseover, mouseoff, and depressed states. However, what if I wanted to derive a button class that would also have, for example, a deactivated state? Thanks in advance! -- ProgrammerZ

Share this post


Link to post
Share on other sites
MortusMaximus    159
I wrote a few widgets last week (for openGL unfortunately ;( ), so here are some things that I recommend based on that:

1.) Start out with a very simple widget, then worry about the others once that one is done. There is no reason that a slider widget needs to know about a push-button widget, so there's no point bogging yourself down by trying to design all your widgets at once.

This brings me to:

2.) Don't worry about a GUI manager class until you get at least 2 widgets done. Just give all the widgets an x and y orthographic value hard-coded at first, then give control to the GUI manager once you have it written.

3.) The different states:
That question is relatively simple - simply add a bool deactivated into the private part of the derived class, and in the virtual overrided functions, simply put an "if" statement in that checks if it is deactivated or not. If it is activated, either call the parent class' corresponding function, or copy+paste it into the virtual function. If it's deactivated, then just don't do anything.

Share this post


Link to post
Share on other sites
ProgrammerZ    180
Thanks for the feedback! I just had one more question about the states thing. I was intending to use a OOP-based state/statemachine system as described here. But, I'm not sure exactly how I would implement derived states in derived widgets. For example, say I have a button with four states: mouseover, mouseoff, deactivated, and depressed. But how would I implement the derived-button-specific states in a derived version of the basic button widget?

EDIT: One more thing I just thought of. Say I have a MyButton class that derives from the basic button, and I want to make all MyButtons the same size. How would I go about doing this?

Share this post


Link to post
Share on other sites
Kylotan    9983
Quote:
Original post by ProgrammerZ
For example, say I have a button with four states: mouseover, mouseoff, deactivated, and depressed. But how would I implement the derived-button-specific states in a derived version of the basic button widget?

If you've done it properly, the point of having the stuff in the base class is that you don't reimplement it in the derived class.

More details about exactly what you want to achieve would help here.

Though my recommendation would generally be that you don't derive concrete classes from other concrete classes. Instead, make a single concrete button class and parameterise it to get the differences you want.

Share this post


Link to post
Share on other sites
ProgrammerZ    180
The issue I was thinking of specifically was what I would do if I wanted to add another state to a derived button class, or just have a derived button execute code not specific to the base button widget.

And about the button size problem -- I was just wondering how I could make all of the buttons in my game the same size. That's why I was considering deriving more specific widget types from my base ones (MyButton) that could pass default (perhaps read from a script) values for width and height to the base Button widget's constructor.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this