JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Widget.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 "Mat3.hpp"
8#include "Vec2.hpp"
9
10#include <memory>
11#include <set>
12#include <vector>
13
14namespace jngl {
15
16class Effect;
17
18class Widget {
19public:
22
23 virtual ~Widget();
24
25 enum class Action : uint8_t {
26 NONE,
27 REMOVE,
28 REQUEST_FOCUS,
29 };
30
34 [[nodiscard]] virtual Action step();
35
37 virtual void draw() const;
38
40 virtual void drawSelf(Mat3 modelview) const = 0;
41
42 void addEffect(std::unique_ptr<Effect>);
43
44 template<class T, class... Args>
45 void addEffect(Args&&... args) {
46 return addEffect(std::make_unique<T>(std::forward<Args>(args)...));
47 }
48
49 void removeEffect(Effect*);
50
52 virtual void removeEffects();
53
56
57protected:
60
61private:
63 std::set<Effect*> needToRemove;
64};
65
66} // namespace jngl
Contains jngl::Mat3 class.
Contains jngl::Vec2 class.
Base class for effects that can be applied to jngl::Widget.
Definition effects.hpp:14
3x3 matrix
Definition Mat3.hpp:18
Two-dimensional vector.
Definition Vec2.hpp:36
virtual Action step()
Steps all Effects.
virtual void removeEffects()
Removes all effects.
virtual void drawSelf(Mat3 modelview) const =0
Override this function to draw the widget.
jngl::Vec2 position
Center.
Definition Widget.hpp:59
virtual void draw() const
Draws the widget with all effects applied.
jngl::Vec2 getPosition() const
Returns the center.
Widget(jngl::Vec2 position)
Creates a Widget centered at position.
JNGL's main namespace.
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.