Screen.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Control.h"
4 #include "../RenderQueue.h"
5 #include <Data/BitSet.h>
6 #include <Platform/Timers.h>
7 
8 namespace Graphics
9 {
10 enum class InputEvent {
11  move,
12  down,
13  up,
14 };
15 
16 enum class ControlEvent {
17  activate,
18  deactivate,
19 };
20 
21 class Screen
22 {
23 public:
29  using DrawMethod = Delegate<bool(SceneObject& scene)>;
30 
37  using ControlMethod = Delegate<bool(ControlEvent event, Control& control)>;
38 
39  Screen(RenderTarget& target) : target(target), renderQueue(target), flags(Flag::redrawFull)
40  {
41  }
42 
43  void input(InputEvent event, Point pos);
44 
45  void update(bool fullRedraw = false);
46 
47  void onDraw(DrawMethod method)
48  {
49  drawMethod = method;
50  }
51 
52  void onControl(ControlMethod method)
53  {
54  controlMethod = method;
55  }
56 
58 
59 protected:
60  virtual void draw(SceneObject& scene);
61  virtual void handleControlEvent(ControlEvent event, Control& ctrl);
62 
63 private:
64  void doUpdate();
65 
66  enum class Flag {
67  redraw,
68  redrawFull,
69  inputDown,
70  };
71 
72  RenderTarget& target;
73  RenderQueue renderQueue;
74  DrawMethod drawMethod;
75  ControlMethod controlMethod;
77  Control* activeControl{};
78  OneShotFastMs ctrlTimer;
79 };
80 
81 } // namespace Graphics
Definition: Libraries/Graphics/src/include/Graphics/Control/Control.h:16
Basic interactive button on screen.
Definition: Libraries/Graphics/src/include/Graphics/Control/Control.h:13
Top-level manager to queue objects for rendering to a specific target.
Definition: RenderQueue.h:35
Interface for objects which support writing via surfaces.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:739
A Scene containing multiple objects.
Definition: Scene.h:32
Definition: Screen.h:22
void input(InputEvent event, Point pos)
virtual void draw(SceneObject &scene)
virtual void handleControlEvent(ControlEvent event, Control &ctrl)
Delegate< bool(ControlEvent event, Control &control)> ControlMethod
Invoked in response to user input.
Definition: Screen.h:37
Control::List controls
Definition: Screen.h:57
Delegate< bool(SceneObject &scene)> DrawMethod
Invoked when screen is drawn.
Definition: Screen.h:29
void onControl(ControlMethod method)
Definition: Screen.h:52
Screen(RenderTarget &target)
Definition: Screen.h:39
void onDraw(DrawMethod method)
Definition: Screen.h:47
void update(bool fullRedraw=false)
Template class to implement a polled timer.
Definition: PolledTimer.h:68
Definition: Virtual.h:31
InputEvent
Definition: Screen.h:10
ControlEvent
Definition: Screen.h:16