![]() |
Skylicht Engine
|
This class manages GUI components, including creating and deleting images and sprites. More...
#include <Graphics2D/CCanvas.h>
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. | |
| CGUIElement * | getHitTest (CCamera *camera, float x, float y, const core::recti &viewport) |
| Perform hit-testing to find the GUI element under the given coordinates. | |
| CEntityPrefab * | getEntityManager () |
| 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::rectf & | getDefaultRect () |
| 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::vector3df & | getRootScale () |
| Get the root element's scale vector. | |
| CGUIElement * | getRootElement () |
| 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. | |
| CGUIElement * | createElement () |
| Create a generic GUI element as a child of root. | |
| CGUIElement * | createElement (const core::rectf &r) |
| Create a GUI element with a specific rectangle as a child of root. | |
| CGUIElement * | createElement (CGUIElement *e, const core::rectf &r) |
| Create a GUI element with a specific parent and rectangle. | |
| CGUIImage * | createImage () |
| Create an image element as a child of root. | |
| CGUIImage * | createImage (const core::rectf &r) |
| Create an image element with a rectangle as a child of root. | |
| CGUIImage * | createImage (CGUIElement *e, const core::rectf &r) |
| Create an image element with a parent and rectangle. | |
| CGUIText * | createText (IFont *font) |
| Create a text element with a font as a child of root. | |
| CGUIText * | createText (const core::rectf &r, IFont *font) |
| Create a text element with a rectangle and font as a child of root. | |
| CGUIText * | createText (CGUIElement *e, IFont *font) |
| Create a text element with a parent and font. | |
| CGUIText * | createText (CGUIElement *e, const core::rectf &r, IFont *font) |
| Create a text element with a parent, rectangle and font. | |
| CGUISprite * | createSprite (SFrame *frame) |
| Create a sprite element with a frame as a child of root. | |
| CGUISprite * | createSprite (const core::rectf &r, SFrame *frame) |
| Create a sprite element with a rectangle and frame. | |
| CGUISprite * | createSprite (CGUIElement *e, SFrame *frame) |
| Create a sprite element with a parent and frame. | |
| CGUISprite * | createSprite (CGUIElement *e, const core::rectf &r, SFrame *frame) |
| Create a sprite element with a parent, rectangle, and frame. | |
| CGUIMask * | createMask (const core::rectf &r) |
| Create a mask element with a rectangle as a child of root. | |
| CGUIMask * | createMask (CGUIElement *e, const core::rectf &r) |
| Create a mask element with a parent and rectangle. | |
| CGUIRect * | createRect (const video::SColor &c) |
| Create a rectangle element with a color as a child of root. | |
| CGUIRect * | createRect (const core::rectf &r, const video::SColor &c) |
| Create a rectangle element with a rectangle and color. | |
| CGUIRect * | createRect (CGUIElement *e, const core::rectf &r, const video::SColor &c) |
| Create a rectangle element with a parent, rectangle, and color. | |
| CGUIElipse * | createElipse (const video::SColor &c) |
| Create an elipse element with a color as a child of root. | |
| CGUIElipse * | createElipse (const core::rectf &r, const video::SColor &c) |
| Create an elipse element with a rectangle and color. | |
| CGUIElipse * | createElipse (CGUIElement *e, const core::rectf &r, const video::SColor &c) |
| Create an elipse element with a parent, rectangle, and color. | |
| CGUILayout * | createLayout () |
| Create a layout element as a child of root. | |
| CGUILayout * | createLayout (const core::rectf &r) |
| Create a layout element with a rectangle. | |
| CGUILayout * | createLayout (CGUIElement *e, const core::rectf &r) |
| Create a layout element with a parent and rectangle. | |
| CGUIFitSprite * | createFitSprite (SFrame *frame) |
| Create a fit sprite element with a frame as a child of root. | |
| CGUIFitSprite * | createFitSprite (const core::rectf &r, SFrame *frame) |
| Create a fit sprite element with a rectangle and frame. | |
| CGUIFitSprite * | createFitSprite (CGUIElement *e, SFrame *frame) |
| Create a fit sprite element with a parent and frame. | |
| CGUIFitSprite * | createFitSprite (CGUIElement *e, const core::rectf &r, SFrame *frame) |
| Create a fit sprite element with a parent, rectangle and frame. | |
| virtual CGUIElement * | createNullElement (CGUIElement *parent, const char *type) |
| Create a null GUI element by type (UTF-8). | |
| virtual CGUIElement * | createNullElement (CGUIElement *parent, const wchar_t *type) |
| Create a null GUI element by type (Unicode). | |
| const core::matrix4 & | getRenderWorldTransform () |
| Get the world transform matrix for rendering. | |
| void | setRenderWorldTransform (core::matrix4 &w) |
| Set the world transform matrix for rendering. | |
| CCamera * | getRenderCamera () |
| Get the camera currently used for rendering. | |
| CGUIElement * | getGUIByID (const char *id) |
| Find a GUI element by its ID. | |
| CGUIElement * | getGUIByPath (const char *path) |
| Find a GUI element by its path (separated by / or ). | |
| CGUIElement * | searchGUI (const char *name) |
| Find a GUI element by name. | |
| CGUIElement * | getGUIByPath (CGUIElement *search, const char *path) |
| Find a GUI element by path starting from a specific element. | |
| CGUIElement * | searchGUI (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 CObjectSerializable * | createSerializable () |
| 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. | |
| CGUIElement * | m_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. | |
| CCamera * | m_renderCamera |
| The camera currently used for rendering. | |
| CGUIMask * | m_currentMask |
| The current mask applied during rendering. | |
| CEntityPrefab * | m_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) |
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:
Skylicht-Editor
To design the GUI, open the Skylicht-Editor and switch to the GUI design window.
Setting
Working with .gui Files
You can save the design file to .gui formats and use CGUIImporter to load it into the Canvas.
| 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).
| widthOrHeight | Scale value (default = 1.0). |
| CGUIElement * Skylicht::CCanvas::createElement | ( | ) |
Create a generic GUI element as a child of root.
| CGUIElement * Skylicht::CCanvas::createElement | ( | CGUIElement * | e, |
| const core::rectf & | r ) |
Create a GUI element with a specific parent and rectangle.
| e | Parent element. |
| r | Rectangle for the element. |
| CGUIElement * Skylicht::CCanvas::createElement | ( | const core::rectf & | r | ) |
Create a GUI element with a specific rectangle as a child of root.
| r | Rectangle for the element. |
| CGUIElipse * Skylicht::CCanvas::createElipse | ( | CGUIElement * | e, |
| const core::rectf & | r, | ||
| const video::SColor & | c ) |
Create an elipse element with a parent, rectangle, and color.
| e | Parent element. |
| r | Rectangle. |
| c | Color. |
| CGUIElipse * Skylicht::CCanvas::createElipse | ( | const core::rectf & | r, |
| const video::SColor & | c ) |
Create an elipse element with a rectangle and color.
| r | Rectangle. |
| c | Color. |
| CGUIElipse * Skylicht::CCanvas::createElipse | ( | const video::SColor & | c | ) |
Create an elipse element with a color as a child of root.
| c | Color. |
| CGUIFitSprite * Skylicht::CCanvas::createFitSprite | ( | CGUIElement * | e, |
| const core::rectf & | r, | ||
| SFrame * | frame ) |
Create a fit sprite element with a parent, rectangle and frame.
| e | Parent element. |
| r | Rectangle. |
| frame | Sprite frame. |
| CGUIFitSprite * Skylicht::CCanvas::createFitSprite | ( | CGUIElement * | e, |
| SFrame * | frame ) |
Create a fit sprite element with a parent and frame.
| e | Parent element. |
| frame | Sprite frame. |
| CGUIFitSprite * Skylicht::CCanvas::createFitSprite | ( | const core::rectf & | r, |
| SFrame * | frame ) |
Create a fit sprite element with a rectangle and frame.
| r | Rectangle. |
| frame | Sprite frame. |
| CGUIFitSprite * Skylicht::CCanvas::createFitSprite | ( | SFrame * | frame | ) |
Create a fit sprite element with a frame as a child of root.
| frame | Sprite frame. |
| CGUIImage * Skylicht::CCanvas::createImage | ( | ) |
Create an image element as a child of root.
| CGUIImage * Skylicht::CCanvas::createImage | ( | CGUIElement * | e, |
| const core::rectf & | r ) |
Create an image element with a parent and rectangle.
| e | Parent element. |
| r | Rectangle for the image. |
| CGUIImage * Skylicht::CCanvas::createImage | ( | const core::rectf & | r | ) |
Create an image element with a rectangle as a child of root.
| r | Rectangle for the image. |
| CGUILayout * Skylicht::CCanvas::createLayout | ( | ) |
Create a layout element as a child of root.
| CGUILayout * Skylicht::CCanvas::createLayout | ( | CGUIElement * | e, |
| const core::rectf & | r ) |
Create a layout element with a parent and rectangle.
| e | Parent element. |
| r | Rectangle. |
| CGUILayout * Skylicht::CCanvas::createLayout | ( | const core::rectf & | r | ) |
| CGUIMask * Skylicht::CCanvas::createMask | ( | CGUIElement * | e, |
| const core::rectf & | r ) |
Create a mask element with a parent and rectangle.
| e | Parent element. |
| r | Rectangle. |
| CGUIMask * Skylicht::CCanvas::createMask | ( | const core::rectf & | r | ) |
Create a mask element with a rectangle as a child of root.
| r | Rectangle. |
|
virtual |
Create a null GUI element by type (UTF-8).
| parent | Parent element. |
| type | Type name. |
|
virtual |
Create a null GUI element by type (Unicode).
| parent | Parent element. |
| type | Type name (wide char). |
| CGUIRect * Skylicht::CCanvas::createRect | ( | CGUIElement * | e, |
| const core::rectf & | r, | ||
| const video::SColor & | c ) |
Create a rectangle element with a parent, rectangle, and color.
| e | Parent element. |
| r | Rectangle. |
| c | Color. |
| CGUIRect * Skylicht::CCanvas::createRect | ( | const core::rectf & | r, |
| const video::SColor & | c ) |
Create a rectangle element with a rectangle and color.
| r | Rectangle. |
| c | Color. |
| CGUIRect * Skylicht::CCanvas::createRect | ( | const video::SColor & | c | ) |
Create a rectangle element with a color as a child of root.
| c | Color. |
| CGUISprite * Skylicht::CCanvas::createSprite | ( | CGUIElement * | e, |
| const core::rectf & | r, | ||
| SFrame * | frame ) |
Create a sprite element with a parent, rectangle, and frame.
| e | Parent element. |
| r | Rectangle. |
| frame | Sprite frame. |
| CGUISprite * Skylicht::CCanvas::createSprite | ( | CGUIElement * | e, |
| SFrame * | frame ) |
Create a sprite element with a parent and frame.
| e | Parent element. |
| frame | Sprite frame. |
| CGUISprite * Skylicht::CCanvas::createSprite | ( | const core::rectf & | r, |
| SFrame * | frame ) |
Create a sprite element with a rectangle and frame.
| r | Rectangle. |
| frame | Sprite frame. |
| CGUISprite * Skylicht::CCanvas::createSprite | ( | SFrame * | frame | ) |
Create a sprite element with a frame as a child of root.
| frame | Sprite frame. |
| CGUIText * Skylicht::CCanvas::createText | ( | CGUIElement * | e, |
| const core::rectf & | r, | ||
| IFont * | font ) |
Create a text element with a parent, rectangle and font.
| e | Parent element. |
| r | Rectangle. |
| font | Font. |
| CGUIText * Skylicht::CCanvas::createText | ( | CGUIElement * | e, |
| IFont * | font ) |
Create a text element with a parent and font.
| e | Parent element. |
| font | Font. |
| CGUIText * Skylicht::CCanvas::createText | ( | const core::rectf & | r, |
| IFont * | font ) |
Create a text element with a rectangle and font as a child of root.
| r | Rectangle. |
| font | Font. |
Create a text element with a font as a child of root.
| font | Font for the text. |
|
inline |
Get the default rectangle.
| std::vector< T * > Skylicht::CCanvas::getElementsInChild | ( | bool | addThis | ) |
Find all child elements of a certain type.
| T | Type to search for. |
| addThis | If true, include the root element. |
|
inline |
Get the entity manager.
| CGUIElement * Skylicht::CCanvas::getGUIByID | ( | const char * | id | ) |
Find a GUI element by its ID.
| id | String ID. |
| CGUIElement * Skylicht::CCanvas::getGUIByPath | ( | CGUIElement * | search, |
| const char * | path ) |
Find a GUI element by path starting from a specific element.
| search | Starting element. |
| path | String path. |
| CGUIElement * Skylicht::CCanvas::getGUIByPath | ( | const char * | path | ) |
Find a GUI element by its path (separated by / or ).
| path | String path. |
| 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.
| camera | The camera used for projection. |
| x | Screen X coordinate. |
| y | Screen Y coordinate. |
| viewport | The viewport rectangle. |
|
inline |
Get the camera currently used for rendering.
|
inline |
Get the world transform matrix for rendering.
|
inline |
Get the root GUI element.
| const core::vector3df & Skylicht::CCanvas::getRootScale | ( | ) |
Get the root element's scale vector.
|
inline |
Get the current sort depth value.
|
virtual |
Initialize the canvas component.
Implements Skylicht::CComponentSystem.
|
inline |
Check if 3D billboard rendering is enabled.
| void Skylicht::CCanvas::render | ( | CCamera * | camera | ) |
Render the GUI elements tree using the specified camera.
| camera | The camera to use for rendering. |
| CGUIElement * Skylicht::CCanvas::searchGUI | ( | CGUIElement * | search, |
| const char * | name ) |
Find a GUI element by name starting from a specific element.
| search | Starting element. |
| name | Name of the element to find. |
| CGUIElement * Skylicht::CCanvas::searchGUI | ( | const char * | name | ) |
Find a GUI element by name.
| name | Name of the element to find. |
|
inline |
Set the default rectangle value.
| r | Rectangle value. |
|
inline |
Enable or disable 3D billboard rendering.
| b | True to enable. |
|
inline |
Set the canvas rectangle.
| r | Rectangle value. |
|
inline |
Set the world transform matrix for rendering.
| w | Matrix to set. |
|
inline |
Set the sort depth for rendering.
| d | Depth value. |
|
virtual |
Update the canvas component.
Implements Skylicht::CComponentSystem.