JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
effects.hpp
Go to the documentation of this file.
1// Copyright 2020-2024 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Vec2.hpp"
8#include <cstdint>
9#include <functional>
10
11namespace jngl {
12
13class Mat3;
14
16class Effect {
17public:
18 enum class Action : uint8_t {
19 NONE,
20 REMOVE_EFFECT,
21 REMOVE_WIDGET,
22 };
23
24 virtual ~Effect();
25 [[nodiscard]] virtual Action step() = 0;
26 virtual void beginDraw() const = 0;
27 virtual void endDraw() const = 0;
28
30 virtual void updateModelview(Mat3& modelview) const;
31};
32
33class UpdateModelview : public Effect {
34public:
46 explicit UpdateModelview(std::function<void(float t, Mat3&)>);
47 Action step() override;
48 void beginDraw() const override;
49 void endDraw() const override;
50 void updateModelview(Mat3& modelview) const override;
51
52private:
53 std::function<void(float t, Mat3&)> function;
54 float time = 0;
55};
56
58class Zoom : public Effect {
59public:
61 explicit Zoom(std::function<float(float)>);
62 Action step() override;
63 void beginDraw() const override;
64 void endDraw() const override;
65
66private:
67 std::function<float(float)> function;
68 float time = 0;
69};
70
72class Executor : public Effect {
73public:
74 explicit Executor(std::function<Action(float)>);
75 Action step() override;
76
78 void beginDraw() const override;
79 void endDraw() const override;
80
81private:
82 std::function<Action(float)> function;
83 float time = 0;
84};
85
86class Move : public Effect {
87public:
88 explicit Move(Vec2 offset, std::function<float(float)>);
89 Action step() override;
90 void beginDraw() const override;
91 void endDraw() const override;
92
93private:
94 Vec2 offset;
95 float progress;
96 std::function<float(float)> function;
97 float time = 0;
98};
99
100namespace easing {
101
102float linear(float);
103float elastic(float);
104float cubic(float);
105float expo(float);
106
107} // namespace easing
108
109} // namespace jngl
Contains jngl::Vec2 class.
Base class for effects that can be applied to jngl::Widget.
Definition effects.hpp:16
virtual void updateModelview(Mat3 &modelview) const
Called before drawing the widget.
Executes a specific action, e.g. removes the Widget.
Definition effects.hpp:72
void beginDraw() const override
Does nothing.
3x3 matrix
Definition Mat3.hpp:18
UpdateModelview(std::function< void(float t, Mat3 &)>)
Pass a function that gets the time the effect is in use and a reference to the Modelview so that it c...
void updateModelview(Mat3 &modelview) const override
Called before drawing the widget.
Two-dimensional vector.
Definition Vec2.hpp:36
Scales the ModelView matrix.
Definition effects.hpp:58
Zoom(std::function< float(float)>)
f(t)
JNGL's main namespace.
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.