Jump to content
  • Advertisement
Sign in to follow this  
altich88

Question regarding GUI structure

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

Hi,

I'm currently making a GUI in OpenGL and C++. The systems uses a family tree style structure, where each element has a number of child elements. A window say, could have several buttons and sliders as its children, for example. Each element has fields such as position, width and height etc. associated with it. All elements however use the same font for their text labels. I'm not sure where the best place for the UI's font would be. It would seem wasteful for each element to have a "font" field as it would be exactly the same for each element. Another thought was to have some sort of "UserInterface" class which would house the root element of the system, and therefore indirectly, all its children too. If the UI font was associated with this UserInterface class however, how would each element have access to it without every single element having a pointer to it? This seems a hacky way of doing things.

What would be the best way to go about this?

Cheers.

Share this post


Link to post
Share on other sites
Advertisement
Hi altich,

You can store a font pointer in all of your objects. If it's null, the system can default to a given font (the root item's font). Otherwise it can use its own. In my UI (which was written for a camera, not a desktop game), each window/widget in the tree has a pointer to a decorator object. The decorator contains all kinds of information about things like border thickness, background colour, font colour, font size and so on. If the decorator object is null for any given node in the tree, the node defers to the default decorator, otherwise it uses its own. Making changes to the properties of the default decorator and then redrawing causes all items in the tree that don't have their own decoration to change too.

The truth of the matter is that if you want to give your widget the ability to have a different font, it follows that each widget must at least contain a pointer to a font, even if they're all pointing to the same, default font initially.

Hope this is useful.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!