AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AAnimator.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <AUI/Common/AObject.h>
15#include <AUI/Common/AVector.h>
16#include <glm/gtc/matrix_transform.hpp>
17#include "Curves/linear.h"
18#include "Curves/bezier.h"
19#include "Curves/viscous_fluid.h"
20
21class AView;
22class IRenderer;
23
24using AAnimationCurve = std::function<float(float)>;
25
26class API_AUI_VIEWS AAnimator {
27private:
28 AView* mView = nullptr;
29
30 float mCurrentTheta = 0;
31 float mDuration = 1;
32
33 bool mIsPlaying = true;
34 bool mIsRepeating = false;
35
36 std::chrono::milliseconds mLastFrameTime = std::chrono::milliseconds(0);
37
38 AAnimationCurve mCurve = aui::animation_curves::Standard();
39
40protected:
45 virtual void doAnimation(AView* view, float theta, IRenderer& render) {};
46
47 virtual void doPostRender(AView* view, float theta, IRenderer& render) {};
48
49 void translateToCenter(IRenderer& render);
50 void translateToCorner(IRenderer& render);
51
52 static void translateToCenter(AView* view, IRenderer& render);
53 static void translateToCorner(AView* view, IRenderer& render);
54
55public:
56
57 void setCurve(const std::function<float(float)>& curve) {
58 mCurve = curve;
59 }
60
61 void animate(AView* view, IRenderer& render);
62 void postRender(AView* view, IRenderer& render);
63 void pause();
64
65 void setDuration(float period) {
66 mDuration = period;
67 }
68
69 void setRepeating(bool repeating) {
70 mIsRepeating = repeating;
71 }
72
73 [[nodiscard]] const AView* getView() const {
74 return mView;
75 }
76
77 void setView(AView* view) {
78 mView = view;
79 }
80
81 static _<AAnimator> combine(const AVector<_<AAnimator>>& animators);
82};
Definition: AAnimator.h:26
virtual void doAnimation(AView *view, float theta, IRenderer &render)
Does the animation (sets matrix, colors, etc...)
Definition: AAnimator.h:45
A std::vector with AUI extensions.
Definition: AVector.h:38
Base class of all UI objects.
Definition: AView.h:77
Base class for rendering.
Definition: IRenderer.h:149
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: bezier.h:38