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
14class Effect {
15public:
16 enum class Action : uint8_t {
17 NONE,
18 REMOVE_EFFECT,
19 REMOVE_WIDGET,
20 };
21
22 virtual ~Effect();
23 [[nodiscard]] virtual Action step() = 0;
24 virtual void beginDraw() const = 0;
25 virtual void endDraw() const = 0;
26};
27
29class Zoom : public Effect {
30public:
32 explicit Zoom(std::function<float(float)>);
33 Action step() override;
34 void beginDraw() const override;
35 void endDraw() const override;
36
37private:
38 std::function<float(float)> function;
39 float time = 0;
40};
41
43class Executor : public Effect {
44public:
45 explicit Executor(std::function<Action(float)>);
46 Action step() override;
47
49 void beginDraw() const override;
50 void endDraw() const override;
51
52private:
53 std::function<Action(float)> function;
54 float time = 0;
55};
56
57class Move : public Effect {
58public:
59 explicit Move(Vec2 offset, std::function<float(float)>);
60 Action step() override;
61 void beginDraw() const override;
62 void endDraw() const override;
63
64private:
65 Vec2 offset;
66 float progress;
67 std::function<float(float)> function;
68 float time = 0;
69};
70
71namespace easing {
72
73float linear(float);
74float elastic(float);
75float cubic(float);
76float expo(float);
77
78} // namespace easing
79
80} // namespace jngl
Contains jngl::Vec2 class.
Base class for effects that can be applied to jngl::Widget.
Definition effects.hpp:14
Executes a specific action, e.g. removes the Widget.
Definition effects.hpp:43
void beginDraw() const override
Does nothing.
Two-dimensional vector.
Definition Vec2.hpp:36
Scales the ModelView matrix.
Definition effects.hpp:29
Zoom(std::function< float(float)>)
f(t)
JNGL's main namespace.