Skip to main content
GameDev.net gamedev.net
🔒 Locked

GUI Architecture

Started by gatofedorento May 22, 2012 at 12:50 AM 2 replies 2k views
Original Post
gatofedorento
gatofedorento
Hey there.

I'm coding a GUI using C++ and openGL, but my problem is more design specific than API related.

Right now I'm using classes that derive from a base GUI class, and some of them use a composite pattern, such as Windows for example, I can add buttons, scrollbars, etc to it. The GUI is functional as it is, but sometimes, from a more user point of view it might not work very well, for an example I would like to have my buttons shine everytime my mouse cursor is over them.

Since I have a composite pattern I start from one element from my GUI and after it draws itself it calls the drawing function of the elements attached to it, all this starts in a GUIManager class. To make things like the button shine I would need to pass to the draw functions the required data for the elements to know which element the mouse is over and make a different draw, but i really wouldn't like to give this kind of task to my GUI elements.

Another way I had in mind would be my elements having a function that returns a list of their children elements, and the drawing functions would be called from my GUIManager class in which it would know what element a "special effect" should be applied, this seems more reasonable to me, the only requirement would be that the elements had to have an extra function where they would return their children.

Are there better options to do this?
Ashaman73
Ashaman73

Are there better options to do this?

Atleast other ways smile.png
Each gui widget in my gui have one of following states: normal, disabled, highlighted, selected
A gui controller will change the state according to the mouse position (i.e. set to highlight when not disabled or selected), the rendering will consider the state, i.e. I can assign different images to a single gui element for each state.
gatofedorento
gatofedorento
So, before rendering, you have an evaluation step where, for example, the mouse was over Button1 and now it's over Button2, what your controller does is change the state in Button1 to normal and Button2 to highlighted, right?

This is pretty easy to implement in my GUI, I can use the same mechanism as I'm using for picking, and when I have to highlight multiple elements, like in a toolbar, my composite pattern will know how to solve these multiple highlights.

Thanks a lot, I will think about this option, for now it's good because I just need to add something like 2 functions, instead of rewritting almost all my GUI code.
Ashaman73
Ashaman73

So, before rendering, you have an evaluation step where, for example, the mouse was over Button1 and now it's over Button2, what your controller does is change the state in Button1 to normal and Button2 to highlighted, right?

Yep, I'm using this in my game, it is easy, flexible,fast...

Some tips:
Add a flag to block highlights for underlying elements, this way you can highlight a whole dialog or just a icon on it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.