MyGUI: MyGUI_CommonStateInfo.h Source File

MyGUI 3.4.3

MyGUI_CommonStateInfo.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_COMMON_STATE_INFO_H_
8#define MYGUI_COMMON_STATE_INFO_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_IStateInfo.h"
12#include "MyGUI_CoordConverter.h"
13#include "MyGUI_LanguageManager.h"
14#include "MyGUI_TextureUtility.h"
15
16namespace MyGUI
17{
18
19 class MYGUI_EXPORT SubSkinStateInfo : public IStateInfo
20 {
21 MYGUI_RTTI_DERIVED(SubSkinStateInfo)
22
23 public:
24 const FloatRect& getRect() const
25 {
26 return mRect;
27 }
28
29 private:
30 void deserialization(xml::ElementPtr _node, Version _version) override
31 {
32 std::string texture{_node->getParent()->getParent()->findAttribute("texture")};
33
34 // tags replacement support for Skins
35 if (_version >= Version(1, 1))
36 {
37 texture = LanguageManager::getInstance().replaceTags(texture);
38 }
39
40 const IntSize& size = texture_utility::getTextureSize(texture);
41 IntCoord coord = IntCoord::parse(_node->findAttribute("offset"));
42 mRect = CoordConverter::convertTextureCoord(coord, size);
43 }
44
45 private:
46 FloatRect mRect;
47 };
48
49 class MYGUI_EXPORT TileRectStateInfo : public IStateInfo
50 {
51 MYGUI_RTTI_DERIVED(TileRectStateInfo)
52
53 public:
54 const FloatRect& getRect() const
55 {
56 return mRect;
57 }
58
59 const IntSize& getTileSize() const
60 {
61 return mTileSize;
62 }
63
64 bool getTileH() const
65 {
66 return mTileH;
67 }
68
69 bool getTileV() const
70 {
71 return mTileV;
72 }
73
74 private:
75 void deserialization(xml::ElementPtr _node, Version _version) override
76 {
77 std::string texture{_node->getParent()->getParent()->findAttribute("texture")};
78
79 // tags replacement support for Skins
80 if (_version >= Version(1, 1))
81 {
82 texture = LanguageManager::getInstance().replaceTags(texture);
83 }
84
85 const IntSize& size = texture_utility::getTextureSize(texture);
86 IntCoord coord = IntCoord::parse(_node->findAttribute("offset"));
87 mRect = CoordConverter::convertTextureCoord(coord, size);
88
89 xml::ElementEnumerator prop = _node->getElementEnumerator();
90 while (prop.next("Property"))
91 {
92 std::string_view key = prop->findAttribute("key");
93 std::string_view value = prop->findAttribute("value");
94 if (key == "TileH")
95 mTileH = utility::parseBool(value);
96 else if (key == "TileV")
97 mTileV = utility::parseBool(value);
98 else if (key == "TileSize")
99 mTileSize = IntSize::parse(value);
100 }
101 }
102
103 private:
104 FloatRect mRect;
105 IntSize mTileSize;
106 bool mTileH{true};
107 bool mTileV{true};
108 };
109
110 class MYGUI_EXPORT RotatingSkinStateInfo : public IStateInfo
111 {
112 MYGUI_RTTI_DERIVED(RotatingSkinStateInfo)
113
114 public:
115 float getAngle() const
116 {
117 return mAngle;
118 }
119
120 const IntPoint& getCenter() const
121 {
122 return mCenter;
123 }
124
125 const FloatRect& getRect() const
126 {
127 return mRect;
128 }
129
130 private:
131 void deserialization(xml::ElementPtr _node, Version _version) override
132 {
133 xml::ElementEnumerator prop = _node->getElementEnumerator();
134 while (prop.next("Property"))
135 {
136 std::string_view key = prop->findAttribute("key");
137 std::string_view value = prop->findAttribute("value");
138 if (key == "Angle")
139 mAngle = utility::parseFloat(value);
140 if (key == "Center")
141 mCenter = IntPoint::parse(value);
142 }
143
144 std::string texture{_node->getParent()->getParent()->findAttribute("texture")};
145
146 // tags replacement support for Skins
147 if (_version >= Version(1, 1))
148 {
149 texture = LanguageManager::getInstance().replaceTags(texture);
150 }
151
152 const IntSize& size = texture_utility::getTextureSize(texture);
153 IntCoord coord = IntCoord::parse(_node->findAttribute("offset"));
154 mRect = CoordConverter::convertTextureCoord(coord, size);
155 }
156
157 private:
158 FloatRect mRect;
159 IntPoint mCenter;
160 float mAngle{0}; // Angle in radians
161 };
162
163
164 class MYGUI_EXPORT EditTextStateInfo : public IStateInfo
165 {
166 MYGUI_RTTI_DERIVED(EditTextStateInfo)
167
168 public:
169 const Colour& getColour() const
170 {
171 return mColour;
172 }
173
174 bool getShift() const
175 {
176 return mShift;
177 }
178
179 private:
180 void deserialization(xml::ElementPtr _node, Version _version) override
181 {
182 mShift = utility::parseBool(_node->findAttribute("shift"));
183
184 std::string colour{_node->findAttribute("colour")};
185 if (_version >= Version(1, 1))
186 {
187 colour = LanguageManager::getInstance().replaceTags(colour);
188 }
189
190 mColour = Colour::parse(colour);
191 }
192
193 private:
194 Colour mColour{Colour::White};
195 bool mShift{false};
196 };
197
198} // namespace MyGUI
199
200#endif // MYGUI_COMMON_STATE_INFO_H_
MyGUI_CoordConverter.h
MyGUI_IStateInfo.h
MyGUI_LanguageManager.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
MyGUI_TextureUtility.h
MyGUI::EditTextStateInfo
Definition MyGUI_CommonStateInfo.h:165
MyGUI::EditTextStateInfo::getColour
const Colour & getColour() const
Definition MyGUI_CommonStateInfo.h:169
MyGUI::EditTextStateInfo::getShift
bool getShift() const
Definition MyGUI_CommonStateInfo.h:174
MyGUI::IStateInfo
Definition MyGUI_IStateInfo.h:17
MyGUI::RotatingSkinStateInfo
Definition MyGUI_CommonStateInfo.h:111
MyGUI::RotatingSkinStateInfo::getCenter
const IntPoint & getCenter() const
Definition MyGUI_CommonStateInfo.h:120
MyGUI::RotatingSkinStateInfo::getRect
const FloatRect & getRect() const
Definition MyGUI_CommonStateInfo.h:125
MyGUI::RotatingSkinStateInfo::getAngle
float getAngle() const
Definition MyGUI_CommonStateInfo.h:115
MyGUI::SubSkinStateInfo
Definition MyGUI_CommonStateInfo.h:20
MyGUI::SubSkinStateInfo::getRect
const FloatRect & getRect() const
Definition MyGUI_CommonStateInfo.h:24
MyGUI::TileRectStateInfo
Definition MyGUI_CommonStateInfo.h:50
MyGUI::TileRectStateInfo::getTileV
bool getTileV() const
Definition MyGUI_CommonStateInfo.h:69
MyGUI::TileRectStateInfo::getRect
const FloatRect & getRect() const
Definition MyGUI_CommonStateInfo.h:54
MyGUI::TileRectStateInfo::getTileSize
const IntSize & getTileSize() const
Definition MyGUI_CommonStateInfo.h:59
MyGUI::TileRectStateInfo::getTileH
bool getTileH() const
Definition MyGUI_CommonStateInfo.h:64
MyGUI::Version
Definition MyGUI_Version.h:18
MyGUI::xml::ElementEnumerator
Definition MyGUI_XmlDocument.h:121
MyGUI::xml::ElementEnumerator::next
bool next()
Definition MyGUI_XmlDocument.cpp:107
MyGUI::xml::Element::findAttribute
bool findAttribute(std::string_view _name, std::string &_value)
Definition MyGUI_XmlDocument.cpp:242
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition MyGUI_XmlDocument.cpp:348
MyGUI::xml::Element::getParent
ElementPtr getParent() const
Definition MyGUI_XmlDocument.cpp:343
MyGUI::utility::parseBool
bool parseBool(std::string_view _value)
Definition MyGUI_StringUtility.h:127
MyGUI::utility::parseFloat
float parseFloat(std::string_view _value)
Definition MyGUI_StringUtility.h:117
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition MyGUI_XmlDocument.h:112
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::FloatRect
types::TRect< float > FloatRect
Definition MyGUI_Types.h:34
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::Colour
Definition MyGUI_Colour.h:17
MyGUI::types::TPoint< int >::parse
static TPoint< int > parse(std::string_view _value)
Definition MyGUI_TPoint.h:102