Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::CCanvas Class Reference

This class manages GUI components, including creating and deleting images and sprites. More...

#include <Graphics2D/CCanvas.h>

Inheritance diagram for Skylicht::CCanvas:
Skylicht::CComponentSystem Skylicht::IActivatorObject

Public Member Functions

 CCanvas ()
 Constructor.
virtual ~CCanvas ()
 Destructor. Cleans up GUI elements and systems.
virtual void initComponent ()
 Initialize the canvas component.
virtual void updateComponent ()
 Update the canvas component.
virtual void onResize ()
 Handle canvas resizing (usually called when screen size changes).
void updateEntities ()
 Update internal entity lists and sorting for rendering.
void render (CCamera *camera)
 Render the GUI elements tree using the specified camera.
CGUIElementgetHitTest (CCamera *camera, float x, float y, const core::recti &viewport)
 Perform hit-testing to find the GUI element under the given coordinates.
CEntityPrefabgetEntityManager ()
 Get the entity manager.
void setSortDepth (int d)
 Set the sort depth for rendering.
int getSortDepth ()
 Get the current sort depth value.
void setRect (const core::rectf &r)
 Set the canvas rectangle.
void setDefaultRect (const core::rectf &r)
 Set the default rectangle value.
const core::rectfgetDefaultRect ()
 Get the default rectangle.
void applyGUIScale (float widthOrHeight=1.0f)
 Apply GUI scaling based on width or height ratio.
void resetGUIScale ()
 Reset the GUI scaling to default (no scale).
const core::vector3dfgetRootScale ()
 Get the root element's scale vector.
CGUIElementgetRootElement ()
 Get the root GUI element.
void setEnable3DBillboard (bool b)
 Enable or disable 3D billboard rendering.
bool is3DBillboardEnabled ()
 Check if 3D billboard rendering is enabled.
void removeAllElements ()
 Remove all GUI elements from the canvas.
CGUIElementcreateElement ()
 Create a generic GUI element as a child of root.
CGUIElementcreateElement (const core::rectf &r)
 Create a GUI element with a specific rectangle as a child of root.
CGUIElementcreateElement (CGUIElement *e, const core::rectf &r)
 Create a GUI element with a specific parent and rectangle.
CGUIImagecreateImage ()
 Create an image element as a child of root.
CGUIImagecreateImage (const core::rectf &r)
 Create an image element with a rectangle as a child of root.
CGUIImagecreateImage (CGUIElement *e, const core::rectf &r)
 Create an image element with a parent and rectangle.
CGUITextcreateText (IFont *font)
 Create a text element with a font as a child of root.
CGUITextcreateText (const core::rectf &r, IFont *font)
 Create a text element with a rectangle and font as a child of root.
CGUITextcreateText (CGUIElement *e, IFont *font)
 Create a text element with a parent and font.
CGUITextcreateText (CGUIElement *e, const core::rectf &r, IFont *font)
 Create a text element with a parent, rectangle and font.
CGUISpritecreateSprite (SFrame *frame)
 Create a sprite element with a frame as a child of root.
CGUISpritecreateSprite (const core::rectf &r, SFrame *frame)
 Create a sprite element with a rectangle and frame.
CGUISpritecreateSprite (CGUIElement *e, SFrame *frame)
 Create a sprite element with a parent and frame.
CGUISpritecreateSprite (CGUIElement *e, const core::rectf &r, SFrame *frame)
 Create a sprite element with a parent, rectangle, and frame.
CGUIMaskcreateMask (const core::rectf &r)
 Create a mask element with a rectangle as a child of root.
CGUIMaskcreateMask (CGUIElement *e, const core::rectf &r)
 Create a mask element with a parent and rectangle.
CGUIRectcreateRect (const video::SColor &c)
 Create a rectangle element with a color as a child of root.
CGUIRectcreateRect (const core::rectf &r, const video::SColor &c)
 Create a rectangle element with a rectangle and color.
