TGUI  0.8-dev
Animation.hpp
1 //
3 // TGUI - Texus' 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 
50  SlideFromBottom = SlideToTop
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 
85 
86  class TGUI_API MoveAnimation : public Animation
87  {
88  public:
89  MoveAnimation(Widget::Ptr widget, sf::Vector2f start, sf::Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
90 
91  virtual bool update(sf::Time elapsedTime) override;
92 
93  virtual void finish() override;
94 
95  private:
96  sf::Vector2f m_startPos;
97  sf::Vector2f m_endPos;
98  };
99 
101 
102  class TGUI_API ResizeAnimation : public Animation
103  {
104  public:
105  ResizeAnimation(Widget::Ptr widget, sf::Vector2f start, sf::Vector2f end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
106 
107  virtual bool update(sf::Time elapsedTime) override;
108 
109  virtual void finish() override;
110 
111  private:
112  sf::Vector2f m_startSize;
113  sf::Vector2f m_endSize;
114  };
115 
117 
118  class TGUI_API FadeAnimation : public Animation
119  {
120  public:
121  FadeAnimation(Widget::Ptr widget, float start, float end, sf::Time duration, std::function<void()> finishedCallback = nullptr);
122 
123  virtual bool update(sf::Time elapsedTime) override;
124 
125  virtual void finish() override;
126 
127  private:
128  float m_startOpacity;
129  float m_endOpacity;
130  };
131 
133 
134  } // namespace priv
135 } // namespace tgui
136 
138 
139 #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.
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.