TGUI  v0.7.5
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  Type getType() const;
69 
70  virtual bool update(sf::Time elapsedTime) = 0;
71 
72  virtual void finish();
73 
74  protected:
75  Type m_type = Type::None;
76  Widget::Ptr m_widget;
77 
78  sf::Time m_totalDuration;
79  sf::Time m_elapsedTime;
80 
81  std::function<void()> m_finishedCallback;
82 
83  friend class tgui::Widget;
84  };
85 
87 
88  class TGUI_API MoveAnimation : public Animation
89  {
90  public:
91  MoveAnimation(Widget::Ptr widget, sf::Vector2f start, sf::Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
92 
93  virtual bool update(sf::Time elapsedTime) override;
94 
95  virtual void finish() override;
96 
97  private:
98  sf::Vector2f m_startPos;
99  sf::Vector2f m_endPos;
100  };
101 
103 
104  class TGUI_API ResizeAnimation : public Animation
105  {
106  public:
107  ResizeAnimation(Widget::Ptr widget, sf::Vector2f start, sf::Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
108 
109  virtual bool update(sf::Time elapsedTime) override;
110 
111  virtual void finish() override;
112 
113  private:
114  sf::Vector2f m_startSize;
115  sf::Vector2f m_endSize;
116  };
117 
119 
120  class TGUI_API FadeAnimation : public Animation
121  {
122  public:
123  FadeAnimation(Widget::Ptr widget, float start, float end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
124 
125  virtual bool update(sf::Time elapsedTime) override;
126 
127  virtual void finish() override;
128 
129  private:
130  float m_startOpacity;
131  float m_endOpacity;
132  };
133 
135 
136  } // namespace priv
137 } // namespace tgui
138 
140 
141 #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.