CGUIRectcreateRect (CGUIElement *e, const core::rectf &r, const video::SColor &c)
 Create a rectangle element with a parent, rectangle, and color.
CGUIElipsecreateElipse (const video::SColor &c)
 Create an elipse element with a color as a child of root.
CGUIElipsecreateElipse (const core::rectf &r, const video::SColor &c)
 Create an elipse element with a rectangle and color.
CGUIElipsecreateElipse (CGUIElement *e, const core::rectf &r, const video::SColor &c)
 Create an elipse element with a parent, rectangle, and color.
CGUILayoutcreateLayout ()
 Create a layout element as a child of root.
CGUILayoutcreateLayout (const core::rectf &r)
 Create a layout element with a rectangle.
CGUILayoutcreateLayout (CGUIElement *e, const core::rectf &r)
 Create a layout element with a parent and rectangle.
CGUIFitSpritecreateFitSprite (SFrame *frame)
 Create a fit sprite element with a frame as a child of root.
CGUIFitSpritecreateFitSprite (const core::rectf &r, SFrame *frame)
 Create a fit sprite element with a rectangle and frame.
CGUIFitSpritecreateFitSprite (CGUIElement *e, SFrame *frame)
 Create a fit sprite element with a parent and frame.
CGUIFitSpritecreateFitSprite (CGUIElement *e, const core::rectf &r, SFrame *frame)
 Create a fit sprite element with a parent, rectangle and frame.
virtual CGUIElementcreateNullElement (CGUIElement *parent, const char *type)
 Create a null GUI element by type (UTF-8).
virtual CGUIElementcreateNullElement (CGUIElement *parent, const wchar_t *type)
 Create a null GUI element by type (Unicode).
const core::matrix4getRenderWorldTransform ()
 Get the world transform matrix for rendering.
void setRenderWorldTransform (core::matrix4 &w)
 Set the world transform matrix for rendering.
CCameragetRenderCamera ()
 Get the camera currently used for rendering.
CGUIElementgetGUIByID (const char *id)
 Find a GUI element by its ID.
CGUIElementgetGUIByPath (const char *path)
 Find a GUI element by its path (separated by / or ).
CGUIElementsearchGUI (const char *name)
 Find a GUI element by name.
CGUIElementgetGUIByPath (CGUIElement *search, const char *path)
 Find a GUI element by path starting from a specific element.
CGUIElementsearchGUI (CGUIElement *search, const char *name)
 Find a GUI element by name starting from a specific element.
template<typename T>
std::vector< T * > getElementsInChild (bool addThis)
 Find all child elements of a certain type.
void updateLocalizedText ()
 Find all CGUIText* and update localized text, the event OnLocalize must bind to the localize function.
bool isClipped (CGUIElement *element)
Public Member Functions inherited from Skylicht::CComponentSystem
const char * getName ()
virtual void reset ()
virtual void startComponent ()
virtual void endUpdate ()
virtual void onEnable (bool b)
virtual void onUpdateCullingLayer (u32 mask)
virtual CObjectSerializablecreateSerializable ()
virtual void loadSerializable (CObjectSerializable *object)
void setEnable (bool b)
bool isEnable ()
CGameObject * getGameObject ()
void setEnableSerializable (bool b)
bool isSerializable ()
void addLinkComponent (CComponentSystem *comp)
void removeAllLink ()
Public Member Functions inherited from Skylicht::IActivatorObject
virtual ~IActivatorObject ()
 Virtual destructor for polymorphic activator objects.

Public Attributes

bool IsInEditor
 True if the canvas is shown in editor mode.
bool DrawOutline
 True to draw outlines for GUI elements.
std::function< void(CGUIElement *)> OnGUILoaded
std::function< void(CGUIText *)> OnLocalize

Protected Attributes

core::rectf m_rect
 The rectangle representing the canvas size.
core::rectf m_defaultRect
 The default rectangle size of the canvas.
CGUIElementm_root
 The root GUI element of the canvas.
int m_sortDepth
 Sorting depth for rendering.
float m_scaleGUI
 Scale factor for GUI.
