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 "BsCorePrerequisites.h" |
6 | #include "Reflection/BsRTTIType.h" |
7 | #include "Text/BsFont.h" |
8 | #include "Image/BsTexture.h" |
9 | |
10 | namespace bs |
11 | { |
12 | /** @cond RTTI */ |
13 | /** @addtogroup RTTI-Impl-Core |
14 | * @{ |
15 | */ |
16 | |
17 | class BS_CORE_EXPORT FontBitmapRTTI : public RTTIType<FontBitmap, IReflectable, FontBitmapRTTI> |
18 | { |
19 | private: |
20 | BS_BEGIN_RTTI_MEMBERS |
21 | BS_RTTI_MEMBER_PLAIN(size, 0) |
22 | BS_RTTI_MEMBER_PLAIN(baselineOffset, 1) |
23 | BS_RTTI_MEMBER_PLAIN(lineHeight, 2) |
24 | BS_RTTI_MEMBER_PLAIN(missingGlyph, 3) |
25 | BS_RTTI_MEMBER_PLAIN(spaceWidth, 4) |
26 | BS_RTTI_MEMBER_REFL_ARRAY(texturePages, 5) |
27 | BS_RTTI_MEMBER_PLAIN(characters, 6) |
28 | BS_END_RTTI_MEMBERS |
29 | |
30 | public: |
31 | const String& getRTTIName() override |
32 | { |
33 | static String name = "FontData" ; |
34 | return name; |
35 | } |
36 | |
37 | UINT32 getRTTIId() override |
38 | { |
39 | return TID_FontBitmap; |
40 | } |
41 | |
42 | SPtr<IReflectable> newRTTIObject() override |
43 | { |
44 | return bs_shared_ptr_new<FontBitmap>(); |
45 | } |
46 | }; |
47 | |
48 | class BS_CORE_EXPORT FontRTTI : public RTTIType<Font, Resource, FontRTTI> |
49 | { |
50 | private: |
51 | FontBitmap& getBitmap(Font* obj, UINT32 idx) |
52 | { |
53 | if(idx >= obj->mFontDataPerSize.size()) |
54 | BS_EXCEPT(InternalErrorException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((int)obj->mFontDataPerSize.size())); |
55 | |
56 | auto iter = obj->mFontDataPerSize.begin(); |
57 | for(UINT32 i = 0; i < idx; i++, ++iter) |
58 | { } |
59 | |
60 | return *iter->second; |
61 | } |
62 | |
63 | void setBitmap(Font* obj, UINT32 idx, FontBitmap& value) |
64 | { |
65 | mFontDataPerSize[idx] = bs_shared_ptr_new<FontBitmap>(); |
66 | *mFontDataPerSize[idx] = value; |
67 | } |
68 | |
69 | UINT32 getNumBitmaps(Font* obj) |
70 | { |
71 | return (UINT32)obj->mFontDataPerSize.size(); |
72 | } |
73 | |
74 | void setNumBitmaps(Font* obj, UINT32 size) |
75 | { |
76 | mFontDataPerSize.resize(size); |
77 | } |
78 | |
79 | public: |
80 | FontRTTI() |
81 | { |
82 | addReflectableArrayField("mBitmaps" , 0, &FontRTTI::getBitmap, &FontRTTI::getNumBitmaps, &FontRTTI::setBitmap, &FontRTTI::setNumBitmaps); |
83 | } |
84 | |
85 | const String& getRTTIName() override |
86 | { |
87 | static String name = "Font" ; |
88 | return name; |
89 | } |
90 | |
91 | UINT32 getRTTIId() override |
92 | { |
93 | return TID_Font; |
94 | } |
95 | |
96 | SPtr<IReflectable> newRTTIObject() override |
97 | { |
98 | return Font::_createEmpty(); |
99 | } |
100 | |
101 | protected: |
102 | void onDeserializationEnded(IReflectable* obj, SerializationContext* context) override |
103 | { |
104 | Font* font = static_cast<Font*>(obj); |
105 | font->initialize(mFontDataPerSize); |
106 | } |
107 | |
108 | Vector<SPtr<FontBitmap>> mFontDataPerSize; |
109 | }; |
110 | |
111 | /** @} */ |
112 | /** @endcond */ |
113 | } |
114 | |