SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
UIComponent.h
1#ifndef UIComponent_H
2#define UIComponent_H
3
4#include "UIComponentType.h"
5
6class Canvas;
7
32{
33public:
37 virtual ~UIComponent() = default;
38
43 int GetLayer() const { return Layer; }
44
49 virtual void SetLayer(int layer);
50
55 UIComponentType GetType() const { return Type; }
56
61 bool IsEnabled() const { return Enabled; }
62
67 void SetEnabled(bool enabled) { Enabled = enabled; }
68
73 void SetOwningCanvas(Canvas* canvas) { pOwningCanvas = canvas; }
74
75protected:
76 bool Enabled = true;
77 int Layer = 0;
78 UIComponentType Type = UIComponentType::None;
79 Canvas* pOwningCanvas = nullptr;
80
81private:
82 friend class UIAttorney;
83
88 virtual void Render() = 0;
89
97 virtual bool IsMouseOver(float xPos, float yPos) = 0;
98
103 virtual void OnPress() = 0;
104};
105
106#endif
A UI container for managing and rendering UI components.
Definition Canvas.h:29
Abstract base class for all UI components.
Definition UIComponent.h:32
void SetOwningCanvas(Canvas *canvas)
Gets the owning canvas of the component.
Definition UIComponent.h:73
int Layer
Rendering layer in.
Definition UIComponent.h:77
virtual bool IsMouseOver(float xPos, float yPos)=0
Checks if the mouse is over the component. Must be implemented by derived classes.
virtual void SetLayer(int layer)
Sets the rendering layer of the component.
Definition UIComponent.cpp:4
UIComponentType Type
Type of the UI component.
Definition UIComponent.h:78
bool Enabled
Indicates if the component is enabled or not.
Definition UIComponent.h:76
UIComponentType GetType() const
Gets the type of the UI component.
Definition UIComponent.h:55
Canvas * pOwningCanvas
Pointer to the owning canvas, if any.
Definition UIComponent.h:79
int GetLayer() const
Gets the rendering layer of the component.
Definition UIComponent.h:43
virtual void Render()=0
Renders the UI component. Must be implemented by derived classes.
virtual ~UIComponent()=default
Virtual destructor.
bool IsEnabled() const
Returns whether the component is enabled or not.
Definition UIComponent.h:61
virtual void OnPress()=0
Handles press events on the component. Must be implemented by derived classes.
void SetEnabled(bool enabled)
Sets the enabled state of the component.
Definition UIComponent.h:67