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

This is the object class for displaying a frame image in sprite. More...

#include <Graphics2D/GUI/CGUISprite.h>

Inheritance diagram for Skylicht::CGUISprite:
Skylicht::CGUIElement

Public Member Functions

virtual ~CGUISprite ()
 Destructor.
virtual void update (CCamera *camera)
 Update element state (auto-rotation, etc.).
virtual void render (CCamera *camera)
 Render the sprite frame.
virtual const core::rectf getNativeRect ()
 Get the native rectangle of the frame. The native rectangle is a rectangle whose size matches the size of the frame. It is useful for positioning or aligning the sprite in the GUI according to its actual image dimensions.
void setFrame (SFrame *frame)
 Set the sprite frame to display.
SFramegetFrame ()
 Get the current sprite frame.
const char * getFrameName ()
 Get the frame name.
const char * getSpriteName ()
 Get the sprite name (path).
const char * getSpriteId ()
 Get the sprite ID.
const char * getFrameId ()
 Get the frame ID (GUID).
void setStretch (bool b)
 Set stretching mode.
bool isStretch ()
 Check whether stretching is enabled.
void reloadSpriteFrame ()
 Reload the sprite frame by stored identifiers.
void setFrameSource (const char *spritePath, const char *frameName, const char *editorFileRef=NULL)
 Set the frame source by sprite path and frame name.
void setAutoRotate (bool rotate, float rotateAngle, float framePerSec)
 Enable auto-rotation with parameters.
void setAlignCenterModule ()
 Align the frame to the center.
void setAlignModuleDefault ()
 Restore the default module alignment.
void setOffsetModule (float x, float y)
 Set manual offset for the module.
virtual CObjectSerializablecreateSerializable ()
 Create a serializable object for saving state.
virtual void loadSerializable (CObjectSerializable *object)
 Load state from a serializable object.
Public Member Functions inherited from Skylicht::CGUIElement
void remove ()
void removeAllChilds ()
CCanvas * getCanvas ()
CGUIElement * getParent ()
void setName (const char *name)
const char * getName ()
const char * getID ()
void setTagInt (int i)
void setTagString (const char *s)
int getTagInt ()
const std::string & getTagString ()
void setName (const wchar_t *name)
std::wstring getNameW ()
void setParent (CGUIElement *parent)
std::vector< CGUIElement * > & getChilds ()
void getAllChilds (std::vector< CGUIElement * > &childs)
void setColor (const SColor &c)
const SColorgetColor ()
float getHeight ()
float getWidth ()
void setHeight (float h)
void setWidth (float w)
const core::rectfgetRect ()
int getDepth ()
int getRenderOrder ()
void setDock (EGUIDock dock)
EGUIDock getDock ()
const SMargingetMargin ()
void setMargin (const SMargin &m)
void setMargin (float l, float t, float r, float b)
void setRect (const core::rectf &r)
void setWorldTransform (const core::matrix4 &world)
void setRelativeTransform (const core::matrix4 &relative)
const core::vector3df getAlignPosition ()
const core::vector3dfgetPosition ()
void invalidate ()
void setPosition (const core::vector3df &v)
const core::vector3dfgetScale ()
void setScale (const core::vector3df &v)
const core::vector3dfgetRotation ()
void setRotation (const core::vector3df &v)
core::quaternion getRotationQuaternion ()
EGUIVerticalAlign getVerticalAlign ()
EGUIHorizontalAlign getHorizontalAlign ()
void setVerticalAlign (EGUIVerticalAlign a)
void setHorizontalAlign (EGUIHorizontalAlign a)
void setAlign (EGUIHorizontalAlign h, EGUIVerticalAlign v)
void setShaderID (int id)
int getShaderID ()
int getMaterialId ()
void setMaterialId (int id)
void setMaterial (CMaterial *material)
void setMaterialSource (const char *materialFile)
CMaterialgetMaterial ()
CGUIMaskgetMask ()
CGUIMaskgetParentMask ()
void setMask (CGUIMask *mask)
void setDrawBorder (bool b)
bool isEnableMaterial ()
const core::matrix4getRelativeTransform ()
const core::matrix4getAbsoluteTransform ()
void setVisible (bool b)
bool isVisible ()
bool isVisibleInHierarchy ()
CEntitygetEntity ()
void notifyChanged ()
CGUIElement * getChildBefore (CGUIElement *object)
void bringToNext (CGUIElement *object, CGUIElement *target, bool behind)
void bringToChild (CGUIElement *object)
bool isChild (CGUIElement *e)
CGUIElement * getGUIByPath (const char *path)
void generateNewId ()

