2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
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
};
14 // forward definitions
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
31 ANIM_TYPE_UNFOCUS
= -3,
33 ANIM_TYPE_WINDOW_CLOSE
,
35 ANIM_TYPE_WINDOW_OPEN
,
38 ANIM_TYPE_CONDITIONAL
// for animations triggered by a condition change
48 EFFECT_TYPE_FADE_DIFFUSE
,
56 CAnimEffect(const TiXmlElement
*node
, EFFECT_TYPE effect
);
57 CAnimEffect(unsigned int delay
, unsigned int length
, EFFECT_TYPE effect
);
58 CAnimEffect(const CAnimEffect
&src
);
60 virtual ~CAnimEffect();
61 CAnimEffect
& operator=(const CAnimEffect
&src
);
63 void Calculate(unsigned int time
, const CPoint
¢er
);
64 void ApplyState(ANIMATION_STATE state
, const CPoint
¢er
);
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
; }
71 static std::shared_ptr
<Tweener
> GetTweener(const TiXmlElement
*pAnimationNode
);
73 TransformMatrix m_matrix
;
77 virtual void ApplyEffect(float offset
, const CPoint
¢er
)=0;
80 unsigned int m_length
;
83 std::shared_ptr
<Tweener
> m_pTweener
;
86 class CFadeEffect
: public CAnimEffect
89 CFadeEffect(const TiXmlElement
* node
, bool reverseDefaults
, EFFECT_TYPE effect
);
90 CFadeEffect(float start
, float end
, unsigned int delay
, unsigned int length
);
91 CFadeEffect(KODI::UTILS::COLOR::Color start
,
92 KODI::UTILS::COLOR::Color end
,
95 ~CFadeEffect() override
= default;
97 void ApplyEffect(float offset
, const CPoint
¢er
) override
;
101 KODI::UTILS::COLOR::ColorFloats m_startColor
;
102 KODI::UTILS::COLOR::ColorFloats m_endColor
;
105 class CSlideEffect
: public CAnimEffect
108 explicit CSlideEffect(const TiXmlElement
*node
);
109 ~CSlideEffect() override
= default;
111 void ApplyEffect(float offset
, const CPoint
¢er
) override
;
119 class CRotateEffect
: public CAnimEffect
122 CRotateEffect(const TiXmlElement
*node
, EFFECT_TYPE effect
);
123 ~CRotateEffect() override
= default;
125 void ApplyEffect(float offset
, const CPoint
¢er
) override
;
134 class CZoomEffect
: public CAnimEffect
137 CZoomEffect(const TiXmlElement
*node
, const CRect
&rect
);
138 ~CZoomEffect() override
= default;
140 void ApplyEffect(float offset
, const CPoint
¢er
) override
;
155 CAnimation(const CAnimation
&src
);
157 virtual ~CAnimation();
159 CAnimation
& operator=(const CAnimation
&src
);
161 static CAnimation
CreateFader(float start
, float end
, unsigned int delay
, unsigned int length
, ANIMATION_TYPE type
= ANIM_TYPE_NONE
);
163 void Create(const TiXmlElement
*node
, const CRect
&rect
, int context
);
165 void Animate(unsigned int time
, bool startAnim
);
166 void ResetAnimation();
167 void ApplyAnimation();
168 inline void RenderAnimation(TransformMatrix
&matrix
)
170 RenderAnimation(matrix
, CPoint());
172 void RenderAnimation(TransformMatrix
&matrix
, const CPoint
¢er
);
173 void QueueAnimation(ANIMATION_PROCESS process
);
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
; }
181 bool CheckCondition();
182 void UpdateCondition(const CGUIListItem
*item
= NULL
);
183 void SetInitialCondition();
186 void Calculate(const CPoint
&point
);
187 void AddEffect(const std::string
&type
, const TiXmlElement
*node
, const CRect
&rect
);
189 enum ANIM_REPEAT
{ ANIM_REPEAT_NONE
= 0, ANIM_REPEAT_PULSE
, ANIM_REPEAT_LOOP
};
192 ANIMATION_TYPE m_type
;
194 INFO::InfoPtr m_condition
;
196 // conditional anims can repeat
197 ANIM_REPEAT m_repeatAnim
;
198 bool m_lastCondition
;
200 // state of animation
201 ANIMATION_PROCESS m_queuedProcess
;
202 ANIMATION_PROCESS m_currentProcess
;
203 ANIMATION_STATE m_currentState
;
205 // timing of animation
206 unsigned int m_start
;
207 unsigned int m_length
;
208 unsigned int m_delay
;
209 unsigned int m_amount
;
211 std::vector
<CAnimEffect
*> m_effects
;
215 * Class used to handle scrolling, allow using tweeners.
217 * start scrolling using ScrollTo() method / stop scrolling using Stop() method
218 * update scroll value each frame with current time using Update() method
219 * get/set scroll value using GetValue()/SetValue()
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
);
230 * Set target value scroller will be scrolling to
231 * @param endPos target
233 void ScrollTo(float endPos
);
236 * Immediately stop scrolling
238 void Stop() { m_delta
= 0; }
240 * Update the scroller to where it would be at the given time point, calculating a new Value.
241 * @param time time point
242 * @return True if we are scrolling at given time point
244 bool Update(unsigned int time
);
249 float GetValue() const { return m_scrollValue
; }
250 void SetValue(float scrollValue
) { m_scrollValue
= scrollValue
; }
252 bool IsScrolling() const { return m_delta
!= 0; }
253 bool IsScrollingUp() const { return m_delta
< 0; }
254 bool IsScrollingDown() const { return m_delta
> 0; }
256 unsigned int GetDuration() const { return m_duration
; }
259 float Tween(float progress
);
262 float m_delta
; //!< Brief distance that we have to travel during scroll
263 float m_startPosition
; //!< Brief starting position of scroll
264 bool m_hasResumePoint
; //!< Brief check if we should tween from middle of the tween
265 unsigned int m_startTime
; //!< Brief starting time of scroll
267 unsigned int m_duration
; //!< Brief duration of scroll
268 std::shared_ptr
<Tweener
> m_pTweener
;