MyGUI  3.2.1
MyGUI_CommonStateInfo.h
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #ifndef __MYGUI_COMMON_STATE_INFO_H__
00008 #define __MYGUI_COMMON_STATE_INFO_H__
00009 
00010 #include "MyGUI_Prerequest.h"
00011 #include "MyGUI_IStateInfo.h"
00012 #include "MyGUI_CoordConverter.h"
00013 #include "MyGUI_LanguageManager.h"
00014 #include "MyGUI_TextureUtility.h"
00015 
00016 namespace MyGUI
00017 {
00018 
00019     class MYGUI_EXPORT SubSkinStateInfo :
00020         public IStateInfo
00021     {
00022         MYGUI_RTTI_DERIVED( SubSkinStateInfo )
00023 
00024     public:
00025         virtual ~SubSkinStateInfo() { }
00026 
00027         const FloatRect& getRect() const
00028         {
00029             return mRect;
00030         }
00031 
00032     private:
00033         virtual void deserialization(xml::ElementPtr _node, Version _version)
00034         {
00035             std::string texture = _node->getParent()->getParent()->findAttribute("texture");
00036 
00037             // tags replacement support for Skins
00038             if (_version >= Version(1, 1))
00039             {
00040                 texture = LanguageManager::getInstance().replaceTags(texture);
00041             }
00042 
00043             const IntSize& size = texture_utility::getTextureSize(texture);
00044             const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
00045             mRect = CoordConverter::convertTextureCoord(coord, size);
00046         }
00047 
00048     private:
00049         FloatRect mRect;
00050     };
00051 
00052     class MYGUI_EXPORT TileRectStateInfo :
00053         public IStateInfo
00054     {
00055         MYGUI_RTTI_DERIVED( TileRectStateInfo )
00056 
00057     public:
00058         TileRectStateInfo() :
00059             mTileH(true),
00060             mTileV(true)
00061         {
00062         }
00063 
00064         virtual ~TileRectStateInfo() { }
00065 
00066         const FloatRect& getRect() const
00067         {
00068             return mRect;
00069         }
00070 
00071         const IntSize& getTileSize() const
00072         {
00073             return mTileSize;
00074         }
00075 
00076         bool getTileH() const
00077         {
00078             return mTileH;
00079         }
00080 
00081         bool getTileV() const
00082         {
00083             return mTileV;
00084         }
00085 
00086     private:
00087         virtual void deserialization(xml::ElementPtr _node, Version _version)
00088         {
00089             std::string texture = _node->getParent()->getParent()->findAttribute("texture");
00090 
00091             // tags replacement support for Skins
00092             if (_version >= Version(1, 1))
00093             {
00094                 texture = LanguageManager::getInstance().replaceTags(texture);
00095             }
00096 
00097             const IntSize& size = texture_utility::getTextureSize(texture);
00098             const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
00099             mRect = CoordConverter::convertTextureCoord(coord, size);
00100 
00101             xml::ElementEnumerator prop = _node->getElementEnumerator();
00102             while (prop.next("Property"))
00103             {
00104                 const std::string& key = prop->findAttribute("key");
00105                 const std::string& value = prop->findAttribute("value");
00106                 if (key == "TileH") mTileH = utility::parseBool(value);
00107                 else if (key == "TileV") mTileV = utility::parseBool(value);
00108                 else if (key == "TileSize") mTileSize = IntSize::parse(value);
00109             }
00110         }
00111 
00112     private:
00113         FloatRect mRect;
00114         IntSize mTileSize;
00115         bool mTileH;
00116         bool mTileV;
00117     };
00118 
00119     class MYGUI_EXPORT RotatingSkinStateInfo :
00120         public IStateInfo
00121     {
00122         MYGUI_RTTI_DERIVED( RotatingSkinStateInfo )
00123 
00124     public:
00125         RotatingSkinStateInfo() :
00126             mAngle(0),
00127             mCenter(0,0)
00128         {
00129         }
00130 
00131         virtual ~RotatingSkinStateInfo() { }
00132 
00133         float getAngle() const
00134         {
00135             return mAngle;
00136         }
00137 
00138         const IntPoint& getCenter() const
00139         {
00140             return mCenter;
00141         }
00142 
00143         const FloatRect& getRect() const
00144         {
00145             return mRect;
00146         }
00147 
00148     private:
00149         virtual void deserialization(xml::ElementPtr _node, Version _version)
00150         {
00151             xml::ElementEnumerator prop = _node->getElementEnumerator();
00152             while (prop.next("Property"))
00153             {
00154                 const std::string& key = prop->findAttribute("key");
00155                 const std::string& value = prop->findAttribute("value");
00156                 if (key == "Angle") mAngle = utility::parseFloat(value);
00157                 if (key == "Center") mCenter = IntPoint::parse(value);
00158             }
00159 
00160             std::string texture = _node->getParent()->getParent()->findAttribute("texture");
00161 
00162             // tags replacement support for Skins
00163             if (_version >= Version(1, 1))
00164             {
00165                 texture = LanguageManager::getInstance().replaceTags(texture);
00166             }
00167 
00168             const IntSize& size = texture_utility::getTextureSize(texture);
00169             const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
00170             mRect = CoordConverter::convertTextureCoord(coord, size);
00171         }
00172 
00173     private:
00174         FloatRect mRect;
00175         IntPoint mCenter;
00176         float mAngle; // Angle in radians
00177     };
00178 
00179 
00180     class MYGUI_EXPORT EditTextStateInfo :
00181         public IStateInfo
00182     {
00183         MYGUI_RTTI_DERIVED( EditTextStateInfo )
00184 
00185     public:
00186         EditTextStateInfo() :
00187             mColour(Colour::White),
00188             mShift(false)
00189         {
00190         }
00191 
00192         virtual ~EditTextStateInfo() { }
00193 
00194         const Colour& getColour() const
00195         {
00196             return mColour;
00197         }
00198 
00199         bool getShift() const
00200         {
00201             return mShift;
00202         }
00203 
00204     private:
00205         virtual void deserialization(xml::ElementPtr _node, Version _version)
00206         {
00207             mShift = utility::parseBool(_node->findAttribute("shift"));
00208 
00209             std::string colour = _node->findAttribute("colour");
00210             if (_version >= Version(1, 1))
00211             {
00212                 colour = LanguageManager::getInstance().replaceTags(colour);
00213             }
00214 
00215             mColour = Colour::parse(colour);
00216         }
00217 
00218     private:
00219         Colour mColour;
00220         bool mShift;
00221     };
00222 
00223 } // namespace MyGUI
00224 
00225 #endif // __MYGUI_COMMON_STATE_INFO_H__