4 * Copyright (C) 2005-2013 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
23 enum ANIMATION_PROCESS { ANIM_PROCESS_NONE = 0, ANIM_PROCESS_NORMAL, ANIM_PROCESS_REVERSE };
24 enum ANIMATION_STATE { ANIM_STATE_NONE = 0, ANIM_STATE_DELAYED, ANIM_STATE_IN_PROCESS, ANIM_STATE_APPLIED };
26 // forward definitions
32 #include "TransformMatrix.h" // needed for the TransformMatrix member
33 #include "Geometry.h" // for CPoint, CRect
34 #include "utils/StdString.h"
35 #include "boost/shared_ptr.hpp"
36 #include "interfaces/info/InfoBool.h"
40 ANIM_TYPE_UNFOCUS = -3,
42 ANIM_TYPE_WINDOW_CLOSE,
44 ANIM_TYPE_WINDOW_OPEN,
47 ANIM_TYPE_CONDITIONAL // for animations triggered by a condition change
53 enum EFFECT_TYPE { EFFECT_TYPE_NONE = 0, EFFECT_TYPE_FADE, EFFECT_TYPE_SLIDE, EFFECT_TYPE_ROTATE_X, EFFECT_TYPE_ROTATE_Y, EFFECT_TYPE_ROTATE_Z, EFFECT_TYPE_ZOOM };
55 CAnimEffect(const TiXmlElement *node, EFFECT_TYPE effect);
56 CAnimEffect(unsigned int delay, unsigned int length, EFFECT_TYPE effect);
57 CAnimEffect(const CAnimEffect &src);
59 virtual ~CAnimEffect();
60 CAnimEffect& operator=(const CAnimEffect &src);
62 void Calculate(unsigned int time, const CPoint ¢er);
63 void ApplyState(ANIMATION_STATE state, const CPoint ¢er);
65 unsigned int GetDelay() const { return m_delay; };
66 unsigned int GetLength() const { return m_delay + m_length; };
67 const TransformMatrix &GetTransform() const { return m_matrix; };
68 EFFECT_TYPE GetType() const { return m_effect; };
70 static boost::shared_ptr<Tweener> GetTweener(const TiXmlElement *pAnimationNode);
72 TransformMatrix m_matrix;
76 virtual void ApplyEffect(float offset, const CPoint ¢er)=0;
79 unsigned int m_length;
82 boost::shared_ptr<Tweener> m_pTweener;
85 class CFadeEffect : public CAnimEffect
88 CFadeEffect(const TiXmlElement *node, bool reverseDefaults);
89 CFadeEffect(float start, float end, unsigned int delay, unsigned int length);
90 virtual ~CFadeEffect() {};
92 virtual void ApplyEffect(float offset, const CPoint ¢er);
98 class CSlideEffect : public CAnimEffect
101 CSlideEffect(const TiXmlElement *node);
102 virtual ~CSlideEffect() {};
104 virtual void ApplyEffect(float offset, const CPoint ¢er);
112 class CRotateEffect : public CAnimEffect
115 CRotateEffect(const TiXmlElement *node, EFFECT_TYPE effect);
116 virtual ~CRotateEffect() {};
118 virtual void ApplyEffect(float offset, const CPoint ¢er);
127 class CZoomEffect : public CAnimEffect
130 CZoomEffect(const TiXmlElement *node, const CRect &rect);
131 virtual ~CZoomEffect() {};
133 virtual void ApplyEffect(float offset, const CPoint ¢er);
148 CAnimation(const CAnimation &src);
150 virtual ~CAnimation();
152 CAnimation& operator=(const CAnimation &src);
154 static CAnimation CreateFader(float start, float end, unsigned int delay, unsigned int length, ANIMATION_TYPE type = ANIM_TYPE_NONE);
156 void Create(const TiXmlElement *node, const CRect &rect, int context);
158 void Animate(unsigned int time, bool startAnim);
159 void ResetAnimation();
160 void ApplyAnimation();
161 inline void RenderAnimation(TransformMatrix &matrix)
163 RenderAnimation(matrix, CPoint());
165 void RenderAnimation(TransformMatrix &matrix, const CPoint ¢er);
166 void QueueAnimation(ANIMATION_PROCESS process);
168 inline bool IsReversible() const { return m_reversible; };
169 inline ANIMATION_TYPE GetType() const { return m_type; };
170 inline ANIMATION_STATE GetState() const { return m_currentState; };
171 inline ANIMATION_PROCESS GetProcess() const { return m_currentProcess; };
172 inline ANIMATION_PROCESS GetQueuedProcess() const { return m_queuedProcess; };
174 bool CheckCondition();
175 void UpdateCondition(const CGUIListItem *item = NULL);
176 void SetInitialCondition();
179 void Calculate(const CPoint &point);
180 void AddEffect(const CStdString &type, const TiXmlElement *node, const CRect &rect);
182 enum ANIM_REPEAT { ANIM_REPEAT_NONE = 0, ANIM_REPEAT_PULSE, ANIM_REPEAT_LOOP };
185 ANIMATION_TYPE m_type;
187 INFO::InfoPtr m_condition;
189 // conditional anims can repeat
190 ANIM_REPEAT m_repeatAnim;
191 bool m_lastCondition;
193 // state of animation
194 ANIMATION_PROCESS m_queuedProcess;
195 ANIMATION_PROCESS m_currentProcess;
196 ANIMATION_STATE m_currentState;
198 // timing of animation
199 unsigned int m_start;
200 unsigned int m_length;
201 unsigned int m_delay;
202 unsigned int m_amount;
204 std::vector<CAnimEffect *> m_effects;
208 * Class used to handle scrolling, allow using tweeners.
210 * start scrolling using ScrollTo() method / stop scrolling using Stop() method
211 * update scroll value each frame with current time using Update() method
212 * get/set scroll value using GetValue()/SetValue()
217 CScroller(unsigned int duration = 200, boost::shared_ptr<Tweener> tweener = boost::shared_ptr<Tweener>());
218 CScroller(const CScroller& right);
219 CScroller& operator=(const CScroller &src);
223 * Set target value scroller will be scrolling to
224 * @param endPos target
226 void ScrollTo(float endPos);
229 * Immediately stop scrolling
231 void Stop() { m_delta = 0; };
233 * Update the scroller to where it would be at the given time point, calculating a new Value.
234 * @param time time point
235 * @return True if we are scrolling at given time point
237 bool Update(unsigned int time);
242 float GetValue() const { return m_scrollValue; };
243 void SetValue(float scrollValue) { m_scrollValue = scrollValue; };
245 bool IsScrolling() const { return m_delta != 0; };
246 bool IsScrollingUp() const { return m_delta < 0; };
247 bool IsScrollingDown() const { return m_delta > 0; };
249 unsigned int GetDuration() const { return m_duration; };
251 float Tween(float progress);
254 float m_delta; //!< Brief distance that we have to travel during scroll
255 float m_startPosition; //!< Brief starting position of scroll
256 bool m_hasResumePoint; //!< Brief check if we should tween from middle of the tween
257 unsigned int m_startTime; //!< Brief starting time of scroll
258 unsigned int m_lastTime; //!< Brief last remember time (updated each time Scroll() method is called)
260 unsigned int m_duration; //!< Brief duration of scroll
261 boost::shared_ptr<Tweener> m_pTweener;