Skylicht Engine
Loading...
Searching...
No Matches
CValuePropertyTemplate.h
1/*
2!@
3MIT License
4
5Copyright (c) 2020 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 "CValueProperty.h"
28
29namespace Skylicht
30{
31 template<class T>
32 class SKYLICHT_API CValuePropertyTemplate : public CValueProperty
33 {
34 protected:
35 T m_value;
36
37 public:
38 CValuePropertyTemplate(CObjectSerializable* owner, EPropertyDataType dataType, const char* name) :
39 CValueProperty(owner, dataType, name)
40 {
41 }
42
43 virtual ~CValuePropertyTemplate()
44 {
45
46 }
47
48 inline void set(const T& v)
49 {
50 m_value = v;
51 }
52
53 inline const T& get() const
54 {
55 return m_value;
56 }
57
58 T& operator*()
59 {
60 return m_value;
61 }
62 };
63
64 class SKYLICHT_API CIntProperty : public CValuePropertyTemplate<int>
65 {
66 public:
67 int Min;
68 int Max;
69 bool ClampMin;
70 bool ClampMax;
71
72 public:
73 CIntProperty() :
74 CIntProperty(NULL, "CIntProperty")
75 {
76 }
77
78 CIntProperty(CObjectSerializable* owner, const char* name) :
79 CValuePropertyTemplate(owner, Integer, name),
80 Min(INT_MIN),
81 Max(INT_MAX),
82 ClampMin(false),
83 ClampMax(false)
84 {
85 set(0);
86 }
87
88 CIntProperty(CObjectSerializable* owner, const char* name, int value) :
89 CValuePropertyTemplate(owner, Integer, name),
90 Min(INT_MIN),
91 Max(INT_MAX),
92 ClampMin(false),
93 ClampMax(false)
94 {
95 set(value);
96 }
97
98 CIntProperty(CObjectSerializable* owner, const char* name, int value, int min) :
99 CValuePropertyTemplate(owner, Integer, name),
100 Min(min),
101 Max(INT_MAX),
102 ClampMin(true),
103 ClampMax(false)
104 {
105 set(value);
106 }
107
108 CIntProperty(CObjectSerializable* owner, const char* name, int value, int min, int max) :
109 CValuePropertyTemplate(owner, Integer, name),
110 Min(min),
111 Max(max),
112 ClampMin(true),
113 ClampMax(true)
114 {
115 set(value);
116 }
117
118 virtual void serialize(io::IAttributes* io)
119 {
120 io->addInt(Name.c_str(), m_value);
121 }
122
123 virtual void deserialize(io::IAttributes* io)
124 {
125 m_value = io->getAttributeAsInt(Name.c_str(), m_value);
126 }
127
128 virtual CValueProperty* clone()
129 {
130 CIntProperty* value = new CIntProperty(NULL, Name.c_str());
131 value->m_value = m_value;
132 value->Min = Min;
133 value->Max = Max;
134 value->ClampMin = ClampMin;
135 value->ClampMax = ClampMax;
136 return value;
137 }
138 };
139
140 class SKYLICHT_API CUIntProperty : public CValuePropertyTemplate<u32>
141 {
142 public:
143 u32 Max;
144 bool ClampMax;
145
146 public:
147 CUIntProperty() :
148 CUIntProperty(NULL, "CUIntProperty")
149 {
150 }
151
152 CUIntProperty(CObjectSerializable* owner, const char* name) :
153 CValuePropertyTemplate(owner, UInteger, name),
154 Max(UINT_MAX),
155 ClampMax(false)
156 {
157 set(0);
158 }
159
160 CUIntProperty(CObjectSerializable* owner, const char* name, u32 value) :
161 CValuePropertyTemplate(owner, UInteger, name),
162 Max(UINT_MAX),
163 ClampMax(false)
164 {
165 set(value);
166 }
167
168 CUIntProperty(CObjectSerializable* owner, const char* name, u32 value, u32 max) :
169 CValuePropertyTemplate(owner, UInteger, name),
170 Max(max),
171 ClampMax(true)
172 {
173 set(value);
174 }
175
176 virtual void serialize(io::IAttributes* io)
177 {
178 io->addUInt(Name.c_str(), m_value);
179 }
180
181 virtual void deserialize(io::IAttributes* io)
182 {
183 m_value = io->getAttributeAsInt(Name.c_str(), m_value);
184 }
185
186 virtual CValueProperty* clone()
187 {
188 CUIntProperty* value = new CUIntProperty(NULL, Name.c_str());
189 value->m_value = m_value;
190 value->Max = Max;
191 value->ClampMax = ClampMax;
192 return value;
193 }
194 };
195
196 class SKYLICHT_API CFloatProperty : public CValuePropertyTemplate<float>
197 {
198 public:
199 float Min;
200 float Max;
201 bool ClampMin;
202 bool ClampMax;
203
204 public:
205 CFloatProperty() :
206 CFloatProperty(NULL, "CFloatProperty")
207 {
208 }
209
210 CFloatProperty(CObjectSerializable* owner, const char* name) :
211 CValuePropertyTemplate(owner, Float, name),
212 ClampMin(false),
213 ClampMax(false),
214 Min(-FLT_MAX),
215 Max(FLT_MAX)
216 {
217 set(0.0f);
218 }
219
220 CFloatProperty(CObjectSerializable* owner, const char* name, float value) :
221 CValuePropertyTemplate(owner, Float, name),
222 ClampMin(false),
223 ClampMax(false),
224 Min(-FLT_MAX),
225 Max(FLT_MAX)
226 {
227 set(value);
228 }
229
230 CFloatProperty(CObjectSerializable* owner, const char* name, float value, float min, float max) :
231 CValuePropertyTemplate(owner, Float, name),
232 ClampMin(true),
233 ClampMax(true),
234 Min(min),
235 Max(max)
236 {
237 set(value);
238 }
239
240 CFloatProperty(CObjectSerializable* owner, const char* name, float value, float min) :
241 CValuePropertyTemplate(owner, Float, name),
242 ClampMin(true),
243 ClampMax(false),
244 Min(min),
245 Max(FLT_MAX)
246 {
247 set(value);
248 }
249
250 virtual void serialize(io::IAttributes* io)
251 {
252 io->addFloat(Name.c_str(), m_value);
253 }
254
255 virtual void deserialize(io::IAttributes* io)
256 {
257 m_value = io->getAttributeAsFloat(Name.c_str(), m_value);
258 }
259
260 virtual CValueProperty* clone()
261 {
262 CFloatProperty* value = new CFloatProperty(NULL, Name.c_str());
263 value->m_value = m_value;
264 value->Min = Min;
265 value->Max = Max;
266 value->ClampMin = ClampMin;
267 value->ClampMax = ClampMax;
268 return value;
269 }
270 };
271
272 class SKYLICHT_API CDoubleProperty : public CValuePropertyTemplate<double>
273 {
274 public:
275 double Min;
276 double Max;
277 bool ClampMin;
278 bool ClampMax;
279
280 public:
281 CDoubleProperty() :
282 CDoubleProperty(NULL, "CDoubleProperty")
283 {
284
285 }
286
287 CDoubleProperty(CObjectSerializable* owner, const char* name) :
288 CValuePropertyTemplate(owner, Double, name),
289 ClampMin(false),
290 ClampMax(false),
291 Min(-FLT_MAX),
292 Max(FLT_MAX)
293 {
294 set(0.0);
295 }
296
297 CDoubleProperty(CObjectSerializable* owner, const char* name, double value) :
298 CValuePropertyTemplate(owner, Double, name),
299 ClampMin(false),
300 ClampMax(false),
301 Min(-FLT_MAX),
302 Max(FLT_MAX)
303 {
304 set(value);
305 }
306
307 CDoubleProperty(CObjectSerializable* owner, const char* name, double value, double min, double max) :
308 CValuePropertyTemplate(owner, Double, name),
309 ClampMin(true),
310 ClampMax(true),
311 Min(min),
312 Max(max)
313 {
314 set(value);
315 }
316
317 CDoubleProperty(CObjectSerializable* owner, const char* name, double value, double min) :
318 CValuePropertyTemplate(owner, Double, name),
319 ClampMin(true),
320 ClampMax(false),
321 Min(min),
322 Max(FLT_MAX)
323 {
324 set(value);
325 }
326
327 virtual void serialize(io::IAttributes* io)
328 {
329 io->addDouble(Name.c_str(), m_value);
330 }
331
332 virtual void deserialize(io::IAttributes* io)
333 {
334 m_value = io->getAttributeAsDouble(Name.c_str(), m_value);
335 }
336
337 virtual CValueProperty* clone()
338 {
339 CDoubleProperty* value = new CDoubleProperty(NULL, Name.c_str());
340 value->m_value = m_value;
341 value->Min = Min;
342 value->Max = Max;
343 value->ClampMin = ClampMin;
344 value->ClampMax = ClampMax;
345 return value;
346 }
347 };
348
349 class SKYLICHT_API CStringProperty : public CValuePropertyTemplate<std::string>
350 {
351 public:
352 CStringProperty() :
353 CStringProperty(NULL, "CStringProperty")
354 {
355 }
356
357 CStringProperty(CObjectSerializable* owner, const char* name) :
358 CValuePropertyTemplate(owner, String, name)
359 {
360 }
361
362 CStringProperty(CObjectSerializable* owner, const char* name, const char* value) :
363 CValuePropertyTemplate(owner, String, name)
364 {
365 set(value);
366 }
367
368 [[deprecated("Use cstr() instead")]]
369 const char* getString()
370 {
371 return m_value.c_str();
372 }
373
374 const char* cstr()
375 {
376 return m_value.c_str();
377 }
378
379 virtual void serialize(io::IAttributes* io)
380 {
381 io->addString(Name.c_str(), m_value.c_str());
382 }
383
384 virtual void deserialize(io::IAttributes* io)
385 {
386 m_value = io->getAttributeAsString(Name.c_str(), m_value.c_str()).c_str();
387 }
388
389 virtual CValueProperty* clone()
390 {
391 CStringProperty* value = new CStringProperty(NULL, Name.c_str());
392 value->m_value = m_value;
393 return value;
394 }
395 };
396
397 class SKYLICHT_API CFolderPathProperty : public CValuePropertyTemplate<std::string>
398 {
399 public:
400 CFolderPathProperty() :
401 CFolderPathProperty(NULL, "CFolderPathProperty")
402 {
403 }
404
405 CFolderPathProperty(CObjectSerializable* owner, const char* name) :
406 CValuePropertyTemplate(owner, FolderPath, name)
407 {
408 }
409
410 CFolderPathProperty(CObjectSerializable* owner, const char* name, const char* value) :
411 CValuePropertyTemplate(owner, FolderPath, name)
412 {
413 set(value);
414 }
415
416 [[deprecated("Use cstr() instead")]]
417 const char* getString()
418 {
419 return m_value.c_str();
420 }
421
422 const char* cstr()
423 {
424 return m_value.c_str();
425 }
426
427 virtual void serialize(io::IAttributes* io)
428 {
429 io->addString(Name.c_str(), m_value.c_str());
430 }
431
432 virtual void deserialize(io::IAttributes* io)
433 {
434 m_value = io->getAttributeAsString(Name.c_str(), m_value.c_str()).c_str();
435 }
436
437 virtual CValueProperty* clone()
438 {
439 CFolderPathProperty* value = new CFolderPathProperty(NULL, Name.c_str());
440 value->m_value = m_value;
441 return value;
442 }
443 };
444
445 class SKYLICHT_API CFilePathProperty : public CValuePropertyTemplate<std::string>
446 {
447 public:
448 std::vector<std::string> Exts;
449
450 public:
451 CFilePathProperty() :
452 CFilePathProperty(NULL, "CFilePathProperty")
453 {
454 }
455
456 CFilePathProperty(CObjectSerializable* owner, const char* name) :
457 CValuePropertyTemplate(owner, FilePath, name)
458 {
459 }
460
461 CFilePathProperty(CObjectSerializable* owner, const char* name, const char* value, const std::vector<std::string>& exts) :
462 CValuePropertyTemplate(owner, FilePath, name)
463 {
464 Exts = exts;
465 set(value);
466 }
467
468 CFilePathProperty(CObjectSerializable* owner, const char* name, const char* value, const char* ext) :
469 CValuePropertyTemplate(owner, FilePath, name)
470 {
471 Exts.push_back(ext);
472 set(value);
473 }
474
475 [[deprecated("Use cstr() instead")]]
476 const char* getString()
477 {
478 return m_value.c_str();
479 }
480
481 const char* cstr()
482 {
483 return m_value.c_str();
484 }
485
486 virtual void serialize(io::IAttributes* io)
487 {
488 io->addString(Name.c_str(), m_value.c_str());
489 }
490
491 virtual void deserialize(io::IAttributes* io)
492 {
493 m_value = io->getAttributeAsString(Name.c_str(), m_value.c_str()).c_str();
494 }
495
496 virtual CValueProperty* clone()
497 {
498 CFilePathProperty* value = new CFilePathProperty(NULL, Name.c_str());
499 value->m_value = m_value;
500 value->Exts = Exts;
501 return value;
502 }
503 };
504
505 class SKYLICHT_API CGUIDResourceProperty : public CValuePropertyTemplate<std::string>
506 {
507 protected:
508 std::string m_guid;
509
510 public:
511 CGUIDResourceProperty(CObjectSerializable* owner, EPropertyDataType dataType, const char* name) :
512 CValuePropertyTemplate(owner, dataType, name)
513 {
514
515 }
516
517 [[deprecated("Use cstr() instead")]]
518 const char* getString()
519 {
520 return m_value.c_str();
521 }
522
523 const char* cstr()
524 {
525 return m_value.c_str();
526 }
527
528 virtual void serialize(io::IAttributes* io)
529 {
530 io->addString(Name.c_str(), m_value.c_str());
531
532 std::string GUID = Name;
533 GUID += ".guid";
534 io->addString(GUID.c_str(), m_guid.c_str());
535 }
536
537 virtual void deserialize(io::IAttributes* io)
538 {
539 m_value = io->getAttributeAsString(Name.c_str(), m_value.c_str()).c_str();
540
541 std::string GUID = Name;
542 GUID += ".guid";
543 m_guid = io->getAttributeAsString(GUID.c_str()).c_str();
544 }
545
546 inline void setGUID(const char* guid)
547 {
548 m_guid = guid;
549 }
550
551 inline const char* getGUID()
552 {
553 return m_guid.c_str();
554 }
555 };
556
557 class SKYLICHT_API CImageSourceProperty : public CGUIDResourceProperty
558 {
559 public:
560 CImageSourceProperty() :
561 CImageSourceProperty(NULL, "CImageSourceProperty")
562 {
563 }
564
565 CImageSourceProperty(CObjectSerializable* owner, const char* name) :
566 CGUIDResourceProperty(owner, ImageSource, name)
567 {
568 }
569
570 CImageSourceProperty(CObjectSerializable* owner, const char* name, const char* value) :
571 CGUIDResourceProperty(owner, ImageSource, name)
572 {
573 set(value);
574 }
575
576 virtual CValueProperty* clone()
577 {
578 CImageSourceProperty* value = new CImageSourceProperty(NULL, Name.c_str());
579 value->m_value = m_value;
580 value->m_guid = m_guid;
581 return value;
582 }
583 };
584
585 class SKYLICHT_API CFrameSourceProperty : public CGUIDResourceProperty
586 {
587 protected:
588 std::string m_sprite;
589 std::string m_spriteId;
590
591 public:
592 CFrameSourceProperty() :
593 CFrameSourceProperty(NULL, "CFrameSourceProperty")
594 {
595 }
596
597 CFrameSourceProperty(CObjectSerializable* owner, const char* name) :
598 CGUIDResourceProperty(owner, FrameSource, name)
599 {
600 }
601
602 CFrameSourceProperty(CObjectSerializable* owner, const char* name, const char* value) :
603 CGUIDResourceProperty(owner, FrameSource, name)
604 {
605 set(value);
606 }
607
608 virtual CValueProperty* clone()
609 {
610 CFrameSourceProperty* value = new CFrameSourceProperty(NULL, Name.c_str());
611 value->m_value = m_value;
612 value->m_guid = m_guid;
613 value->m_sprite = m_sprite;
614 value->m_spriteId = m_spriteId;
615 return value;
616 }
617
618 virtual void serialize(io::IAttributes* io)
619 {
620 CGUIDResourceProperty::serialize(io);
621
622 std::string spriteName = Name;
623 spriteName += ".sprite";
624 io->addString(spriteName.c_str(), m_sprite.c_str());
625
626 spriteName = Name;
627 spriteName += ".spriteGUID";
628 io->addString(spriteName.c_str(), m_spriteId.c_str());
629 }
630
631 virtual void deserialize(io::IAttributes* io)
632 {
633 CGUIDResourceProperty::deserialize(io);
634
635 std::string spriteName = Name;
636 spriteName += ".sprite";
637 m_sprite = io->getAttributeAsString(spriteName.c_str(), m_value.c_str()).c_str();
638
639 spriteName = Name;
640 spriteName += ".spriteGUID";
641 m_spriteId = io->getAttributeAsString(spriteName.c_str()).c_str();
642 }
643
644 void setSprite(const char* sprite)
645 {
646 m_sprite = sprite;
647 }
648
649 const char* getSprite()
650 {
651 return m_sprite.c_str();
652 }
653
654 void setSpriteId(const char* id)
655 {
656 m_spriteId = id;
657 }
658
659 const char* getSpriteId()
660 {
661 return m_spriteId.c_str();
662 }
663 };
664
665 class SKYLICHT_API CBoolProperty : public CValuePropertyTemplate<bool>
666 {
667 public:
668 CBoolProperty() :
669 CBoolProperty(NULL, "CBoolProperty")
670 {
671 }
672
673 CBoolProperty(CObjectSerializable* owner, const char* name) :
674 CValuePropertyTemplate(owner, Bool, name)
675 {
676 }
677
678 CBoolProperty(CObjectSerializable* owner, const char* name, bool value) :
679 CValuePropertyTemplate(owner, Bool, name)
680 {
681 set(value);
682 }
683
684 virtual void serialize(io::IAttributes* io)
685 {
686 io->addBool(Name.c_str(), m_value);
687 }
688
689 virtual void deserialize(io::IAttributes* io)
690 {
691 m_value = io->getAttributeAsBool(Name.c_str(), m_value);
692 }
693
694 virtual CValueProperty* clone()
695 {
696 CBoolProperty* value = new CBoolProperty(NULL, Name.c_str());
697 value->m_value = m_value;
698 return value;
699 }
700 };
701
702 class SKYLICHT_API CDateTimeProperty : public CValuePropertyTemplate<long>
703 {
704 public:
705 CDateTimeProperty() :
706 CDateTimeProperty(NULL, "CDateTimeProperty")
707 {
708 }
709
710 CDateTimeProperty(CObjectSerializable* owner, const char* name) :
711 CValuePropertyTemplate(owner, DateTime, name)
712 {
713 set(0);
714 }
715
716 CDateTimeProperty(CObjectSerializable* owner, const char* name, long value) :
717 CValuePropertyTemplate(owner, DateTime, name)
718 {
719 set(value);
720 }
721
722 virtual void serialize(io::IAttributes* io)
723 {
724 io->addFloat(Name.c_str(), (float)m_value);
725 }
726
727 virtual void deserialize(io::IAttributes* io)
728 {
729 m_value = (long)io->getAttributeAsFloat(Name.c_str(), (float)m_value);
730 }
731
732 virtual CValueProperty* clone()
733 {
734 CDateTimeProperty* value = new CDateTimeProperty(NULL, Name.c_str());
735 value->m_value = m_value;
736 return value;
737 }
738 };
739
740 class SKYLICHT_API CVector3Property : public CValuePropertyTemplate<core::vector3df>
741 {
742 public:
743 CVector3Property() :
744 CVector3Property(NULL, "CVector3Property")
745 {
746 }
747
748 CVector3Property(CObjectSerializable* owner, const char* name) :
749 CValuePropertyTemplate(owner, Vector3, name)
750 {
751 set(core::vector3df());
752 }
753
754 CVector3Property(CObjectSerializable* owner, const char* name, const core::vector3df& value) :
755 CValuePropertyTemplate(owner, Vector3, name)
756 {
757 set(value);
758 }
759
760 virtual void serialize(io::IAttributes* io)
761 {
762 io->addVector3d(Name.c_str(), m_value);
763 }
764
765 virtual void deserialize(io::IAttributes* io)
766 {
767 m_value = io->getAttributeAsVector3d(Name.c_str(), m_value);
768 }
769
770 virtual CValueProperty* clone()
771 {
772 CVector3Property* value = new CVector3Property(NULL, Name.c_str());
773 value->m_value = m_value;
774 return value;
775 }
776 };
777
778 class SKYLICHT_API CVector2Property : public CValuePropertyTemplate<core::vector2df>
779 {
780 public:
781 CVector2Property() :
782 CVector2Property(NULL, "CVector2Property")
783 {
784 }
785
786 CVector2Property(CObjectSerializable* owner, const char* name) :
787 CValuePropertyTemplate(owner, Vector2, name)
788 {
789 set(core::vector2df());
790 }
791
792 CVector2Property(CObjectSerializable* owner, const char* name, const core::vector2df& value) :
793 CValuePropertyTemplate(owner, Vector2, name)
794 {
795 set(value);
796 }
797
798 virtual void serialize(io::IAttributes* io)
799 {
800 io->addVector2d(Name.c_str(), m_value);
801 }
802
803 virtual void deserialize(io::IAttributes* io)
804 {
805 m_value = io->getAttributeAsVector2d(Name.c_str(), m_value);
806 }
807
808 virtual CValueProperty* clone()
809 {
810 CVector2Property* value = new CVector2Property(NULL, Name.c_str());
811 value->m_value = m_value;
812 return value;
813 }
814 };
815
816 class SKYLICHT_API CQuaternionProperty : public CValuePropertyTemplate<core::quaternion>
817 {
818 public:
819 CQuaternionProperty() :
820 CQuaternionProperty(NULL, "CQuaternionProperty")
821 {
822 }
823
824 CQuaternionProperty(CObjectSerializable* owner, const char* name) :
825 CValuePropertyTemplate(owner, Quaternion, name)
826 {
827 set(core::quaternion());
828 }
829
830 CQuaternionProperty(CObjectSerializable* owner, const char* name, const core::quaternion& value) :
831 CValuePropertyTemplate(owner, Quaternion, name)
832 {
833 set(value);
834 }
835
836 virtual void serialize(io::IAttributes* io)
837 {
838 io->addQuaternion(Name.c_str(), m_value);
839 }
840
841 virtual void deserialize(io::IAttributes* io)
842 {
843 m_value = io->getAttributeAsQuaternion(Name.c_str(), m_value);
844 }
845
846 virtual CValueProperty* clone()
847 {
848 CQuaternionProperty* value = new CQuaternionProperty(NULL, Name.c_str());
849 value->m_value = m_value;
850 return value;
851 }
852 };
853
854 class SKYLICHT_API CColorProperty : public CValuePropertyTemplate<video::SColor>
855 {
856 public:
857 CColorProperty() :
858 CColorProperty(NULL, "CColorProperty")
859 {
860 }
861
862 CColorProperty(CObjectSerializable* owner, const char* name) :
863 CValuePropertyTemplate(owner, Color, name)
864 {
865 set(SColor(255, 255, 255, 255));
866 }
867
868 CColorProperty(CObjectSerializable* owner, const char* name, const video::SColor& value) :
869 CValuePropertyTemplate(owner, Color, name)
870 {
871 set(value);
872 }
873
874 virtual void serialize(io::IAttributes* io)
875 {
876 io->addColor(Name.c_str(), m_value);
877 }
878
879 virtual void deserialize(io::IAttributes* io)
880 {
881 m_value = io->getAttributeAsColor(Name.c_str(), m_value);
882 }
883
884 virtual CValueProperty* clone()
885 {
886 CColorProperty* value = new CColorProperty(NULL, Name.c_str());
887 value->m_value = m_value;
888 return value;
889 }
890 };
891
892 class SKYLICHT_API CMatrixProperty : public CValuePropertyTemplate<core::matrix4>
893 {
894 public:
895 CMatrixProperty() :
896 CMatrixProperty(NULL, "CMatrixProperty")
897 {
898 }
899
900 CMatrixProperty(CObjectSerializable* owner, const char* name) :
901 CValuePropertyTemplate(owner, Matrix4, name)
902 {
903 set(core::IdentityMatrix);
904 }
905
906 CMatrixProperty(CObjectSerializable* owner, const char* name, const core::matrix4& value) :
907 CValuePropertyTemplate(owner, Matrix4, name)
908 {
909 set(value);
910 }
911
912 virtual void serialize(io::IAttributes* io)
913 {
914 io->addMatrix(Name.c_str(), m_value);
915 }
916
917 virtual void deserialize(io::IAttributes* io)
918 {
919 m_value = io->getAttributeAsMatrix(Name.c_str(), m_value);
920 }
921
922 virtual CValueProperty* clone()
923 {
924 CMatrixProperty* value = new CMatrixProperty(NULL, Name.c_str());
925 value->m_value = m_value;
926 return value;
927 }
928 };
929
930 class SKYLICHT_API CEnumPropertyData
931 {
932 public:
933 struct SEnumString
934 {
935 std::string Name;
936 int Value;
937
938 SEnumString(const char* name, int value)
939 {
940 Name = name;
941 Value = value;
942 }
943 };
944
945 protected:
946 std::vector<SEnumString> m_enums;
947
948 public:
949
950 void addEnumStringInt(const char* name, int value)
951 {
952 m_enums.push_back(SEnumString(name, (int)value));
953 }
954
955 int getEnumCount()
956 {
957 return (int)m_enums.size();
958 }
959
960 const SEnumString& getEnum(int i)
961 {
962 return m_enums[i];
963 }
964
965 SEnumString* getEnumByValue(int value)
966 {
967 for (int i = 0, n = (int)m_enums.size(); i < n; i++)
968 {
969 if (m_enums[i].Value == value)
970 return &m_enums[i];
971 }
972 return NULL;
973 }
974
975 const std::vector<SEnumString>& getEnum()
976 {
977 return m_enums;
978 }
979
980 void setEnums(const std::vector<SEnumString>& e)
981 {
982 m_enums = e;
983 }
984
985 virtual void setIntValue(int value) = 0;
986
987 virtual int getIntValue() = 0;
988 };
989
990 template<class T>
991 class CEnumProperty :
992 public CValuePropertyTemplate<T>,
993 public CEnumPropertyData
994 {
995 public:
996
997
998 public:
999 CEnumProperty(CObjectSerializable* owner, const char* name, T value) :
1000 CValuePropertyTemplate<T>(owner, Enum, name)
1001 {
1002 CValuePropertyTemplate<T>* obj = dynamic_cast<CValuePropertyTemplate<T>*>(this);
1003 obj->set(value);
1004 }
1005
1006 void addEnumString(const char* name, T value)
1007 {
1008 m_enums.push_back(SEnumString(name, static_cast<int>(value)));
1009 }
1010
1011 virtual void setIntValue(int value)
1012 {
1013 CValuePropertyTemplate<T>* obj = dynamic_cast<CValuePropertyTemplate<T>*>(this);
1014 obj->set(static_cast<T>(value));
1015 }
1016
1017 virtual int getIntValue()
1018 {
1019 CValuePropertyTemplate<T>* obj = dynamic_cast<CValuePropertyTemplate<T>*>(this);
1020 return static_cast<int>(obj->get());
1021 }
1022
1023 virtual void serialize(io::IAttributes* io)
1024 {
1025 CValuePropertyTemplate<T>* obj = dynamic_cast<CValuePropertyTemplate<T>*>(this);
1026 io->addInt(obj->Name.c_str(), static_cast<int>(obj->get()));
1027 }
1028
1029 virtual void deserialize(io::IAttributes* io)
1030 {
1031 CValuePropertyTemplate<T>* obj = dynamic_cast<CValuePropertyTemplate<T>*>(this);
1032 obj->set(static_cast<T>(io->getAttributeAsInt(obj->Name.c_str(), static_cast<int>(obj->get()))));
1033 }
1034
1035 virtual CValueProperty* clone()
1036 {
1037 CValuePropertyTemplate<T>* obj = dynamic_cast<CValuePropertyTemplate<T>*>(this);
1038 CEnumPropertyData* enumObj = dynamic_cast<CEnumPropertyData*>(this);
1039
1040 CEnumProperty<T>* value = new CEnumProperty<T>(NULL, obj->Name.c_str(), obj->get());
1041 CEnumPropertyData* valueEnum = dynamic_cast<CEnumPropertyData*>(value);
1042 valueEnum->setEnums(enumObj->getEnum());
1043
1044 return value;
1045 }
1046 };
1047}
Definition CValuePropertyTemplate.h:931
Definition CObjectSerializable.h:36
Definition CValueProperty.h:68
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
Definition CValuePropertyTemplate.h:934