bool m_haveScaleGUI
 True if GUI scaling is applied.
bool m_is3DBillboard
 Enable 3D billboard rendering for the canvas.
core::matrix4 m_renderWorldTransform
 The world transform used for rendering.
CCameram_renderCamera
 The camera currently used for rendering.
CGUIMaskm_currentMask
 The current mask applied during rendering.
CEntityPrefabm_entityMgr
 Entity manager for managing GUI entities.
std::vector< IEntitySystem * > m_systems
 List of entity systems for GUI logic.
CFastArray< CEntity * > m_depth [MAX_ENTITY_DEPTH]
 Entities sorted by children depth.
CFastArray< CEntity * > m_alives
 List of alive entities.
Protected Attributes inherited from Skylicht::CComponentSystem
CGameObject * m_gameObject
bool m_enable
bool m_serializable
std::vector< CComponentSystem * > m_linkComponent

Additional Inherited Members

Static Public Member Functions inherited from Skylicht::CComponentSystem
static int useComponent (CComponentSystem *used)
Protected Member Functions inherited from Skylicht::CComponentSystem
void setOwner (CGameObject *obj)

Detailed Description

This class manages GUI components, including creating and deleting images and sprites.

Canvas for managing GUI components and their hierarchy, rendering, and interaction. CCanvas serves as the root for all GUI elements rendered on screen. It supports element creation, scaling, resizing, hit - testing, and access by ID or path.

GUI elements can be designed visually in Skylicht-Editor, or loaded from .gui files using CGUIImporter.

Example usage:

// Create an image element
CGUIImage* image = canvas->createImage(rect);
This is the object class for displaying a texture image.
Definition CGUIImage.h:43

Skylicht-Editor

To design the GUI, open the Skylicht-Editor and switch to the GUI design window.

The interface includes features for designing GUIs for Canvas.

Setting

You can adjust the base size of the Canvas in the Settings section.

Working with .gui Files

You can save the design file to .gui formats and use CGUIImporter to load it into the Canvas.

You can refer to the example file Assets\SampleGUIDemo\Setting.gui and the codes in Samples\GUI,

Member Function Documentation

◆ applyGUIScale()

void Skylicht::CCanvas::applyGUIScale ( float widthOrHeight = 1.0f)

Apply GUI scaling based on width or height ratio.

If widthOrHeight = 0.0, the scaling will prioritize the width of the canvas. If widthOrHeight = 1.0, the scaling will prioritize the height of the canvas. Values between 0.0 and 1.0 interpolate between width-priority (0.0) and height-priority (1.0).

Parameters
widthOrHeightScale value (default = 1.0).

◆ createElement() [1/3]

CGUIElement * Skylicht::CCanvas::createElement ( )

Create a generic GUI element as a child of root.

Returns
Pointer to the created CGUIElement.

◆ createElement() [2/3]

CGUIElement * Skylicht::CCanvas::createElement ( CGUIElement * e,
const core::rectf & r )

Create a GUI element with a specific parent and rectangle.

Parameters
eParent element.
rRectangle for the element.
Returns
Pointer to the created CGUIElement.

◆ createElement() [3/3]

CGUIElement * Skylicht::CCanvas::createElement ( const core::rectf & r)

Create a GUI element with a specific rectangle as a child of root.

Parameters
rRectangle for the element.
Returns
Pointer to the created CGUIElement.

◆ createElipse() [1/3]

CGUIElipse * Skylicht::CCanvas::createElipse ( CGUIElement * e,
const core::rectf & r,
const video::SColor & c )

Create an elipse element with a parent, rectangle, and color.

Parameters
eParent element.
rRectangle.
cColor.
Returns
Pointer to CGUIElipse.

◆ createElipse() [2/3]

CGUIElipse * Skylicht::CCanvas::createElipse ( const core::rectf & r,
const video::SColor & c )

Create an elipse element with a rectangle and color.

Parameters
rRectangle.
cColor.
Returns
Pointer to CGUIElipse.

