SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Canvas.h
1#ifndef Canvas_H
2#define Canvas_H
3
4#include "AzulCore.h"
5#include "../Inputable/Inputable.h"
6#include "../Drawable/Drawable.h"
7#include "../Updatable/Updatable.h"
8#include <vector>
9
10class UIComponent;
11
28class Canvas : public Drawable, public Inputable, public Updatable
29{
30public:
31 Canvas();
32 Canvas(const Canvas&) = delete;
33 Canvas& operator=(const Canvas&) = delete;
34 ~Canvas();
35
40 void AddComponent(UIComponent* component);
41
46 void RemoveComponent(UIComponent* component);
47
52 void SetEnabled(bool e);
53
58 bool IsEnabled() const;
59
60private:
61 friend class UIAttorney;
62
63 std::vector<UIComponent*> components;
64
65 // Map: Layer index -> vector of components in that layer
66 std::map<int, std::vector<UIComponent*>> layerMap;
67 // For fast removal: component pointer -> layer index
68 std::map<UIComponent*, int> componentLayerLookup;
69 // Flag to indicate if the canvas is enabled
70 bool enabled;
71
72 // Call this if you change a component's layer after adding it
73 void OnComponentLayerChanged(UIComponent* component, int oldLayer, int newLayer);
74
79 void Update() override;
80
85 void Draw2D() override;
86
91 void MousePress(AZUL_MOUSE m) override;
92
97 void MouseHeld(AZUL_MOUSE m) override;
98
103 void MouseRelease(AZUL_MOUSE m) override;
104
108 void HandleMouseInput();
109
114
118 void HandleScroll();
119
124
128 void HandleHover();
129};
130
131#endif
void Update() override
Updates the canvas and its child components. Called automatically by the engine each frame when regis...
Definition Canvas.cpp:100
void Draw2D() override
Draws the canvas and its child components. Called automatically by the engine each frame when registe...
Definition Canvas.cpp:106
void AddComponent(UIComponent *component)
Adds a UI component to the canvas.
Definition Canvas.cpp:22
void HandleMouseReleaseInput()
Handles released AZUL mouse input.
Definition Canvas.cpp:208
void SetEnabled(bool e)
Sets the canvas to be enabled or disabled.
Definition Canvas.cpp:59
std::vector< UIComponent * > components
List of UI components in this canvas.
Definition Canvas.h:63
void MouseHeld(AZUL_MOUSE m) override
Handles held AZUL mouse input. Called automatically by the engine when mouse input is detected.
Definition Canvas.cpp:129
void HandleHover()
Handles AZUL mouse hover input.
Definition Canvas.cpp:223
void MouseRelease(AZUL_MOUSE m) override
Handles released AZUL mouse input. Called automatically by the engine when mouse input is detected.
Definition Canvas.cpp:137
void MousePress(AZUL_MOUSE m) override
Handles pressed AZUL mouse input. Called automatically by the engine when mouse input is detected.
Definition Canvas.cpp:121
void HandleScroll()
Handles AZUL mouse scroll input.
Definition Canvas.cpp:186
void RemoveComponent(UIComponent *component)
Removes a UI component from the canvas.
Definition Canvas.cpp:34
void HandleMouseInput()
Handles AZUL mouse press/hover input.
Definition Canvas.cpp:145
bool IsEnabled() const
Returns whether the canvas is enabled or not.
Definition Canvas.cpp:81
void HandleHeldMouseInput()
Handles AZUL mouse scroll input.
Definition Canvas.cpp:167
Abstract base class for all UI components.
Definition UIComponent.h:32