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:
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 
52 protected:
55 
56 private:
58  std::set<Effect*> needToRemove;
59 };
60 
61 } // namespace jngl
Contains jngl::Vec2 class.
Two-dimensional vector.
Definition: Vec2.hpp:35
virtual Action step()
Steps all Effects.
virtual void removeEffects()
Removes all effects.
jngl::Vec2 position
Center.
Definition: Widget.hpp:54
virtual void draw() const
Draws the widget with all effects applied.
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: App.hpp:10