As part of the game engine I'm writing I need a GUI system.
This is quite a large chunk so I decided to make a UML diagram first.
Currently, my implementation is this:
A good start, but be sure to consider other events that all GUI systems should have. Be sure to lay out the base class foundations before making all of your component types, because it's quite a pain to do later on for both yourself and your clients (especially if it breaks the interface!). Here are a few items for you to think about:
Component Essentials
1) Is this component focusable?
2) Tab index maintenance
3) Rendering order (what is on top of what?)
- See code at end of post for a suggestion
4) Synchronizing rendering and input (if you're using separate threads)
5) What meta-data do I need to pass to event handlers?
6) Will I support GUI serialization / deserialization?
#include <list>
#include <memory>
#include <boost/assert.hpp>
class ComponentBase
{
std::list<std::shared_ptr<ComponentBase>> children;
public:
void addChild(std::shared_ptr<ComponentBase> child)
{
BOOST_ASSERT(child != nullptr);
children.add(child);
}
virtualvoid render(void) const
{
for(auto iter = children.begin(); iter != children.end(); ++iter)
{
(*iter)->render();
}
}
};
class SomeComponent : public ComponentBase
{
public:
virtualvoid render(void) const
{
// Do custom rendering here
// Then render my children
this->ComponentBase::render();
}
};
Hope it helps :)
PS. I've recently been tasked with creating an OO wrapper library around a procedural rendering API, so this is all still fairly fresh in my memory. Let me know if you have questions.
PPS. I'd use it providing that you distribute prebuilt binaries or VS project files for Windows :D I'm allergic to make-files.