I'm suming up there the way I did it hoping it may useful for someone
First I create a Class Called GuiGroup (maybe not so well named in deeds...):
this is the pattern:
Code: Select all
#pragma once
using namespace irr;
class CGuiGroup
{
public:
CGuiGroup(CToolBox* pToolBox, IrrlichtDevice* pDevice); //CToolBox is my own Tool box Class
~CGuiGroup(void);
virtual void create();
virtual void del();
virtual void update();
virtual bool OnEvent(const SEvent& event);
protected:
CToolBox* m_pToolBox;
IrrlichtDevice* m_pDevice;
gui::IGUIEnvironment* m_pEnv;
core::dimension2d<u32> m_desktopRes;
bool m_bCreated;
};create(): used to add Elements to the GuiEnvironment.
del(): to remove them
update(): to update them
onEvent(...) to catch events
Here is the example of CGuiFpsMonitor : public CGuiGroup
Code: Select all
#pragma once
#include "GuiGroup.h"
class CUserManager;
class CGuiFpsMonitor :
public CGuiGroup
public:
CGuiFpsMonitor(CToolBox* pToolBox, IrrlichtDevice* pDevice, CUserManager* pUserManager);
~CGuiFpsMonitor(void);
void create();
void del();
void update();
bool OnEvent(const SEvent& event);
private:
CUserManager* m_pUserManager;
};I also store all the IDs of the GuiElements in struture there
This vector is used to throw the events to each object of my Gui
This is a shortened version of the .h
Code: Select all
#pragma once
using namespace irr;
enum GUI_ID
{
//FPS MONITOR
GUI_STT_FPS,
};
class CToolBox;
class CConverter;
class CGuiGroup;
class CGuiManager
{
public:
CGuiManager(CToolBox* pToolBox, IrrlichtDevice* pDevice, CUserManager* pUserManager);
~CGuiManager();
//MODES DU GUI
void gotoMainPage();
//ELEMENTS DU GUI
const std::vector<CGuiGroup*> getGuiGroups();
CGuiGroup* getGuiFpsMonitor();
private:
CToolBox* m_pToolBox;
IrrlichtDevice* m_pDevice;
gui::IGUIEnvironment* m_pEnv;
core::dimension2d<u32> m_desktopRes;
//ELEMENTS DU GUI
std::vector<CGuiElement*> m_vGuiElements; //Conteneur des elements
CGuiGroup* m_pGuiFpsMonitor;
};The main advantages I found are:
* I don't get an frightening giant event receiver.
* Each gui part owns it's event receiver
* Each gui part may react to other gui's events thanks to IDs.
Please do not hesitate to give me your opinion, advices or to ask an question.