Protected Member Functions

 CGUISprite (CCanvas *canvas, CGUIElement *parent, SFrame *frame)
 Constructor with frame.
 CGUISprite (CCanvas *canvas, CGUIElement *parent, const core::rectf &rect, SFrame *frame)
 Constructor with rectangle and frame.
Protected Member Functions inherited from Skylicht::CGUIElement
 CGUIElement (CCanvas *canvas, CGUIElement *parent)
 CGUIElement (CCanvas *canvas, CGUIElement *parent, const core::rectf &rect)
void applyCurrentMask (CGUIMask *mask)
CGUIMaskgetCurrentMask ()
bool removeChild (CGUIElement *child)

Protected Attributes

SFramem_frame
 Pointer to the current sprite frame.
bool m_autoRotate
 Enables auto - rotation of the sprite.
float m_frameRotate
 Rotation angle per frame(degrees).
float m_frameSpeed
 Interval between rotations(milliseconds).
float m_animationTime
 Time accumulator for animation.
bool m_stretch
 Enables stretching the sprite to fill the rectangle.
bool m_isCenter
 Flag the frame is centered.
float m_defaultOffsetX
 Default offsets for module alignment.
float m_defaultOffsetY
std::string m_guid
 Identifiers for serialization and sprite management.
std::string m_frameName
std::string m_sprite
std::string m_spriteId
Protected Attributes inherited from Skylicht::CGUIElement
CGUIElement * m_parent
std::vector< CGUIElement * > m_childs
CCanvas * m_canvas
CGUIMaskm_mask
CGUIMaskm_applyCurrentMask
bool m_drawBorder
bool m_enableMaterial
int m_renderOrder
ArrayMaterial m_materials
int m_materialId
CEntitym_entity
CWorldTransformDatam_transform
CGUITransformDatam_guiTransform
CGUIAlignDatam_guiAlign
CGUIRenderDatam_renderData
std::string m_materialFile
int m_tagInt
std::string m_tagString

Friends

class CCanvas

Additional Inherited Members

Public Attributes inherited from Skylicht::CGUIElement
std::function< void(CGUIElement *)> OnRender

Detailed Description

This is the object class for displaying a frame image in sprite.

See also
CSpriteFrame

CGUISprite is used to render a frame from a sprite sheet in the GUI. It supports features such as auto - rotation, stretching to fit its rectangle, alignment, offset, and serialization. Managed by CCanvas, this element is useful for icons, buttons, and other image - based GUI components.

Example usage:

CSpriteFrame* sprite = CSpriteManager::getInstance()->loadSprite("Assets/SampleGUI/SampleGUI.spritedata")
SFrame* frame = sprite->getFrame("skylicht-icon");
CCanvas *canvas = gameobject->addComponent<CCanvas>();
core::rectf r(0.0f, 0.0f, 100.0f, 100.0f);
CGUISprite* gui = canvas->createSprite(r, frame);
This class manages GUI components, including creating and deleting images and sprites.
Definition CCanvas.h:79
CGUISprite * createSprite(SFrame *frame)
Create a sprite element with a frame as a child of root.
CGUISprite(CCanvas *canvas, CGUIElement *parent, SFrame *frame)
Constructor with frame.
The object class holds data on an image, including the locations of sprites and frames on it.
Definition CSpriteFrame.h:144
rect< f32 > rectf
Rectangle with float values.
Definition rect.h:271
The gui namespace contains useful classes for easy creation of a graphical user interface.
Definition ICursorControl.h:15
Definition CSpriteFrame.h:93

Constructor & Destructor Documentation

◆ CGUISprite() [1/2]

