From daef517aa9211688e6b072bae7d9d3c010f61eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 14 Jul 2018 20:43:29 -0300 Subject: [PATCH] Added NodeAttribute, now UIWidgets can setAttribute from attribute name and value. --HG-- branch : dev --- include/eepp/scene/nodeattribute.hpp | 52 +++ include/eepp/ui/uicheckbox.hpp | 2 +- include/eepp/ui/uidropdownlist.hpp | 4 +- include/eepp/ui/uigridlayout.hpp | 2 +- include/eepp/ui/uiimage.hpp | 2 +- include/eepp/ui/uilinearlayout.hpp | 2 +- include/eepp/ui/uilistbox.hpp | 2 + include/eepp/ui/uiloader.hpp | 2 +- include/eepp/ui/uiprogressbar.hpp | 2 +- include/eepp/ui/uipushbutton.hpp | 2 +- include/eepp/ui/uiradiobutton.hpp | 2 +- include/eepp/ui/uiscrollbar.hpp | 3 +- include/eepp/ui/uiscrollview.hpp | 2 +- include/eepp/ui/uiselectbutton.hpp | 2 +- include/eepp/ui/uislider.hpp | 2 +- include/eepp/ui/uispinbox.hpp | 2 +- include/eepp/ui/uisprite.hpp | 2 +- include/eepp/ui/uitab.hpp | 2 +- include/eepp/ui/uitable.hpp | 2 +- include/eepp/ui/uitabwidget.hpp | 2 +- include/eepp/ui/uitextedit.hpp | 2 +- include/eepp/ui/uitextinput.hpp | 2 +- include/eepp/ui/uitextureregion.hpp | 4 +- include/eepp/ui/uitextview.hpp | 2 +- include/eepp/ui/uitouchdragablewidget.hpp | 2 +- include/eepp/ui/uiwidget.hpp | 12 +- include/eepp/ui/uiwindow.hpp | 2 + projects/linux/ee.files | 2 + src/eepp/scene/nodeattribute.cpp | 69 ++++ src/eepp/ui/uicheckbox.cpp | 19 +- src/eepp/ui/uicombobox.cpp | 4 +- src/eepp/ui/uidropdownlist.cpp | 29 +- src/eepp/ui/uigridlayout.cpp | 85 ++-- src/eepp/ui/uiimage.cpp | 53 ++- src/eepp/ui/uilinearlayout.cpp | 29 +- src/eepp/ui/uilistbox.cpp | 125 +++--- src/eepp/ui/uiloader.cpp | 55 ++- src/eepp/ui/uimenu.cpp | 4 +- src/eepp/ui/uiprogressbar.cpp | 53 ++- src/eepp/ui/uipushbutton.cpp | 43 +-- src/eepp/ui/uiradiobutton.cpp | 19 +- src/eepp/ui/uiscrollbar.cpp | 10 +- src/eepp/ui/uiscrollview.cpp | 67 ++-- src/eepp/ui/uiselectbutton.cpp | 19 +- src/eepp/ui/uislider.cpp | 49 +-- src/eepp/ui/uispinbox.cpp | 33 +- src/eepp/ui/uisprite.cpp | 25 +- src/eepp/ui/uitab.cpp | 27 +- src/eepp/ui/uitable.cpp | 79 ++-- src/eepp/ui/uitabwidget.cpp | 127 +++--- src/eepp/ui/uitextedit.cpp | 47 +-- src/eepp/ui/uitextinput.cpp | 41 +- src/eepp/ui/uitextureregion.cpp | 49 +-- src/eepp/ui/uitextview.cpp | 133 +++---- src/eepp/ui/uitouchdragablewidget.cpp | 23 +- src/eepp/ui/uiwidget.cpp | 451 +++++++++++----------- src/eepp/ui/uiwindow.cpp | 87 ++--- src/eepp/ui/uiwinmenu.cpp | 4 +- 58 files changed, 985 insertions(+), 994 deletions(-) create mode 100644 include/eepp/scene/nodeattribute.hpp create mode 100644 src/eepp/scene/nodeattribute.cpp diff --git a/include/eepp/scene/nodeattribute.hpp b/include/eepp/scene/nodeattribute.hpp new file mode 100644 index 000000000..9daef6504 --- /dev/null +++ b/include/eepp/scene/nodeattribute.hpp @@ -0,0 +1,52 @@ +#ifndef EE_NODEATTRIBUTE_HPP +#define EE_NODEATTRIBUTE_HPP + +#include +#include + +namespace EE { namespace Scene { + +class NodeAttribute { + public: + NodeAttribute( std::string name, std::string value ); + + std::string getName() const; + + void setName(const std::string & name); + + const std::string& getValue() const; + + const std::string& value() const; + + void setValue(const std::string & value); + + std::string asString( const std::string& defaultValue = "" ) const; + + template + Type asType( Type defaultValue ) const { + Type val = defaultValue; + return String::fromString( val, mValue ) ? val : defaultValue; + } + + int asInt( int defaultValue = 0 ) const; + + unsigned int asUint( unsigned int defaultValue = 0 ) const; + + double asDouble( double defaultValue = 0 ) const; + + float asFloat( float defaultValue = 0 ) const; + + long long asLlong( long long defaultValue = 0) const; + + unsigned long long asUllong( unsigned long long defaultValue = 0 ) const; + + bool asBool( bool defaultValue = false ) const; + + protected: + std::string mName; + std::string mValue; +}; + +}} + +#endif diff --git a/include/eepp/ui/uicheckbox.hpp b/include/eepp/ui/uicheckbox.hpp index 5821b3406..6d869e0ec 100644 --- a/include/eepp/ui/uicheckbox.hpp +++ b/include/eepp/ui/uicheckbox.hpp @@ -32,7 +32,7 @@ class EE_API UICheckBox : public UITextView { void setTextSeparation(const Int32 & textSeparation); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: UINode * mActiveButton; UINode * mInactiveButton; diff --git a/include/eepp/ui/uidropdownlist.hpp b/include/eepp/ui/uidropdownlist.hpp index 238de6fb4..861c7296f 100644 --- a/include/eepp/ui/uidropdownlist.hpp +++ b/include/eepp/ui/uidropdownlist.hpp @@ -38,7 +38,9 @@ class EE_API UIDropDownList : public UITextInput { void setStyleConfig(const UIDropDownListStyleConfig & styleConfig); - void loadFromXmlNode(const pugi::xml_node & node); + virtual void setAttribute( const NodeAttribute& attribute ); + + virtual void loadFromXmlNode(const pugi::xml_node & node); protected: friend class UIComboBox; diff --git a/include/eepp/ui/uigridlayout.hpp b/include/eepp/ui/uigridlayout.hpp index 4c70806cb..ab333d6f4 100644 --- a/include/eepp/ui/uigridlayout.hpp +++ b/include/eepp/ui/uigridlayout.hpp @@ -53,7 +53,7 @@ class EE_API UIGridLayout : public UILayout { void setPadding(const Rect & padding); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: Rect mPadding; Sizei mSpan; diff --git a/include/eepp/ui/uiimage.hpp b/include/eepp/ui/uiimage.hpp index 8be80a5ca..c243a5e47 100644 --- a/include/eepp/ui/uiimage.hpp +++ b/include/eepp/ui/uiimage.hpp @@ -31,7 +31,7 @@ class EE_API UIImage : public UIWidget { const Vector2f& getAlignOffset() const; - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); Uint32 getScaleType() const; diff --git a/include/eepp/ui/uilinearlayout.hpp b/include/eepp/ui/uilinearlayout.hpp index f16aab5d2..e52327416 100644 --- a/include/eepp/ui/uilinearlayout.hpp +++ b/include/eepp/ui/uilinearlayout.hpp @@ -25,7 +25,7 @@ class EE_API UILinearLayout : public UILayout { UILinearLayout * add( UIWidget * widget ); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: UI_ORIENTATION mOrientation; diff --git a/include/eepp/ui/uilistbox.hpp b/include/eepp/ui/uilistbox.hpp index e9a274134..f510fb974 100644 --- a/include/eepp/ui/uilistbox.hpp +++ b/include/eepp/ui/uilistbox.hpp @@ -112,6 +112,8 @@ class EE_API UIListBox : public UITouchDragableWidget { void setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig); void loadFromXmlNode(const pugi::xml_node & node); + + virtual void setAttribute( const NodeAttribute& attribute ); protected: friend class UIListBoxItem; friend class UIItemContainer; diff --git a/include/eepp/ui/uiloader.hpp b/include/eepp/ui/uiloader.hpp index c983937e6..76a07f2f9 100644 --- a/include/eepp/ui/uiloader.hpp +++ b/include/eepp/ui/uiloader.hpp @@ -49,7 +49,7 @@ class EE_API UILoader : public UIWidget { UILoader * setAnimationSpeed( const Float& animationSpeed ); - virtual void loadFromXmlNode( const pugi::xml_node& node); + virtual void setAttribute( const NodeAttribute& attribute ); Float getArcStartAngle() const; diff --git a/include/eepp/ui/uiprogressbar.hpp b/include/eepp/ui/uiprogressbar.hpp index 79eae2ab8..f05141957 100644 --- a/include/eepp/ui/uiprogressbar.hpp +++ b/include/eepp/ui/uiprogressbar.hpp @@ -51,7 +51,7 @@ class EE_API UIProgressBar : public UIWidget { UITextView * getTextBox() const; - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: UIProgressBarStyleConfig mStyleConfig; Float mProgress; diff --git a/include/eepp/ui/uipushbutton.hpp b/include/eepp/ui/uipushbutton.hpp index b70b0d58a..048d314fd 100644 --- a/include/eepp/ui/uipushbutton.hpp +++ b/include/eepp/ui/uipushbutton.hpp @@ -75,7 +75,7 @@ class EE_API UIPushButton : public UIWidget { void setStyleConfig(const UIPushButtonStyleConfig & styleConfig); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: UIPushButtonStyleConfig mStyleConfig; UIImage * mIcon; diff --git a/include/eepp/ui/uiradiobutton.hpp b/include/eepp/ui/uiradiobutton.hpp index a8499b195..a622cd295 100644 --- a/include/eepp/ui/uiradiobutton.hpp +++ b/include/eepp/ui/uiradiobutton.hpp @@ -32,7 +32,7 @@ class EE_API UIRadioButton : public UITextView { void setTextSeparation(const Int32 & textSeparation); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: UINode * mActiveButton; UINode * mInactiveButton; diff --git a/include/eepp/ui/uiscrollbar.hpp b/include/eepp/ui/uiscrollbar.hpp index 44ca915bf..76bab118e 100644 --- a/include/eepp/ui/uiscrollbar.hpp +++ b/include/eepp/ui/uiscrollbar.hpp @@ -67,8 +67,7 @@ class EE_API UIScrollBar : public UIWidget { void setExpandBackground( bool expandBackground ); - virtual void loadFromXmlNode( const pugi::xml_node& node ); - + virtual void setAttribute( const NodeAttribute& attribute ); protected: ScrollBarType mScrollBarType; UISlider * mSlider; diff --git a/include/eepp/ui/uiscrollview.hpp b/include/eepp/ui/uiscrollview.hpp index 279752b4e..3524b060c 100644 --- a/include/eepp/ui/uiscrollview.hpp +++ b/include/eepp/ui/uiscrollview.hpp @@ -40,7 +40,7 @@ class EE_API UIScrollView : public UITouchDragableWidget { UINode * getContainer() const; - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: ScrollViewType mViewType; UI_SCROLLBAR_MODE mVScrollMode; diff --git a/include/eepp/ui/uiselectbutton.hpp b/include/eepp/ui/uiselectbutton.hpp index 70cc54ae5..70ab084c7 100644 --- a/include/eepp/ui/uiselectbutton.hpp +++ b/include/eepp/ui/uiselectbutton.hpp @@ -27,7 +27,7 @@ class EE_API UISelectButton : public UIPushButton { const Color& getFontSelectedColor() const; - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: virtual void onStateChange(); }; diff --git a/include/eepp/ui/uislider.hpp b/include/eepp/ui/uislider.hpp index c78cda791..64848980e 100644 --- a/include/eepp/ui/uislider.hpp +++ b/include/eepp/ui/uislider.hpp @@ -64,7 +64,7 @@ class EE_API UISlider : public UIWidget { void setPageStep( const Float & pageStep ); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: friend class Private::UISliderButton; diff --git a/include/eepp/ui/uispinbox.hpp b/include/eepp/ui/uispinbox.hpp index abfefb497..617e710f7 100644 --- a/include/eepp/ui/uispinbox.hpp +++ b/include/eepp/ui/uispinbox.hpp @@ -56,7 +56,7 @@ class EE_API UISpinBox : public UIWidget { bool dotsInNumbersAllowed(); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: UITextInput * mInput; UINode * mPushUp; diff --git a/include/eepp/ui/uisprite.hpp b/include/eepp/ui/uisprite.hpp index c44758cb2..48d168708 100644 --- a/include/eepp/ui/uisprite.hpp +++ b/include/eepp/ui/uisprite.hpp @@ -46,7 +46,7 @@ class EE_API UISprite : public UIWidget { bool getDeallocSprite(); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: Graphics::Sprite * mSprite; RenderMode mRender; diff --git a/include/eepp/ui/uitab.hpp b/include/eepp/ui/uitab.hpp index a14204a16..0ab3b6e39 100644 --- a/include/eepp/ui/uitab.hpp +++ b/include/eepp/ui/uitab.hpp @@ -31,7 +31,7 @@ class EE_API UITab : public UISelectButton { virtual void update( const Time& time ); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: Node * mControlOwned; std::string mOwnedName; diff --git a/include/eepp/ui/uitable.hpp b/include/eepp/ui/uitable.hpp index 9e3b765d2..11a848689 100644 --- a/include/eepp/ui/uitable.hpp +++ b/include/eepp/ui/uitable.hpp @@ -79,7 +79,7 @@ class EE_API UITable : public UITouchDragableWidget { void setContainerPadding( const Rectf& containerPadding ); - void loadFromXmlNode(const pugi::xml_node & node); + virtual void setAttribute( const NodeAttribute& attribute ); protected: friend class UIItemContainer; friend class UITableCell; diff --git a/include/eepp/ui/uitabwidget.hpp b/include/eepp/ui/uitabwidget.hpp index 25454a275..c0a383b31 100644 --- a/include/eepp/ui/uitabwidget.hpp +++ b/include/eepp/ui/uitabwidget.hpp @@ -135,7 +135,7 @@ class EE_API UITabWidget : public UIWidget { void setStyleConfig(const UITabWidgetStyleConfig & styleConfig); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: friend class UITab; diff --git a/include/eepp/ui/uitextedit.hpp b/include/eepp/ui/uitextedit.hpp index c38e75521..c5787f437 100644 --- a/include/eepp/ui/uitextedit.hpp +++ b/include/eepp/ui/uitextedit.hpp @@ -49,7 +49,7 @@ class EE_API UITextEdit : public UIWidget { void setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: UITextInput * mTextInput; UIScrollBar * mHScrollBar; diff --git a/include/eepp/ui/uitextinput.hpp b/include/eepp/ui/uitextinput.hpp index d349bfd62..7e5436b27 100644 --- a/include/eepp/ui/uitextinput.hpp +++ b/include/eepp/ui/uitextinput.hpp @@ -47,7 +47,7 @@ class EE_API UITextInput : public UITextView { bool isFreeEditingEnabled(); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: InputTextBuffer mTextBuffer; Float mWaitCursorTime; diff --git a/include/eepp/ui/uitextureregion.hpp b/include/eepp/ui/uitextureregion.hpp index bfc9f4c40..119ba5a21 100644 --- a/include/eepp/ui/uitextureregion.hpp +++ b/include/eepp/ui/uitextureregion.hpp @@ -39,11 +39,11 @@ class EE_API UITextureRegion : public UIWidget { const Vector2f& getAlignOffset() const; - virtual void loadFromXmlNode( const pugi::xml_node& node ); - Uint32 getScaleType() const; UITextureRegion * setScaleType(const Uint32 & scaleType); + + virtual void setAttribute( const NodeAttribute& attribute ); protected: Uint32 mScaleType; Graphics::TextureRegion * mTextureRegion; diff --git a/include/eepp/ui/uitextview.hpp b/include/eepp/ui/uitextview.hpp index 02d1750ab..555c59533 100644 --- a/include/eepp/ui/uitextview.hpp +++ b/include/eepp/ui/uitextview.hpp @@ -80,7 +80,7 @@ class EE_API UITextView : public UIWidget { UITextView * setPadding(const Rectf& padding); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: Text * mTextCache; String mString; diff --git a/include/eepp/ui/uitouchdragablewidget.hpp b/include/eepp/ui/uitouchdragablewidget.hpp index 8cc493c4b..d7167d0c4 100644 --- a/include/eepp/ui/uitouchdragablewidget.hpp +++ b/include/eepp/ui/uitouchdragablewidget.hpp @@ -29,7 +29,7 @@ class EE_API UITouchDragableWidget : public UIWidget { UITouchDragableWidget * setTouchDragDeceleration( const Vector2f& touchDragDeceleration ); - virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); protected: Vector2f mTouchDragPoint; Vector2f mTouchDragAcceleration; diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index bf8bf38ea..faf61bac4 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -1,6 +1,7 @@ #ifndef EE_UIUIWIDGET_HPP #define EE_UIUIWIDGET_HPP +#include #include #include @@ -85,6 +86,10 @@ class EE_API UIWidget : public UINode { void notifyLayoutAttrChange(); void notifyLayoutAttrChangeParent(); + + void setAttribute( const std::string& name, const std::string& value ); + + virtual void setAttribute( const NodeAttribute& attribute ); protected: friend class UIManager; friend class UISceneNode; @@ -101,7 +106,8 @@ class EE_API UIWidget : public UINode { LayoutSizeRules mLayoutHeightRules; LayoutPositionRules mLayoutPositionRule; UIWidget * mLayoutPositionRuleWidget; - int mPropertiesTransactionCount; + int mAttributesTransactionCount; + std::string mSkinName; void createTooltip(); @@ -115,9 +121,9 @@ class EE_API UIWidget : public UINode { virtual void onWidgetCreated(); - void beginPropertiesTransaction(); + void beginAttributesTransaction(); - void endPropertiesTransaction(); + void endAttributesTransaction(); void updateAnchors( const Vector2f & SizeChange ); diff --git a/include/eepp/ui/uiwindow.hpp b/include/eepp/ui/uiwindow.hpp index a2abce028..81bb32a9f 100644 --- a/include/eepp/ui/uiwindow.hpp +++ b/include/eepp/ui/uiwindow.hpp @@ -109,6 +109,8 @@ class EE_API UIWindow : public UIWidget { virtual void loadFromXmlNode( const pugi::xml_node& node ); + virtual void setAttribute( const NodeAttribute& attribute ); + virtual void internalDraw(); void invalidate(); diff --git a/projects/linux/ee.files b/projects/linux/ee.files index d0d011b1a..aa1cfdba8 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -216,6 +216,7 @@ ../../include/eepp/scene/keyevent.hpp ../../include/eepp/scene/mouseevent.hpp ../../include/eepp/scene/node.hpp +../../include/eepp/scene/nodeattribute.hpp ../../include/eepp/scene/nodemessage.hpp ../../include/eepp/scene/scenemanager.hpp ../../include/eepp/scene/scenenode.hpp @@ -625,6 +626,7 @@ ../../src/eepp/scene/keyevent.cpp ../../src/eepp/scene/mouseevent.cpp ../../src/eepp/scene/node.cpp +../../src/eepp/scene/nodeattribute.cpp ../../src/eepp/scene/nodemessage.cpp ../../src/eepp/scene/scenemanager.cpp ../../src/eepp/scene/scenenode.cpp diff --git a/src/eepp/scene/nodeattribute.cpp b/src/eepp/scene/nodeattribute.cpp new file mode 100644 index 000000000..1148c2cbb --- /dev/null +++ b/src/eepp/scene/nodeattribute.cpp @@ -0,0 +1,69 @@ +#include + +namespace EE { namespace Scene { + +NodeAttribute::NodeAttribute( std::string name, std::string value ) : + mName( String::toLower( name ) ), + mValue( value ) +{} + +std::string NodeAttribute::getName() const { + return mName; +} + +void NodeAttribute::setName( const std::string& name ) { + mName = name; +} + +const std::string& NodeAttribute::getValue() const { + return mValue; +} + +const std::string& NodeAttribute::value() const { + return mValue; +} + +void NodeAttribute::setValue( const std::string& value ) { + mValue = value; +} + +std::string NodeAttribute::asString( const std::string& defaultValue ) const { + return mValue.empty() ? defaultValue : mValue; +} + +int NodeAttribute::asInt( int defaultValue ) const { + return asType( defaultValue ); +} + +unsigned int NodeAttribute::asUint( unsigned int defaultValue ) const { + return asType( defaultValue ); +} + +double NodeAttribute::asDouble( double defaultValue ) const { + return asType( defaultValue ); +} + +float NodeAttribute::asFloat(float defaultValue) const { + return asType( defaultValue ); +} + +long long NodeAttribute::asLlong(long long defaultValue) const { + return asType( defaultValue ); +} + +unsigned long long NodeAttribute::asUllong(unsigned long long defaultValue) const { + return asType( defaultValue ); +} + +bool NodeAttribute::asBool( bool defaultValue ) const { + if ( mValue.empty() ) + return defaultValue; + + // only look at first char + char first = mValue[0]; + + // 1*, t* (true), T* (True), y* (yes), Y* (YES) + return (first == '1' || first == 't' || first == 'T' || first == 'y' || first == 'Y'); +} + +}} diff --git a/src/eepp/ui/uicheckbox.cpp b/src/eepp/ui/uicheckbox.cpp index 10fc9f01e..04bfbaba7 100644 --- a/src/eepp/ui/uicheckbox.cpp +++ b/src/eepp/ui/uicheckbox.cpp @@ -167,21 +167,14 @@ void UICheckBox::setTextSeparation(const Int32 & textSeparation) { setPadding( getPadding() ); } -void UICheckBox::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UICheckBox::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "selected" == name || "active" == name ) { - setActive( ait->as_bool() ); - } + if ( "selected" == name || "active" == name ) { + setActive( attribute.asBool() ); + } else { + UITextView::setAttribute( attribute ); } - - endPropertiesTransaction(); } Uint32 UICheckBox::onKeyDown( const KeyEvent& Event ) { diff --git a/src/eepp/ui/uicombobox.cpp b/src/eepp/ui/uicombobox.cpp index 1986ac275..a95b5364d 100644 --- a/src/eepp/ui/uicombobox.cpp +++ b/src/eepp/ui/uicombobox.cpp @@ -74,13 +74,13 @@ const String& UIComboBox::getText() { } void UIComboBox::loadFromXmlNode(const pugi::xml_node& node) { - beginPropertiesTransaction(); + beginAttributesTransaction(); UIWidget::loadFromXmlNode( node ); mDropDownList->loadFromXmlNode( node ); - endPropertiesTransaction(); + endAttributesTransaction(); } Uint32 UIComboBox::onMessage( const NodeMessage * Msg ) { diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index 5999b4ea5..6dff60e23 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -265,25 +265,28 @@ void UIDropDownList::destroyListBox() { } } +void UIDropDownList::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); + + if ( "popuptomaincontrol" == name ) { + setPopUpToMainControl( attribute.asBool() ); + } else if ( "maxnumvisibleitems" == name ) { + setMaxNumVisibleItems( attribute.asUint() ); + } else { + UITextInput::setAttribute( attribute ); + } + + mListBox->setAttribute( attribute ); +} + void UIDropDownList::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); + beginAttributesTransaction(); UITextInput::loadFromXmlNode( node ); mListBox->loadFromXmlNode( node ); - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "popuptomaincontrol" == name ) { - setPopUpToMainControl( ait->as_bool() ); - } else if ( "maxnumvisibleitems" == name ) { - setMaxNumVisibleItems( ait->as_uint() ); - } - } - - endPropertiesTransaction(); + endAttributesTransaction(); } }} diff --git a/src/eepp/ui/uigridlayout.cpp b/src/eepp/ui/uigridlayout.cpp index 3b14180de..1d0761746 100644 --- a/src/eepp/ui/uigridlayout.cpp +++ b/src/eepp/ui/uigridlayout.cpp @@ -206,54 +206,47 @@ Sizef UIGridLayout::getTargetElementSize() { mRowMode == Size ? mRowHeight : ( ( getLayoutHeightRules() == WRAP_CONTENT ? getParent()->getSize().getHeight() : mDpSize.getHeight() ) - mPadding.Top - mPadding.Bottom ) * mRowWeight ); } -void UIGridLayout::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UIGridLayout::setAttribute( const NodeAttribute &attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "columnspan" == name ) { - setSpan( Sizei( ait->as_int(), mSpan.y ) ); - } else if ( "rowspan" == name ) { - setSpan( Sizei( mSpan.x, ait->as_int() ) ); - } else if ( "span" == name ) { - setSpan( Sizei( ait->as_int(), ait->as_int() ) ); - } else if ( "columnmode" == name ) { - std::string val( ait->as_string() ); - String::toLowerInPlace( val ); - setColumnMode( "size" == val ? Size : Weight ); - } else if ( "rowmode" == name ) { - std::string val( ait->as_string() ); - String::toLowerInPlace( val ); - setRowMode( "size" == val ? Size : Weight ); - } else if ( "columnweight" == name ) { - setColumnWeight( ait->as_float() ); - } else if ( "columnwidth" == name ) { - setColumnWidth( ait->as_int() ); - } else if ( "rowweight" == name ) { - setRowWeight( ait->as_float() ); - } else if ( "rowheight" == name ) { - setRowHeight( ait->as_int() ); - } else if ( "padding" == name ) { - int val = PixelDensity::toDpFromStringI( ait->as_string() ); - setPadding( Rect( val, val, val, val ) ); - } else if ( "paddingleft" == name ) { - setPadding( Rect( PixelDensity::toDpFromStringI( ait->as_string() ), mPadding.Top, mPadding.Right, mPadding.Bottom ) ); - } else if ( "paddingright" == name ) { - setPadding( Rect( mPadding.Left, mPadding.Top, PixelDensity::toDpFromStringI( ait->as_string() ), mPadding.Bottom ) ); - } else if ( "paddingtop" == name ) { - setPadding( Rect( mPadding.Left, PixelDensity::toDpFromStringI( ait->as_string() ), mPadding.Right, mPadding.Bottom ) ); - } else if ( "paddingbottom" == name ) { - setPadding( Rect( mPadding.Left, mPadding.Top, mPadding.Right, PixelDensity::toDpFromStringI( ait->as_string() ) ) ); - } else if ( "reversedraw" == name ) { - setReverseDraw( ait->as_bool() ); - } + if ( "columnspan" == name ) { + setSpan( Sizei( attribute.asInt(), mSpan.y ) ); + } else if ( "rowspan" == name ) { + setSpan( Sizei( mSpan.x, attribute.asInt() ) ); + } else if ( "span" == name ) { + setSpan( Sizei( attribute.asInt(), attribute.asInt() ) ); + } else if ( "columnmode" == name ) { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + setColumnMode( "size" == val ? Size : Weight ); + } else if ( "rowmode" == name ) { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + setRowMode( "size" == val ? Size : Weight ); + } else if ( "columnweight" == name ) { + setColumnWeight( attribute.asFloat() ); + } else if ( "columnwidth" == name ) { + setColumnWidth( attribute.asInt() ); + } else if ( "rowweight" == name ) { + setRowWeight( attribute.asFloat() ); + } else if ( "rowheight" == name ) { + setRowHeight( attribute.asInt() ); + } else if ( "padding" == name ) { + int val = PixelDensity::toDpFromStringI( attribute.asString() ); + setPadding( Rect( val, val, val, val ) ); + } else if ( "paddingleft" == name ) { + setPadding( Rect( PixelDensity::toDpFromStringI( attribute.asString() ), mPadding.Top, mPadding.Right, mPadding.Bottom ) ); + } else if ( "paddingright" == name ) { + setPadding( Rect( mPadding.Left, mPadding.Top, PixelDensity::toDpFromStringI( attribute.asString() ), mPadding.Bottom ) ); + } else if ( "paddingtop" == name ) { + setPadding( Rect( mPadding.Left, PixelDensity::toDpFromStringI( attribute.asString() ), mPadding.Right, mPadding.Bottom ) ); + } else if ( "paddingbottom" == name ) { + setPadding( Rect( mPadding.Left, mPadding.Top, mPadding.Right, PixelDensity::toDpFromStringI( attribute.asString() ) ) ); + } else if ( "reversedraw" == name ) { + setReverseDraw( attribute.asBool() ); + } else { + UILayout::setAttribute( attribute ); } - - endPropertiesTransaction(); } }} diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index 2cd73a435..143fd6ddb 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -175,41 +175,34 @@ const Vector2f& UIImage::getAlignOffset() const { return mAlignOffset; } -void UIImage::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UIImage::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "src" == name ) { + Drawable * res = NULL; - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); + if ( NULL != ( res = DrawableSearcher::searchByName( attribute.asString() ) ) ) { + if ( res->getDrawableType() == Drawable::SPRITE ) + mDrawableOwner = true; - if ( "src" == name ) { - Drawable * res = NULL; - - if ( NULL != ( res = DrawableSearcher::searchByName( ait->as_string() ) ) ) { - if ( res->getDrawableType() == Drawable::SPRITE ) - mDrawableOwner = true; - - setDrawable( res ); - } - } else if ( "scaletype" == name ) { - std::string val = ait->as_string(); - String::toLowerInPlace( val ); - - if ( "expand" == val ) { - setScaleType( UIScaleType::Expand ); - } else if ( "fit_inside" == val || "fitinside" == val ) { - setScaleType( UIScaleType::FitInside ); - } else if ( "none" == val ) { - setScaleType( UIScaleType::None ); - } - } else if ( "tint" == name ) { - setColor( Color::fromString( ait->as_string() ) ); + setDrawable( res ); } - } + } else if ( "scaletype" == name ) { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); - endPropertiesTransaction(); + if ( "expand" == val ) { + setScaleType( UIScaleType::Expand ); + } else if ( "fit_inside" == val || "fitinside" == val ) { + setScaleType( UIScaleType::FitInside ); + } else if ( "none" == val ) { + setScaleType( UIScaleType::None ); + } + } else if ( "tint" == name ) { + setColor( Color::fromString( attribute.asString() ) ); + } else { + UIWidget::setAttribute( attribute ); + } } Uint32 UIImage::getScaleType() const { diff --git a/src/eepp/ui/uilinearlayout.cpp b/src/eepp/ui/uilinearlayout.cpp index 8b47e6f43..85b013d70 100644 --- a/src/eepp/ui/uilinearlayout.cpp +++ b/src/eepp/ui/uilinearlayout.cpp @@ -328,27 +328,20 @@ Sizei UILinearLayout::getTotalUsedSize() { return size; } -void UILinearLayout::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UILinearLayout::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "orientation" == name ) { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "orientation" == name ) { - std::string val = ait->as_string(); - String::toLowerInPlace( val ); - - if ( "horizontal" == val ) - setOrientation( UI_HORIZONTAL ); - else if ( "vertical" == val ) - setOrientation( UI_VERTICAL ); - } + if ( "horizontal" == val ) + setOrientation( UI_HORIZONTAL ); + else if ( "vertical" == val ) + setOrientation( UI_VERTICAL ); + } else { + UILayout::setAttribute( attribute ); } - - endPropertiesTransaction(); } Uint32 UILinearLayout::onMessage(const NodeMessage * Msg) { diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 7881e248c..a67034f3c 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -985,8 +985,69 @@ void UIListBox::setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig) { setFontColor( mFontStyleConfig.FontColor ); } +void UIListBox::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); + + if ( "rowheight" == name ) { + setRowHeight( attribute.asInt() ); + } else if ( "textcolor" == name ) { + setFontColor( Color::fromString( attribute.asString() ) ); + } else if ( "textshadowcolor" == name ) { + mFontStyleConfig.ShadowColor = ( Color::fromString( attribute.asString() ) ); + } else if ( "textovercolor" == name ) { + setFontOverColor( Color::fromString( attribute.asString() ) ); + } else if ( "textselectedcolor" == name ) { + setFontSelectedColor( Color::fromString( attribute.asString() ) ); + } else if ( "textselectionbackcolor" == name ) { + mFontStyleConfig.FontSelectionBackColor = ( Color::fromString( attribute.asString() ) ); + } else if ( "fontfamily" == name || "fontname" == name ) { + Font * font = FontManager::instance()->getByName( attribute.asString() ); + + if ( NULL != font ) + setFont( font ); + } else if ( "padding" == name ) { + int val = attribute.asInt(); + setContainerPadding( Rectf( val, val, val, val ) ); + } else if ( "paddingleft" == name ) { + setContainerPadding( Rectf( attribute.asInt(), mContainerPadding.Top, mContainerPadding.Right, mContainerPadding.Bottom ) ); + } else if ( "paddingright" == name ) { + setContainerPadding( Rectf( mContainerPadding.Left, mContainerPadding.Top, attribute.asInt(), mContainerPadding.Bottom ) ); + } else if ( "paddingtop" == name ) { + setContainerPadding( Rectf( mContainerPadding.Left, attribute.asInt(), mContainerPadding.Right, mContainerPadding.Bottom ) ); + } else if ( "paddingbottom" == name ) { + setContainerPadding( Rectf( mContainerPadding.Left, mContainerPadding.Top, mContainerPadding.Right, attribute.asInt() ) ); + } else if ( "verticalscrollmode" == name || "vscrollmode" == name ) { + std::string val = attribute.asString(); + if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + } else if ( "horizontalscrollmode" == name || "hscrollmode" == name ) { + std::string val = attribute.asString(); + if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + } else if ( "selectedindex" == name ) { + setSelected( attribute.asUint() ); + } else if ( "selectedtext" == name ) { + setSelected( attribute.asString() ); + } else if ( "scrollbartype" == name ) { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + + if ( "nobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "twobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } + } else { + UITouchDragableWidget::setAttribute( attribute ); + } +} + void UIListBox::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); + beginAttributesTransaction(); UITouchDragableWidget::loadFromXmlNode( node ); @@ -1004,67 +1065,7 @@ void UIListBox::loadFromXmlNode(const pugi::xml_node & node) { addListBoxItems( items ); } - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "rowheight" == name ) { - setRowHeight( ait->as_int() ); - } else if ( "textcolor" == name ) { - setFontColor( Color::fromString( ait->as_string() ) ); - } else if ( "textshadowcolor" == name ) { - mFontStyleConfig.ShadowColor = ( Color::fromString( ait->as_string() ) ); - } else if ( "textovercolor" == name ) { - setFontOverColor( Color::fromString( ait->as_string() ) ); - } else if ( "textselectedcolor" == name ) { - setFontSelectedColor( Color::fromString( ait->as_string() ) ); - } else if ( "textselectionbackcolor" == name ) { - mFontStyleConfig.FontSelectionBackColor = ( Color::fromString( ait->as_string() ) ); - } else if ( "fontfamily" == name || "fontname" == name ) { - Font * font = FontManager::instance()->getByName( ait->as_string() ); - - if ( NULL != font ) - setFont( font ); - } else if ( "padding" == name ) { - int val = ait->as_int(); - setContainerPadding( Rectf( val, val, val, val ) ); - } else if ( "paddingleft" == name ) { - setContainerPadding( Rectf( ait->as_int(), mContainerPadding.Top, mContainerPadding.Right, mContainerPadding.Bottom ) ); - } else if ( "paddingright" == name ) { - setContainerPadding( Rectf( mContainerPadding.Left, mContainerPadding.Top, ait->as_int(), mContainerPadding.Bottom ) ); - } else if ( "paddingtop" == name ) { - setContainerPadding( Rectf( mContainerPadding.Left, ait->as_int(), mContainerPadding.Right, mContainerPadding.Bottom ) ); - } else if ( "paddingbottom" == name ) { - setContainerPadding( Rectf( mContainerPadding.Left, mContainerPadding.Top, mContainerPadding.Right, ait->as_int() ) ); - } else if ( "verticalscrollmode" == name || "vscrollmode" == name ) { - std::string val = ait->as_string(); - if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "horizontalscrollmode" == name || "hscrollmode" == name ) { - std::string val = ait->as_string(); - if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "selectedindex" == name ) { - setSelected( ait->as_uint() ); - } else if ( "selectedtext" == name ) { - setSelected( ait->as_string() ); - } else if ( "scrollbartype" == name ) { - std::string val( ait->as_string() ); - String::toLowerInPlace( val ); - - if ( "nobuttons" == val ) { - mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - } else if ( "twobuttons" == val ) { - mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); - mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - } - } - } - - endPropertiesTransaction(); + endAttributesTransaction(); } }} diff --git a/src/eepp/ui/uiloader.cpp b/src/eepp/ui/uiloader.cpp index 20ead7ee5..c46e8b06a 100644 --- a/src/eepp/ui/uiloader.cpp +++ b/src/eepp/ui/uiloader.cpp @@ -154,6 +154,30 @@ UILoader * UILoader::setAnimationSpeed( const Float& animationSpeed ) { return this; } +void UILoader::setAttribute( const NodeAttribute& attribute ) { + std::string name = attribute.getName(); + + if ( "indeterminate" == name ) { + setIndeterminate( attribute.asBool() ); + } else if ( "maxprogress" == name ) { + setMaxProgress( attribute.asFloat() ); + } else if ( "progress" == name ) { + setProgress( attribute.asFloat() ); + } else if ( "fillcolor" == name ) { + setFillColor( Color::fromString( attribute.asString() ) ); + } else if ( "radius" == name ) { + setRadius( attribute.asFloat() ); + } else if ( "outlinethickness" == name ) { + setOutlineThickness( attribute.asFloat() ); + } else if ( "animationspeed" == name ) { + setAnimationSpeed( attribute.asFloat() ); + } else if ( "arcstartangle" == name ) { + setArcStartAngle( attribute.asFloat() ); + } else { + UIWidget::setAttribute( attribute ); + } +} + Float UILoader::getArcStartAngle() const { return mArcStartAngle; } @@ -163,35 +187,4 @@ UILoader * UILoader::setArcStartAngle( const Float& arcStartAngle ) { return this; } -void UILoader::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); - - UIWidget::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "indeterminate" == name ) { - setIndeterminate( ait->as_bool() ); - } else if ( "maxprogress" == name ) { - setMaxProgress( ait->as_float() ); - } else if ( "progress" == name ) { - setProgress( ait->as_float() ); - } else if ( "fillcolor" == name ) { - setFillColor( Color::fromString( ait->as_string() ) ); - } else if ( "radius" == name ) { - setRadius( ait->as_float() ); - } else if ( "outlinethickness" == name ) { - setOutlineThickness( ait->as_float() ); - } else if ( "animationspeed" == name ) { - setAnimationSpeed( ait->as_float() ); - } else if ( "arcstartangle" == name ) { - setArcStartAngle( ait->as_float() ); - } - } - - endPropertiesTransaction(); -} - }} diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 7a72b1c72..1717f664e 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -552,7 +552,7 @@ static Drawable * getIconDrawable( const std::string& name ) { } void UIMenu::loadFromXmlNode( const pugi::xml_node& node ) { - beginPropertiesTransaction(); + beginAttributesTransaction(); UIWidget::loadFromXmlNode( node ); @@ -590,7 +590,7 @@ void UIMenu::loadFromXmlNode( const pugi::xml_node& node ) { } } - endPropertiesTransaction(); + endAttributesTransaction(); } void UIMenu::fixMenuPos( Vector2f& Pos, UIMenu * Menu, UIMenu * Parent, UIMenuSubMenu * SubMenu ) { diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index 95e7eeb0d..85ef8cd0d 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -213,38 +213,31 @@ UITextView * UIProgressBar::getTextBox() const { return mTextBox; } -void UIProgressBar::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UIProgressBar::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "totalsteps" == name ) { - setTotalSteps( ait->as_float() ); - } else if ( "progress" == name ) { - setProgress( ait->as_float() ); - } else if ( "verticalexpand" == name ) { - setVerticalExpand( ait->as_bool() ); - } else if ( "displaypercent" == name ) { - setDisplayPercent( ait->as_bool() ); - } else if ( "fillerpadding" == name ) { - Float val = PixelDensity::toDpFromString( ait->as_string() ); - setFillerPadding( Rectf( val, val, val, val ) ); - } else if ( "fillerpaddingleft" == name ) { - setFillerPadding( Rectf( PixelDensity::toDpFromString( ait->as_string() ), mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, mStyleConfig.FillerPadding.Bottom ) ); - } else if ( "fillerpaddingright" == name ) { - setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, PixelDensity::toDpFromString( ait->as_string() ), mStyleConfig.FillerPadding.Bottom ) ); - } else if ( "fillerpaddingtop" == name ) { - setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, PixelDensity::toDpFromString( ait->as_string() ), mStyleConfig.FillerPadding.Right, mStyleConfig.FillerPadding.Bottom ) ); - } else if ( "fillerpaddingbottom" == name ) { - setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, PixelDensity::toDpFromString( ait->as_string() ) ) ); - } + if ( "totalsteps" == name ) { + setTotalSteps( attribute.asFloat() ); + } else if ( "progress" == name ) { + setProgress( attribute.asFloat() ); + } else if ( "verticalexpand" == name ) { + setVerticalExpand( attribute.asBool() ); + } else if ( "displaypercent" == name ) { + setDisplayPercent( attribute.asBool() ); + } else if ( "fillerpadding" == name ) { + Float val = PixelDensity::toDpFromString( attribute.asString() ); + setFillerPadding( Rectf( val, val, val, val ) ); + } else if ( "fillerpaddingleft" == name ) { + setFillerPadding( Rectf( PixelDensity::toDpFromString( attribute.asString() ), mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, mStyleConfig.FillerPadding.Bottom ) ); + } else if ( "fillerpaddingright" == name ) { + setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, PixelDensity::toDpFromString( attribute.asString() ), mStyleConfig.FillerPadding.Bottom ) ); + } else if ( "fillerpaddingtop" == name ) { + setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, PixelDensity::toDpFromString( attribute.asString() ), mStyleConfig.FillerPadding.Right, mStyleConfig.FillerPadding.Bottom ) ); + } else if ( "fillerpaddingbottom" == name ) { + setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, PixelDensity::toDpFromString( attribute.asString() ) ) ); + } else { + UIWidget::setAttribute( attribute ); } - - endPropertiesTransaction(); } void UIProgressBar::onAlphaChange() { diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index f8364329c..8977982bf 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -344,36 +344,29 @@ void UIPushButton::setStyleConfig(const UIPushButtonStyleConfig & styleConfig) { onStateChange(); } -void UIPushButton::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UIPushButton::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "text" == name ) { + if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) + setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); + } else if ( "textovercolor" == name ) { + setFontOverColor( Color::fromString( attribute.asString() ) ); + } else if ( "icon" == name ) { + std::string val = attribute.asString(); + Drawable * icon = NULL; - mTextBox->loadFromXmlNode( node ); - mTextBox->setLayoutSizeRules( FIXED, FIXED ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "text" == name ) { - if ( NULL != mSceneNode ) - setText( static_cast( mSceneNode )->getTranslatorString( ait->as_string() ) ); - } else if ( "textovercolor" == name ) { - setFontOverColor( Color::fromString( ait->as_string() ) ); - } else if ( "icon" == name ) { - std::string val = ait->as_string(); - Drawable * icon = NULL; - - if ( NULL != mTheme && NULL != ( icon = mTheme->getIconByName( val ) ) ) { - setIcon( icon ); - } else if ( NULL != ( icon = GlobalTextureAtlas::instance()->getByName( val ) ) ) { - setIcon( icon ); - } + if ( NULL != mTheme && NULL != ( icon = mTheme->getIconByName( val ) ) ) { + setIcon( icon ); + } else if ( NULL != ( icon = GlobalTextureAtlas::instance()->getByName( val ) ) ) { + setIcon( icon ); } + } else { + UIWidget::setAttribute( attribute ); } - endPropertiesTransaction(); + mTextBox->setAttribute( attribute ); + mTextBox->setLayoutSizeRules( FIXED, FIXED ); } }} diff --git a/src/eepp/ui/uiradiobutton.cpp b/src/eepp/ui/uiradiobutton.cpp index f76b9f1a2..5f5a99728 100644 --- a/src/eepp/ui/uiradiobutton.cpp +++ b/src/eepp/ui/uiradiobutton.cpp @@ -229,21 +229,14 @@ void UIRadioButton::setTextSeparation(const Int32 & textSeparation) { setPadding( getPadding() ); } -void UIRadioButton::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UIRadioButton::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UITextView::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "selected" == name || "active" == name ) { - setActive( ait->as_bool() ); - } + if ( "selected" == name || "active" == name ) { + setActive( attribute.asBool() ); + } else { + UITextView::setAttribute( attribute ); } - - endPropertiesTransaction(); } Uint32 UIRadioButton::onKeyDown( const KeyEvent& Event ) { diff --git a/src/eepp/ui/uiscrollbar.cpp b/src/eepp/ui/uiscrollbar.cpp index 14133fd65..37abc2ee5 100644 --- a/src/eepp/ui/uiscrollbar.cpp +++ b/src/eepp/ui/uiscrollbar.cpp @@ -282,14 +282,10 @@ void UIScrollBar::setExpandBackground( bool expandBackground ) { adjustChilds(); } -void UIScrollBar::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UIScrollBar::setAttribute(const NodeAttribute & attribute) { + UIScrollBar::setAttribute( attribute ); - UIWidget::loadFromXmlNode( node ); - - mSlider->loadFromXmlNode( node ); - - endPropertiesTransaction(); + mSlider->setAttribute( attribute ); } UIScrollBar::ScrollBarType UIScrollBar::getScrollBarType() const { diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index a78e0c4fa..fb39dac12 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -222,50 +222,43 @@ bool UIScrollView::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds() && mScrollView->isMouseOverMeOrChilds() && ret; } -void UIScrollView::loadFromXmlNode( const pugi::xml_node& node ) { - beginPropertiesTransaction(); +void UIScrollView::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UITouchDragableWidget::loadFromXmlNode( node ); + if ( "type" == name ) { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); + if ( "inclusive" == val ) setViewType( Inclusive ); + else if ( "exclusive" == val ) setViewType( Exclusive ); + } else if ( "vscroll_mode" == name ) { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); - if ( "type" == name ) { - std::string val( ait->as_string() ); - String::toLowerInPlace( val ); + if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + } else if ( "hscroll_mode" == name ) { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); - if ( "inclusive" == val ) setViewType( Inclusive ); - else if ( "exclusive" == val ) setViewType( Exclusive ); - } else if ( "vscroll_mode" == name ) { - std::string val( ait->as_string() ); - String::toLowerInPlace( val ); + if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + } else if ( "scrollbartype" == name ) { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); - if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); - } else if ( "hscroll_mode" == name ) { - std::string val( ait->as_string() ); - String::toLowerInPlace( val ); - - if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); - } else if ( "scrollbartype" == name ) { - std::string val( ait->as_string() ); - String::toLowerInPlace( val ); - - if ( "nobuttons" == val ) { - mVScroll->setScrollBarType( UIScrollBar::NoButtons ); - mHScroll->setScrollBarType( UIScrollBar::NoButtons ); - } else if ( "twobuttons" == val ) { - mVScroll->setScrollBarType( UIScrollBar::TwoButtons ); - mHScroll->setScrollBarType( UIScrollBar::NoButtons ); - } + if ( "nobuttons" == val ) { + mVScroll->setScrollBarType( UIScrollBar::NoButtons ); + mHScroll->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "twobuttons" == val ) { + mVScroll->setScrollBarType( UIScrollBar::TwoButtons ); + mHScroll->setScrollBarType( UIScrollBar::NoButtons ); } + } else { + UITouchDragableWidget::setAttribute( attribute ); } - - endPropertiesTransaction(); } }} diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index 2ee2204fa..7f117c7ab 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -89,21 +89,14 @@ const Color &UISelectButton::getFontSelectedColor() const { return mStyleConfig.FontSelectedColor; } -void UISelectButton::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UISelectButton::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIPushButton::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "textselectedcolor" == name ) { - setFontSelectedColor( Color::fromString( ait->as_string() ) ); - } + if ( "textselectedcolor" == name ) { + setFontSelectedColor( Color::fromString( attribute.asString() ) ); + } else { + UIPushButton::setAttribute( attribute ); } - - endPropertiesTransaction(); } }} diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 4e4c2bf56..2f2fa22d2 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -402,37 +402,30 @@ void UISlider::onAlphaChange() { mSlider->setAlpha( mAlpha ); } -void UISlider::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UISlider::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "orientation" == name ) { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "orientation" == name ) { - std::string val = ait->as_string(); - String::toLowerInPlace( val ); - - if ( "horizontal" == val ) - setOrientation( UI_HORIZONTAL ); - else if ( "vertical" == val ) - setOrientation( UI_VERTICAL ); - } else if ( "minvalue" == name ) { - setMinValue( ait->as_float() ); - } else if ( "maxvalue" == name ) { - setMaxValue( ait->as_float() ); - } else if ( "value" == name ) { - setValue( ait->as_float() ); - } else if ( "clickstep" == name ) { - setClickStep( ait->as_float() ); - } else if ( "pagestep" == name ) { - setPageStep( ait->as_float() ); - } + if ( "horizontal" == val ) + setOrientation( UI_HORIZONTAL ); + else if ( "vertical" == val ) + setOrientation( UI_VERTICAL ); + } else if ( "minvalue" == name ) { + setMinValue( attribute.asFloat() ); + } else if ( "maxvalue" == name ) { + setMaxValue( attribute.asFloat() ); + } else if ( "value" == name ) { + setValue( attribute.asFloat() ); + } else if ( "clickstep" == name ) { + setClickStep( attribute.asFloat() ); + } else if ( "pagestep" == name ) { + setPageStep( attribute.asFloat() ); + } else { + UIWidget::setAttribute( attribute ); } - - endPropertiesTransaction(); } }} diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index 80966046d..dbaed5516 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -264,29 +264,22 @@ void UISpinBox::onAlphaChange() { mPushDown->setAlpha( mAlpha ); } -void UISpinBox::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UISpinBox::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); - - mInput->loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "minvalue" == name ) { - setMinValue( ait->as_float() ); - } else if ( "maxvalue" == name ) { - setMaxValue( ait->as_float() ); - } else if ( "value" == name ) { - setValue( ait->as_float() ); - } else if ( "clickstep" == name ) { - setClickStep( ait->as_float() ); - } + if ( "minvalue" == name ) { + setMinValue(attribute.asFloat() ); + } else if ( "maxvalue" == name ) { + setMaxValue(attribute.asFloat() ); + } else if ( "value" == name ) { + setValue(attribute.asFloat() ); + } else if ( "clickstep" == name ) { + setClickStep(attribute.asFloat() ); + } else { + UIWidget::setAttribute( attribute ); } - endPropertiesTransaction(); + mInput->setAttribute( attribute ); } }} diff --git a/src/eepp/ui/uisprite.cpp b/src/eepp/ui/uisprite.cpp index 9195c6076..20a614468 100644 --- a/src/eepp/ui/uisprite.cpp +++ b/src/eepp/ui/uisprite.cpp @@ -175,26 +175,19 @@ void UISprite::onSizeChange() { UIWidget::onSizeChange(); } -void UISprite::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UISprite::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "src" == name ) { + std::string val = attribute.asString(); - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "src" == name ) { - std::string val = ait->as_string(); - - if ( val.size() ) { - setDeallocSprite( true ); - setSprite( eeNew( Sprite, ( val ) ) ); - } + if ( val.size() ) { + setDeallocSprite( true ); + setSprite( eeNew( Sprite, ( val ) ) ); } + } else { + UIWidget::setAttribute( attribute ); } - - endPropertiesTransaction(); } }} diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 8499a65cc..8ed78e0d0 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -1,5 +1,6 @@ #include #include +#include #include namespace EE { namespace UI { @@ -175,24 +176,18 @@ void UITab::update( const Time& time ) { } } -void UITab::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UITab::setAttribute( const NodeAttribute& attribute ) { + std::string name = attribute.getName(); - UISelectButton::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "name" == name || "text" == name ) { - setText( ait->as_string() ); - } else if ( "controlowned" == name || "owns" == name ) { - mOwnedName = ait->as_string(); - setOwnedControl(); - } + if ( "name" == name || "text" == name ) { + if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) + setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); + } else if ( "controlowned" == name || "owns" == name ) { + mOwnedName = attribute.asString(); + setOwnedControl(); + } else { + UISelectButton::setAttribute( attribute ); } - - endPropertiesTransaction(); } void UITab::setOwnedControl() { diff --git a/src/eepp/ui/uitable.cpp b/src/eepp/ui/uitable.cpp index 49c4d9a10..145a33938 100644 --- a/src/eepp/ui/uitable.cpp +++ b/src/eepp/ui/uitable.cpp @@ -618,53 +618,46 @@ bool UITable::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds() && !mVScrollBar->isMouseOverMeOrChilds() && !mHScrollBar->isMouseOverMeOrChilds(); } -void UITable::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UITable::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UITouchDragableWidget::loadFromXmlNode( node ); + if ( "rowheight" == name ) { + setRowHeight( attribute.asInt() ); + } else if ( "padding" == name ) { + int val = attribute.asInt(); + setContainerPadding( Rectf( val, val, val, val ) ); + } else if ( "paddingleft" == name ) { + setContainerPadding( Rectf( attribute.asInt(), mContainerPadding.Top, mContainerPadding.Right, mContainerPadding.Bottom ) ); + } else if ( "paddingright" == name ) { + setContainerPadding( Rectf( mContainerPadding.Left, mContainerPadding.Top, attribute.asInt(), mContainerPadding.Bottom ) ); + } else if ( "paddingtop" == name ) { + setContainerPadding( Rectf( mContainerPadding.Left, attribute.asInt(), mContainerPadding.Right, mContainerPadding.Bottom ) ); + } else if ( "paddingbottom" == name ) { + setContainerPadding( Rectf( mContainerPadding.Left, mContainerPadding.Top, mContainerPadding.Right, attribute.asInt() ) ); + } else if ( "verticalscrollmode" == name || "vscrollmode" == name ) { + std::string val = attribute.asString(); + if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + } else if ( "horizontalscrollmode" == name || "hscrollmode" == name ) { + std::string val = attribute.asString(); + if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + } else if ( "scrollbartype" == name ) { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "rowheight" == name ) { - setRowHeight( ait->as_int() ); - } else if ( "padding" == name ) { - int val = ait->as_int(); - setContainerPadding( Rectf( val, val, val, val ) ); - } else if ( "paddingleft" == name ) { - setContainerPadding( Rectf( ait->as_int(), mContainerPadding.Top, mContainerPadding.Right, mContainerPadding.Bottom ) ); - } else if ( "paddingright" == name ) { - setContainerPadding( Rectf( mContainerPadding.Left, mContainerPadding.Top, ait->as_int(), mContainerPadding.Bottom ) ); - } else if ( "paddingtop" == name ) { - setContainerPadding( Rectf( mContainerPadding.Left, ait->as_int(), mContainerPadding.Right, mContainerPadding.Bottom ) ); - } else if ( "paddingbottom" == name ) { - setContainerPadding( Rectf( mContainerPadding.Left, mContainerPadding.Top, mContainerPadding.Right, ait->as_int() ) ); - } else if ( "verticalscrollmode" == name || "vscrollmode" == name ) { - std::string val = ait->as_string(); - if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "horizontalscrollmode" == name || "hscrollmode" == name ) { - std::string val = ait->as_string(); - if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "scrollbartype" == name ) { - std::string val( ait->as_string() ); - String::toLowerInPlace( val ); - - if ( "nobuttons" == val ) { - mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - } else if ( "twobuttons" == val ) { - mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); - mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - } + if ( "nobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "twobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); } + } else { + UITouchDragableWidget::setAttribute( attribute ); } - - endPropertiesTransaction(); } }} diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 68bcefe73..963830e1c 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -185,79 +185,72 @@ void UITabWidget::setStyleConfig(const UITabWidgetStyleConfig & styleConfig) { orderTabs(); } -void UITabWidget::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UITabWidget::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "textcolor" == name ) { + setFontColor( Color::fromString( attribute.asString() ) ); + } else if ( "textshadowcolor" == name ) { + setFontShadowColor( Color::fromString( attribute.asString() ) ); + } else if ( "textovercolor" == name ) { + setFontOverColor( Color::fromString( attribute.asString() ) ); + } else if ( "textselectedcolor" == name ) { + setFontSelectedColor( Color::fromString( attribute.asString() ) ); + } else if ( "fontfamily" == name || "fontname" == name ) { + Font * font = FontManager::instance()->getByName( attribute.asString() ); - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); + if ( NULL != font ) + setFont( font ); + } else if ( "textsize" == name || "fontsize" == name || "charactersize" == name ) { + setCharacterSize( PixelDensity::toDpFromStringI( attribute.asString() ) ); + } else if ( "textstyle" == name || "fontstyle" == name ) { + std::string valStr = attribute.asString(); + String::toLowerInPlace( valStr ); + std::vector strings = String::split( valStr, '|' ); + Uint32 flags = Text::Regular; - if ( "textcolor" == name ) { - setFontColor( Color::fromString( ait->as_string() ) ); - } else if ( "textshadowcolor" == name ) { - setFontShadowColor( Color::fromString( ait->as_string() ) ); - } else if ( "textovercolor" == name ) { - setFontOverColor( Color::fromString( ait->as_string() ) ); - } else if ( "textselectedcolor" == name ) { - setFontSelectedColor( Color::fromString( ait->as_string() ) ); - } else if ( "fontfamily" == name || "fontname" == name ) { - Font * font = FontManager::instance()->getByName( ait->as_string() ); + if ( strings.size() ) { + for ( std::size_t i = 0; i < strings.size(); i++ ) { + std::string cur = strings[i]; + String::toLowerInPlace( cur ); - if ( NULL != font ) - setFont( font ); - } else if ( "textsize" == name || "fontsize" == name || "charactersize" == name ) { - setCharacterSize( PixelDensity::toDpFromStringI( ait->as_string() ) ); - } else if ( "textstyle" == name || "fontstyle" == name ) { - std::string valStr = ait->as_string(); - String::toLowerInPlace( valStr ); - std::vector strings = String::split( valStr, '|' ); - Uint32 flags = Text::Regular; - - if ( strings.size() ) { - for ( std::size_t i = 0; i < strings.size(); i++ ) { - std::string cur = strings[i]; - String::toLowerInPlace( cur ); - - if ( "underlined" == cur || "underline" == cur ) - flags |= Text::Underlined; - else if ( "bold" == cur ) - flags |= Text::Bold; - else if ( "italic" == cur ) - flags |= Text::Italic; - else if ( "strikethrough" == cur ) - flags |= Text::StrikeThrough; - else if ( "shadowed" == cur || "shadow" == cur ) - flags |= Text::Shadow; - } - - setFontStyle( flags ); + if ( "underlined" == cur || "underline" == cur ) + flags |= Text::Underlined; + else if ( "bold" == cur ) + flags |= Text::Bold; + else if ( "italic" == cur ) + flags |= Text::Italic; + else if ( "strikethrough" == cur ) + flags |= Text::StrikeThrough; + else if ( "shadowed" == cur || "shadow" == cur ) + flags |= Text::Shadow; } - } else if ( "fontoutlinethickness" == name ) { - setOutlineThickness( PixelDensity::toDpFromString( ait->as_string() ) ); - } else if ( "fontoutlinecolor" == name ) { - setOutlineColor( Color::fromString( ait->as_string() ) ); - } else if ( "maxtextlength" == name ) { - setMaxTextLength( ait->as_uint(1) ); - } else if ( "mintabwidth" == name ) { - setMinTabWidth( ait->as_uint(1) ); - } else if ( "maxtabwidth" == name ) { - setMaxTabWidth( ait->as_uint() ); - } else if ( "tabclosable" == name ) { - setTabsClosable( ait->as_bool() ); - } else if ( "specialbordertabs" == name ) { - setSpecialBorderTabs( ait->as_bool() ); - } else if ( "drawlinebelowtabs" == name ) { - setDrawLineBelowTabs( ait->as_bool() ); - } else if ( "linebelowtabscolor" == name ) { - setLineBelowTabsColor( Color::fromString( ait->as_string() ) ); - } else if ( "linebelowtabsyoffset" == name ) { - setLineBelowTabsYOffset( ait->as_int() ); - } - } - endPropertiesTransaction(); + setFontStyle( flags ); + } + } else if ( "fontoutlinethickness" == name ) { + setOutlineThickness( PixelDensity::toDpFromString( attribute.asString() ) ); + } else if ( "fontoutlinecolor" == name ) { + setOutlineColor( Color::fromString( attribute.asString() ) ); + } else if ( "maxtextlength" == name ) { + setMaxTextLength( attribute.asUint(1) ); + } else if ( "mintabwidth" == name ) { + setMinTabWidth( attribute.asUint(1) ); + } else if ( "maxtabwidth" == name ) { + setMaxTabWidth( attribute.asUint() ); + } else if ( "tabclosable" == name ) { + setTabsClosable( attribute.asBool() ); + } else if ( "specialbordertabs" == name ) { + setSpecialBorderTabs( attribute.asBool() ); + } else if ( "drawlinebelowtabs" == name ) { + setDrawLineBelowTabs( attribute.asBool() ); + } else if ( "linebelowtabscolor" == name ) { + setLineBelowTabsColor( Color::fromString( attribute.asString() ) ); + } else if ( "linebelowtabsyoffset" == name ) { + setLineBelowTabsYOffset( attribute.asInt() ); + } else { + UIWidget::setAttribute( attribute ); + } } Font * UITabWidget::getFont() const { diff --git a/src/eepp/ui/uitextedit.cpp b/src/eepp/ui/uitextedit.cpp index 6b6c88a46..636ba66e1 100644 --- a/src/eepp/ui/uitextedit.cpp +++ b/src/eepp/ui/uitextedit.cpp @@ -447,37 +447,30 @@ void UITextEdit::setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig) { } } -void UITextEdit::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UITextEdit::setAttribute( const NodeAttribute &attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); - - mTextInput->loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "text" == name ) { - if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) { - setText( static_cast( mSceneNode )->getTranslatorString( ait->as_string() ) ); - } - } else if ( "allowediting" == name ) { - setAllowEditing( ait->as_bool() ); - } else if ( "verticalscrollmode" == name || "vscrollmode" == name ) { - std::string val = ait->as_string(); - if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "horizontalscrollmode" == name || "hscrollmode" == name ) { - std::string val = ait->as_string(); - if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + if ( "text" == name ) { + if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) { + setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); } + } else if ( "allowediting" == name ) { + setAllowEditing( attribute.asBool() ); + } else if ( "verticalscrollmode" == name || "vscrollmode" == name ) { + std::string val = attribute.asString(); + if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + } else if ( "horizontalscrollmode" == name || "hscrollmode" == name ) { + std::string val = attribute.asString(); + if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + } else { + UIWidget::setAttribute( attribute ); } - endPropertiesTransaction(); + mTextInput->setAttribute( attribute ); } }} diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index f02e220e9..3db005196 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -339,33 +339,26 @@ bool UITextInput::isFreeEditingEnabled() { return mTextBuffer.isFreeEditingEnabled(); } -void UITextInput::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UITextInput::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UITextView::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "text" == name ) { - if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) { - setText( static_cast( mSceneNode )->getTranslatorString( ait->as_string() ) ); - } - } else if ( "allowediting" == name ) { - setAllowEditing( ait->as_bool() ); - } else if ( "maxlength" == name ) { - setMaxLength( ait->as_uint() ); - } else if ( "freeediting" == name ) { - setFreeEditing( ait->as_bool() ); - } else if ( "onlynumbers" == name ) { - getInputTextBuffer()->setAllowOnlyNumbers( ait->as_bool(), getInputTextBuffer()->dotsInNumbersAllowed() ); - } else if ( "allowdot" == name ) { - getInputTextBuffer()->setAllowOnlyNumbers( getInputTextBuffer()->onlyNumbersAllowed(), ait->as_bool() ); + if ( "text" == name ) { + if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) { + setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); } + } else if ( "allowediting" == name ) { + setAllowEditing( attribute.asBool() ); + } else if ( "maxlength" == name ) { + setMaxLength( attribute.asUint() ); + } else if ( "freeediting" == name ) { + setFreeEditing( attribute.asBool() ); + } else if ( "onlynumbers" == name ) { + getInputTextBuffer()->setAllowOnlyNumbers( attribute.asBool(), getInputTextBuffer()->dotsInNumbersAllowed() ); + } else if ( "allowdot" == name ) { + getInputTextBuffer()->setAllowOnlyNumbers( getInputTextBuffer()->onlyNumbersAllowed(), attribute.asBool() ); + } else { + UITextView::setAttribute( attribute ); } - - endPropertiesTransaction(); } }} diff --git a/src/eepp/ui/uitextureregion.cpp b/src/eepp/ui/uitextureregion.cpp index 35181abec..5cb64e725 100644 --- a/src/eepp/ui/uitextureregion.cpp +++ b/src/eepp/ui/uitextureregion.cpp @@ -183,38 +183,31 @@ const Vector2f& UITextureRegion::getAlignOffset() const { return mAlignOffset; } -void UITextureRegion::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UITextureRegion::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "src" == name || "textureregion" == name || "subtexture" == name ) { + DrawableResource * res = NULL; - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "src" == name || "textureregion" == name || "subtexture" == name ) { - DrawableResource * res = NULL; - - if ( NULL != ( res = GlobalTextureAtlas::instance()->getByName( ait->as_string() ) ) && res->getDrawableType() == Drawable::TEXTUREREGION ) { - setTextureRegion( static_cast( res ) ); - } - } else if ( "scaletype" == name ) { - std::string val = ait->as_string(); - String::toLowerInPlace( val ); - - if ( "expand" == val ) { - setScaleType( UIScaleType::Expand ); - } else if ( "fit_inside" == val || "fitinside" == val ) { - setScaleType( UIScaleType::FitInside ); - } else if ( "none" == val ) { - setScaleType( UIScaleType::None ); - } - } else if ( "tint" == name ) { - setColor( Color::fromString( ait->as_string() ) ); + if ( NULL != ( res = GlobalTextureAtlas::instance()->getByName( attribute.asString() ) ) && res->getDrawableType() == Drawable::TEXTUREREGION ) { + setTextureRegion( static_cast( res ) ); } - } + } else if ( "scaletype" == name ) { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); - endPropertiesTransaction(); + if ( "expand" == val ) { + setScaleType( UIScaleType::Expand ); + } else if ( "fit_inside" == val || "fitinside" == val ) { + setScaleType( UIScaleType::FitInside ); + } else if ( "none" == val ) { + setScaleType( UIScaleType::None ); + } + } else if ( "tint" == name ) { + setColor( Color::fromString( attribute.asString() ) ); + } else { + UIWidget::setAttribute( attribute ); + } } Uint32 UITextureRegion::getScaleType() const { diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index df1c85408..b3435e200 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -524,83 +524,76 @@ void UITextView::onPaddingChange() { invalidateDraw(); } -void UITextView::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UITextView::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "text" == name ) { + if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) + setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); + } else if ( "textcolor" == name ) { + setFontColor( Color::fromString( attribute.asString() ) ); + } else if ( "textshadowcolor" == name ) { + setFontShadowColor( Color::fromString( attribute.asString() ) ); + } else if ( "textovercolor" == name ) { + mFontStyleConfig.FontOverColor = Color::fromString( attribute.asString() ); + } else if ( "textselectedcolor" == name ) { + mFontStyleConfig.FontSelectedColor = Color::fromString( attribute.asString() ); + } else if ( "textselectionbackcolor" == name ) { + setSelectionBackColor( Color::fromString( attribute.asString() ) ); + } else if ( "fontfamily" == name || "fontname" == name ) { + Font * font = FontManager::instance()->getByName( attribute.asString() ); - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); + if ( NULL != font ) + setFont( font ); + } else if ( "textsize" == name || "fontsize" == name || "charactersize" == name ) { + setCharacterSize( PixelDensity::toDpFromStringI( attribute.asString() ) ); + } else if ( "textstyle" == name || "fontstyle" == name ) { + std::string valStr = attribute.asString(); + String::toLowerInPlace( valStr ); + std::vector strings = String::split( valStr, '|' ); + Uint32 flags = Text::Regular; - if ( "text" == name ) { - if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) - setText( static_cast( mSceneNode )->getTranslatorString( ait->as_string() ) ); - } else if ( "textcolor" == name ) { - setFontColor( Color::fromString( ait->as_string() ) ); - } else if ( "textshadowcolor" == name ) { - setFontShadowColor( Color::fromString( ait->as_string() ) ); - } else if ( "textovercolor" == name ) { - mFontStyleConfig.FontOverColor = Color::fromString( ait->as_string() ); - } else if ( "textselectedcolor" == name ) { - mFontStyleConfig.FontSelectedColor = Color::fromString( ait->as_string() ); - } else if ( "textselectionbackcolor" == name ) { - setSelectionBackColor( Color::fromString( ait->as_string() ) ); - } else if ( "fontfamily" == name || "fontname" == name ) { - Font * font = FontManager::instance()->getByName( ait->as_string() ); + if ( strings.size() ) { + for ( std::size_t i = 0; i < strings.size(); i++ ) { + std::string cur = strings[i]; + String::toLowerInPlace( cur ); - if ( NULL != font ) - setFont( font ); - } else if ( "textsize" == name || "fontsize" == name || "charactersize" == name ) { - setCharacterSize( PixelDensity::toDpFromStringI( ait->as_string() ) ); - } else if ( "textstyle" == name || "fontstyle" == name ) { - std::string valStr = ait->as_string(); - String::toLowerInPlace( valStr ); - std::vector strings = String::split( valStr, '|' ); - Uint32 flags = Text::Regular; - - if ( strings.size() ) { - for ( std::size_t i = 0; i < strings.size(); i++ ) { - std::string cur = strings[i]; - String::toLowerInPlace( cur ); - - if ( "underlined" == cur || "underline" == cur ) - flags |= Text::Underlined; - else if ( "bold" == cur ) - flags |= Text::Bold; - else if ( "italic" == cur ) - flags |= Text::Italic; - else if ( "strikethrough" == cur ) - flags |= Text::StrikeThrough; - else if ( "shadowed" == cur || "shadow" == cur ) - flags |= Text::Shadow; - else if ( "wordwrap" == cur ) { - mFlags |= UI_WORD_WRAP; - autoShrink(); - } + if ( "underlined" == cur || "underline" == cur ) + flags |= Text::Underlined; + else if ( "bold" == cur ) + flags |= Text::Bold; + else if ( "italic" == cur ) + flags |= Text::Italic; + else if ( "strikethrough" == cur ) + flags |= Text::StrikeThrough; + else if ( "shadowed" == cur || "shadow" == cur ) + flags |= Text::Shadow; + else if ( "wordwrap" == cur ) { + mFlags |= UI_WORD_WRAP; + autoShrink(); } - - setFontStyle( flags ); } - } else if ( "fontoutlinethickness" == name ) { - setOutlineThickness( PixelDensity::toDpFromString( ait->as_string() ) ); - } else if ( "fontoutlinecolor" == name ) { - setOutlineColor( Color::fromString( ait->as_string() ) ); - } else if ( "padding" == name ) { - int val = PixelDensity::toDpFromStringI( ait->as_string() ); - setPadding( Rectf( val, val, val, val ) ); - } else if ( "paddingleft" == name ) { - setPadding( Rectf( PixelDensity::toDpFromString( ait->as_string() ), mPadding.Top, mPadding.Right, mPadding.Bottom ) ); - } else if ( "paddingright" == name ) { - setPadding( Rectf( mPadding.Left, mPadding.Top, PixelDensity::toDpFromString( ait->as_string() ), mPadding.Bottom ) ); - } else if ( "paddingtop" == name ) { - setPadding( Rectf( mPadding.Left, PixelDensity::toDpFromString( ait->as_string() ), mPadding.Right, mPadding.Bottom ) ); - } else if ( "paddingbottom" == name ) { - setPadding( Rectf( mPadding.Left, mPadding.Top, mPadding.Right, PixelDensity::toDpFromString( ait->as_string() ) ) ); - } - } - endPropertiesTransaction(); + setFontStyle( flags ); + } + } else if ( "fontoutlinethickness" == name ) { + setOutlineThickness( PixelDensity::toDpFromString( attribute.asString() ) ); + } else if ( "fontoutlinecolor" == name ) { + setOutlineColor( Color::fromString( attribute.asString() ) ); + } else if ( "padding" == name ) { + int val = PixelDensity::toDpFromStringI( attribute.asString() ); + setPadding( Rectf( val, val, val, val ) ); + } else if ( "paddingleft" == name ) { + setPadding( Rectf( PixelDensity::toDpFromString( attribute.asString() ), mPadding.Top, mPadding.Right, mPadding.Bottom ) ); + } else if ( "paddingright" == name ) { + setPadding( Rectf( mPadding.Left, mPadding.Top, PixelDensity::toDpFromString( attribute.asString() ), mPadding.Bottom ) ); + } else if ( "paddingtop" == name ) { + setPadding( Rectf( mPadding.Left, PixelDensity::toDpFromString( attribute.asString() ), mPadding.Right, mPadding.Bottom ) ); + } else if ( "paddingbottom" == name ) { + setPadding( Rectf( mPadding.Left, mPadding.Top, mPadding.Right, PixelDensity::toDpFromString( attribute.asString() ) ) ); + } else { + UIWidget::setAttribute( attribute ); + } } }} diff --git a/src/eepp/ui/uitouchdragablewidget.cpp b/src/eepp/ui/uitouchdragablewidget.cpp index e24ae213a..991769c06 100644 --- a/src/eepp/ui/uitouchdragablewidget.cpp +++ b/src/eepp/ui/uitouchdragablewidget.cpp @@ -135,23 +135,16 @@ bool UITouchDragableWidget::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds(); } -void UITouchDragableWidget::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UITouchDragableWidget::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); - - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "touchdrag" == name ) { - setTouchDragEnabled( ait->as_bool() ); - } else if ( "touchdragdeceleration" == name ) { - setTouchDragDeceleration( Vector2f( ait->as_float(), ait->as_float() ) ); - } + if ( "touchdrag" == name ) { + setTouchDragEnabled( attribute.asBool() ); + } else if ( "touchdragdeceleration" == name ) { + setTouchDragDeceleration( Vector2f( attribute.asFloat(), attribute.asFloat() ) ); + } else { + UIWidget::setAttribute( attribute ); } - - endPropertiesTransaction(); } }} diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index 5cf8f2f01..4d7379d73 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -21,7 +21,7 @@ UIWidget::UIWidget() : mLayoutHeightRules(WRAP_CONTENT), mLayoutPositionRule(NONE), mLayoutPositionRuleWidget(NULL), - mPropertiesTransactionCount(0) + mAttributesTransactionCount(0) { mNodeFlags |= NODE_FLAG_WIDGET; @@ -319,14 +319,14 @@ void UIWidget::onWidgetCreated() { } void UIWidget::notifyLayoutAttrChange() { - if ( 0 == mPropertiesTransactionCount ) { + if ( 0 == mAttributesTransactionCount ) { NodeMessage msg( this, NodeMessage::LayoutAttributeChange ); messagePost( &msg ); } } void UIWidget::notifyLayoutAttrChangeParent() { - if ( 0 == mPropertiesTransactionCount && NULL != mParentCtrl ) { + if ( 0 == mAttributesTransactionCount && NULL != mParentCtrl ) { NodeMessage msg( this, NodeMessage::LayoutAttributeChange ); mParentCtrl->messagePost( &msg ); } @@ -398,14 +398,14 @@ void UIWidget::alignAgainstLayout() { setInternalPosition( pos ); } -void UIWidget::beginPropertiesTransaction() { - mPropertiesTransactionCount++; +void UIWidget::beginAttributesTransaction() { + mAttributesTransactionCount++; } -void UIWidget::endPropertiesTransaction() { - mPropertiesTransactionCount--; +void UIWidget::endAttributesTransaction() { + mAttributesTransactionCount--; - if ( 0 == mPropertiesTransactionCount ) { + if ( 0 == mAttributesTransactionCount ) { notifyLayoutAttrChange(); } } @@ -449,226 +449,231 @@ static BlendMode toBlendMode( std::string val ) { return blendMode; } -void UIWidget::loadFromXmlNode( const pugi::xml_node& node ) { - beginPropertiesTransaction(); +void UIWidget::setAttribute( const std::string& name, const std::string& value ) { + setAttribute( NodeAttribute( name, value ) ); +} - std::string skinName; +void UIWidget::setAttribute(const NodeAttribute & attribute) { + std::string name = attribute.getName(); + + if ( "id" == name ) { + setId( attribute.value() ); + } else if ( "x" == name ) { + setInternalPosition( Vector2f( PixelDensity::toDpFromString( attribute.asString() ), mDpPos.y ) ); + } else if ( "y" == name ) { + setInternalPosition( Vector2f( mDpPos.x, PixelDensity::toDpFromString( attribute.asString() ) ) ); + } else if ( "width" == name ) { + setInternalWidth( PixelDensity::toDpFromStringI( attribute.asString() ) ); + notifyLayoutAttrChange(); + } else if ( "height" == name ) { + setInternalHeight( PixelDensity::toDpFromStringI( attribute.asString() ) ); + notifyLayoutAttrChange(); + } else if ( "backgroundcolor" == name ) { + setBackgroundColor( Color::fromString( attribute.asString() ) ); + } else if ( "bordercolor" == name ) { + setBorderColor( Color::fromString( attribute.asString() ) ); + } else if ( "borderwidth" == name ) { + setBorderWidth( PixelDensity::toDpFromStringI( attribute.asString("1") ) ); + } else if ( "bordercorners" == name || "backgroundcorners" == name ) { + setBackgroundCorners( attribute.asUint() ); + } else if ( "background" == name ) { + Drawable * res = NULL; + + if ( NULL != ( res = DrawableSearcher::searchByName( attribute.asString() ) ) ) { + setBackgroundDrawable( res, res->getDrawableType() == Drawable::SPRITE ); + } + } else if ( "visible" == name ) { + setVisible( attribute.asBool() ); + } else if ( "enabled" == name ) { + setEnabled( attribute.asBool() ); + } else if ( "theme" == name ) { + setThemeByName( attribute.asString() ); + + if ( !mSkinName.empty() ) + setThemeSkin( mSkinName ); + } else if ( "skin" == name ) { + mSkinName = attribute.asString(); + setThemeSkin( mSkinName ); + } else if ( "gravity" == name ) { + std::string gravity = attribute.asString(); + String::toLowerInPlace( gravity ); + std::vector strings = String::split( gravity, '|' ); + + if ( strings.size() ) { + for ( std::size_t i = 0; i < strings.size(); i++ ) { + std::string cur = strings[i]; + String::toLowerInPlace( cur ); + + if ( "left" == cur ) + setHorizontalAlign( UI_HALIGN_LEFT ); + else if ( "right" == cur ) + setHorizontalAlign( UI_HALIGN_RIGHT ); + else if ( "center_horizontal" == cur ) + setHorizontalAlign( UI_HALIGN_CENTER ); + else if ( "top" == cur ) + setVerticalAlign( UI_VALIGN_TOP ); + else if ( "bottom" == cur ) + setVerticalAlign( UI_VALIGN_BOTTOM ); + else if ( "center_vertical" == cur ) { + setVerticalAlign( UI_VALIGN_CENTER ); + } else if ( "center" == cur ) { + setHorizontalAlign( UI_HALIGN_CENTER ); + setVerticalAlign( UI_VALIGN_CENTER ); + } + } + + notifyLayoutAttrChange(); + } + } else if ( "flags" == name ) { + std::string flags = attribute.asString(); + String::toLowerInPlace( flags ); + std::vector strings = String::split( flags, '|' ); + + if ( strings.size() ) { + for ( std::size_t i = 0; i < strings.size(); i++ ) { + std::string cur = strings[i]; + String::toLowerInPlace( cur ); + + if ( "auto_size" == cur || "autosize" == cur ) { + setFlags( UI_AUTO_SIZE ); + notifyLayoutAttrChange(); + } else if ( "clip" == cur ) { + clipEnable(); + } else if ( "word_wrap" == cur || "wordwrap" == cur ) { + setFlags( UI_WORD_WRAP ); + } else if ( "multi" == cur ) { + setFlags( UI_MULTI_SELECT ); + } else if ( "auto_padding" == cur || "autopadding" == cur ) { + setFlags( UI_AUTO_PADDING ); + notifyLayoutAttrChange(); + } else if ( "reportsizechangetochilds" == cur || "report_size_change_to_childs" == cur ) { + enableReportSizeChangeToChilds(); + } + } + } + } else if ( "layout_margin" == name ) { + int val = PixelDensity::toDpFromStringI( attribute.asString() ); + setLayoutMargin( Rect( val, val, val, val ) ); + } else if ( "layout_marginleft" == name ) { + setLayoutMargin( Rect( PixelDensity::toDpFromStringI( attribute.asString() ), mLayoutMargin.Top, mLayoutMargin.Right, mLayoutMargin.Bottom ) ); + } else if ( "layout_marginright" == name ) { + setLayoutMargin( Rect( mLayoutMargin.Left, mLayoutMargin.Top, PixelDensity::toDpFromStringI( attribute.asString() ), mLayoutMargin.Bottom ) ); + } else if ( "layout_margintop" == name ) { + setLayoutMargin( Rect( mLayoutMargin.Left, PixelDensity::toDpFromStringI( attribute.asString() ), mLayoutMargin.Right, mLayoutMargin.Bottom ) ); + } else if ( "layout_marginbottom" == name ) { + setLayoutMargin( Rect( mLayoutMargin.Left, mLayoutMargin.Top, mLayoutMargin.Right, PixelDensity::toDpFromStringI( attribute.asString() ) ) ); + } else if ( "tooltip" == name ) { + setTooltipText( attribute.asString() ); + } else if ( "layout_weight" == name ) { + setLayoutWeight( attribute.asFloat() ); + } else if ( "layout_gravity" == name ) { + std::string gravityStr = attribute.asString(); + String::toLowerInPlace( gravityStr ); + std::vector strings = String::split( gravityStr, '|' ); + Uint32 gravity = 0; + + if ( strings.size() ) { + for ( std::size_t i = 0; i < strings.size(); i++ ) { + std::string cur = strings[i]; + String::toLowerInPlace( cur ); + + if ( "left" == cur ) + gravity |= UI_HALIGN_LEFT; + else if ( "right" == cur ) + gravity |= UI_HALIGN_RIGHT; + else if ( "center_horizontal" == cur ) + gravity |= UI_HALIGN_CENTER; + else if ( "top" == cur ) + gravity |= UI_VALIGN_TOP; + else if ( "bottom" == cur ) + gravity |= UI_VALIGN_BOTTOM; + else if ( "center_vertical" == cur ) { + gravity |= UI_VALIGN_CENTER; + } else if ( "center" == cur ) { + gravity |= UI_VALIGN_CENTER | UI_HALIGN_CENTER; + } + } + + setLayoutGravity( gravity ); + } + } else if ( "layout_width" == name ) { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); + + if ( "match_parent" == val ) { + setLayoutWidthRules( MATCH_PARENT ); + } else if ( "wrap_content" == val ) { + setLayoutWidthRules( WRAP_CONTENT ); + } else if ( "fixed" == val ) { + setLayoutWidthRules( FIXED ); + unsetFlags( UI_AUTO_SIZE ); + } else { + unsetFlags( UI_AUTO_SIZE ); + setLayoutWidthRules( FIXED ); + setInternalWidth( PixelDensity::toDpFromStringI( val ) ); + onSizeChange(); + } + } else if ( "layout_height" == name ) { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); + + if ( "match_parent" == val ) { + setLayoutHeightRules( MATCH_PARENT ); + } else if ( "wrap_content" == val ) { + setLayoutHeightRules( WRAP_CONTENT ); + } else if ( "fixed" == val ) { + setLayoutHeightRules( FIXED ); + unsetFlags( UI_AUTO_SIZE ); + } else { + unsetFlags( UI_AUTO_SIZE ); + setLayoutHeightRules( FIXED ); + setInternalHeight( PixelDensity::toDpFromStringI( val ) ); + onSizeChange(); + } + } else if ( String::startsWith( name, "layout_to_" ) || String::startsWith( name, "layoutto" ) ) { + LayoutPositionRules rule = NONE; + if ( "layout_to_left_of" == name || "layouttoleftof" == name ) rule = LEFT_OF; + else if ( "layout_to_right_of" == name || "layouttorightof" == name ) rule = RIGHT_OF; + else if ( "layout_to_top_of" == name || "layouttotopof" == name ) rule = TOP_OF; + else if ( "layout_to_bottom_of" == name || "layouttobottomof" == name ) rule = BOTTOM_OF; + + std::string id = attribute.asString(); + + Node * control = getParent()->find( id ); + + if ( NULL != control && control->isWidget() ) { + UIWidget * widget = static_cast( control ); + + setLayoutPositionRule( rule, widget ); + } + } else if ( "clip" == name ) { + if ( attribute.asBool() ) + clipEnable(); + else + clipDisable(); + } else if ( "rotation" == name ) { + setRotation( attribute.asFloat() ); + } else if ( "scale" == name ) { + setScale( attribute.asFloat() ); + } else if ( "rotationoriginpoint" == name ) { + setRotationOriginPoint( toOriginPoint( attribute.asString() ) ); + } else if ( "scaleoriginpoint" == name ) { + setScaleOriginPoint( toOriginPoint( attribute.asString() ) ); + } else if ( "blendmode" == name ) { + setBlendMode( toBlendMode( attribute.asString() ) ); + } else if ( "backgroundblendmode" == name ) { + setBackgroundBlendMode( toBlendMode( attribute.asString() ) ); + } +} + +void UIWidget::loadFromXmlNode( const pugi::xml_node& node ) { + beginAttributesTransaction(); for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); - - if ( "id" == name ) { - setId( ait->value() ); - } else if ( "x" == name ) { - setInternalPosition( Vector2f( PixelDensity::toDpFromString( ait->as_string() ), mDpPos.y ) ); - } else if ( "y" == name ) { - setInternalPosition( Vector2f( mDpPos.x, PixelDensity::toDpFromString( ait->as_string() ) ) ); - } else if ( "width" == name ) { - setInternalWidth( PixelDensity::toDpFromStringI( ait->as_string() ) ); - notifyLayoutAttrChange(); - } else if ( "height" == name ) { - setInternalHeight( PixelDensity::toDpFromStringI( ait->as_string() ) ); - notifyLayoutAttrChange(); - } else if ( "backgroundcolor" == name ) { - setBackgroundColor( Color::fromString( ait->as_string() ) ); - } else if ( "bordercolor" == name ) { - setBorderColor( Color::fromString( ait->as_string() ) ); - } else if ( "borderwidth" == name ) { - setBorderWidth( PixelDensity::toDpFromStringI( ait->as_string("1") ) ); - } else if ( "bordercorners" == name || "backgroundcorners" == name ) { - setBackgroundCorners( ait->as_uint() ); - } else if ( "background" == name ) { - Drawable * res = NULL; - - if ( NULL != ( res = DrawableSearcher::searchByName( ait->as_string() ) ) ) { - setBackgroundDrawable( res, res->getDrawableType() == Drawable::SPRITE ); - } - } else if ( "visible" == name ) { - setVisible( ait->as_bool() ); - } else if ( "enabled" == name ) { - setEnabled( ait->as_bool() ); - } else if ( "theme" == name ) { - setThemeByName( ait->as_string() ); - - if ( !skinName.empty() ) - setThemeSkin( skinName ); - } else if ( "skin" == name ) { - skinName = ait->as_string(); - setThemeSkin( skinName ); - } else if ( "gravity" == name ) { - std::string gravity = ait->as_string(); - String::toLowerInPlace( gravity ); - std::vector strings = String::split( gravity, '|' ); - - if ( strings.size() ) { - for ( std::size_t i = 0; i < strings.size(); i++ ) { - std::string cur = strings[i]; - String::toLowerInPlace( cur ); - - if ( "left" == cur ) - setHorizontalAlign( UI_HALIGN_LEFT ); - else if ( "right" == cur ) - setHorizontalAlign( UI_HALIGN_RIGHT ); - else if ( "center_horizontal" == cur ) - setHorizontalAlign( UI_HALIGN_CENTER ); - else if ( "top" == cur ) - setVerticalAlign( UI_VALIGN_TOP ); - else if ( "bottom" == cur ) - setVerticalAlign( UI_VALIGN_BOTTOM ); - else if ( "center_vertical" == cur ) { - setVerticalAlign( UI_VALIGN_CENTER ); - } else if ( "center" == cur ) { - setHorizontalAlign( UI_HALIGN_CENTER ); - setVerticalAlign( UI_VALIGN_CENTER ); - } - } - - notifyLayoutAttrChange(); - } - } else if ( "flags" == name ) { - std::string flags = ait->as_string(); - String::toLowerInPlace( flags ); - std::vector strings = String::split( flags, '|' ); - - if ( strings.size() ) { - for ( std::size_t i = 0; i < strings.size(); i++ ) { - std::string cur = strings[i]; - String::toLowerInPlace( cur ); - - if ( "auto_size" == cur || "autosize" == cur ) { - setFlags( UI_AUTO_SIZE ); - notifyLayoutAttrChange(); - } else if ( "clip" == cur ) { - clipEnable(); - } else if ( "word_wrap" == cur || "wordwrap" == cur ) { - setFlags( UI_WORD_WRAP ); - } else if ( "multi" == cur ) { - setFlags( UI_MULTI_SELECT ); - } else if ( "auto_padding" == cur || "autopadding" == cur ) { - setFlags( UI_AUTO_PADDING ); - notifyLayoutAttrChange(); - } else if ( "reportsizechangetochilds" == cur || "report_size_change_to_childs" == cur ) { - enableReportSizeChangeToChilds(); - } - } - } - } else if ( "layout_margin" == name ) { - int val = PixelDensity::toDpFromStringI( ait->as_string() ); - setLayoutMargin( Rect( val, val, val, val ) ); - } else if ( "layout_marginleft" == name ) { - setLayoutMargin( Rect( PixelDensity::toDpFromStringI( ait->as_string() ), mLayoutMargin.Top, mLayoutMargin.Right, mLayoutMargin.Bottom ) ); - } else if ( "layout_marginright" == name ) { - setLayoutMargin( Rect( mLayoutMargin.Left, mLayoutMargin.Top, PixelDensity::toDpFromStringI( ait->as_string() ), mLayoutMargin.Bottom ) ); - } else if ( "layout_margintop" == name ) { - setLayoutMargin( Rect( mLayoutMargin.Left, PixelDensity::toDpFromStringI( ait->as_string() ), mLayoutMargin.Right, mLayoutMargin.Bottom ) ); - } else if ( "layout_marginbottom" == name ) { - setLayoutMargin( Rect( mLayoutMargin.Left, mLayoutMargin.Top, mLayoutMargin.Right, PixelDensity::toDpFromStringI( ait->as_string() ) ) ); - } else if ( "tooltip" == name ) { - setTooltipText( ait->as_string() ); - } else if ( "layout_weight" == name ) { - setLayoutWeight( ait->as_float() ); - } else if ( "layout_gravity" == name ) { - std::string gravityStr = ait->as_string(); - String::toLowerInPlace( gravityStr ); - std::vector strings = String::split( gravityStr, '|' ); - Uint32 gravity = 0; - - if ( strings.size() ) { - for ( std::size_t i = 0; i < strings.size(); i++ ) { - std::string cur = strings[i]; - String::toLowerInPlace( cur ); - - if ( "left" == cur ) - gravity |= UI_HALIGN_LEFT; - else if ( "right" == cur ) - gravity |= UI_HALIGN_RIGHT; - else if ( "center_horizontal" == cur ) - gravity |= UI_HALIGN_CENTER; - else if ( "top" == cur ) - gravity |= UI_VALIGN_TOP; - else if ( "bottom" == cur ) - gravity |= UI_VALIGN_BOTTOM; - else if ( "center_vertical" == cur ) { - gravity |= UI_VALIGN_CENTER; - } else if ( "center" == cur ) { - gravity |= UI_VALIGN_CENTER | UI_HALIGN_CENTER; - } - } - - setLayoutGravity( gravity ); - } - } else if ( "layout_width" == name ) { - std::string val = ait->as_string(); - String::toLowerInPlace( val ); - - if ( "match_parent" == val ) { - setLayoutWidthRules( MATCH_PARENT ); - } else if ( "wrap_content" == val ) { - setLayoutWidthRules( WRAP_CONTENT ); - } else if ( "fixed" == val ) { - setLayoutWidthRules( FIXED ); - unsetFlags( UI_AUTO_SIZE ); - } else { - unsetFlags( UI_AUTO_SIZE ); - setLayoutWidthRules( FIXED ); - setInternalWidth( PixelDensity::toDpFromStringI( val ) ); - onSizeChange(); - } - } else if ( "layout_height" == name ) { - std::string val = ait->as_string(); - String::toLowerInPlace( val ); - - if ( "match_parent" == val ) { - setLayoutHeightRules( MATCH_PARENT ); - } else if ( "wrap_content" == val ) { - setLayoutHeightRules( WRAP_CONTENT ); - } else if ( "fixed" == val ) { - setLayoutHeightRules( FIXED ); - unsetFlags( UI_AUTO_SIZE ); - } else { - unsetFlags( UI_AUTO_SIZE ); - setLayoutHeightRules( FIXED ); - setInternalHeight( PixelDensity::toDpFromStringI( val ) ); - onSizeChange(); - } - } else if ( String::startsWith( name, "layout_to_" ) || String::startsWith( name, "layoutto" ) ) { - LayoutPositionRules rule = NONE; - if ( "layout_to_left_of" == name || "layouttoleftof" == name ) rule = LEFT_OF; - else if ( "layout_to_right_of" == name || "layouttorightof" == name ) rule = RIGHT_OF; - else if ( "layout_to_top_of" == name || "layouttotopof" == name ) rule = TOP_OF; - else if ( "layout_to_bottom_of" == name || "layouttobottomof" == name ) rule = BOTTOM_OF; - - std::string id = ait->as_string(); - - Node * control = getParent()->find( id ); - - if ( NULL != control && control->isWidget() ) { - UIWidget * widget = static_cast( control ); - - setLayoutPositionRule( rule, widget ); - } - } else if ( "clip" == name ) { - if ( ait->as_bool() ) - clipEnable(); - else - clipDisable(); - } else if ( "rotation" == name ) { - setRotation( ait->as_float() ); - } else if ( "scale" == name ) { - setScale( ait->as_float() ); - } else if ( "rotationoriginpoint" == name ) { - setRotationOriginPoint( toOriginPoint( ait->as_string() ) ); - } else if ( "scaleoriginpoint" == name ) { - setScaleOriginPoint( toOriginPoint( ait->as_string() ) ); - } else if ( "blendmode" == name ) { - setBlendMode( toBlendMode( ait->as_string() ) ); - } else if ( "backgroundblendmode" == name ) { - setBackgroundBlendMode( toBlendMode( ait->as_string() ) ); - } + setAttribute( ait->name(), ait->value() ); } - endPropertiesTransaction(); + endAttributesTransaction(); } }} diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 23557ef3c..2af24ac70 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -1397,56 +1397,53 @@ void UIWindow::resizeCursor() { } } -void UIWindow::loadFromXmlNode(const pugi::xml_node & node) { - beginPropertiesTransaction(); +void UIWindow::setAttribute( const NodeAttribute& attribute ) { + const std::string& name = attribute.getName(); - UIWidget::loadFromXmlNode( node ); + if ( "width" == name ) { + setSize( attribute.asInt(), mDpSize.getHeight() ); + } else if ( "height" == name ) { + setSize( mDpSize.getWidth(), attribute.asInt() ); + } else if ( "title" == name ) { + setTitle( attribute.asString() ); + } else if ( "basealpha" == name ) { + unsigned int val = attribute.asUint(); + if ( val <= 255 ) + setBaseAlpha( (Uint8)val ); + } else if ( "winflags" == name ) { + std::string flagsStr = attribute.asString(); + String::toLowerInPlace( flagsStr ); + std::vector strings = String::split( flagsStr, '|' ); + Uint32 winflags = 0; - for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - std::string name = ait->name(); - String::toLowerInPlace( name ); + if ( strings.size() ) { + for ( std::size_t i = 0; i < strings.size(); i++ ) { + std::string cur = strings[i]; - if ( "width" == name ) { - setSize( ait->as_int(), mDpSize.getHeight() ); - } else if ( "height" == name ) { - setSize( mDpSize.getWidth(), ait->as_int() ); - } else if ( "title" == name ) { - setTitle( ait->as_string() ); - } else if ( "basealpha" == name ) { - unsigned int val = ait->as_uint(); - if ( val <= 255 ) - setBaseAlpha( (Uint8)val ); - } else if ( "winflags" == name ) { - std::string flagsStr = ait->as_string(); - String::toLowerInPlace( flagsStr ); - std::vector strings = String::split( flagsStr, '|' ); - Uint32 winflags = 0; - - if ( strings.size() ) { - for ( std::size_t i = 0; i < strings.size(); i++ ) { - std::string cur = strings[i]; - - if ( "default" == cur ) winflags |= UI_WIN_DEFAULT_FLAGS; - else if ( "close" == cur ) winflags |= UI_WIN_CLOSE_BUTTON; - else if ( "maximize" == cur ) winflags |= UI_WIN_MAXIMIZE_BUTTON; - else if ( "minimize" == cur ) winflags |= UI_WIN_MINIMIZE_BUTTON; - else if ( "dragable" == cur ) winflags |= UI_WIN_DRAGABLE_CONTAINER; - else if ( "shadow" == cur ) winflags |= UI_WIN_SHADOW; - else if ( "modal" == cur ) winflags |= UI_WIN_MODAL; - else if ( "noborder" == cur || "borderless" == cur ) winflags |= UI_WIN_NO_BORDER; - else if ( "resizeable" == cur ) winflags |= UI_WIN_RESIZEABLE; - else if ( "sharealpha" == cur ) winflags |= UI_WIN_SHARE_ALPHA_WITH_CHILDS; - else if ( "buttonactions" == cur ) winflags |= UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS; - else if ( "framebuffer"== cur ) winflags |= UI_WIN_FRAME_BUFFER; - else if ( "colorbuffer"== cur ) winflags |= UI_WIN_COLOR_BUFFER; - } - - setWinFlags( winflags ); + if ( "default" == cur ) winflags |= UI_WIN_DEFAULT_FLAGS; + else if ( "close" == cur ) winflags |= UI_WIN_CLOSE_BUTTON; + else if ( "maximize" == cur ) winflags |= UI_WIN_MAXIMIZE_BUTTON; + else if ( "minimize" == cur ) winflags |= UI_WIN_MINIMIZE_BUTTON; + else if ( "dragable" == cur ) winflags |= UI_WIN_DRAGABLE_CONTAINER; + else if ( "shadow" == cur ) winflags |= UI_WIN_SHADOW; + else if ( "modal" == cur ) winflags |= UI_WIN_MODAL; + else if ( "noborder" == cur || "borderless" == cur ) winflags |= UI_WIN_NO_BORDER; + else if ( "resizeable" == cur ) winflags |= UI_WIN_RESIZEABLE; + else if ( "sharealpha" == cur ) winflags |= UI_WIN_SHARE_ALPHA_WITH_CHILDS; + else if ( "buttonactions" == cur ) winflags |= UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS; + else if ( "framebuffer"== cur ) winflags |= UI_WIN_FRAME_BUFFER; + else if ( "colorbuffer"== cur ) winflags |= UI_WIN_COLOR_BUFFER; } - } - } - endPropertiesTransaction(); + setWinFlags( winflags ); + } + } else { + UIWidget::setAttribute( attribute ); + } +} + +void UIWindow::loadFromXmlNode(const pugi::xml_node & node) { + UIWidget::loadFromXmlNode( node ); show(); } diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index ac644016c..ee3646106 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -302,7 +302,7 @@ void UIWinMenu::destroyMenues() { } void UIWinMenu::loadFromXmlNode( const pugi::xml_node& node ) { - beginPropertiesTransaction(); + beginAttributesTransaction(); UIWidget::loadFromXmlNode( node ); @@ -325,7 +325,7 @@ void UIWinMenu::loadFromXmlNode( const pugi::xml_node& node ) { } } - endPropertiesTransaction(); + endAttributesTransaction(); } }}