2014-05-29 20:41:47 +00:00
# pragma once
2013-06-02 15:08:32 +00:00
# include "InputConfig.h"
2013-12-08 17:35:43 +00:00
# include <memory>
2013-07-17 03:41:39 +00:00
# include <Eigen/Dense>
2014-05-29 20:41:47 +00:00
# include "HelpStyle.h"
2013-06-02 15:08:32 +00:00
class Window ;
2013-12-08 17:35:43 +00:00
class Animation ;
class AnimationController ;
2014-01-01 05:39:22 +00:00
class ThemeData ;
2014-05-29 20:41:47 +00:00
class Font ;
2013-06-02 15:08:32 +00:00
2014-01-25 23:34:29 +00:00
typedef std : : pair < const char * , const char * > HelpPrompt ;
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-08-19 15:36:48 +00:00
virtual void textInput ( const char * text ) ;
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
2014-06-05 19:29:07 +00:00
//Called when time passes. Default implementation calls updateSelf(deltaTime) and updateChildren(deltaTime) - so you should probably call GuiComponent::update(deltaTime) at some point (or at least updateSelf so animations work).
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 ( ) { } ;
2017-01-25 15:00:56 +00:00
2017-04-22 14:15:16 +00:00
float getZIndex ( ) const ;
void setZIndex ( float zIndex ) ;
float getDefaultZIndex ( ) const ;
void setDefaultZIndex ( float zIndex ) ;
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 ( ) ;
2017-04-22 14:15:16 +00:00
void sortChildren ( ) ;
2013-07-10 11:29:43 +00:00
unsigned int getChildCount ( ) const ;
GuiComponent * getChild ( unsigned int i ) const ;
2013-12-08 17:35:43 +00:00
// animation will be automatically deleted when it completes or is stopped.
2014-01-25 00:10:13 +00:00
bool isAnimationPlaying ( unsigned char slot ) const ;
bool isAnimationReversed ( unsigned char slot ) const ;
int getAnimationTime ( unsigned char slot ) const ;
2014-04-18 17:19:46 +00:00
void setAnimation ( Animation * animation , int delay = 0 , std : : function < void ( ) > finishedCallback = nullptr , bool reverse = false , unsigned char slot = 0 ) ;
bool stopAnimation ( unsigned char slot ) ;
2014-05-15 01:58:16 +00:00
bool cancelAnimation ( unsigned char slot ) ; // Like stopAnimation, but doesn't call finishedCallback - only removes the animation, leaving things in their current state. Returns true if successful (an animation was in this slot).
bool finishAnimation ( unsigned char slot ) ; // Calls update(1.f) and finishedCallback, then deletes the animation - basically skips to the end. Returns true if successful (an animation was in this slot).
bool advanceAnimation ( unsigned char slot , unsigned int time ) ; // Returns true if successful (an animation was in this slot).
2014-04-15 02:03:11 +00:00
void stopAllAnimations ( ) ;
void cancelAllAnimations ( ) ;
2013-12-08 17:35:43 +00:00
2013-10-10 21:14:33 +00:00
virtual unsigned char getOpacity ( ) const ;
virtual void setOpacity ( unsigned char opacity ) ;
2013-06-02 16:11:29 +00:00
2014-05-29 20:41:47 +00:00
const Eigen : : Affine3f & getTransform ( ) ;
2013-07-17 04:18:30 +00:00
2013-08-14 12:16:49 +00:00
virtual std : : string getValue ( ) const ;
virtual void setValue ( const std : : string & value ) ;
2013-08-18 14:16:11 +00:00
virtual void onFocusGained ( ) { } ;
virtual void onFocusLost ( ) { } ;
2017-01-25 15:00:56 +00:00
2016-12-04 23:47:34 +00:00
virtual void onShow ( ) ;
virtual void onHide ( ) ;
2017-01-25 15:00:56 +00:00
virtual void onScreenSaverActivate ( ) ;
virtual void onScreenSaverDeactivate ( ) ;
virtual void topWindow ( bool isTop ) ;
2013-08-18 14:16:11 +00:00
2014-01-01 05:39:22 +00:00
// Default implementation just handles <pos> and <size> tags as normalized float pairs.
// You probably want to keep this behavior for any derived classes as well as add your own.
virtual void applyTheme ( const std : : shared_ptr < ThemeData > & theme , const std : : string & view , const std : : string & element , unsigned int properties ) ;
2014-01-25 23:34:29 +00:00
// Returns a list of help prompts.
virtual std : : vector < HelpPrompt > getHelpPrompts ( ) { return std : : vector < HelpPrompt > ( ) ; } ;
// Called whenever help prompts change.
void updateHelpPrompts ( ) ;
2017-01-25 15:00:56 +00:00
2014-05-29 20:41:47 +00:00
virtual HelpStyle getHelpStyle ( ) ;
2014-01-25 23:34:29 +00:00
2016-09-12 11:31:44 +00:00
// Returns true if the component is busy doing background processing (e.g. HTTP downloads)
bool isProcessing ( ) const ;
2013-06-02 15:08:32 +00:00
protected :
2013-07-10 11:29:43 +00:00
void renderChildren ( const Eigen : : Affine3f & transform ) const ;
2014-06-05 19:29:07 +00:00
void updateSelf ( int deltaTime ) ; // updates animations
void updateChildren ( int deltaTime ) ; // updates animations
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 ;
2017-04-22 14:15:16 +00:00
float mDefaultZIndex = 0 ;
float mZIndex = 0 ;
2016-09-12 11:31:44 +00:00
bool mIsProcessing ;
2013-12-13 03:17:59 +00:00
public :
const static unsigned char MAX_ANIMATIONS = 4 ;
2013-07-10 11:29:43 +00:00
private :
Eigen : : Affine3f mTransform ; //Don't access this directly! Use getTransform()!
2013-12-13 03:17:59 +00:00
AnimationController * mAnimationMap [ MAX_ANIMATIONS ] ;
2013-06-02 15:08:32 +00:00
} ;