TGUI 1.13
Loading...
Searching...
No Matches
Animation.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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#ifndef TGUI_ANIMATION_HPP
26#define TGUI_ANIMATION_HPP
27
28#include <TGUI/Duration.hpp>
29#include <TGUI/Layout.hpp>
30
31#include <functional>
32#include <memory>
33
35
36namespace tgui
37{
38 class Widget;
39
57
61 enum class AnimationType
62 {
66 };
67
68 namespace priv
69 {
71
72 class TGUI_API Animation
73 {
74 public:
75 // Move constructor has to be explicitly declared since this class has a destructor
76 Animation(const Animation&) = default;
77 Animation(Animation&&) = default;
78 Animation& operator=(const Animation&) = default;
79 Animation& operator=(Animation&&) = default;
80 virtual ~Animation() = default;
81
82 [[nodiscard]] AnimationType getType() const;
83
84 virtual bool update(Duration elapsedTime) = 0;
85 virtual void finish();
86
87 protected:
88 Animation(AnimationType type, std::shared_ptr<Widget> widget, Duration duration, std::function<void()> finishedCallback);
89
90 protected:
91 AnimationType m_type;
92 std::shared_ptr<Widget> m_widget;
93
94 Duration m_totalDuration;
95 Duration m_elapsedTime;
96
97 std::function<void()> m_finishedCallback;
98 };
99
101
102 class TGUI_API MoveAnimation : public Animation
103 {
104 public:
105 MoveAnimation(std::shared_ptr<Widget> widget,
106 Vector2f start,
107 Layout2d end,
108 Duration duration,
109 std::function<void()> finishedCallback = nullptr);
110
111 bool update(Duration elapsedTime) override;
112
113 void finish() override;
114
115 private:
116 Vector2f m_startPos;
117 Layout2d m_endPos;
118 };
119
121
122 class TGUI_API ResizeAnimation : public Animation
123 {
124 public:
125 ResizeAnimation(std::shared_ptr<Widget> widget,
126 Vector2f start,
127 Layout2d end,
128 Duration duration,
129 std::function<void()> finishedCallback = nullptr);
130
131 bool update(Duration elapsedTime) override;
132
133 void finish() override;
134
135 private:
136 Vector2f m_startSize;
137 Layout2d m_endSize;
138 };
139
141
142 class TGUI_API FadeAnimation : public Animation
143 {
144 public:
145 FadeAnimation(std::shared_ptr<Widget> widget,
146 float start,
147 float end,
148 Duration duration,
149 std::function<void()> finishedCallback = nullptr);
150
151 bool update(Duration elapsedTime) override;
152
153 void finish() override;
154
155 private:
156 float m_startOpacity;
157 float m_endOpacity;
158 };
159 } // namespace priv
160} // namespace tgui
161
162#endif // TGUI_ANIMATION_HPP
The parent class for every widget.
Definition Widget.hpp:83
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
ShowEffectType
Type of effect to show/hide widget.
Definition Animation.hpp:44
@ Fade
Fade widget in or out.
Definition Animation.hpp:45
@ SlideFromBottom
Slide from bottom to show or to the top to hide.
Definition Animation.hpp:55
@ SlideToLeft
Slide to the left to hide or from right to show.
Definition Animation.hpp:48
@ SlideToRight
Slide to the right to hide or from left to show.
Definition Animation.hpp:47
@ SlideFromLeft
Slide from left to show or to the right to hide.
Definition Animation.hpp:52
@ Scale
Shrink to the center of the widget to hide or grow from its center to show.
Definition Animation.hpp:46
@ SlideToBottom
Slide to the bottom to hide or from top to show.
Definition Animation.hpp:49
@ SlideFromTop
Slide from top to show or to the bottom to hide.
Definition Animation.hpp:54
@ SlideToTop
Slide to the top to hide or from bottom to show.
Definition Animation.hpp:50
@ SlideFromRight
Slide from right to show or to the left to hide.
Definition Animation.hpp:53
AnimationType
Type of animation.
Definition Animation.hpp:62
@ Move
Position is being changed.
Definition Animation.hpp:63
@ Resize
Size is being changed.
Definition Animation.hpp:64
@ Opacity
Opacity is being changed.
Definition Animation.hpp:65