xbmc
VisibleEffect.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 enum ANIMATION_PROCESS { ANIM_PROCESS_NONE = 0, ANIM_PROCESS_NORMAL, ANIM_PROCESS_REVERSE };
12 enum ANIMATION_STATE { ANIM_STATE_NONE = 0, ANIM_STATE_DELAYED, ANIM_STATE_IN_PROCESS, ANIM_STATE_APPLIED };
13 
14 // forward definitions
15 
16 class TiXmlElement;
17 class Tweener;
18 class CGUIListItem;
19 
20 #include "interfaces/info/InfoBool.h"
21 #include "utils/ColorUtils.h"
22 #include "utils/Geometry.h" // for CPoint, CRect
23 #include "utils/TransformMatrix.h" // needed for the TransformMatrix member
24 
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 enum ANIMATION_TYPE
30 {
31  ANIM_TYPE_UNFOCUS = -3,
32  ANIM_TYPE_HIDDEN,
33  ANIM_TYPE_WINDOW_CLOSE,
34  ANIM_TYPE_NONE,
35  ANIM_TYPE_WINDOW_OPEN,
36  ANIM_TYPE_VISIBLE,
37  ANIM_TYPE_FOCUS,
38  ANIM_TYPE_CONDITIONAL // for animations triggered by a condition change
39 };
40 
42 {
43 public:
44  enum EFFECT_TYPE
45  {
46  EFFECT_TYPE_NONE = 0,
47  EFFECT_TYPE_FADE,
48  EFFECT_TYPE_FADE_DIFFUSE,
49  EFFECT_TYPE_SLIDE,
50  EFFECT_TYPE_ROTATE_X,
51  EFFECT_TYPE_ROTATE_Y,
52  EFFECT_TYPE_ROTATE_Z,
53  EFFECT_TYPE_ZOOM
54  };
55 
56  CAnimEffect(const TiXmlElement *node, EFFECT_TYPE effect);
57  CAnimEffect(unsigned int delay, unsigned int length, EFFECT_TYPE effect);
58  CAnimEffect(const CAnimEffect &src);
59 
60  virtual ~CAnimEffect();
61  CAnimEffect& operator=(const CAnimEffect &src);
62 
63  void Calculate(unsigned int time, const CPoint &center);
64  void ApplyState(ANIMATION_STATE state, const CPoint &center);
65 
66  unsigned int GetDelay() const { return m_delay; }
67  unsigned int GetLength() const { return m_delay + m_length; }
68  const TransformMatrix& GetTransform() const { return m_matrix; }
69  EFFECT_TYPE GetType() const { return m_effect; }
70 
71  static std::shared_ptr<Tweener> GetTweener(const TiXmlElement *pAnimationNode);
72 protected:
73  TransformMatrix m_matrix;
74  EFFECT_TYPE m_effect;
75 
76 private:
77  virtual void ApplyEffect(float offset, const CPoint &center)=0;
78 
79  // timing variables
80  unsigned int m_length;
81  unsigned int m_delay;
82 
83  std::shared_ptr<Tweener> m_pTweener;
84 };
85 
86 class CFadeEffect : public CAnimEffect
87 {
88 public:
89  CFadeEffect(const TiXmlElement* node, bool reverseDefaults, EFFECT_TYPE effect);
90  CFadeEffect(float start, float end, unsigned int delay, unsigned int length);
91  CFadeEffect(UTILS::COLOR::Color start,
92  UTILS::COLOR::Color end,
93  unsigned int delay,
94  unsigned int length);
95  ~CFadeEffect() override = default;
96 private:
97  void ApplyEffect(float offset, const CPoint &center) override;
98 
99  float m_startAlpha;
100  float m_endAlpha;
101  UTILS::COLOR::ColorFloats m_startColor;
102  UTILS::COLOR::ColorFloats m_endColor;
103 };
104 
105 class CSlideEffect : public CAnimEffect
106 {
107 public:
108  explicit CSlideEffect(const TiXmlElement *node);
109  ~CSlideEffect() override = default;
110 private:
111  void ApplyEffect(float offset, const CPoint &center) override;
112 
113  float m_startX;
114  float m_startY;
115  float m_endX;
116  float m_endY;
117 };
118 
120 {
121 public:
122  CRotateEffect(const TiXmlElement *node, EFFECT_TYPE effect);
123  ~CRotateEffect() override = default;
124 private:
125  void ApplyEffect(float offset, const CPoint &center) override;
126 
127  float m_startAngle;
128  float m_endAngle;
129 
130  bool m_autoCenter;
131  CPoint m_center;
132 };
133 
134 class CZoomEffect : public CAnimEffect
135 {
136 public:
137  CZoomEffect(const TiXmlElement *node, const CRect &rect);
138  ~CZoomEffect() override = default;
139 private:
140  void ApplyEffect(float offset, const CPoint &center) override;
141 
142  float m_startX;
143  float m_startY;
144  float m_endX;
145  float m_endY;
146 
147  bool m_autoCenter;
148  CPoint m_center;
149 };
150 
152 {
153 public:
154  CAnimation();
155  CAnimation(const CAnimation &src);
156 
157  virtual ~CAnimation();
158 
159  CAnimation& operator=(const CAnimation &src);
160 
161  static CAnimation CreateFader(float start, float end, unsigned int delay, unsigned int length, ANIMATION_TYPE type = ANIM_TYPE_NONE);
162 
163  void Create(const TiXmlElement *node, const CRect &rect, int context);
164 
165  void Animate(unsigned int time, bool startAnim);
166  void ResetAnimation();
167  void ApplyAnimation();
168  inline void RenderAnimation(TransformMatrix &matrix)
169  {
170  RenderAnimation(matrix, CPoint());
171  }
172  void RenderAnimation(TransformMatrix &matrix, const CPoint &center);
173  void QueueAnimation(ANIMATION_PROCESS process);
174 
175  inline bool IsReversible() const { return m_reversible; }
176  inline ANIMATION_TYPE GetType() const { return m_type; }
177  inline ANIMATION_STATE GetState() const { return m_currentState; }
178  inline ANIMATION_PROCESS GetProcess() const { return m_currentProcess; }
179  inline ANIMATION_PROCESS GetQueuedProcess() const { return m_queuedProcess; }
180 
181  bool CheckCondition();
182  void UpdateCondition(const CGUIListItem *item = NULL);
183  void SetInitialCondition();
184 
185 private:
186  void Calculate(const CPoint &point);
187  void AddEffect(const std::string &type, const TiXmlElement *node, const CRect &rect);
188 
189  enum ANIM_REPEAT { ANIM_REPEAT_NONE = 0, ANIM_REPEAT_PULSE, ANIM_REPEAT_LOOP };
190 
191  // type of animation
192  ANIMATION_TYPE m_type;
193  bool m_reversible;
194  INFO::InfoPtr m_condition;
195 
196  // conditional anims can repeat
197  ANIM_REPEAT m_repeatAnim;
198  bool m_lastCondition;
199 
200  // state of animation
201  ANIMATION_PROCESS m_queuedProcess;
202  ANIMATION_PROCESS m_currentProcess;
203  ANIMATION_STATE m_currentState;
204 
205  // timing of animation
206  unsigned int m_start;
207  unsigned int m_length;
208  unsigned int m_delay;
209  unsigned int m_amount;
210 
211  std::vector<CAnimEffect *> m_effects;
212 };
213 
222 {
223 public:
224  CScroller(unsigned int duration = 200, std::shared_ptr<Tweener> tweener = std::shared_ptr<Tweener>());
225  CScroller(const CScroller& right);
226  CScroller& operator=(const CScroller &src);
227  ~CScroller();
228 
233  void ScrollTo(float endPos);
234 
238  void Stop() { m_delta = 0; }
244  bool Update(unsigned int time);
245 
249  float GetValue() const { return m_scrollValue; }
250  void SetValue(float scrollValue) { m_scrollValue = scrollValue; }
251 
252  bool IsScrolling() const { return m_delta != 0; }
253  bool IsScrollingUp() const { return m_delta < 0; }
254  bool IsScrollingDown() const { return m_delta > 0; }
255 
256  unsigned int GetDuration() const { return m_duration; }
257 
258 private:
259  float Tween(float progress);
260 
261  float m_scrollValue;
262  float m_delta;
263  float m_startPosition;
264  bool m_hasResumePoint;
265  unsigned int m_startTime;
266 
267  unsigned int m_duration;
268  std::shared_ptr<Tweener> m_pTweener;
269 };
Definition: GUIListItem.h:30
Definition: VisibleEffect.h:151
Class used to handle scrolling, allow using tweeners.
Definition: VisibleEffect.h:221
Definition: VisibleEffect.h:41
Definition: TransformMatrix.h:25
void Stop()
Immediately stop scrolling.
Definition: VisibleEffect.h:238
Definition: ColorUtils.h:59
Definition: VisibleEffect.h:119
Definition: VisibleEffect.h:134
Definition: Tween.h:48
Definition: VisibleEffect.h:86
float GetValue() const
Value of scroll.
Definition: VisibleEffect.h:249
Definition: VisibleEffect.h:105