TGUI  v0.7.7
Animation.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2017 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  virtual ~Animation() = default;
69 
70  Type getType() const;
71 
72  virtual bool update(sf::Time elapsedTime) = 0;
73 
74  virtual void finish();
75 
76  protected:
77  Type m_type = Type::None;
78  Widget::Ptr m_widget;
79 
80  sf::Time m_totalDuration;
81  sf::Time m_elapsedTime;
82 
83  std::function<void()> m_finishedCallback;
84 
85  friend class tgui::Widget;
86  };
87 
89 
90  class TGUI_API MoveAnimation : public Animation
91  {
92  public:
93  MoveAnimation(Widget::Ptr widget, sf::Vector2f start, sf::Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
94 
95  virtual bool update(sf::Time elapsedTime) override;
96 
97  virtual void finish() override;
98 
99  private:
100  sf::Vector2f m_startPos;
101  sf::Vector2f m_endPos;
102  };
103 
105 
106  class TGUI_API ResizeAnimation : public Animation
107  {
108  public:
109  ResizeAnimation(Widget::Ptr widget, sf::Vector2f start, sf::Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
110 
111  virtual bool update(sf::Time elapsedTime) override;
112 
113  virtual void finish() override;
114 
115  private:
116  sf::Vector2f m_startSize;
117  sf::Vector2f m_endSize;
118  };
119 
121 
122  class TGUI_API FadeAnimation : public Animation
123  {
124  public:
125  FadeAnimation(Widget::Ptr widget, float start, float end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
126 
127  virtual bool update(sf::Time elapsedTime) override;
128 
129  virtual void finish() override;
130 
131  private:
132  float m_startOpacity;
133  float m_endOpacity;
134  };
135 
137 
138  } // namespace priv
139 } // namespace tgui
140 
142 
143 #endif // TGUI_ANIMATION_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Slide to the top to hide or from bottom to show.
Slide to the left to hide or from right to show.
The parent class for every widget.
Definition: Widget.hpp:71
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:75
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.