MyGUI  3.2.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  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 
53  public IStateInfo
54  {
56 
57  public:
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 
120  public IStateInfo
121  {
123 
124  public:
126  mAngle(0),
127  mCenter(0,0)
128  {
129  }
130 
132 
133  float getAngle() const
134  {
135  return mAngle;
136  }
137 
138  const IntPoint& getCenter() const
139  {
140  return mCenter;
141  }
142 
143  const FloatRect& getRect() const
144  {
145  return mRect;
146  }
147 
148  private:
149  virtual void deserialization(xml::ElementPtr _node, Version _version)
150  {
152  while (prop.next("Property"))
153  {
154  const std::string& key = prop->findAttribute("key");
155  const std::string& value = prop->findAttribute("value");
156  if (key == "Angle") mAngle = utility::parseFloat(value);
157  if (key == "Center") mCenter = IntPoint::parse(value);
158  }
159 
160  std::string texture = _node->getParent()->getParent()->findAttribute("texture");
161 
162  // tags replacement support for Skins
163  if (_version >= Version(1, 1))
164  {
165  texture = LanguageManager::getInstance().replaceTags(texture);
166  }
167 
168  const IntSize& size = texture_utility::getTextureSize(texture);
169  const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
170  mRect = CoordConverter::convertTextureCoord(coord, size);
171  }
172 
173  private:
174  FloatRect mRect;
175  IntPoint mCenter;
176  float mAngle; // Angle in radians
177  };
178 
179 
181  public IStateInfo
182  {
184 
185  public:
187  mColour(Colour::White),
188  mShift(false)
189  {
190  }
191 
192  virtual ~EditTextStateInfo() { }
193 
194  const Colour& getColour() const
195  {
196  return mColour;
197  }
198 
199  bool getShift() const
200  {
201  return mShift;
202  }
203 
204  private:
205  virtual void deserialization(xml::ElementPtr _node, Version _version)
206  {
207  mShift = utility::parseBool(_node->findAttribute("shift"));
208 
209  std::string colour = _node->findAttribute("colour");
210  if (_version >= Version(1, 1))
211  {
212  colour = LanguageManager::getInstance().replaceTags(colour);
213  }
214 
215  mColour = Colour::parse(colour);
216  }
217 
218  private:
219  Colour mColour;
220  bool mShift;
221  };
222 
223 } // namespace MyGUI
224 
225 #endif // __MYGUI_COMMON_STATE_INFO_H__