MyGUI 3.2.2

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
16 namespace MyGUI
17 {
18
19 class MYGUI_EXPORT SubSkinStateInfo :
20 public IStateInfo
21 {
22 MYGUI_RTTI_DERIVED( SubSkinStateInfo )
23
24 public:
25 virtual ~SubSkinStateInfo() { }
26
27 const FloatRect& getRect() const
28 {
29 return mRect;
30 }
31
32 private:
33 virtual void deserialization(xml::ElementPtr _node, Version _version)
34 {
35 std::string texture = _node->getParent()->getParent()->findAttribute("texture");
36
37 // tags replacement support for Skins
38 if (_version >= Version(1, 1))
39 {
40 texture = LanguageManager::getInstance().replaceTags(texture);
41 }
42
43 const IntSize& size = texture_utility::getTextureSize(texture);
44 const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
45 mRect = CoordConverter::convertTextureCoord(coord, size);
46 }
47
48 private:
49 FloatRect mRect;
50 };
51
52 class MYGUI_EXPORT TileRectStateInfo :
53 public IStateInfo
54 {
55 MYGUI_RTTI_DERIVED( TileRectStateInfo )
56
57 public:
58 TileRectStateInfo() :
59 mTileH(true),
60 mTileV(true)
61 {
62 }
63
64 virtual ~TileRectStateInfo() { }
65
66 const FloatRect& getRect() const
67 {
68 return mRect;
69 }
70
71 const IntSize& getTileSize() const
72 {
73 return mTileSize;
74 }
75
76 bool getTileH() const
77 {
78 return mTileH;
79 }
80
81 bool getTileV() const
82 {
83 return mTileV;
84 }
85
86 private:
87 virtual void deserialization(xml::ElementPtr _node, Version _version)
88 {
89 std::string texture = _node->getParent()->getParent()->findAttribute("texture");
90
91 // tags replacement support for Skins
92 if (_version >= Version(1, 1))
93 {
94 texture = LanguageManager::getInstance().replaceTags(texture);
95 }
96
97 const IntSize& size = texture_utility::getTextureSize(texture);
98 const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
99 mRect = CoordConverter::convertTextureCoord(coord, size);
100
101 xml::ElementEnumerator prop = _node->getElementEnumerator();
102 while (prop.next("Property"))
103 {
104 const std::string& key = prop->findAttribute("key");
105 const std::string& value = prop->findAttribute("value");
106 if (key == "TileH") mTileH = utility::parseBool(value);
107 else if (key == "TileV") mTileV = utility::parseBool(value);
108 else if (key == "TileSize") mTileSize = IntSize::parse(value);
109 }
110 }
111
112 private:
113 FloatRect mRect;
114 IntSize mTileSize;
115 bool mTileH;
116 bool mTileV;
117 };
118
119 class MYGUI_EXPORT RotatingSkinStateInfo :
120 public IStateInfo
121 {
122 MYGUI_RTTI_DERIVED( RotatingSkinStateInfo )
123
124 public:
125 RotatingSkinStateInfo() :
126 mAngle(0)
127 {
128 }
129
130 virtual ~RotatingSkinStateInfo() { }
131
132 float getAngle() const
133 {
134 return mAngle;
135 }
136
137 const IntPoint& getCenter() const
138 {
139 return mCenter;
140 }
141
142 const FloatRect& getRect() const
143 {
144 return mRect;
145 }
146
147 private:
148 virtual void deserialization(xml::ElementPtr _node, Version _version)
149 {
150 xml::ElementEnumerator prop = _node->getElementEnumerator();
151 while (prop.next("Property"))
152 {
153 const std::string& key = prop->findAttribute("key");
154 const std::string& value = prop->findAttribute("value");
155 if (key == "Angle") mAngle = utility::parseFloat(value);
156 if (key == "Center") mCenter = IntPoint::parse(value);
157 }
158
159 std::string texture = _node->getParent()->getParent()->findAttribute("texture");
160
161 // tags replacement support for Skins
162 if (_version >= Version(1, 1))
163 {
164 texture = LanguageManager::getInstance().replaceTags(texture);
165 }
166
167 const IntSize& size = texture_utility::getTextureSize(texture);
168 const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
169 mRect = CoordConverter::convertTextureCoord(coord, size);
170 }
171
172 private:
173 FloatRect mRect;
174 IntPoint mCenter;
175 float mAngle; // Angle in radians
176 };
177
178
179 class MYGUI_EXPORT EditTextStateInfo :
180 public IStateInfo
181 {
182 MYGUI_RTTI_DERIVED( EditTextStateInfo )
183
184 public:
185 EditTextStateInfo() :
186 mColour(Colour::White),
187 mShift(false)
188 {
189 }
190
191 virtual ~EditTextStateInfo() { }
192
193 const Colour& getColour() const
194 {
195 return mColour;
196 }
197
198 bool getShift() const
199 {
200 return mShift;
201 }
202
203 private:
204 virtual void deserialization(xml::ElementPtr _node, Version _version)
205 {
206 mShift = utility::parseBool(_node->findAttribute("shift"));
207
208 std::string colour = _node->findAttribute("colour");
209 if (_version >= Version(1, 1))
210 {
211 colour = LanguageManager::getInstance().replaceTags(colour);
212 }
213
214 mColour = Colour::parse(colour);
215 }
216
217 private:
218 Colour mColour;
219 bool mShift;
220 };
221
222 } // namespace MyGUI
223
224 #endif // MYGUI_COMMON_STATE_INFO_H_
MyGUI::SubSkinStateInfo::~SubSkinStateInfo
virtual ~SubSkinStateInfo()
Definition: MyGUI_CommonStateInfo.h:25
MyGUI::types::TCoord< int >
MyGUI_TextureUtility.h
MyGUI::TileRectStateInfo::getTileH
bool getTileH() const
Definition: MyGUI_CommonStateInfo.h:76
MyGUI::RotatingSkinStateInfo::getRect
const FloatRect & getRect() const
Definition: MyGUI_CommonStateInfo.h:142
MyGUI::types::TPoint< int >
MyGUI::EditTextStateInfo::getColour
const Colour & getColour() const
Definition: MyGUI_CommonStateInfo.h:193
MyGUI_Prerequest.h
MyGUI::RotatingSkinStateInfo::RotatingSkinStateInfo
RotatingSkinStateInfo()
Definition: MyGUI_CommonStateInfo.h:125
MyGUI::IStateInfo
Definition: MyGUI_IStateInfo.h:16
MyGUI::SubSkinStateInfo::getRect
const FloatRect & getRect() const
Definition: MyGUI_CommonStateInfo.h:27
MyGUI::types::TSize< int >
MyGUI::Singleton< LanguageManager >::getInstance
static LanguageManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI::texture_utility::getTextureSize
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
Definition: MyGUI_TextureUtility.cpp:20
MyGUI::xml::Element::findAttribute
bool findAttribute(const std::string &_name, std::string &_value)
Definition: MyGUI_XmlDocument.cpp:246
MyGUI::TileRectStateInfo::getTileSize
const IntSize & getTileSize() const
Definition: MyGUI_CommonStateInfo.h:71
MyGUI::RotatingSkinStateInfo::~RotatingSkinStateInfo
virtual ~RotatingSkinStateInfo()
Definition: MyGUI_CommonStateInfo.h:130
MyGUI::types::TSize< int >::parse
static TSize< int > parse(const std::string &_value)
Definition: MyGUI_TSize.h:120
MyGUI_LanguageManager.h
MyGUI::xml::ElementEnumerator
Definition: MyGUI_XmlDocument.h:114
MyGUI_IStateInfo.h
MyGUI::EditTextStateInfo
Definition: MyGUI_CommonStateInfo.h:179
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI_CoordConverter.h
MyGUI::TileRectStateInfo::getRect
const FloatRect & getRect() const
Definition: MyGUI_CommonStateInfo.h:66
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:65
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103
MyGUI::xml::ElementEnumerator::next
bool next()
Definition: MyGUI_XmlDocument.cpp:100
MyGUI::types::TRect< float >
MyGUI::RotatingSkinStateInfo
Definition: MyGUI_CommonStateInfo.h:119
MyGUI::EditTextStateInfo::~EditTextStateInfo
virtual ~EditTextStateInfo()
Definition: MyGUI_CommonStateInfo.h:191
MyGUI::xml::Element
Definition: MyGUI_XmlDocument.h:158
MyGUI::utility::parseFloat
float parseFloat(const std::string &_value)
Definition: MyGUI_StringUtility.h:181
MyGUI::Version
Definition: MyGUI_Version.h:17
MyGUI::TileRectStateInfo
Definition: MyGUI_CommonStateInfo.h:52
MyGUI::RotatingSkinStateInfo::getCenter
const IntPoint & getCenter() const
Definition: MyGUI_CommonStateInfo.h:137
MyGUI::xml::Element::getParent
ElementPtr getParent() const
Definition: MyGUI_XmlDocument.cpp:347
MyGUI::SubSkinStateInfo
Definition: MyGUI_CommonStateInfo.h:19
MyGUI::TileRectStateInfo::~TileRectStateInfo
virtual ~TileRectStateInfo()
Definition: MyGUI_CommonStateInfo.h:64
MyGUI::utility::parseBool
bool parseBool(const std::string &_value)
Definition: MyGUI_StringUtility.h:191
MyGUI::types::TPoint< int >::parse
static TPoint< int > parse(const std::string &_value)
Definition: MyGUI_TPoint.h:120
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition: MyGUI_XmlDocument.cpp:352
MyGUI::Colour::parse
static Colour parse(const std::string &_value)
Definition: MyGUI_Colour.cpp:80
MyGUI::TileRectStateInfo::TileRectStateInfo
TileRectStateInfo()
Definition: MyGUI_CommonStateInfo.h:58
MyGUI::LanguageManager::replaceTags
UString replaceTags(const UString &_line)
Definition: MyGUI_LanguageManager.cpp:195
MyGUI::Colour
Definition: MyGUI_Colour.h:16
MyGUI::CoordConverter::convertTextureCoord
static FloatRect convertTextureCoord(const IntCoord &_coord, const IntSize &_textureSize)
Definition: MyGUI_CoordConverter.h:20
MyGUI::types::TCoord< int >::parse
static TCoord< int > parse(const std::string &_value)
Definition: MyGUI_TCoord.h:207
MyGUI::TileRectStateInfo::getTileV
bool getTileV() const
Definition: MyGUI_CommonStateInfo.h:81
MyGUI::EditTextStateInfo::EditTextStateInfo
EditTextStateInfo()
Definition: MyGUI_CommonStateInfo.h:185
MyGUI::EditTextStateInfo::getShift
bool getShift() const
Definition: MyGUI_CommonStateInfo.h:198
MyGUI::RotatingSkinStateInfo::getAngle
float getAngle() const
Definition: MyGUI_CommonStateInfo.h:132