TGUI  1.0-alpha
Animation.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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/Layout.hpp>
30#include <TGUI/Duration.hpp>
31#include <functional>
32#include <memory>
33
35
36namespace tgui
37{
38 class Widget;
39
43 enum class ShowEffectType
44 {
45 Fade,
46 Scale,
51
56 };
57
58
62 enum class AnimationType
63 {
64 Move,
65 Resize,
66 Opacity,
67 };
68
69
70 namespace priv
71 {
73
74 class TGUI_API Animation
75 {
76 public:
77
78 // Move constructor has to be explicitly declared since this class has a destructor
79 Animation(const Animation&) = default;
80 Animation(Animation&&) = default;
81 Animation& operator=(const Animation&) = default;
82 Animation& operator=(Animation&&) = default;
83 virtual ~Animation() = default;
84
85 AnimationType getType() const;
86
87 virtual bool update(Duration elapsedTime) = 0;
88 virtual void finish();
89
90 protected:
91 Animation(AnimationType type, std::shared_ptr<Widget> widget, Duration duration, std::function<void()> finishedCallback);
92
93 protected:
94 AnimationType m_type;
95 std::shared_ptr<Widget> m_widget;
96
97 Duration m_totalDuration;
98 Duration m_elapsedTime;
99
100 std::function<void()> m_finishedCallback;
101 };
102
104
105 class TGUI_API MoveAnimation : public Animation
106 {
107 public:
108 MoveAnimation(std::shared_ptr<Widget> widget, Vector2f start, Layout2d end, Duration duration, std::function<void()> finishedCallback = nullptr);
109
110 bool update(Duration elapsedTime) override;
111
112 void finish() override;
113
114 private:
115 Vector2f m_startPos;
116 Layout2d m_endPos;
117 };
118
120
121 class TGUI_API ResizeAnimation : public Animation
122 {
123 public:
124 ResizeAnimation(std::shared_ptr<Widget> widget, Vector2f start, Layout2d end, Duration duration, std::function<void()> finishedCallback = nullptr);
125
126 bool update(Duration elapsedTime) override;
127
128 void finish() override;
129
130 private:
131 Vector2f m_startSize;
132 Layout2d m_endSize;
133 };
134
136
137 class TGUI_API FadeAnimation : public Animation
138 {
139 public:
140 FadeAnimation(std::shared_ptr<Widget> widget, float start, float end, Duration duration, std::function<void()> finishedCallback = nullptr);
141
142 bool update(Duration elapsedTime) override;
143
144 void finish() override;
145
146 private:
147 float m_startOpacity;
148 float m_endOpacity;
149 };
150
152
153 } // namespace priv
154} // namespace tgui
155
157
158#endif // TGUI_ANIMATION_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
ShowEffectType
Type of effect 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.
AnimationType
Type of animation.
Definition: Animation.hpp:63
@ Move
Position is being changed.
@ Resize
Size is being changed.
@ Opacity
Opacity is being changed.