SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Canvas Class Reference

A UI container for managing and rendering UI components. More...

#include <Canvas.h>

Inheritance diagram for Canvas:
Inheritance graph

Public Member Functions

 Canvas (const Canvas &)=delete
 
Canvasoperator= (const Canvas &)=delete
 
void AddComponent (UIComponent *component)
 Adds a UI component to the canvas.
 
void RemoveComponent (UIComponent *component)
 Removes a UI component from the canvas.
 
void SetEnabled (bool e)
 Sets the canvas to be enabled or disabled.
 
bool IsEnabled () const
 Returns whether the canvas is enabled or not.
 

Private Member Functions

void OnComponentLayerChanged (UIComponent *component, int oldLayer, int newLayer)
 
void Update () override
 Updates the canvas and its child components. Called automatically by the engine each frame when registered.
 
void Draw2D () override
 Draws the canvas and its child components. Called automatically by the engine each frame when registered.
 
void MousePress (AZUL_MOUSE m) override
 Handles pressed AZUL mouse input. Called automatically by the engine when mouse input is detected.
 
void MouseHeld (AZUL_MOUSE m) override
 Handles held AZUL mouse input. Called automatically by the engine when mouse input is detected.
 
void MouseRelease (AZUL_MOUSE m) override
 Handles released AZUL mouse input. Called automatically by the engine when mouse input is detected.
 
void HandleMouseInput ()
 Handles AZUL mouse press/hover input.
 
void HandleHeldMouseInput ()
 Handles AZUL mouse scroll input.
 
void HandleScroll ()
 Handles AZUL mouse scroll input.
 
void HandleMouseReleaseInput ()
 Handles released AZUL mouse input.
 
void HandleHover ()
 Handles AZUL mouse hover input.
 

Private Attributes

std::vector< UIComponent * > components
 List of UI components in this canvas.
 
std::map< int, std::vector< UIComponent * > > layerMap
 
std::map< UIComponent *, int > componentLayerLookup
 
bool enabled
 

Friends

class UIAttorney
 

Additional Inherited Members

- Protected Member Functions inherited from Drawable
 Drawable (const Drawable &)=delete
 
Drawableoperator= (const Drawable &)=delete
 
void SubmitDrawRegistration ()
 Submits the draw registration for the GameObject.
 
void SubmitDrawDeregistration ()
 Submits the draw deregistration for the GameObject.
 
- Protected Member Functions inherited from Inputable
 Inputable (const Inputable &)=delete
 
Inputableoperator= (const Inputable &)=delete
 
void SubmitKeyRegistration (AZUL_KEY k, EventType e)
 Submits the key registration for the GameObject.
 
void SubmitKeyDeregistration (AZUL_KEY k, EventType e)
 Submits the key deregistration for the GameObject.
 
void SubmitMouseKeyRegistration (AZUL_MOUSE m, EventType e)
 Submits the mouse key registration for the GameObject.
 
void SubmitMouseKeyDeregistration (AZUL_MOUSE m, EventType e)
 Submits the mouse key deregistration for the GameObject.
 
- Protected Member Functions inherited from Updatable
 Updatable (const Updatable &)=delete
 
Updatableoperator= (const Updatable &)=delete
 
void SubmitUpdateRegistration ()
 Submits the update registration for the GameObject.
 
void SubmitUpdateDeregistration ()
 Submits the update deregistration for the GameObject.
 

Detailed Description

A UI container for managing and rendering UI components.

The Canvas class acts as a root container for UI elements such as buttons, sliders, dropdowns, and more. It handles input, drawing, and updating of its child components, and can be added to a scene as a 2D overlay.

Typical usage:

Canvas* pCanvas = new Canvas();
pCanvas->AddComponent(new Button("Button"));
// Add more UI components as needed
A clickable UI button component.
Definition Button.h:30
void AddComponent(UIComponent *component)
Adds a UI component to the canvas.
Definition Canvas.cpp:22
See also
Button, Slider, Dropdown, Textbox, ScrollList

Member Function Documentation

◆ AddComponent()

void Canvas::AddComponent ( UIComponent * component)

Adds a UI component to the canvas.

Parameters
componentPointer to the UIComponent to add.
Here is the call graph for this function:

◆ Draw2D()

void Canvas::Draw2D ( )
overrideprivatevirtual

Draws the canvas and its child components. Called automatically by the engine each frame when registered.

Reimplemented from Drawable.

Here is the call graph for this function:

◆ IsEnabled()

bool Canvas::IsEnabled ( ) const

Returns whether the canvas is enabled or not.

Returns
True if enabled, false otherwise.

◆ MouseHeld()

void Canvas::MouseHeld ( AZUL_MOUSE m)
overrideprivatevirtual

Handles held AZUL mouse input. Called automatically by the engine when mouse input is detected.

Reimplemented from Inputable.

Here is the call graph for this function:

◆ MousePress()

void Canvas::MousePress ( AZUL_MOUSE m)
overrideprivatevirtual

Handles pressed AZUL mouse input. Called automatically by the engine when mouse input is detected.

Reimplemented from Inputable.

Here is the call graph for this function:

◆ MouseRelease()

void Canvas::MouseRelease ( AZUL_MOUSE m)
overrideprivatevirtual

Handles released AZUL mouse input. Called automatically by the engine when mouse input is detected.

Reimplemented from Inputable.

Here is the call graph for this function:

◆ RemoveComponent()

void Canvas::RemoveComponent ( UIComponent * component)

Removes a UI component from the canvas.

Parameters
componentPointer to the UIComponent to remove.
Here is the call graph for this function:

◆ SetEnabled()

void Canvas::SetEnabled ( bool e)

Sets the canvas to be enabled or disabled.

Parameters
enabledTrue to enable the canvas, false to disable it.
Here is the call graph for this function:

◆ Update()

void Canvas::Update ( )
overrideprivatevirtual

Updates the canvas and its child components. Called automatically by the engine each frame when registered.

Reimplemented from Updatable.

Here is the call graph for this function:

The documentation for this class was generated from the following files: