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-2026 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 Widget(Widget&&) noexcept = default;
23 Widget& operator=(Widget&&) noexcept = default;
24
25 virtual ~Widget();
26
27 enum class Action : uint8_t {
28 NONE,
29 REMOVE,
30 REQUEST_FOCUS,
31 };
32
36 [[nodiscard]] virtual Action step();
37
39 virtual void draw(Mat3 modelview) const;
40
42 virtual void drawSelf(Mat3 modelview) const = 0;
43
44 void addEffect(std::unique_ptr<Effect>);
45
46 template<class T, class... Args>
47 void addEffect(Args&&... args) {
48 return addEffect(std::make_unique<T>(std::forward<Args>(args)...));
49 }
50
51 void removeEffect(Effect*);
52
54 virtual void removeEffects();
55
58
59protected:
62
63private:
65 std::set<Effect*> needToRemove;
66};
67
68} // namespace jngl
Contains jngl::Mat3 class.
Contains jngl::Vec2 class.
Base class for effects that can be applied to jngl::Widget.
Definition effects.hpp:16
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 draw(Mat3 modelview) const
Draws the widget with all effects applied.
virtual void drawSelf(Mat3 modelview) const =0
Override this function to draw the widget.
jngl::Vec2 position
Center.
Definition Widget.hpp:61
jngl::Vec2 getPosition() const
Returns the center.
Widget(jngl::Vec2 position)
Creates a Widget centered at position.
T forward(T... args)
T make_unique(T... args)
JNGL's main namespace.
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.