◆ createElipse() [3/3]

CGUIElipse * Skylicht::CCanvas::createElipse ( const video::SColor & c)

Create an elipse element with a color as a child of root.

Parameters
cColor.
Returns
Pointer to CGUIElipse.

◆ createFitSprite() [1/4]

CGUIFitSprite * Skylicht::CCanvas::createFitSprite ( CGUIElement * e,
const core::rectf & r,
SFrame * frame )

Create a fit sprite element with a parent, rectangle and frame.

Parameters
eParent element.
rRectangle.
frameSprite frame.
Returns
Pointer to CGUIFitSprite.

◆ createFitSprite() [2/4]

CGUIFitSprite * Skylicht::CCanvas::createFitSprite ( CGUIElement * e,
SFrame * frame )

Create a fit sprite element with a parent and frame.

Parameters
eParent element.
frameSprite frame.
Returns
Pointer to CGUIFitSprite.

◆ createFitSprite() [3/4]

CGUIFitSprite * Skylicht::CCanvas::createFitSprite ( const core::rectf & r,
SFrame * frame )

Create a fit sprite element with a rectangle and frame.

Parameters
rRectangle.
frameSprite frame.
Returns
Pointer to CGUIFitSprite.

◆ createFitSprite() [4/4]

CGUIFitSprite * Skylicht::CCanvas::createFitSprite ( SFrame * frame)

Create a fit sprite element with a frame as a child of root.

Parameters
frameSprite frame.
Returns
Pointer to CGUIFitSprite.

◆ createImage() [1/3]

CGUIImage * Skylicht::CCanvas::createImage ( )

Create an image element as a child of root.

Returns
Pointer to CGUIImage.

◆ createImage() [2/3]

CGUIImage * Skylicht::CCanvas::createImage ( CGUIElement * e,
const core::rectf & r )

Create an image element with a parent and rectangle.

Parameters
eParent element.
rRectangle for the image.
Returns
Pointer to CGUIImage.

◆ createImage() [3/3]

CGUIImage * Skylicht::CCanvas::createImage ( const core::rectf & r)

Create an image element with a rectangle as a child of root.

Parameters
rRectangle for the image.
Returns
Pointer to CGUIImage.

◆ createLayout() [1/3]

CGUILayout * Skylicht::CCanvas::createLayout ( )

Create a layout element as a child of root.

Returns
Pointer to CGUILayout.

◆ createLayout() [2/3]

CGUILayout * Skylicht::CCanvas::createLayout ( CGUIElement * e,
const core::rectf & r )

Create a layout element with a parent and rectangle.

Parameters
eParent element.
rRectangle.
Returns
Pointer to CGUILayout.

◆ createLayout() [3/3]

CGUILayout * Skylicht::CCanvas::createLayout ( const core::rectf & r)

Create a layout element with a rectangle.

Parameters
rRectangle.
Returns
Pointer to CGUILayout.

◆ createMask() [1/2]

CGUIMask * Skylicht::CCanvas::createMask ( CGUIElement * e,
const core::rectf & r )

Create a mask element with a parent and rectangle.

Parameters
eParent element.
rRectangle.
Returns
Pointer to CGUIMask.

◆ createMask() [2/2]

CGUIMask * Skylicht::CCanvas::createMask ( const core::rectf & r)

Create a mask element with a rectangle as a child of root.

Parameters
rRectangle.
Returns
Pointer to CGUIMask.

◆ createNullElement() [1/2]

virtual CGUIElement * Skylicht::CCanvas::createNullElement ( CGUIElement * parent,
const char * type )
virtual

Create a null GUI element by type (UTF-8).

Parameters
parentParent element.
typeType name.
Returns
Pointer to CGUIElement or derived type.

◆ createNullElement() [2/2]

virtual CGUIElement * Skylicht::CCanvas::createNullElement ( CGUIElement * parent,
const wchar_t * type )
virtual

Create a null GUI element by type (Unicode).

Parameters
parentParent element.
typeType name (wide char).
Returns
Pointer to CGUIElement or derived type.

