Merge pull request #3007 from aballier/ffmpeg_includes
[vuplus_xbmc] / xbmc / guilib / VisibleEffect.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
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)
10  *  any later version.
11  *
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.
16  *
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/>.
20  *
21  */
22
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 };
25
26 // forward definitions
27
28 class TiXmlElement;
29 class Tweener;
30 class CGUIListItem;
31
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
37 enum ANIMATION_TYPE
38 {
39   ANIM_TYPE_UNFOCUS = -3,
40   ANIM_TYPE_HIDDEN,
41   ANIM_TYPE_WINDOW_CLOSE,
42   ANIM_TYPE_NONE,
43   ANIM_TYPE_WINDOW_OPEN,
44   ANIM_TYPE_VISIBLE,
45   ANIM_TYPE_FOCUS,
46   ANIM_TYPE_CONDITIONAL       // for animations triggered by a condition change
47 };
48
49 class CAnimEffect
50 {
51 public:
52   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 };
53
54   CAnimEffect(const TiXmlElement *node, EFFECT_TYPE effect);
55   CAnimEffect(unsigned int delay, unsigned int length, EFFECT_TYPE effect);
56   CAnimEffect(const CAnimEffect &src);
57
58   virtual ~CAnimEffect();
59   const CAnimEffect &operator=(const CAnimEffect &src);
60
61   void Calculate(unsigned int time, const CPoint &center);
62   void ApplyState(ANIMATION_STATE state, const CPoint &center);
63
64   unsigned int GetDelay() const { return m_delay; };
65   unsigned int GetLength() const { return m_delay + m_length; };
66   const TransformMatrix &GetTransform() const { return m_matrix; };
67   EFFECT_TYPE GetType() const { return m_effect; };
68
69   static boost::shared_ptr<Tweener> GetTweener(const TiXmlElement *pAnimationNode);
70 protected:
71   TransformMatrix m_matrix;
72   EFFECT_TYPE m_effect;
73
74 private:
75   virtual void ApplyEffect(float offset, const CPoint &center)=0;
76
77   // timing variables
78   unsigned int m_length;
79   unsigned int m_delay;
80
81   boost::shared_ptr<Tweener> m_pTweener;
82 };
83
84 class CFadeEffect : public CAnimEffect
85 {
86 public:
87   CFadeEffect(const TiXmlElement *node, bool reverseDefaults);
88   CFadeEffect(float start, float end, unsigned int delay, unsigned int length);
89   virtual ~CFadeEffect() {};
90 private:
91   virtual void ApplyEffect(float offset, const CPoint &center);
92
93   float m_startAlpha;
94   float m_endAlpha;
95 };
96
97 class CSlideEffect : public CAnimEffect
98 {
99 public:
100   CSlideEffect(const TiXmlElement *node);
101   virtual ~CSlideEffect() {};
102 private:
103   virtual void ApplyEffect(float offset, const CPoint &center);
104
105   float m_startX;
106   float m_startY;
107   float m_endX;
108   float m_endY;
109 };
110
111 class CRotateEffect : public CAnimEffect
112 {
113 public:
114   CRotateEffect(const TiXmlElement *node, EFFECT_TYPE effect);
115   virtual ~CRotateEffect() {};
116 private:
117   virtual void ApplyEffect(float offset, const CPoint &center);
118
119   float m_startAngle;
120   float m_endAngle;
121
122   bool m_autoCenter;
123   CPoint m_center;
124 };
125
126 class CZoomEffect : public CAnimEffect
127 {
128 public:
129   CZoomEffect(const TiXmlElement *node, const CRect &rect);
130   virtual ~CZoomEffect() {};
131 private:
132   virtual void ApplyEffect(float offset, const CPoint &center);
133
134   float m_startX;
135   float m_startY;
136   float m_endX;
137   float m_endY;
138
139   bool m_autoCenter;
140   CPoint m_center;
141 };
142
143 class CAnimation
144 {
145 public:
146   CAnimation();
147   CAnimation(const CAnimation &src);
148
149   virtual ~CAnimation();
150
151   const CAnimation &operator=(const CAnimation &src);
152
153   static CAnimation CreateFader(float start, float end, unsigned int delay, unsigned int length, ANIMATION_TYPE type = ANIM_TYPE_NONE);
154
155   void Create(const TiXmlElement *node, const CRect &rect, int context);
156
157   void Animate(unsigned int time, bool startAnim);
158   void ResetAnimation();
159   void ApplyAnimation();
160   inline void RenderAnimation(TransformMatrix &matrix)
161   {
162     RenderAnimation(matrix, CPoint());
163   }
164   void RenderAnimation(TransformMatrix &matrix, const CPoint &center);
165   void QueueAnimation(ANIMATION_PROCESS process);
166
167   inline bool IsReversible() const { return m_reversible; };
168   inline ANIMATION_TYPE GetType() const { return m_type; };
169   inline ANIMATION_STATE GetState() const { return m_currentState; };
170   inline ANIMATION_PROCESS GetProcess() const { return m_currentProcess; };
171   inline ANIMATION_PROCESS GetQueuedProcess() const { return m_queuedProcess; };
172
173   bool CheckCondition();
174   void UpdateCondition(const CGUIListItem *item = NULL);
175   void SetInitialCondition();
176
177 private:
178   void Calculate(const CPoint &point);
179   void AddEffect(const CStdString &type, const TiXmlElement *node, const CRect &rect);
180   void AddEffect(CAnimEffect *effect);
181
182   enum ANIM_REPEAT { ANIM_REPEAT_NONE = 0, ANIM_REPEAT_PULSE, ANIM_REPEAT_LOOP };
183
184   // type of animation
185   ANIMATION_TYPE m_type;
186   bool m_reversible;
187   unsigned int m_condition;
188
189   // conditional anims can repeat
190   ANIM_REPEAT m_repeatAnim;
191   bool m_lastCondition;
192
193   // state of animation
194   ANIMATION_PROCESS m_queuedProcess;
195   ANIMATION_PROCESS m_currentProcess;
196   ANIMATION_STATE m_currentState;
197
198   // timing of animation
199   unsigned int m_start;
200   unsigned int m_length;
201   unsigned int m_delay;
202   unsigned int m_amount;
203
204   std::vector<CAnimEffect *> m_effects;
205 };
206
207 /**
208  * Class used to handle scrolling, allow using tweeners.
209  * Usage:
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()
213  */
214 class CScroller
215 {
216 public:
217   CScroller(unsigned int duration = 200, boost::shared_ptr<Tweener> tweener = boost::shared_ptr<Tweener>());
218   CScroller(const CScroller& right);
219   const CScroller &operator=(const CScroller &src);
220   ~CScroller();
221
222   /**
223    * Set target value scroller will be scrolling to
224    * @param endPos target 
225    */
226   void ScrollTo(float endPos);
227   
228   /**
229    * Immediately stop scrolling
230    */
231   void Stop() { m_delta = 0; };
232   /**
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
236    */
237   bool Update(unsigned int time);
238
239   /**
240    * Value of scroll
241    */
242   float GetValue() const { return m_scrollValue; };
243   void SetValue(float scrollValue) { m_scrollValue = scrollValue; };
244
245   bool IsScrolling() const { return m_delta != 0; };
246   bool IsScrollingUp() const { return m_delta < 0; };
247   bool IsScrollingDown() const { return m_delta > 0; };
248
249   unsigned int GetDuration() const { return m_duration; };
250 private:
251   float Tween(float progress);
252
253   float        m_scrollValue;
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)
259
260   unsigned int m_duration;                //!< Brief duration of scroll
261   boost::shared_ptr<Tweener> m_pTweener;
262 };