TGUI 1.11
Loading...
Searching...
No Matches
Animation.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2025 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/Layout.hpp>
29#include <TGUI/Duration.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
76 // Move constructor has to be explicitly declared since this class has a destructor
77 Animation(const Animation&) = default;
78 Animation(Animation&&) = default;
79 Animation& operator=(const Animation&) = default;
80 Animation& operator=(Animation&&) = default;
81 virtual ~Animation() = default;
82
83 TGUI_NODISCARD AnimationType getType() const;
84
85 virtual bool update(Duration elapsedTime) = 0;
86 virtual void finish();
87
88 protected:
89 Animation(AnimationType type, std::shared_ptr<Widget> widget, Duration duration, std::function<void()> finishedCallback);
90
91 protected:
92 AnimationType m_type;
93 std::shared_ptr<Widget> m_widget;
94
95 Duration m_totalDuration;
96 Duration m_elapsedTime;
97
98 std::function<void()> m_finishedCallback;
99 };
100
102
103 class TGUI_API MoveAnimation : public Animation
104 {
105 public:
106 MoveAnimation(std::shared_ptr<Widget> widget, Vector2f start, Layout2d end, Duration duration, std::function<void()> finishedCallback = nullptr);
107
108 bool update(Duration elapsedTime) override;
109
110 void finish() override;
111
112 private:
113 Vector2f m_startPos;
114 Layout2d m_endPos;
115 };
116
118
119 class TGUI_API ResizeAnimation : public Animation
120 {
121 public:
122 ResizeAnimation(std::shared_ptr<Widget> widget, Vector2f start, Layout2d end, Duration duration, std::function<void()> finishedCallback = nullptr);
123
124 bool update(Duration elapsedTime) override;
125
126 void finish() override;
127
128 private:
129 Vector2f m_startSize;
130 Layout2d m_endSize;
131 };
132
134
135 class TGUI_API FadeAnimation : public Animation
136 {
137 public:
138 FadeAnimation(std::shared_ptr<Widget> widget, float start, float end, Duration duration, std::function<void()> finishedCallback = nullptr);
139
140 bool update(Duration elapsedTime) override;
141
142 void finish() override;
143
144 private:
145 float m_startOpacity;
146 float m_endOpacity;
147 };
148
150
151 } // namespace priv
152} // namespace tgui
153
155
156#endif // TGUI_ANIMATION_HPP
The parent class for every widget.
Definition Widget.hpp:84
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.
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