2013-06-02 15:08:32 +00:00
# ifndef _GUICOMPONENT_H_
# define _GUICOMPONENT_H_
# include "InputConfig.h"
# include "Vector2.h"
class Window ;
2013-06-02 16:11:29 +00:00
class GuiComponent
2013-06-02 15:08:32 +00:00
{
public :
GuiComponent ( Window * window ) ;
virtual ~ GuiComponent ( ) ;
2013-06-02 19:34:50 +00:00
//Called when input is received.
2013-06-02 15:08:32 +00:00
//Return true if the input is consumed, false if it should continue to be passed to other children.
virtual bool input ( InputConfig * config , Input input ) ;
2013-06-02 19:34:50 +00:00
//Called when time passes. Default implementation also calls update(deltaTime) on children - so you should probably call GuiComponent::update(deltaTime) at some point.
2013-06-02 15:08:32 +00:00
virtual void update ( int deltaTime ) ;
2013-06-02 19:34:50 +00:00
//Called when it's time to render. Translates the OpenGL matrix, calls onRender() (which renders children), then un-translates the OpenGL matrix.
2013-06-02 22:33:49 +00:00
//You probably don't need to override this, and should use the protected method onRender.
2013-06-02 15:08:32 +00:00
virtual void render ( ) ;
2013-06-02 19:34:50 +00:00
//Called when the Renderer initializes. Passes to children.
2013-06-02 15:08:32 +00:00
virtual void init ( ) ;
2013-06-02 19:34:50 +00:00
//Called when the Renderer deinitializes. Passes to children.
2013-06-02 15:08:32 +00:00
virtual void deinit ( ) ;
2013-06-19 01:12:30 +00:00
virtual Vector2i getGlobalOffset ( ) ;
2013-06-02 15:08:32 +00:00
Vector2i getOffset ( ) ;
void setOffset ( Vector2i offset ) ;
void setOffset ( int x , int y ) ;
2013-06-19 01:12:30 +00:00
virtual void onOffsetChanged ( ) { } ;
2013-06-02 15:08:32 +00:00
2013-06-02 22:33:49 +00:00
Vector2u getSize ( ) ;
2013-07-02 23:48:39 +00:00
void setSize ( Vector2u size ) ;
void setSize ( unsigned int w , unsigned int h ) ;
virtual void onSizeChanged ( ) { } ;
2013-06-02 22:33:49 +00:00
2013-06-02 15:08:32 +00:00
void setParent ( GuiComponent * parent ) ;
GuiComponent * getParent ( ) ;
2013-06-02 16:11:29 +00:00
void addChild ( GuiComponent * cmp ) ;
void removeChild ( GuiComponent * cmp ) ;
void clearChildren ( ) ;
unsigned int getChildCount ( ) ;
GuiComponent * getChild ( unsigned int i ) ;
2013-07-02 14:51:33 +00:00
unsigned char getOpacity ( ) ;
void setOpacity ( unsigned char opacity ) ;
2013-06-02 16:11:29 +00:00
2013-06-02 15:08:32 +00:00
protected :
2013-06-02 19:34:50 +00:00
//Default implementation just renders children - you should probably always call GuiComponent::onRender at some point in your custom onRender.
virtual void onRender ( ) ;
2013-07-02 14:51:33 +00:00
unsigned char mOpacity ;
2013-06-02 15:08:32 +00:00
Window * mWindow ;
GuiComponent * mParent ;
Vector2i mOffset ;
2013-06-02 22:33:49 +00:00
Vector2u mSize ;
2013-06-02 16:11:29 +00:00
std : : vector < GuiComponent * > mChildren ;
2013-06-02 15:08:32 +00:00
} ;
# endif