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 "Vec2.hpp"
8
9#include <memory>
10#include <set>
11#include <vector>
12
13namespace jngl {
14
15class Effect;
16
17class Widget {
18public:
21
22 virtual ~Widget();
23
24 enum class Action {
25 NONE,
26 REMOVE,
27 REQUEST_FOCUS,
28 };
29
33 [[nodiscard]] virtual Action step();
34
36 virtual void draw() const;
37
39 virtual void drawSelf() const = 0;
40
41 void addEffect(std::unique_ptr<Effect>);
42
43 template<class T, class... Args>
44 void addEffect(Args&&... args) {
45 return addEffect(std::make_unique<T>(std::forward<Args>(args)...));
46 }
47
48 void removeEffect(Effect*);
49
51 virtual void removeEffects();
52
55
56protected:
59
60private:
62 std::set<Effect*> needToRemove;
63};
64
65} // namespace jngl
Contains jngl::Vec2 class.
Base class for effects that can be applied to jngl::Widget.
Definition: effects.hpp:13
Two-dimensional vector.
Definition: Vec2.hpp:32
virtual Action step()
Steps all Effects.
virtual void removeEffects()
Removes all effects.
jngl::Vec2 position
Center.
Definition: Widget.hpp:58
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.
virtual void drawSelf() const =0
Override this function to draw the widget.
JNGL's main namespace.
Definition: Achievement.hpp:10