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