TGUI  0.8-alpha
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/Widget.hpp>
30 
32 
33 namespace tgui
34 {
38  enum class ShowAnimationType
39  {
40  Fade,
41  Scale,
42  SlideToRight,
43  SlideToLeft,
45  SlideToTop,
46 
51  };
52 
53  namespace priv
54  {
56 
57  class TGUI_API Animation
58  {
59  public:
60  enum class Type
61  {
62  None = 0,
63  Move = 1,
64  Resize = 2,
65  Fade = 4
66  };
67 
68  // Move constructor has to be explicitly declared since this class has a destructor
69  Animation() = default;
70  Animation(const Animation&) = default;
71  Animation(Animation&&) = default;
72  Animation& operator=(const Animation&) = default;
73  Animation& operator=(Animation&&) = default;
74  virtual ~Animation() = default;
75 
76  Type getType() const;
77 
78  virtual bool update(sf::Time elapsedTime) = 0;
79  virtual void finish();
80 
81  protected:
82  Animation(Type type, Widget::Ptr widget, sf::Time duration, std::function<void()> finishedCallback);
83 
84  protected:
85  Type m_type = Type::None;
86  Widget::Ptr m_widget;
87 
88  sf::Time m_totalDuration;
89  sf::Time m_elapsedTime;
90 
91  std::function<void()> m_finishedCallback;
92  };
93 
95 
96  class TGUI_API MoveAnimation : public Animation
97  {
98  public:
99  MoveAnimation(Widget::Ptr widget, Vector2f start, Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
100 
101  bool update(sf::Time elapsedTime) override;
102 
103  void finish() override;
104 
105  private:
106  Vector2f m_startPos;
107  Vector2f m_endPos;
108  };
109 
111 
112  class TGUI_API ResizeAnimation : public Animation
113  {
114  public:
115  ResizeAnimation(Widget::Ptr widget, Vector2f start, Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
116 
117  bool update(sf::Time elapsedTime) override;
118 
119  void finish() override;
120 
121  private:
122  Vector2f m_startSize;
123  Vector2f m_endSize;
124  };
125 
127 
128  class TGUI_API FadeAnimation : public Animation
129  {
130  public:
131  FadeAnimation(Widget::Ptr widget, float start, float end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
132 
133  bool update(sf::Time elapsedTime) override;
134 
135  void finish() override;
136 
137  private:
138  float m_startOpacity;
139  float m_endOpacity;
140  };
141 
143 
144  } // namespace priv
145 } // namespace tgui
146 
148 
149 #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:38
Slide to the bottom to hide or from top to show.
Slide from left to show or to the right to hide.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
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.