2013-06-02 15:08:32 +00:00
# ifndef _GUICOMPONENT_H_
# define _GUICOMPONENT_H_
# include "InputConfig.h"
2013-07-17 03:41:39 +00:00
# include <Eigen/Dense>
2013-06-02 15:08:32 +00:00
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
2013-08-14 12:16:49 +00:00
//Called when it's time to render. By default, just calls renderChildren(parentTrans * getTransform()).
2013-07-10 11:29:43 +00:00
//You probably want to override this like so:
//1. Calculate the new transform that your control will draw at with Eigen::Affine3f t = parentTrans * getTransform().
2013-08-14 12:16:49 +00:00
//2. Set the renderer to use that new transform as the model matrix - Renderer::setMatrix(t);
2013-07-10 11:29:43 +00:00
//3. Draw your component.
//4. Tell your children to render, based on your component's transform - renderChildren(t).
virtual void render ( const Eigen : : Affine3f & parentTrans ) ;
2013-06-02 19:34:50 +00:00
2013-07-10 11:29:43 +00:00
Eigen : : Vector3f getPosition ( ) const ;
void setPosition ( const Eigen : : Vector3f & offset ) ;
void setPosition ( float x , float y , float z = 0.0f ) ;
virtual void onPositionChanged ( ) { } ;
2013-06-02 15:08:32 +00:00
2013-07-10 11:29:43 +00:00
Eigen : : Vector2f getSize ( ) const ;
void setSize ( const Eigen : : Vector2f & size ) ;
void setSize ( float w , float h ) ;
2013-07-02 23:48:39 +00:00
virtual void onSizeChanged ( ) { } ;
2013-06-02 22:33:49 +00:00
2013-06-02 15:08:32 +00:00
void setParent ( GuiComponent * parent ) ;
2013-07-10 11:29:43 +00:00
GuiComponent * getParent ( ) const ;
2013-06-02 15:08:32 +00:00
2013-06-02 16:11:29 +00:00
void addChild ( GuiComponent * cmp ) ;
void removeChild ( GuiComponent * cmp ) ;
void clearChildren ( ) ;
2013-07-10 11:29:43 +00:00
unsigned int getChildCount ( ) const ;
GuiComponent * getChild ( unsigned int i ) const ;
unsigned char getOpacity ( ) const ;
2013-07-02 14:51:33 +00:00
void setOpacity ( unsigned char opacity ) ;
2013-06-02 16:11:29 +00:00
2013-07-17 04:18:30 +00:00
const Eigen : : Affine3f getTransform ( ) ;
2013-08-14 12:16:49 +00:00
virtual std : : string getValue ( ) const ;
virtual void setValue ( const std : : string & value ) ;
2013-06-02 15:08:32 +00:00
protected :
2013-07-10 11:29:43 +00:00
void renderChildren ( const Eigen : : Affine3f & transform ) const ;
2013-06-02 19:34:50 +00:00
2013-07-02 14:51:33 +00:00
unsigned char mOpacity ;
2013-06-02 15:08:32 +00:00
Window * mWindow ;
2013-07-10 11:29:43 +00:00
2013-06-02 15:08:32 +00:00
GuiComponent * mParent ;
2013-06-02 16:11:29 +00:00
std : : vector < GuiComponent * > mChildren ;
2013-07-10 11:29:43 +00:00
Eigen : : Vector3f mPosition ;
Eigen : : Vector2f mSize ;
private :
Eigen : : Affine3f mTransform ; //Don't access this directly! Use getTransform()!
2013-06-02 15:08:32 +00:00
} ;
# endif