MyGUI  3.2.0
MyGUI_CommonStateInfo.h
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #ifndef __MYGUI_COMMON_STATE_INFO_H__
00023 #define __MYGUI_COMMON_STATE_INFO_H__
00024 
00025 #include "MyGUI_Prerequest.h"
00026 #include "MyGUI_IStateInfo.h"
00027 #include "MyGUI_CoordConverter.h"
00028 #include "MyGUI_LanguageManager.h"
00029 #include "MyGUI_TextureUtility.h"
00030 
00031 namespace MyGUI
00032 {
00033 
00034     class MYGUI_EXPORT SubSkinStateInfo :
00035         public IStateInfo
00036     {
00037         MYGUI_RTTI_DERIVED( SubSkinStateInfo )
00038 
00039     public:
00040         virtual ~SubSkinStateInfo() { }
00041 
00042         const FloatRect& getRect() const
00043         {
00044             return mRect;
00045         }
00046 
00047     private:
00048         virtual void deserialization(xml::ElementPtr _node, Version _version)
00049         {
00050             std::string texture = _node->getParent()->getParent()->findAttribute("texture");
00051 
00052             // поддержка замены тегов в скинах
00053             if (_version >= Version(1, 1))
00054             {
00055                 texture = LanguageManager::getInstance().replaceTags(texture);
00056             }
00057 
00058             const IntSize& size = texture_utility::getTextureSize(texture);
00059             const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
00060             mRect = CoordConverter::convertTextureCoord(coord, size);
00061         }
00062 
00063     private:
00064         FloatRect mRect;
00065     };
00066 
00067     class MYGUI_EXPORT TileRectStateInfo :
00068         public IStateInfo
00069     {
00070         MYGUI_RTTI_DERIVED( TileRectStateInfo )
00071 
00072     public:
00073         TileRectStateInfo() :
00074             mTileH(true),
00075             mTileV(true)
00076         {
00077         }
00078 
00079         virtual ~TileRectStateInfo() { }
00080 
00081         const FloatRect& getRect() const
00082         {
00083             return mRect;
00084         }
00085 
00086         const IntSize& getTileSize() const
00087         {
00088             return mTileSize;
00089         }
00090 
00091         bool getTileH() const
00092         {
00093             return mTileH;
00094         }
00095 
00096         bool getTileV() const
00097         {
00098             return mTileV;
00099         }
00100 
00101     private:
00102         virtual void deserialization(xml::ElementPtr _node, Version _version)
00103         {
00104             std::string texture = _node->getParent()->getParent()->findAttribute("texture");
00105 
00106             // поддержка замены тегов в скинах
00107             if (_version >= Version(1, 1))
00108             {
00109                 texture = LanguageManager::getInstance().replaceTags(texture);
00110             }
00111 
00112             const IntSize& size = texture_utility::getTextureSize(texture);
00113             const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
00114             mRect = CoordConverter::convertTextureCoord(coord, size);
00115 
00116             xml::ElementEnumerator prop = _node->getElementEnumerator();
00117             while (prop.next("Property"))
00118             {
00119                 const std::string& key = prop->findAttribute("key");
00120                 const std::string& value = prop->findAttribute("value");
00121                 if (key == "TileH") mTileH = utility::parseBool(value);
00122                 else if (key == "TileV") mTileV = utility::parseBool(value);
00123                 else if (key == "TileSize") mTileSize = IntSize::parse(value);
00124             }
00125         }
00126 
00127     private:
00128         FloatRect mRect;
00129         IntSize mTileSize;
00130         bool mTileH;
00131         bool mTileV;
00132     };
00133 
00134     class MYGUI_EXPORT EditTextStateInfo :
00135         public IStateInfo
00136     {
00137         MYGUI_RTTI_DERIVED( EditTextStateInfo )
00138 
00139     public:
00140         EditTextStateInfo() :
00141             mColour(Colour::White),
00142             mShift(false)
00143         {
00144         }
00145 
00146         virtual ~EditTextStateInfo() { }
00147 
00148         const Colour& getColour() const
00149         {
00150             return mColour;
00151         }
00152 
00153         bool getShift() const
00154         {
00155             return mShift;
00156         }
00157 
00158     private:
00159         virtual void deserialization(xml::ElementPtr _node, Version _version)
00160         {
00161             mShift = utility::parseBool(_node->findAttribute("shift"));
00162 
00163             std::string colour = _node->findAttribute("colour");
00164             if (_version >= Version(1, 1))
00165             {
00166                 colour = LanguageManager::getInstance().replaceTags(colour);
00167             }
00168 
00169             mColour = Colour::parse(colour);
00170         }
00171 
00172     private:
00173         Colour mColour;
00174         bool mShift;
00175     };
00176 
00177 } // namespace MyGUI
00178 
00179 #endif // __MYGUI_COMMON_STATE_INFO_H__