Jump to content

  • Log In with Google      Sign In   
  • Create Account

Question regarding GUI structure


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 altich88   Members   -  Reputation: 124

Like
0Likes
Like

Posted 13 February 2012 - 04:52 AM

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.

Sponsor:

#2 RobinsonUK   Members   -  Reputation: 108

Like
1Likes
Like

Posted 13 February 2012 - 06:51 AM

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.

#3 altich88   Members   -  Reputation: 124

Like
0Likes
Like

Posted 13 February 2012 - 07:35 AM

..


Hey,
Thanks for the reply. Yeah that does sound like a good idea what with the flexibility and all, thanks Posted Image.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS