1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsPrerequisites.h"
6#include "Reflection/BsRTTIType.h"
7#include "GUI/BsGUISkin.h"
8
9namespace bs
10{
11 /** @cond RTTI */
12 /** @addtogroup RTTI-Impl-Engine
13 * @{
14 */
15
16 class BS_EXPORT GUISkinEntry : public IReflectable
17 {
18 public:
19 GUISkinEntry() = default;
20 GUISkinEntry(const String& name, const GUIElementStyle& style);
21
22 String name;
23 GUIElementStyle style;
24
25 public:
26 friend class GUISkinEntryRTTI;
27 static RTTITypeBase* getRTTIStatic();
28 RTTITypeBase* getRTTI() const override;
29 };
30
31 class BS_EXPORT GUISkinEntryRTTI : public RTTIType <GUISkinEntry, IReflectable, GUISkinEntryRTTI>
32 {
33 private:
34 String& getName(GUISkinEntry* obj) { return obj->name; }
35 void setName(GUISkinEntry* obj, String& val) { obj->name = val; }
36
37 GUIElementStyle& getStyle(GUISkinEntry* obj) { return obj->style; }
38 void setStyle(GUISkinEntry* obj, GUIElementStyle& val) { obj->style = val; }
39
40 public:
41 GUISkinEntryRTTI()
42 {
43 addPlainField("name", 0, &GUISkinEntryRTTI::getName, &GUISkinEntryRTTI::setName);
44 addReflectableField("style", 1, &GUISkinEntryRTTI::getStyle, &GUISkinEntryRTTI::setStyle);
45 }
46
47 const String& getRTTIName() override
48 {
49 static String name = "GUISkinEntry";
50 return name;
51 }
52
53 UINT32 getRTTIId() override
54 {
55 return TID_GUISkinEntry;
56 }
57
58 SPtr<IReflectable> newRTTIObject() override
59 {
60 return bs_shared_ptr_new<GUISkinEntry>();
61 }
62 };
63
64 class BS_EXPORT GUISkinRTTI : public RTTIType <GUISkin, Resource, GUISkinRTTI>
65 {
66 private:
67 GUISkinEntry& getStyle(GUISkin* obj, UINT32 idx)
68 {
69 return mStyles[idx];
70 }
71
72 void setStyle(GUISkin* obj, UINT32 idx, GUISkinEntry& val) { obj->mStyles[val.name] = val.style; }
73 UINT32 getStyleArraySize(GUISkin* obj) { return (UINT32)obj->mStyles.size(); }
74 void setStyleArraySize(GUISkin* obj, UINT32 size) { /* Do nothing */ }
75
76 public:
77 GUISkinRTTI()
78 {
79 addReflectableArrayField("mStyles", 0, &GUISkinRTTI::getStyle, &GUISkinRTTI::getStyleArraySize,
80 &GUISkinRTTI::setStyle, &GUISkinRTTI::setStyleArraySize);
81 }
82
83 void onSerializationStarted(IReflectable* obj, SerializationContext* context) override
84 {
85 GUISkin* skin = static_cast<GUISkin*>(obj);
86
87 for (auto& style : skin->mStyles)
88 mStyles.push_back(GUISkinEntry(style.first, style.second));
89 }
90
91 const String& getRTTIName() override
92 {
93 static String name = "GUISkin";
94 return name;
95 }
96
97 UINT32 getRTTIId() override
98 {
99 return TID_GUISkin;
100 }
101
102 SPtr<IReflectable> newRTTIObject() override
103 {
104 return GUISkin::_createPtr();
105 }
106
107 private:
108 Vector<GUISkinEntry> mStyles;
109 };
110
111 /** @} */
112 /** @endcond */
113}