TGUI  0.8.0
Animation.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_ANIMATION_HPP
27 #define TGUI_ANIMATION_HPP
28 
29 #include <TGUI/Vector2f.hpp>
30 #include <SFML/System/Time.hpp>
31 #include <functional>
32 #include <memory>
33 
35 
36 namespace tgui
37 {
38  class Widget;
39 
43  enum class ShowAnimationType
44  {
45  Fade,
46  Scale,
47  SlideToRight,
48  SlideToLeft,
50  SlideToTop,
51 
56  };
57 
58  namespace priv
59  {
61 
62  class TGUI_API Animation
63  {
64  public:
65  enum class Type
66  {
67  None = 0,
68  Move = 1,
69  Resize = 2,
70  Fade = 4
71  };
72 
73  // Move constructor has to be explicitly declared since this class has a destructor
74  Animation() = default;
75  Animation(const Animation&) = default;
76  Animation(Animation&&) = default;
77  Animation& operator=(const Animation&) = default;
78  Animation& operator=(Animation&&) = default;
79  virtual ~Animation() = default;
80 
81  Type getType() const;
82 
83  virtual bool update(sf::Time elapsedTime) = 0;
84  virtual void finish();
85 
86  protected:
87  Animation(Type type, std::shared_ptr<Widget> widget, sf::Time duration, std::function<void()> finishedCallback);
88 
89  protected:
90  Type m_type = Type::None;
91  std::shared_ptr<Widget> m_widget;
92 
93  sf::Time m_totalDuration;
94  sf::Time m_elapsedTime;
95 
96  std::function<void()> m_finishedCallback;
97  };
98 
100 
101  class TGUI_API MoveAnimation : public Animation
102  {
103  public:
104  MoveAnimation(std::shared_ptr<Widget> widget, Vector2f start, Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
105 
106  bool update(sf::Time elapsedTime) override;
107 
108  void finish() override;
109 
110  private:
111  Vector2f m_startPos;
112  Vector2f m_endPos;
113  };
114 
116 
117  class TGUI_API ResizeAnimation : public Animation
118  {
119  public:
120  ResizeAnimation(std::shared_ptr<Widget> widget, Vector2f start, Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
121 
122  bool update(sf::Time elapsedTime) override;
123 
124  void finish() override;
125 
126  private:
127  Vector2f m_startSize;
128  Vector2f m_endSize;
129  };
130 
132 
133  class TGUI_API FadeAnimation : public Animation
134  {
135  public:
136  FadeAnimation(std::shared_ptr<Widget> widget, float start, float end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
137 
138  bool update(sf::Time elapsedTime) override;
139 
140  void finish() override;
141 
142  private:
143  float m_startOpacity;
144  float m_endOpacity;
145  };
146 
148 
149  } // namespace priv
150 } // namespace tgui
151 
153 
154 #endif // TGUI_ANIMATION_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Slide to the top to hide or from bottom to show.
Slide to the left to hide or from right to show.
Shrink to the center of the widget to hide or grow from its center to show.
Slide from top to show or to the bottom to hide.
ShowAnimationType
Type of animation to show/hide widget.
Definition: Animation.hpp:43
Slide to the bottom to hide or from top to show.
Slide from left to show or to the right to hide.
Slide from right to show or to the left to hide.
Slide to the right to hide or from left to show.
Fade widget in or out.
Slide from bottom to show or to the top to hide.