Jump to content
  • Advertisement
Sign in to follow this  
Ezbez

Design of a GUI (programming-wise)

This topic is 4440 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 having difficulty figuring out how I should build my GUI system. I have never used a GUI system before, so this is pretty new to me. I'd rather use my own GUI system becuase I'm doing this to learn as much as possible, and a GUI system is definately a challenge to build well (at least to me). FYI, I'm using C++. Does anyone have a UML diagram (or something similiar) of the structure of a GUI library? I have tried to find one, but I have been unsuccessful. I looked at the documentation of CEGUI, but I found it hard to follow how it was designed without actually using it. I've already done some of it, but it seems inflexible and hard to expand. How does this look, and what would you do with it if you had to continue making a GUI system based off of this? (this isn't real code)
/*Window Class*/
class Window
{
private:
  //Lots of variables defining background color, font size + color, border size+color

  bool isFocused;
  bool isAlive;//In case I want to close it

  //A bunch of Events (class shown later) to handle events
  Event OnFocus;
  Event OnMouseClick;
  //etc.

  std::string text;

  Window *parentWindow;
  std::list<Window*> childWindows;
public:
  //ctor, dtor
  //Variables to change background, font, border, text, etc.
  setFocus(bool newFocus);
};

/*Event*/
class Event
{
private:
  Window *parentWindow;//passes this to the callback
  void (*callBack)(Window*);//pointer to the constructor
public:
  //ctor, dtor
  SetCallBack(void (*function)(Window*));
  SetParentWindow(Window *window);

  Call();
};
I plan on Window being the base class and deriving Button, Text Box, etc. from it. To me, this doesn't seem like it will work. I'm particularly interested in the Callback functions. Should I let them be set through public functions in Window and just? If so, should I have them defualt to different things for different base classes? : Also, how should I pass information or actions from parent to child and vice-versa (eg a button titled 'Close' is clicked which should close the parent Window)? Should I just take the obvious route of having the child call a parent's public function? These are basic questions; I feel like I should be posting in For Beginners, but GUIs are more advanced than what typically goes in For Beginners. Finally, any articles or tutorials regarding how to design a GUI system would be appreciated. Thanks in advanced.

Share this post


Link to post
Share on other sites
Advertisement
I highly recommend these tutorials. They give a good basis for any GUI system. I wrote up such a system using SDL for rendering, then later ported them to be rendered in OpenGL.

One
Two
Three
Four

If you have any questions, drop me a line.

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!