◆ createRect() [1/3]

CGUIRect * Skylicht::CCanvas::createRect ( CGUIElement * e,
const core::rectf & r,
const video::SColor & c )

Create a rectangle element with a parent, rectangle, and color.

Parameters
eParent element.
rRectangle.
cColor.
Returns
Pointer to CGUIRect.

◆ createRect() [2/3]

CGUIRect * Skylicht::CCanvas::createRect ( const core::rectf & r,
const video::SColor & c )

Create a rectangle element with a rectangle and color.

Parameters
rRectangle.
cColor.
Returns
Pointer to CGUIRect.

◆ createRect() [3/3]

CGUIRect * Skylicht::CCanvas::createRect ( const video::SColor & c)

Create a rectangle element with a color as a child of root.

Parameters
cColor.
Returns
Pointer to CGUIRect.

◆ createSprite() [1/4]

CGUISprite * Skylicht::CCanvas::createSprite ( CGUIElement * e,
const core::rectf & r,
SFrame * frame )

Create a sprite element with a parent, rectangle, and frame.

Parameters
eParent element.
rRectangle.
frameSprite frame.
Returns
Pointer to CGUISprite.

◆ createSprite() [2/4]

CGUISprite * Skylicht::CCanvas::createSprite ( CGUIElement * e,
SFrame * frame )

Create a sprite element with a parent and frame.

Parameters
eParent element.
frameSprite frame.
Returns
Pointer to CGUISprite.

◆ createSprite() [3/4]

CGUISprite * Skylicht::CCanvas::createSprite ( const core::rectf & r,
SFrame * frame )

Create a sprite element with a rectangle and frame.

Parameters
rRectangle.
frameSprite frame.
Returns
Pointer to CGUISprite.

◆ createSprite() [4/4]

CGUISprite * Skylicht::CCanvas::createSprite ( SFrame * frame)

Create a sprite element with a frame as a child of root.

Parameters
frameSprite frame.
Returns
Pointer to CGUISprite.

◆ createText() [1/4]

CGUIText * Skylicht::CCanvas::createText ( CGUIElement * e,
const core::rectf & r,
IFont * font )

Create a text element with a parent, rectangle and font.

Parameters
eParent element.
rRectangle.
fontFont.
Returns
Pointer to CGUIText.

◆ createText() [2/4]

CGUIText * Skylicht::CCanvas::createText ( CGUIElement * e,
IFont * font )

Create a text element with a parent and font.

Parameters
eParent element.
fontFont.
Returns
Pointer to CGUIText.

◆ createText() [3/4]

CGUIText * Skylicht::CCanvas::createText ( const core::rectf & r,
IFont * font )

Create a text element with a rectangle and font as a child of root.

Parameters
rRectangle.
fontFont.
Returns
Pointer to CGUIText.

◆ createText() [4/4]

CGUIText * Skylicht::CCanvas::createText ( IFont * font)

Create a text element with a font as a child of root.

Parameters
fontFont for the text.
Returns
Pointer to CGUIText.

◆ getDefaultRect()

const core::rectf & Skylicht::CCanvas::getDefaultRect ( )
inline

Get the default rectangle.

Returns
Default rectangle.

◆ getElementsInChild()

template<typename T>
std::vector< T * > Skylicht::CCanvas::getElementsInChild ( bool addThis)

Find all child elements of a certain type.

Template Parameters
TType to search for.
Parameters
addThisIf true, include the root element.
Returns
Vector of pointers to found elements of type T.

◆ getEntityManager()

CEntityPrefab * Skylicht::CCanvas::getEntityManager ( )
inline

Get the entity manager.

Returns
Pointer to CEntityPrefab.

◆ getGUIByID()

CGUIElement * Skylicht::CCanvas::getGUIByID ( const char * id)

Find a GUI element by its ID.

Parameters
idString ID.
Returns
Pointer to CGUIElement, or NULL if not found.

◆ getGUIByPath() [1/2]

