TDME2  1.9.200
GUIEffect.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include <tdme/tdme.h>
11 #include <tdme/utilities/Action.h>
12 
13 using std::unique_ptr;
14 
20 
21 /**
22  * GUI effect base class
23  * @author Andreas Drewke
24  */
26 {
27 public:
29  static constexpr int REPEAT_UNLIMITED { -1 };
30 
31 protected:
33  bool active { false };
34  int64_t timeLast { -1LL };
35  float timeTotal { 0.0 };
36  float timeLeft { 0.0 };
37  float timePassed { 0.0 };
38  int repeat { 0 };
39  int repeatLeft { 0 };
40  bool yoyo { false };
41  int yoyoLeft { 0 };
42  bool persistant { false };
43  unique_ptr<Action> action;
44  GUINode* node { nullptr };
49 
50 public:
51  // forbid class copy
53 
54  /**
55  * Public constructor
56  * @param type type
57  * @param GUINode GUI node
58  */
59  GUIEffect(EffectType type, GUINode* guiNode);
60 
61  /**
62  * Destructor
63  */
64  virtual ~GUIEffect();
65 
66  /**
67  * @return type
68  */
69  inline EffectType getType() const {
70  return type;
71  }
72 
73  /**
74  * @return active
75  */
76  inline bool isActive() const {
77  return active;
78  }
79 
80  /**
81  * @return time total
82  */
83  inline float getTimeTotal() const {
84  return timeTotal;
85  }
86 
87  /**
88  * Set time total
89  * @param timeTotal time total
90  */
91  inline void setTimeTotal(float timeTotal) {
92  this->timeTotal = timeTotal;
93  }
94 
95  /**
96  * @return repeat count or -1 for unlimited repeating
97  */
98  inline int getRepeat() const {
99  return repeat;
100  }
101 
102  /**
103  * Set repeat count or -1 for unlimited repeating
104  * @param repeat repeat
105  */
106  inline void setRepeat(int repeat) {
107  this->repeat = repeat;
108  }
109 
110  /**
111  * @return yoyo
112  */
113  inline float isYoyo() const {
114  return yoyo;
115  }
116 
117  /**
118  * Set yoyo
119  * @param yoyo yoyo
120  */
121  inline void setYoyo(bool yoyo) {
122  this->yoyo = yoyo;
123  }
124 
125  /**
126  * @return if this effect is persistant, means if duration is reached this effect will still remain until removal
127  */
128  inline float isPersistant() const {
129  return persistant;
130  }
131 
132  /**
133  * Set persistant, means if duration is reached this effect will still remain until removal
134  * @param persistant persistant
135  */
136  inline void setPersistant(bool persistant) {
137  this->persistant = persistant;
138  }
139 
140  /**
141  * @return action to be performed on effect end
142  */
143  inline Action* getAction() const {
144  return action.get();
145  }
146 
147  /**
148  * Set action to be performed on effect end
149  * @param action action
150  */
151  inline void setAction(Action* action) {
152  this->action = unique_ptr<Action>(action);
153  }
154 
155  /**
156  * Start this effect
157  */
158  virtual void start();
159 
160  /**
161  * Stop this effect
162  */
163  virtual void stop();
164 
165  /**
166  * Updates the effect to GUI renderer and updates time
167  * @param guiRenderer gui renderer
168  * @return if action should be called
169  */
170  virtual bool update(GUIRenderer* guiRenderer);
171 
172  /**
173  * Apply effect
174  * @param guiRenderer GUI renderer
175  * @param guiNode GUI node
176  */
177  virtual void apply(GUIRenderer* guiRenderer) = 0;
178 
179 };
GUI effect base class.
Definition: GUIEffect.h:26
GUIEffect(EffectType type, GUINode *guiNode)
Public constructor.
Definition: GUIEffect.cpp:15
float getTimeTotal() const
Definition: GUIEffect.h:83
GUIEffectState originalEndState
Definition: GUIEffect.h:46
void setAction(Action *action)
Set action to be performed on effect end.
Definition: GUIEffect.h:151
virtual void apply(GUIRenderer *guiRenderer)=0
Apply effect.
void setRepeat(int repeat)
Set repeat count or -1 for unlimited repeating.
Definition: GUIEffect.h:106
EffectType getType() const
Definition: GUIEffect.h:69
virtual void start()
Start this effect.
Definition: GUIEffect.cpp:22
void setYoyo(bool yoyo)
Set yoyo.
Definition: GUIEffect.h:121
unique_ptr< Action > action
Definition: GUIEffect.h:43
Action * getAction() const
Definition: GUIEffect.h:143
virtual void stop()
Stop this effect.
Definition: GUIEffect.cpp:34
void setPersistant(bool persistant)
Set persistant, means if duration is reached this effect will still remain until removal.
Definition: GUIEffect.h:136
GUIEffectState originalStartState
Definition: GUIEffect.h:45
virtual bool update(GUIRenderer *guiRenderer)
Updates the effect to GUI renderer and updates time.
Definition: GUIEffect.cpp:39
virtual ~GUIEffect()
Destructor.
Definition: GUIEffect.cpp:19
GUIEffectState startState
Definition: GUIEffect.h:47
void setTimeTotal(float timeTotal)
Set time total.
Definition: GUIEffect.h:91
static constexpr int REPEAT_UNLIMITED
Definition: GUIEffect.h:29
GUI node base class.
Definition: GUINode.h:64
Action Interface.
Definition: Action.h:11
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6