[PATCH] Set RotatingSkin properties from skin xml

scrawl

27-04-2014 10:09:40

I made a patch that allows you to set RotatingSkin properties (Center and Angle) from the skin xml file (previously, you would need to set it manually in code).

This gives you a bit more freedom in creating skins/themes. For example, you can now create a scrollbar skin with top and bottom arrows that use the same image file, but the bottom arrow would just be rotated by 180 degrees.


Index: MyGUIEngine/include/MyGUI_CommonStateInfo.h
===================================================================
--- MyGUIEngine/include/MyGUI_CommonStateInfo.h (revision 5296)
+++ MyGUIEngine/include/MyGUI_CommonStateInfo.h (working copy)
@@ -116,6 +116,67 @@
bool mTileV;
};

+ class MYGUI_EXPORT RotatingSkinStateInfo :
+ public IStateInfo
+ {
+ MYGUI_RTTI_DERIVED( RotatingSkinStateInfo )
+
+ public:
+ RotatingSkinStateInfo() :
+ mAngle(0),
+ mCenter(0,0)
+ {
+ }
+
+ virtual ~RotatingSkinStateInfo() { }
+
+ float getAngle() const
+ {
+ return mAngle;
+ }
+
+ const IntPoint& getCenter() const
+ {
+ return mCenter;
+ }
+
+ const FloatRect& getRect() const
+ {
+ return mRect;
+ }
+
+ private:
+ virtual void deserialization(xml::ElementPtr _node, Version _version)
+ {
+ xml::ElementEnumerator prop = _node->getElementEnumerator();
+ while (prop.next("Property"))
+ {
+ const std::string& key = prop->findAttribute("key");
+ const std::string& 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");
+
+ // поддержка замены тегов в скинах
+ if (_version >= Version(1, 1))
+ {
+ texture = LanguageManager::getInstance().replaceTags(texture);
+ }
+
+ const IntSize& size = texture_utility::getTextureSize(texture);
+ const IntCoord& coord = IntCoord::parse(_node->findAttribute("offset"));
+ mRect = CoordConverter::convertTextureCoord(coord, size);
+ }
+
+ private:
+ FloatRect mRect;
+ IntPoint mCenter;
+ float mAngle; // Angle in radians
+ };
+
+
class MYGUI_EXPORT EditTextStateInfo :
public IStateInfo
{
Index: MyGUIEngine/src/MyGUI_RotatingSkin.cpp
===================================================================
--- MyGUIEngine/src/MyGUI_RotatingSkin.cpp (revision 5296)
+++ MyGUIEngine/src/MyGUI_RotatingSkin.cpp (working copy)
@@ -199,7 +199,12 @@

void RotatingSkin::setStateData(IStateInfo* _data)
{
- _setUVSet(_data->castType<SubSkinStateInfo>()->getRect());
+ RotatingSkinStateInfo* data = _data->castType<RotatingSkinStateInfo>();
+
+ setAngle(data->getAngle());
+ setCenter(data->getCenter());
+
+ _setUVSet(data->getRect());
}

void RotatingSkin::_setUVSet(const FloatRect& _rect)
Index: MyGUIEngine/src/MyGUI_SubWidgetManager.cpp
===================================================================
--- MyGUIEngine/src/MyGUI_SubWidgetManager.cpp (revision 5296)
+++ MyGUIEngine/src/MyGUI_SubWidgetManager.cpp (working copy)
@@ -40,7 +40,7 @@
factory.registerFactory<SubSkinStateInfo>(mStateCategoryName, "SubSkin");
factory.registerFactory<SubSkinStateInfo>(mStateCategoryName, "MainSkin");
factory.registerFactory<SubSkinStateInfo>(mStateCategoryName, "PolygonalSkin");
- factory.registerFactory<SubSkinStateInfo>(mStateCategoryName, "RotatingSkin");
+ factory.registerFactory<RotatingSkinStateInfo>(mStateCategoryName, "RotatingSkin");
factory.registerFactory<TileRectStateInfo>(mStateCategoryName, "TileRect");
factory.registerFactory<EditTextStateInfo>(mStateCategoryName, "EditText");
factory.registerFactory<EditTextStateInfo>(mStateCategoryName, "SimpleText");


Usage example:

<Skin name = "MyRotatingSkin" size = "16 16">
<BasisSkin type="RotatingSkin" offset="0 0 16 16" align="Stretch">
<State name="normal" offset="0 0 16 16">
<Property key="Center" value="8 8"/>
<Property key="Angle" value="3.141"/>
</State>
</BasisSkin>
</Skin>

Altren

28-04-2014 00:08:57

Thank you for a clear and good patch. Committed it.