Skylicht::CGUISprite::CGUISprite ( CCanvas * canvas,
CGUIElement * parent,
SFrame * frame )
protected

Constructor with frame.

Parameters
canvasPointer to the parent canvas.
parentPointer to the parent element.
framePointer to the sprite frame.

◆ CGUISprite() [2/2]

Skylicht::CGUISprite::CGUISprite ( CCanvas * canvas,
CGUIElement * parent,
const core::rectf & rect,
SFrame * frame )
protected

Constructor with rectangle and frame.

Parameters
canvasPointer to the parent canvas.
parentPointer to the parent element.
rectRectangle for the sprite.
framePointer to the sprite frame.

Member Function Documentation

◆ createSerializable()

virtual CObjectSerializable * Skylicht::CGUISprite::createSerializable ( )
virtual

Create a serializable object for saving state.

Returns
Pointer to the serializable object.

Reimplemented from Skylicht::CGUIElement.

◆ getFrame()

SFrame * Skylicht::CGUISprite::getFrame ( )
inline

Get the current sprite frame.

Returns
Pointer to the frame.

◆ getFrameId()

const char * Skylicht::CGUISprite::getFrameId ( )
inline

Get the frame ID (GUID).

Returns
Frame ID string.

◆ getFrameName()

const char * Skylicht::CGUISprite::getFrameName ( )
inline

Get the frame name.

Returns
Frame name string.

◆ getNativeRect()

virtual const core::rectf Skylicht::CGUISprite::getNativeRect ( )
virtual

Get the native rectangle of the frame. The native rectangle is a rectangle whose size matches the size of the frame. It is useful for positioning or aligning the sprite in the GUI according to its actual image dimensions.

Returns
Rectangle in local coordinates with width and height equal to the frame's size.

Reimplemented from Skylicht::CGUIElement.

◆ getSpriteId()

const char * Skylicht::CGUISprite::getSpriteId ( )
inline

Get the sprite ID.

Returns
Sprite ID string.

◆ getSpriteName()

const char * Skylicht::CGUISprite::getSpriteName ( )
inline

Get the sprite name (path).

Returns
Sprite name string.

◆ isStretch()

bool Skylicht::CGUISprite::isStretch ( )
inline

Check whether stretching is enabled.

Returns
True if stretching, false otherwise.

◆ loadSerializable()

virtual void Skylicht::CGUISprite::loadSerializable ( CObjectSerializable * object)
virtual

Load state from a serializable object.

Parameters
objectPointer to the serializable object.

Reimplemented from Skylicht::CGUIElement.

◆ render()

virtual void Skylicht::CGUISprite::render ( CCamera * camera)
virtual

Render the sprite frame.

Parameters
cameraPointer to the camera.

Reimplemented from Skylicht::CGUIElement.

◆ setAutoRotate()

void Skylicht::CGUISprite::setAutoRotate ( bool rotate,
float rotateAngle,
float framePerSec )

Enable auto-rotation with parameters.

Parameters
rotateEnable/disable auto-rotation.
rotateAngleRotation angle per frame.
framePerSecRotation speed (frames per second).

◆ setFrame()

void Skylicht::CGUISprite::setFrame ( SFrame * frame)
inline

Set the sprite frame to display.

Parameters
framePointer to the new frame.

◆ setFrameSource()

void Skylicht::CGUISprite::setFrameSource ( const char * spritePath,
const char * frameName,
const char * editorFileRef = NULL )

Set the frame source by sprite path and frame name.

Parameters
spritePathPath to the sprite.
frameNameName of the frame.
editorFileRefOptional editor reference name.

◆ setOffsetModule()

void Skylicht::CGUISprite::setOffsetModule ( float x,
float y )

Set manual offset for the module.

Parameters
xOffset X.
yOffset Y.

◆ setStretch()

void Skylicht::CGUISprite::setStretch ( bool b)
inline

Set stretching mode.

Parameters
bEnable/disable stretching.

◆ update()

virtual void Skylicht::CGUISprite::update ( CCamera * camera)
virtual

Update element state (auto-rotation, etc.).

Parameters
cameraPointer to the camera.

Reimplemented from Skylicht::CGUIElement.


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