AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
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:
47 virtual void doAnimation(AView* view, float theta, IRenderer& render) {};
48
49 virtual void doPostRender(AView* view, float theta, IRenderer& render) {};
50
51 void translateToCenter(IRenderer& render);
52 void translateToCorner(IRenderer& render);
53
54 static void translateToCenter(AView* view, IRenderer& render);
55 static void translateToCorner(AView* view, IRenderer& render);
56
57public:
58
59 void setCurve(const std::function<float(float)>& curve) {
60 mCurve = curve;
61 }
62
63 void animate(AView* view, IRenderer& render);
64 void postRender(AView* view, IRenderer& render);
65 void pause();
66
67 void setDuration(float period) {
68 mDuration = period;
69 }
70
71 void setRepeating(bool repeating) {
72 mIsRepeating = repeating;
73 }
74
75 [[nodiscard]] const AView* getView() const {
76 return mView;
77 }
78
79 void setView(AView* view) {
80 mView = view;
81 }
82
83 static _<AAnimator> combine(const AVector<_<AAnimator>>& animators);
84};
Definition AAnimator.h:26
virtual void doAnimation(AView *view, float theta, IRenderer &render)
Does the animation (sets matrix, colors, etc...)
Definition AAnimator.h:47
Base class of all UI objects.
Definition AView.h:78
Base class for rendering.
Definition IRenderer.h:149
Definition bezier.h:37