Skylicht Engine
Loading...
Searching...
No Matches
CGUISprite.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "CGUIElement.h"
28#include "Graphics2D/SpriteFrame/CSpriteFrame.h"
29
30namespace Skylicht
31{
53 class SKYLICHT_API CGUISprite : public CGUIElement
54 {
55 friend class CCanvas;
56 protected:
59
62
65
68
71
74
77
80 float m_defaultOffsetY;
81
83 std::string m_guid;
84 std::string m_frameName;
85 std::string m_sprite;
86 std::string m_spriteId;
87
88 protected:
95 CGUISprite(CCanvas* canvas, CGUIElement* parent, SFrame* frame);
96
104 CGUISprite(CCanvas* canvas, CGUIElement* parent, const core::rectf& rect, SFrame* frame);
105
106 public:
110 virtual ~CGUISprite();
111
116 virtual void update(CCamera* camera);
117
122 virtual void render(CCamera* camera);
123
131 virtual const core::rectf getNativeRect();
132
137 inline void setFrame(SFrame* frame)
138 {
139 m_frame = frame;
140 }
141
146 inline SFrame* getFrame()
147 {
148 return m_frame;
149 }
150
155 inline const char* getFrameName()
156 {
157 return m_frameName.c_str();
158 }
159
164 inline const char* getSpriteName()
165 {
166 return m_sprite.c_str();
167 }
168
173 inline const char* getSpriteId()
174 {
175 return m_spriteId.c_str();
176 }
177
182 inline const char* getFrameId()
183 {
184 return m_guid.c_str();
185 }
186
191 inline void setStretch(bool b)
192 {
193 m_stretch = b;
194 }
195
200 inline bool isStretch()
201 {
202 return m_stretch;
203 }
204
209
216 void setFrameSource(const char* spritePath, const char* frameName, const char* editorFileRef = NULL);
217
224 void setAutoRotate(bool rotate, float rotateAngle, float framePerSec);
225
230
235
241 void setOffsetModule(float x, float y);
242
248
254
255 DECLARE_GETTYPENAME(CGUISprite)
256 };
257}
This is an object class used to set up the camera, including its position, viewing angle,...
Definition CCamera.h:70
virtual CObjectSerializable * createSerializable()
Create a serializable object for saving state.
void setStretch(bool b)
Set stretching mode.
Definition CGUISprite.h:191
void setOffsetModule(float x, float y)
Set manual offset for the module.
virtual void loadSerializable(CObjectSerializable *object)
Load state from a serializable object.
void setAlignCenterModule()
Align the frame to the center.
void setAlignModuleDefault()
Restore the default module alignment.
void setFrame(SFrame *frame)
Set the sprite frame to display.
Definition CGUISprite.h:137
virtual void render(CCamera *camera)
Render the sprite frame.
bool m_autoRotate
Enables auto - rotation of the sprite.
Definition CGUISprite.h:61
CGUISprite(CCanvas *canvas, CGUIElement *parent, SFrame *frame)
Constructor with frame.
const char * getFrameName()
Get the frame name.
Definition CGUISprite.h:155
const char * getSpriteName()
Get the sprite name (path).
Definition CGUISprite.h:164
std::string m_guid
Identifiers for serialization and sprite management.
Definition CGUISprite.h:83
const char * getFrameId()
Get the frame ID (GUID).
Definition CGUISprite.h:182
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.
bool isStretch()
Check whether stretching is enabled.
Definition CGUISprite.h:200
float m_animationTime
Time accumulator for animation.
Definition CGUISprite.h:70
void reloadSpriteFrame()
Reload the sprite frame by stored identifiers.
SFrame * m_frame
Pointer to the current sprite frame.
Definition CGUISprite.h:58
bool m_stretch
Enables stretching the sprite to fill the rectangle.
Definition CGUISprite.h:73
const char * getSpriteId()
Get the sprite ID.
Definition CGUISprite.h:173
virtual void update(CCamera *camera)
Update element state (auto-rotation, etc.).
bool m_isCenter
Flag the frame is centered.
Definition CGUISprite.h:76
SFrame * getFrame()
Get the current sprite frame.
Definition CGUISprite.h:146
virtual const core::rectf getNativeRect()
Get the native rectangle of the frame. The native rectangle is a rectangle whose size matches the siz...
float m_defaultOffsetX
Default offsets for module alignment.
Definition CGUISprite.h:79
float m_frameSpeed
Interval between rotations(milliseconds).
Definition CGUISprite.h:67
CGUISprite(CCanvas *canvas, CGUIElement *parent, const core::rectf &rect, SFrame *frame)
Constructor with rectangle and frame.
float m_frameRotate
Rotation angle per frame(degrees).
Definition CGUISprite.h:64
virtual ~CGUISprite()
Destructor.
Definition CObjectSerializable.h:36
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
rect< f32 > rectf
Rectangle with float values.
Definition rect.h:271
Definition CSpriteFrame.h:93