Skylicht Engine
Loading...
Searching...
No Matches
CGUIElement.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 "Camera/CCamera.h"
28#include "Material/CMaterial.h"
29
30#include "Graphics2D/EntityData/CGUITransformData.h"
31#include "Graphics2D/EntityData/CGUIAlignData.h"
32#include "Graphics2D/EntityData/CGUIRenderData.h"
33#include "Graphics2D/EntityData/CGUILayoutData.h"
34
35namespace Skylicht
36{
37 class CCanvas;
38 class CGUIMask;
39
50 class SKYLICHT_API CGUIElement
51 {
52 friend class CCanvas;
53
54 protected:
55 CGUIElement* m_parent;
56 std::vector<CGUIElement*> m_childs;
57
58 CCanvas* m_canvas;
59
60 CGUIMask* m_mask;
61 CGUIMask* m_applyCurrentMask;
62
63 bool m_drawBorder;
64 bool m_enableMaterial;
65
66 int m_renderOrder;
67
68 ArrayMaterial m_materials;
69
70 int m_materialId;
71
72 CEntity* m_entity;
73
74 CWorldTransformData* m_transform;
75 CGUITransformData* m_guiTransform;
76 CGUIAlignData* m_guiAlign;
77 CGUIRenderData* m_renderData;
78
79 std::string m_materialFile;
80
81 int m_tagInt;
82 std::string m_tagString;
83
84 public:
85
86 std::function<void(CGUIElement*)> OnRender;
87
88 protected:
89 CGUIElement(CCanvas* canvas, CGUIElement* parent);
90 CGUIElement(CCanvas* canvas, CGUIElement* parent, const core::rectf& rect);
91
92 inline void applyCurrentMask(CGUIMask* mask)
93 {
94 m_applyCurrentMask = mask;
95 }
96
97 inline CGUIMask* getCurrentMask()
98 {
99 return m_applyCurrentMask;
100 }
101
102 public:
103 virtual ~CGUIElement();
104
105 void remove();
106
107 void removeAllChilds();
108
109 public:
110
111 inline CCanvas* getCanvas()
112 {
113 return m_canvas;
114 }
115
116 inline CGUIElement* getParent()
117 {
118 return m_parent;
119 }
120
121 inline void setName(const char* name)
122 {
123 m_transform->Name = name;
124 }
125
126 inline const char* getName()
127 {
128 return m_transform->Name.c_str();
129 }
130
131 inline const char* getID()
132 {
133 return m_entity->getID().c_str();
134 }
135
136 inline void setTagInt(int i)
137 {
138 m_tagInt = i;
139 }
140
141 inline void setTagString(const char* s)
142 {
143 m_tagString = s;
144 }
145
146 inline int getTagInt()
147 {
148 return m_tagInt;
149 }
150
151 inline const std::string& getTagString()
152 {
153 return m_tagString;
154 }
155
156 void setName(const wchar_t* name);
157
158 std::wstring getNameW();
159
160 void setParent(CGUIElement* parent);
161
162 inline std::vector<CGUIElement*>& getChilds()
163 {
164 return m_childs;
165 }
166
167 void getAllChilds(std::vector<CGUIElement*>& childs);
168
169 inline void setColor(const SColor& c)
170 {
171 m_renderData->Color = c;
172 }
173
174 const SColor& getColor()
175 {
176 return m_renderData->getColor();
177 }
178
179 inline float getHeight()
180 {
181 return m_guiTransform->getHeight();
182 }
183
184 inline float getWidth()
185 {
186 return m_guiTransform->getWidth();
187 }
188
189 inline void setHeight(float h)
190 {
191 m_guiTransform->setHeight(h);
192 }
193
194 inline void setWidth(float w)
195 {
196 m_guiTransform->setWidth(w);
197 }
198
199 inline const core::rectf& getRect()
200 {
201 return m_guiTransform->getRect();
202 }
203
204 virtual const core::rectf getNativeRect();
205
206 inline int getDepth()
207 {
208 return m_transform->Depth;
209 }
210
211 inline int getRenderOrder()
212 {
213 return m_renderOrder;
214 }
215
216 inline void setDock(EGUIDock dock)
217 {
218 m_guiAlign->Dock = dock;
219 }
220
221 inline EGUIDock getDock()
222 {
223 return m_guiAlign->Dock;
224 }
225
226 inline const SMargin& getMargin()
227 {
228 return m_guiAlign->Margin;
229 }
230
231 inline void setMargin(const SMargin& m)
232 {
233 m_guiAlign->Margin = m;
234 }
235
236 inline void setMargin(float l, float t, float r, float b)
237 {
238 m_guiAlign->Margin.Left = l;
239 m_guiAlign->Margin.Top = t;
240 m_guiAlign->Margin.Right = r;
241 m_guiAlign->Margin.Bottom = b;
242 }
243
244 inline void setRect(const core::rectf& r)
245 {
246 m_guiTransform->setRect(r);
247 }
248
249 void setWorldTransform(const core::matrix4& world);
250
251 void setRelativeTransform(const core::matrix4& relative);
252
253 inline const core::vector3df getAlignPosition()
254 {
255 return m_guiTransform->getAlignPosition();
256 }
257
258 inline const core::vector3df& getPosition()
259 {
260 return m_guiTransform->getPosition();
261 }
262
263 inline void invalidate()
264 {
265 m_transform->HasChanged = true;
266 m_guiTransform->HasChanged = true;
267 }
268
269 inline void setPosition(const core::vector3df& v)
270 {
271 m_guiTransform->setPosition(v);
272 }
273
274 inline const core::vector3df& getScale()
275 {
276 return m_guiTransform->getScale();
277 }
278
279 inline void setScale(const core::vector3df& v)
280 {
281 m_guiTransform->setScale(v);
282 }
283
284 inline const core::vector3df& getRotation()
285 {
286 return m_guiTransform->getRotation();
287 }
288
289 inline void setRotation(const core::vector3df& v)
290 {
291 m_guiTransform->setRotation(v);
292 }
293
294 inline core::quaternion getRotationQuaternion()
295 {
296 return core::quaternion(getRotation() * core::DEGTORAD);
297 }
298
299 inline EGUIVerticalAlign getVerticalAlign()
300 {
301 return m_guiAlign->Vertical;
302 }
303
304 inline EGUIHorizontalAlign getHorizontalAlign()
305 {
306 return m_guiAlign->Horizontal;
307 }
308
309 inline void setVerticalAlign(EGUIVerticalAlign a)
310 {
311 m_guiAlign->Vertical = a;
312 }
313
314 inline void setHorizontalAlign(EGUIHorizontalAlign a)
315 {
316 m_guiAlign->Horizontal = a;
317 }
318
319 inline void setAlign(EGUIHorizontalAlign h, EGUIVerticalAlign v)
320 {
321 m_guiAlign->Vertical = v;
322 m_guiAlign->Horizontal = h;
323 }
324
325 inline void setShaderID(int id)
326 {
327 m_renderData->ShaderID = id;
328 }
329
330 inline int getShaderID()
331 {
332 return m_renderData->ShaderID;
333 }
334
335 inline int getMaterialId()
336 {
337 return m_materialId;
338 }
339
340 void setMaterialId(int id);
341
342 inline void setMaterial(CMaterial* material)
343 {
344 m_renderData->Material = material;
345 }
346
347 void setMaterialSource(const char* materialFile);
348
349 inline CMaterial* getMaterial()
350 {
351 return m_renderData->Material;
352 }
353
354 inline CGUIMask* getMask()
355 {
356 return m_mask;
357 }
358
359 CGUIMask* getParentMask();
360
361 inline void setMask(CGUIMask* mask)
362 {
363 m_mask = mask;
364 }
365
366 inline void setDrawBorder(bool b)
367 {
368 m_drawBorder = b;
369 }
370
371 inline bool isEnableMaterial()
372 {
373 return m_enableMaterial;
374 }
375
376 virtual void update(CCamera* camera);
377
378 virtual void render(CCamera* camera);
379
380 const core::matrix4& getRelativeTransform()
381 {
382 return m_transform->Relative;
383 }
384
385 const core::matrix4& getAbsoluteTransform()
386 {
387 return m_transform->World;
388 }
389 inline void setVisible(bool b)
390 {
391 m_entity->setVisible(b);
392 }
393
394 inline bool isVisible()
395 {
396 return m_entity->isVisible();
397 }
398
399 bool isVisibleInHierarchy();
400
401 inline CEntity* getEntity()
402 {
403 return m_entity;
404 }
405
406 void notifyChanged();
407
408 CGUIElement* getChildBefore(CGUIElement* object);
409
410 void bringToNext(CGUIElement* object, CGUIElement* target, bool behind);
411
412 void bringToChild(CGUIElement* object);
413
414 bool isChild(CGUIElement* e);
415
416 CGUIElement* getGUIByPath(const char* path);
417
418 virtual CObjectSerializable* createSerializable();
419
420 virtual void loadSerializable(CObjectSerializable* object);
421
422 void generateNewId();
423
424 DECLARE_GETTYPENAME(CGUIElement)
425
426 protected:
427
428 bool removeChild(CGUIElement* child);
429 };
430}
This is an object class used to set up the camera, including its position, viewing angle,...
Definition CCamera.h:70
This class manages GUI components, including creating and deleting images and sprites.
Definition CCanvas.h:79
This is the object class that describes an entity.
Definition CEntity.h:58
Definition CGUIAlignData.h:80
This is the object class that represents a masked rectangle, and other GUIs will only display within ...
Definition CGUIMask.h:48
Definition CGUIRenderData.h:33
Definition CGUITransformData.h:32
The object class describes material information such as which shader it's associated with,...
Definition CMaterial.h:84
Definition CObjectSerializable.h:36
Definition CWorldTransformData.h:32
Quaternion class for representing rotations.
Definition quaternion.h:27
Class representing a 32 bit ARGB color.
Definition SColor.h:285
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
const f32 DEGTORAD
32bit Constant for converting from degrees to radians
Definition irrMath.h:74
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2241
rect< f32 > rectf
Rectangle with float values.
Definition rect.h:271
Definition CGUIAlignData.h:56