JNGL
Main Page
Namespaces
Classes
Files
File List
File Members
jngl
Widget.hpp
Go to the documentation of this file.
1
// Copyright 2020-2021 Jan Niklas Hasse <
[email protected]
>
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
13
namespace
jngl
{
14
15
class
Effect;
16
17
class
Widget
{
18
public
:
20
explicit
Widget
(
jngl::Vec2
position
);
21
22
virtual
~
Widget
();
23
24
enum class
Action {
25
NONE,
26
REMOVE,
27
};
28
32
[[nodiscard]]
virtual
Action
step
();
33
35
virtual
void
draw
()
const
;
36
38
virtual
void
drawSelf
()
const
= 0;
39
40
void
addEffect(
std::unique_ptr<Effect>
);
41
42
template
<
class
T,
class
... Args>
43
void
addEffect(Args&&... args) {
44
return
addEffect(std::make_unique<T>(std::forward<Args>(args)...));
45
}
46
47
void
removeEffect(
Effect
*);
48
50
virtual
void
removeEffects
();
51
53
jngl::Vec2
getPosition
()
const
;
54
55
protected
:
57
jngl::Vec2
position
;
58
59
private
:
60
std::vector<std::unique_ptr<Effect>
> effects;
61
std::set<Effect*>
needToRemove;
62
};
63
64
}
// namespace jngl
Vec2.hpp
Contains jngl::Vec2 class.
jngl::Effect
Definition:
effects.hpp:11
jngl::Vec2
Two-dimensional vector.
Definition:
Vec2.hpp:35
jngl::Widget
Definition:
Widget.hpp:17
jngl::Widget::step
virtual Action step()
Steps all Effects.
jngl::Widget::removeEffects
virtual void removeEffects()
Removes all effects.
jngl::Widget::position
jngl::Vec2 position
Center.
Definition:
Widget.hpp:57
jngl::Widget::draw
virtual void draw() const
Draws the widget with all effects applied.
jngl::Widget::getPosition
jngl::Vec2 getPosition() const
Returns the center.
jngl::Widget::Widget
Widget(jngl::Vec2 position)
Creates a Widget centered at position.
jngl::Widget::drawSelf
virtual void drawSelf() const =0
Override this function to draw the widget.
memory
jngl
JNGL's main namespace.
Definition:
App.hpp:10
set
std::unique_ptr
vector