MyGUI_CommonStateInfo.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_COMMON_STATE_INFO_H_
#define MYGUI_COMMON_STATE_INFO_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_IStateInfo.h"
#include "MyGUI_CoordConverter.h"
#include "MyGUI_LanguageManager.h"
#include "MyGUI_TextureUtility.h"
namespace MyGUI
{
class MYGUI_EXPORT SubSkinStateInfo : public IStateInfo
{
MYGUI_RTTI_DERIVED(SubSkinStateInfo)
public:
const FloatRect& getRect() const
{
return mRect;
}
private:
void deserialization(xml::ElementPtr _node, Version _version) override
{
std::string texture{_node->getParent()->getParent()->findAttribute("texture")};
// tags replacement support for Skins
if (_version >= Version(1, 1))
{
texture = LanguageManager::getInstance().replaceTags(texture);
}
const IntSize& size = texture_utility::getTextureSize(texture);
IntCoord coord = IntCoord::parse(_node->findAttribute("offset"));
mRect = CoordConverter::convertTextureCoord(coord, size);
}
private:
FloatRect mRect;
};
class MYGUI_EXPORT TileRectStateInfo : public IStateInfo
{
MYGUI_RTTI_DERIVED(TileRectStateInfo)
public:
const FloatRect& getRect() const
{
return mRect;
}
const IntSize& getTileSize() const
{
return mTileSize;
}
bool getTileH() const
{
return mTileH;
}
bool getTileV() const
{
return mTileV;
}
private:
void deserialization(xml::ElementPtr _node, Version _version) override
{
std::string texture{_node->getParent()->getParent()->findAttribute("texture")};
// tags replacement support for Skins
if (_version >= Version(1, 1))
{
texture = LanguageManager::getInstance().replaceTags(texture);
}
const IntSize& size = texture_utility::getTextureSize(texture);
IntCoord coord = IntCoord::parse(_node->findAttribute("offset"));
mRect = CoordConverter::convertTextureCoord(coord, size);
xml::ElementEnumerator prop = _node->getElementEnumerator();
while (prop.next("Property"))
{
std::string_view key = prop->findAttribute("key");
std::string_view value = prop->findAttribute("value");
if (key == "TileH")
mTileH = utility::parseBool(value);
else if (key == "TileV")
mTileV = utility::parseBool(value);
else if (key == "TileSize")
mTileSize = IntSize::parse(value);
}
}
private:
FloatRect mRect;
IntSize mTileSize;
bool mTileH{true};
bool mTileV{true};
};
class MYGUI_EXPORT RotatingSkinStateInfo : public IStateInfo
{
MYGUI_RTTI_DERIVED(RotatingSkinStateInfo)
public:
float getAngle() const
{
return mAngle;
}
const IntPoint& getCenter() const
{
return mCenter;
}
const FloatRect& getRect() const
{
return mRect;
}
private:
void deserialization(xml::ElementPtr _node, Version _version) override
{
xml::ElementEnumerator prop = _node->getElementEnumerator();
while (prop.next("Property"))
{
std::string_view key = prop->findAttribute("key");
std::string_view value = prop->findAttribute("value");
if (key == "Angle")
mAngle = utility::parseFloat(value);
if (key == "Center")
mCenter = IntPoint::parse(value);
}
std::string texture{_node->getParent()->getParent()->findAttribute("texture")};
// tags replacement support for Skins
if (_version >= Version(1, 1))
{
texture = LanguageManager::getInstance().replaceTags(texture);
}
const IntSize& size = texture_utility::getTextureSize(texture);
IntCoord coord = IntCoord::parse(_node->findAttribute("offset"));
mRect = CoordConverter::convertTextureCoord(coord, size);
}
private:
FloatRect mRect;
IntPoint mCenter;
float mAngle{0}; // Angle in radians
};
class MYGUI_EXPORT EditTextStateInfo : public IStateInfo
{
MYGUI_RTTI_DERIVED(EditTextStateInfo)
public:
const Colour& getColour() const
{
return mColour;
}
bool getShift() const
{
return mShift;
}
private:
void deserialization(xml::ElementPtr _node, Version _version) override
{
mShift = utility::parseBool(_node->findAttribute("shift"));
std::string colour{_node->findAttribute("colour")};
if (_version >= Version(1, 1))
{
colour = LanguageManager::getInstance().replaceTags(colour);
}
mColour = Colour::parse(colour);
}
private:
Colour mColour{Colour::White};
bool mShift{false};
};
} // namespace MyGUI
#endif // MYGUI_COMMON_STATE_INFO_H_
MyGUI_CoordConverter.h
MyGUI_IStateInfo.h
MyGUI_LanguageManager.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
MyGUI_TextureUtility.h
MyGUI::EditTextStateInfo
Definition MyGUI_CommonStateInfo.h:165
MyGUI::EditTextStateInfo::getColour
const Colour & getColour() const
Definition MyGUI_CommonStateInfo.h:169
MyGUI::EditTextStateInfo::getShift
bool getShift() const
Definition MyGUI_CommonStateInfo.h:174
MyGUI::IStateInfo
Definition MyGUI_IStateInfo.h:17
MyGUI::RotatingSkinStateInfo
Definition MyGUI_CommonStateInfo.h:111
MyGUI::RotatingSkinStateInfo::getCenter
const IntPoint & getCenter() const
Definition MyGUI_CommonStateInfo.h:120
MyGUI::RotatingSkinStateInfo::getRect
const FloatRect & getRect() const
Definition MyGUI_CommonStateInfo.h:125
MyGUI::RotatingSkinStateInfo::getAngle
float getAngle() const
Definition MyGUI_CommonStateInfo.h:115
MyGUI::SubSkinStateInfo
Definition MyGUI_CommonStateInfo.h:20
MyGUI::SubSkinStateInfo::getRect
const FloatRect & getRect() const
Definition MyGUI_CommonStateInfo.h:24
MyGUI::TileRectStateInfo
Definition MyGUI_CommonStateInfo.h:50
MyGUI::TileRectStateInfo::getTileV
bool getTileV() const
Definition MyGUI_CommonStateInfo.h:69
MyGUI::TileRectStateInfo::getRect
const FloatRect & getRect() const
Definition MyGUI_CommonStateInfo.h:54
MyGUI::TileRectStateInfo::getTileSize
const IntSize & getTileSize() const
Definition MyGUI_CommonStateInfo.h:59
MyGUI::TileRectStateInfo::getTileH
bool getTileH() const
Definition MyGUI_CommonStateInfo.h:64
MyGUI::Version
Definition MyGUI_Version.h:18
MyGUI::xml::ElementEnumerator
Definition MyGUI_XmlDocument.h:121
MyGUI::xml::ElementEnumerator::next
bool next()
Definition MyGUI_XmlDocument.cpp:107
MyGUI::xml::Element::findAttribute
bool findAttribute(std::string_view _name, std::string &_value)
Definition MyGUI_XmlDocument.cpp:242
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition MyGUI_XmlDocument.cpp:348
MyGUI::xml::Element::getParent
ElementPtr getParent() const
Definition MyGUI_XmlDocument.cpp:343
MyGUI::utility::parseBool
bool parseBool(std::string_view _value)
Definition MyGUI_StringUtility.h:127
MyGUI::utility::parseFloat
float parseFloat(std::string_view _value)
Definition MyGUI_StringUtility.h:117
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition MyGUI_XmlDocument.h:112
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::FloatRect
types::TRect< float > FloatRect
Definition MyGUI_Types.h:34
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::Colour
Definition MyGUI_Colour.h:17
MyGUI::types::TPoint< int >::parse
static TPoint< int > parse(std::string_view _value)
Definition MyGUI_TPoint.h:102