Skylicht Engine
Loading...
Searching...
No Matches
CSpriteFrame.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
27namespace Skylicht
28{
29 class CAtlas;
30
31 struct SKYLICHT_API SImage
32 {
33 int ID;
34 std::string Path;
35 ITexture* Texture;
36 CAtlas* Atlas;
37
38 SImage()
39 {
40 ID = -1;
41 Texture = NULL;
42 Atlas = NULL;
43 }
44 };
45
46 struct SKYLICHT_API SModuleRect
47 {
48 int ID;
49 std::string Name;
50
51 float X;
52 float Y;
53 float W;
54 float H;
55
56 SModuleRect()
57 {
58 ID = -1;
59 X = -1;
60 Y = -1;
61 W = -1;
62 H = -1;
63 }
64 };
65
66 struct SFrame;
67
68 struct SKYLICHT_API SModuleOffset
69 {
70 SModuleRect* Module;
71 SFrame* Frame;
72
73 float OffsetX;
74 float OffsetY;
75 float XAdvance;
76 bool FlipX;
77 bool FlipY;
78
79 wchar_t Character;
80
81 SModuleOffset();
82
83 void getPositionBuffer(video::S3DVertex* vertices, u16* indices, int vertexOffset, const core::matrix4& mat, float scaleW = 1.0f, float scaleH = 1.0f);
84
85 void getPositionBuffer(video::S3DVertex* vertices, u16* indices, int vertexOffset, float offsetX, float offsetY, const core::matrix4& mat, float scaleW = 1.0f, float scaleH = 1.0f);
86
87 void getTexCoordBuffer(video::S3DVertex* vertices, float texWidth, float texHeight, float scaleW = 1.0f, float scaleH = 1.0f);
88
89 void getColorBuffer(video::S3DVertex* vertices, const SColor& c);
90 };
91
92 struct SKYLICHT_API SFrame
93 {
94 std::string ID;
95 std::string Name;
96 std::vector<SModuleOffset> ModuleOffset;
97 SImage* Image;
98 core::rectf BoudingRect;
99
100 SFrame()
101 {
102 ID = -1;
103 Image = NULL;
104 }
105
106 inline float getWidth()
107 {
108 return BoudingRect.getWidth();
109 }
110
111 inline float getHeight()
112 {
113 return BoudingRect.getHeight();
114 }
115 };
116
144 class SKYLICHT_API CSpriteFrame : public IReferenceCounted {
145 protected:
146 std::vector<SImage*> m_images;
147 std::vector<SFrame*> m_frames;
148 std::vector<SModuleRect*> m_modules;
149
150 std::map<std::string, SFrame*> m_names;
151 std::map<std::string, SFrame*> m_ids;
152
153 bool m_deleteAtlas;
154
155 std::string m_id;
156 std::string m_path;
157
158 public:
159 CSpriteFrame();
160
161 virtual ~CSpriteFrame();
162
163 bool load(const char* fileName);
164
165 inline std::vector<SFrame*>& getFrames()
166 {
167 return m_frames;
168 }
169
170 inline SFrame* getFrameByName(const char* name)
171 {
172 return m_names[name];
173 }
174
175 inline SFrame* getFrameById(const char* id)
176 {
177 return m_ids[id];
178 }
179
180 inline const char* getId()
181 {
182 return m_id.c_str();
183 }
184
185 inline const char* getPath()
186 {
187 return m_path.c_str();
188 }
189 };
190}
Definition CAtlas.h:30
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
Definition CSpriteFrame.h:93
Definition CSpriteFrame.h:32
Definition CSpriteFrame.h:47