TGUI  0.9.5
Loading...
Searching...
No Matches
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
57
58 using ShowAnimationType TGUI_DEPRECATED("ShowAnimationType was renamed to ShowEffectType") = ShowEffectType;
59
60
61 namespace priv
62 {
64
65 class TGUI_API Animation
66 {
67 public:
68 enum class Type
69 {
70 None = 0,
71 Move = 1,
72 Resize = 2,
73 Fade = 4
74 };
75
76 // Move constructor has to be explicitly declared since this class has a destructor
77 Animation() = default;
78 Animation(const Animation&) = default;
79 Animation(Animation&&) = default;
80 Animation& operator=(const Animation&) = default;
81 Animation& operator=(Animation&&) = default;
82 virtual ~Animation() = default;
83
84 Type getType() const;
85
86 virtual bool update(Duration elapsedTime) = 0;
87 virtual void finish();
88
89 protected:
90 Animation(Type type, std::shared_ptr<Widget> widget, Duration duration, std::function<void()> finishedCallback);
91
92 protected:
93 Type m_type = Type::None;
94 std::shared_ptr<Widget> m_widget;
95
96 Duration m_totalDuration;
97 Duration m_elapsedTime;
98
99 std::function<void()> m_finishedCallback;
100 };
101
103
104 class TGUI_API MoveAnimation : public Animation
105 {
106 public:
107 MoveAnimation(std::shared_ptr<Widget> widget, Vector2f start, Layout2d end, Duration duration, std::function<void()> finishedCallback = nullptr);
108
109 bool update(Duration elapsedTime) override;
110
111 void finish() override;
112
113 private:
114 Vector2f m_startPos;
115 Layout2d m_endPos;
116 };
117
119
120 class TGUI_API ResizeAnimation : public Animation
121 {
122 public:
123 ResizeAnimation(std::shared_ptr<Widget> widget, Vector2f start, Layout2d end, Duration duration, std::function<void()> finishedCallback = nullptr);
124
125 bool update(Duration elapsedTime) override;
126
127 void finish() override;
128
129 private:
130 Vector2f m_startSize;
131 Layout2d m_endSize;
132 };
133
135
136 class TGUI_API FadeAnimation : public Animation
137 {
138 public:
139 FadeAnimation(std::shared_ptr<Widget> widget, float start, float end, Duration duration, std::function<void()> finishedCallback = nullptr);
140
141 bool update(Duration elapsedTime) override;
142
143 void finish() override;
144
145 private:
146 float m_startOpacity;
147 float m_endOpacity;
148 };
149
151
152 } // namespace priv
153} // namespace tgui
154
156
157#endif // TGUI_ANIMATION_HPP
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
ShowEffectType
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.