TGUI  0.10-dev
Animation.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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/Vector2.hpp>
30#include <TGUI/Duration.hpp>
31#include <functional>
32#include <memory>
33
35
36namespace tgui
37{
38 class Widget;
39
44 {
45 Fade,
46 Scale,
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(Duration elapsedTime) = 0;
84 virtual void finish();
85
86 protected:
87 Animation(Type type, std::shared_ptr<Widget> widget, Duration duration, std::function<void()> finishedCallback);
88
89 protected:
90 Type m_type = Type::None;
91 std::shared_ptr<Widget> m_widget;
92
93 Duration m_totalDuration;
94 Duration 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, Duration duration, std::function<void()> finishedCallback = nullptr);
105
106 bool update(Duration 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, Duration duration, std::function<void()> finishedCallback = nullptr);
121
122 bool update(Duration 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, Duration duration, std::function<void()> finishedCallback = nullptr);
137
138 bool update(Duration 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
ShowAnimationType
Type of animation to show/hide widget.
Definition: Animation.hpp:44
@ Fade
Fade widget in or out.
@ SlideFromBottom
Slide from bottom to show or to the top to hide.
@ SlideToLeft
Slide to the left to hide or from right to show.
@ SlideToRight
Slide to the right to hide or from left to show.
@ SlideFromLeft
Slide from left to show or to the right to hide.
@ Scale
Shrink to the center of the widget to hide or grow from its center to show.
@ SlideToBottom
Slide to the bottom to hide or from top to show.
@ SlideFromTop
Slide from top to show or to the bottom to hide.
@ SlideToTop
Slide to the top to hide or from bottom to show.
@ SlideFromRight
Slide from right to show or to the left to hide.