TGUI  1.3-dev
Loading...
Searching...
No Matches
Animation.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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
32#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
33 #include <functional>
34 #include <memory>
35#endif
36
38
39TGUI_MODULE_EXPORT namespace tgui
40{
41 class Widget;
42
60
61
65 enum class AnimationType
66 {
67 Move,
68 Resize,
69 Opacity,
70 };
71
72
73 namespace priv
74 {
76
77 class TGUI_API Animation
78 {
79 public:
80
81 // Move constructor has to be explicitly declared since this class has a destructor
82 Animation(const Animation&) = default;
83 Animation(Animation&&) = default;
84 Animation& operator=(const Animation&) = default;
85 Animation& operator=(Animation&&) = default;
86 virtual ~Animation() = default;
87
88 TGUI_NODISCARD AnimationType getType() const;
89
90 virtual bool update(Duration elapsedTime) = 0;
91 virtual void finish();
92
93 protected:
94 Animation(AnimationType type, std::shared_ptr<Widget> widget, Duration duration, std::function<void()> finishedCallback);
95
96 protected:
97 AnimationType m_type;
98 std::shared_ptr<Widget> m_widget;
99
100 Duration m_totalDuration;
101 Duration m_elapsedTime;
102
103 std::function<void()> m_finishedCallback;
104 };
105
107
108 class TGUI_API MoveAnimation : public Animation
109 {
110 public:
111 MoveAnimation(std::shared_ptr<Widget> widget, Vector2f start, Layout2d end, Duration duration, std::function<void()> finishedCallback = nullptr);
112
113 bool update(Duration elapsedTime) override;
114
115 void finish() override;
116
117 private:
118 Vector2f m_startPos;
119 Layout2d m_endPos;
120 };
121
123
124 class TGUI_API ResizeAnimation : public Animation
125 {
126 public:
127 ResizeAnimation(std::shared_ptr<Widget> widget, Vector2f start, Layout2d end, Duration duration, std::function<void()> finishedCallback = nullptr);
128
129 bool update(Duration elapsedTime) override;
130
131 void finish() override;
132
133 private:
134 Vector2f m_startSize;
135 Layout2d m_endSize;
136 };
137
139
140 class TGUI_API FadeAnimation : public Animation
141 {
142 public:
143 FadeAnimation(std::shared_ptr<Widget> widget, float start, float end, Duration duration, std::function<void()> finishedCallback = nullptr);
144
145 bool update(Duration elapsedTime) override;
146
147 void finish() override;
148
149 private:
150 float m_startOpacity;
151 float m_endOpacity;
152 };
153
155
156 } // namespace priv
157} // namespace tgui
158
160
161#endif // TGUI_ANIMATION_HPP
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
ShowEffectType
Type of effect to show/hide widget.
Definition Animation.hpp:47
@ 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:66
@ Move
Position is being changed.
@ Resize
Size is being changed.
@ Opacity
Opacity is being changed.