CGUIElement * Skylicht::CCanvas::getGUIByPath ( CGUIElement * search,
const char * path )

Find a GUI element by path starting from a specific element.

Parameters
searchStarting element.
pathString path.
Returns
Pointer to CGUIElement, or NULL if not found.

◆ getGUIByPath() [2/2]

CGUIElement * Skylicht::CCanvas::getGUIByPath ( const char * path)

Find a GUI element by its path (separated by / or ).

Parameters
pathString path.
Returns
Pointer to CGUIElement, or NULL if not found.

◆ getHitTest()

CGUIElement * Skylicht::CCanvas::getHitTest ( CCamera * camera,
float x,
float y,
const core::recti & viewport )

Perform hit-testing to find the GUI element under the given coordinates.

Parameters
cameraThe camera used for projection.
xScreen X coordinate.
yScreen Y coordinate.
viewportThe viewport rectangle.
Returns
Pointer to the hit CGUIElement, or NULL if none.

◆ getRenderCamera()

CCamera * Skylicht::CCanvas::getRenderCamera ( )
inline

Get the camera currently used for rendering.

Returns
Pointer to camera.

◆ getRenderWorldTransform()

const core::matrix4 & Skylicht::CCanvas::getRenderWorldTransform ( )
inline

Get the world transform matrix for rendering.

Returns
Reference to the matrix.

◆ getRootElement()

CGUIElement * Skylicht::CCanvas::getRootElement ( )
inline

Get the root GUI element.

Returns
Pointer to the root CGUIElement.

◆ getRootScale()

const core::vector3df & Skylicht::CCanvas::getRootScale ( )

Get the root element's scale vector.

Returns
Reference to the scale vector.

◆ getSortDepth()

int Skylicht::CCanvas::getSortDepth ( )
inline

Get the current sort depth value.

Returns
Depth value.

◆ initComponent()

virtual void Skylicht::CCanvas::initComponent ( )
virtual

Initialize the canvas component.

Implements Skylicht::CComponentSystem.

◆ is3DBillboardEnabled()

bool Skylicht::CCanvas::is3DBillboardEnabled ( )
inline

Check if 3D billboard rendering is enabled.

Returns
True if enabled.

◆ render()

void Skylicht::CCanvas::render ( CCamera * camera)

Render the GUI elements tree using the specified camera.

Parameters
cameraThe camera to use for rendering.

◆ searchGUI() [1/2]

CGUIElement * Skylicht::CCanvas::searchGUI ( CGUIElement * search,
const char * name )

Find a GUI element by name starting from a specific element.

Parameters
searchStarting element.
nameName of the element to find.
Returns
Pointer to CGUIElement, or NULL if not found.

◆ searchGUI() [2/2]

CGUIElement * Skylicht::CCanvas::searchGUI ( const char * name)

Find a GUI element by name.

Parameters
nameName of the element to find.
Returns
Pointer to CGUIElement, or NULL if not found.

◆ setDefaultRect()

void Skylicht::CCanvas::setDefaultRect ( const core::rectf & r)
inline

Set the default rectangle value.

Parameters
rRectangle value.

◆ setEnable3DBillboard()

void Skylicht::CCanvas::setEnable3DBillboard ( bool b)
inline

Enable or disable 3D billboard rendering.

Parameters
bTrue to enable.

◆ setRect()

void Skylicht::CCanvas::setRect ( const core::rectf & r)
inline

Set the canvas rectangle.

Parameters
rRectangle value.

◆ setRenderWorldTransform()

void Skylicht::CCanvas::setRenderWorldTransform ( core::matrix4 & w)
inline

Set the world transform matrix for rendering.

Parameters
wMatrix to set.

◆ setSortDepth()

void Skylicht::CCanvas::setSortDepth ( int d)
inline

Set the sort depth for rendering.

Parameters
dDepth value.

◆ updateComponent()

virtual void Skylicht::CCanvas::updateComponent ( )
virtual

Update the canvas component.

Implements Skylicht::CComponentSystem.


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