I know this may seem like a very obvious question, but I want to be sure I'm approaching this situation correctly, or if I'm doing it wrong and there is a better picture I'm not simply seeing. I'm designing a GUI system for my game engine, since I just need a few controls and I don't need a fancy GUI library with all the bells and whistles. (Buttons, text, console, edit bar, images) So nothing fancy really. I wanted to know since I want to keep "pages" of the GUI. So if the user clicks "Credits" or "New Game" The UI will show another page with UI controls. Pretty simple stuff. Here is what I have already.
#ifndef GUI_MODEL_H
#define GUI_MODEL_H
#include "Vector.h"
enum GUI_STATE
{
STATE_NULL = 0,
STATE_CLICKED,
STATE_HOVER,
STATE_ACTIVE
};
class GUI_Model
{
public:
GUI_Model(void);
virtual ~GUI_Model(void);
void setPosition(Vector<int> pos);
void setSize(Vector<int> size);
void setTexture(GLuint texture);
void setDraw(bool draw);
void enable(bool enable=true);
virtual bool pointInside(Vector<int> pos);
void setState(GUI_STATE state=STATE_NULL);
GUI_STATE getState(void);
virtual void draw(void) { return; };
protected:
Vector<int> m_position;
Vector<int> m_size;
bool m_enabled;
bool m_draw;
GLuint m_texture;
GUI_STATE m_state;
};
#endif
Which can work like this...
#ifndef BUTTON_H
#define BUTTON_H
class Button : public GUI_Model
{
Button(std::string text);
~Button(void);
void draw(void);
protected:
private:
//Custom params. Font, text, etc..
std::string text;
}
#endif
How I would like to see it work in a nutshell...
std::vector<std::vector<GUI_Model*>> pages;
//New Page
pages.push_back(std::vector<GUI_Model*>);
size_t current_page = 0;
Button* myButton = new Button("Click Me!");
myButton->setSize(Vector<int>(100, 30));
std::vector<std::vector<GUI_Model*>>
pages.at(current_page).push_back(myButton);
//Check button states handler / OpenGL calls, etc..
size_t num_pages = pages.size();
for(size_t i = 0; i<num_pages; i++)
{
//etc....
}
I plan on using Game Monkey Script to create the UI for everything, so the code has to be very adaptable.