diff --git a/bin/assets/ui/css/style.css b/bin/assets/ui/css/style.css new file mode 100644 index 000000000..44cec7968 --- /dev/null +++ b/bin/assets/ui/css/style.css @@ -0,0 +1,12 @@ + +PushButton { + foregroundColor: #66666666; +} + +PushButton:hover { + foregroundColor: #66FF6666; +} + +PushButton:pressed { + foregroundColor: #FF666666; +} diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index b1f1e4e01..fb3b1a906 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -47,7 +47,15 @@ #include #include - #include +#include +#include +#include +#include +#include +#include +#include +#include + #endif diff --git a/include/eepp/ui/css/stylesheet.hpp b/include/eepp/ui/css/stylesheet.hpp index 91f036c9c..67c610eeb 100644 --- a/include/eepp/ui/css/stylesheet.hpp +++ b/include/eepp/ui/css/stylesheet.hpp @@ -5,13 +5,17 @@ namespace EE { namespace UI { namespace CSS { -class StyleSheet { +class StyleSheetElement; + +class EE_API StyleSheet { public: StyleSheet(); void addNode( StyleSheetNode node ); - StyleSheetProperties find( const std::string& tagName = "", const std::string& id = "", const std::vector& classes = {}, const std::string& pseudoClass = "" ); + bool isEmpty() const; + + StyleSheetProperties getElementProperties( StyleSheetElement * element, const std::string& pseudoClass = "" ); std::vector nodes; }; diff --git a/include/eepp/ui/css/stylesheetelement.hpp b/include/eepp/ui/css/stylesheetelement.hpp index 566ad203a..78aeea5d3 100644 --- a/include/eepp/ui/css/stylesheetelement.hpp +++ b/include/eepp/ui/css/stylesheetelement.hpp @@ -3,16 +3,17 @@ #include #include +#include namespace EE { namespace UI { namespace CSS { -class StyleSheetElement { +class EE_API StyleSheetElement { public: - virtual std::string getStyleSheetTag() const = 0; + virtual const std::string& getStyleSheetTag() const = 0; - virtual const std::string& getStyleSheetId() const; + virtual const std::string& getStyleSheetId() const = 0; - virtual const std::vector& getStyleSheetClasses() = 0; + virtual const std::vector& getStyleSheetClasses() const = 0; virtual StyleSheetElement * getStyleSheetParentElement() = 0; }; diff --git a/include/eepp/ui/css/stylesheetnode.hpp b/include/eepp/ui/css/stylesheetnode.hpp index dbf99ad31..df7aa0e4b 100644 --- a/include/eepp/ui/css/stylesheetnode.hpp +++ b/include/eepp/ui/css/stylesheetnode.hpp @@ -6,7 +6,7 @@ namespace EE { namespace UI { namespace CSS { -class StyleSheetNode { +class EE_API StyleSheetNode { public: explicit StyleSheetNode( const std::string& selector, const StyleSheetProperties& properties ); diff --git a/include/eepp/ui/css/stylesheetparser.hpp b/include/eepp/ui/css/stylesheetparser.hpp index 3e6f7a7a4..0916dac51 100644 --- a/include/eepp/ui/css/stylesheetparser.hpp +++ b/include/eepp/ui/css/stylesheetparser.hpp @@ -13,9 +13,13 @@ using namespace EE; using namespace EE::System; +namespace EE { namespace System { +class Pack; +}} + namespace EE { namespace UI { namespace CSS { -class StyleSheetParser { +class EE_API StyleSheetParser { public: StyleSheetParser(); @@ -23,6 +27,10 @@ class StyleSheetParser { bool loadFromFile( const std::string& file ); + bool loadFromMemory( const Uint8* RAWData, const Uint32& size ); + + bool loadFromPack( Pack * pack, std::string filePackPath ); + void print(); StyleSheet& getStyleSheet(); diff --git a/include/eepp/ui/css/stylesheetpropertiesparser.hpp b/include/eepp/ui/css/stylesheetpropertiesparser.hpp index 893f46bc2..11f39f7c5 100644 --- a/include/eepp/ui/css/stylesheetpropertiesparser.hpp +++ b/include/eepp/ui/css/stylesheetpropertiesparser.hpp @@ -8,7 +8,7 @@ namespace EE { namespace UI { namespace CSS { -class StyleSheetPropertiesParser { +class EE_API StyleSheetPropertiesParser { public: StyleSheetPropertiesParser(); diff --git a/include/eepp/ui/css/stylesheetproperty.hpp b/include/eepp/ui/css/stylesheetproperty.hpp index 98f1a351e..10d52a028 100644 --- a/include/eepp/ui/css/stylesheetproperty.hpp +++ b/include/eepp/ui/css/stylesheetproperty.hpp @@ -3,10 +3,11 @@ #include #include +#include namespace EE { namespace UI { namespace CSS { -class StyleSheetProperty { +class EE_API StyleSheetProperty { public: StyleSheetProperty(); @@ -14,6 +15,7 @@ class StyleSheetProperty { std::string name; std::string value; + Uint32 specificity; }; typedef std::map StyleSheetProperties; diff --git a/include/eepp/ui/css/stylesheetselector.hpp b/include/eepp/ui/css/stylesheetselector.hpp index c43dc2e28..c6b505fd7 100644 --- a/include/eepp/ui/css/stylesheetselector.hpp +++ b/include/eepp/ui/css/stylesheetselector.hpp @@ -5,7 +5,7 @@ namespace EE { namespace UI { namespace CSS { -class StyleSheetSelector { +class EE_API StyleSheetSelector { public: enum SelectorType { TagName = 1 << 0, @@ -18,7 +18,7 @@ class StyleSheetSelector { SpecificityId = 1000000, SpecificityClass = 100000, SpecificityTag = 10000, - SpecificityPseudoClass = 0 + SpecificityPseudoClass = 100 }; explicit StyleSheetSelector( const std::string& selectorName ); diff --git a/include/eepp/ui/css/stylesheetselectorparser.hpp b/include/eepp/ui/css/stylesheetselectorparser.hpp index 1e0b1c07d..4090eb6c5 100644 --- a/include/eepp/ui/css/stylesheetselectorparser.hpp +++ b/include/eepp/ui/css/stylesheetselectorparser.hpp @@ -5,7 +5,7 @@ namespace EE { namespace UI { namespace CSS { -class StyleSheetSelectorParser { +class EE_API StyleSheetSelectorParser { public: StyleSheetSelectorParser(); diff --git a/include/eepp/ui/uicheckbox.hpp b/include/eepp/ui/uicheckbox.hpp index dbdb4a5ba..43efc5857 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: UINode * mActiveButton; UINode * mInactiveButton; diff --git a/include/eepp/ui/uidropdownlist.hpp b/include/eepp/ui/uidropdownlist.hpp index a01ec0945..6454334cc 100644 --- a/include/eepp/ui/uidropdownlist.hpp +++ b/include/eepp/ui/uidropdownlist.hpp @@ -36,7 +36,7 @@ class EE_API UIDropDownList : public UITextInput { void setStyleConfig(const UIDropDownListStyleConfig & styleConfig); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); virtual void loadFromXmlNode(const pugi::xml_node & node); protected: diff --git a/include/eepp/ui/uigridlayout.hpp b/include/eepp/ui/uigridlayout.hpp index c2dffe5bb..b7cb9a345 100644 --- a/include/eepp/ui/uigridlayout.hpp +++ b/include/eepp/ui/uigridlayout.hpp @@ -49,7 +49,7 @@ class EE_API UIGridLayout : public UILayout { UIGridLayout * setRowWeight(const Float & rowWeight); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: Sizei mSpan; ElementMode mColumnMode; diff --git a/include/eepp/ui/uiimage.hpp b/include/eepp/ui/uiimage.hpp index 4a4177b63..880042d1b 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); Uint32 getScaleType() const; diff --git a/include/eepp/ui/uilayout.hpp b/include/eepp/ui/uilayout.hpp index 725df7469..43d473f27 100644 --- a/include/eepp/ui/uilayout.hpp +++ b/include/eepp/ui/uilayout.hpp @@ -14,6 +14,9 @@ class EE_API UILayout : public UIWidget { virtual Uint32 getType() const; virtual bool isType( const Uint32& type ) const; + protected: + UILayout( const std::string& tag ); + }; }} diff --git a/include/eepp/ui/uilinearlayout.hpp b/include/eepp/ui/uilinearlayout.hpp index 3e205f3d4..6e7966eef 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: UI_ORIENTATION mOrientation; diff --git a/include/eepp/ui/uilistbox.hpp b/include/eepp/ui/uilistbox.hpp index 94953f0fc..34120df8d 100644 --- a/include/eepp/ui/uilistbox.hpp +++ b/include/eepp/ui/uilistbox.hpp @@ -113,7 +113,7 @@ class EE_API UIListBox : public UITouchDragableWidget { void loadItemsFromXmlNode(const pugi::xml_node & node); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: friend class UIListBoxItem; friend class UIItemContainer; diff --git a/include/eepp/ui/uiloader.hpp b/include/eepp/ui/uiloader.hpp index a33760dc7..a8ba188f0 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); Float getArcStartAngle() const; diff --git a/include/eepp/ui/uimenuitem.hpp b/include/eepp/ui/uimenuitem.hpp index 2153baf2c..e0c68eae4 100644 --- a/include/eepp/ui/uimenuitem.hpp +++ b/include/eepp/ui/uimenuitem.hpp @@ -19,6 +19,8 @@ class EE_API UIMenuItem : public UIPushButton { virtual void setTheme( UITheme * Theme ); protected: + UIMenuItem( const std::string& tag ); + virtual Uint32 onMouseEnter( const Vector2i &position, const Uint32 flags ); virtual void onStateChange(); diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index d295a6233..bd650ba6d 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -159,9 +159,9 @@ class EE_API UINode : public Node { void removeSkin(); - void pushState( const Uint32& State, bool emitEvent = true ); + virtual void pushState( const Uint32& State, bool emitEvent = true ); - void popState( const Uint32& State, bool emitEvent = true ); + virtual void popState( const Uint32& State, bool emitEvent = true ); Sizef getSkinSize(); diff --git a/include/eepp/ui/uiprogressbar.hpp b/include/eepp/ui/uiprogressbar.hpp index d320dee19..fe2cc9a14 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: UIProgressBarStyleConfig mStyleConfig; Float mProgress; diff --git a/include/eepp/ui/uipushbutton.hpp b/include/eepp/ui/uipushbutton.hpp index 1fc67f832..7b63d4b03 100644 --- a/include/eepp/ui/uipushbutton.hpp +++ b/include/eepp/ui/uipushbutton.hpp @@ -71,12 +71,14 @@ class EE_API UIPushButton : public UIWidget { void setStyleConfig(const UIPushButtonStyleConfig & styleConfig); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: UIPushButtonStyleConfig mStyleConfig; UIImage * mIcon; UITextView * mTextBox; + UIPushButton( const std::string& tag ); + virtual void onSizeChange(); virtual void onAlphaChange(); diff --git a/include/eepp/ui/uiradiobutton.hpp b/include/eepp/ui/uiradiobutton.hpp index 8894ac50b..fb83cc16c 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: UINode * mActiveButton; UINode * mInactiveButton; diff --git a/include/eepp/ui/uiscenenode.hpp b/include/eepp/ui/uiscenenode.hpp index 51eabf9f3..81ce660f0 100644 --- a/include/eepp/ui/uiscenenode.hpp +++ b/include/eepp/ui/uiscenenode.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace EE { namespace UI { @@ -13,7 +14,7 @@ class EE_API UISceneNode : public SceneNode { public: static UISceneNode * New( EE::Window::Window * window = NULL ); - UISceneNode( EE::Window::Window * window = NULL ); + explicit UISceneNode( EE::Window::Window * window = NULL ); virtual Node * setSize( const Sizef& size ); @@ -41,12 +42,18 @@ class EE_API UISceneNode : public SceneNode { UIWidget * loadLayoutNodes( pugi::xml_node node, Node * parent ); + void setStyleSheet( CSS::StyleSheet styleSheet ); + + CSS::StyleSheet& getStyleSheet(); + + bool hasStyleSheet(); protected: friend class EE::UI::UIWindow; Sizef mDpSize; Uint32 mFlags; Translator mTranslator; std::list mWindowsList; + CSS::StyleSheet mStyleSheet; virtual void resizeControl( EE::Window::Window * win ); @@ -60,9 +67,7 @@ class EE_API UISceneNode : public SceneNode { bool windowExists( UIWindow * win ); - virtual void setInternalSize(const Sizef& size ); - }; }} diff --git a/include/eepp/ui/uiscrollbar.hpp b/include/eepp/ui/uiscrollbar.hpp index e68a3b954..85d599a97 100644 --- a/include/eepp/ui/uiscrollbar.hpp +++ b/include/eepp/ui/uiscrollbar.hpp @@ -69,7 +69,7 @@ class EE_API UIScrollBar : public UIWidget { void setExpandBackground( bool expandBackground ); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: ScrollBarType mScrollBarType; UISlider * mSlider; diff --git a/include/eepp/ui/uiscrollview.hpp b/include/eepp/ui/uiscrollview.hpp index 56e7fd76d..7767f2da8 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: ScrollViewType mViewType; UI_SCROLLBAR_MODE mVScrollMode; diff --git a/include/eepp/ui/uiselectbutton.hpp b/include/eepp/ui/uiselectbutton.hpp index e8fa33541..44d2d9ad1 100644 --- a/include/eepp/ui/uiselectbutton.hpp +++ b/include/eepp/ui/uiselectbutton.hpp @@ -27,8 +27,10 @@ class EE_API UISelectButton : public UIPushButton { const Color& getFontSelectedColor() const; - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: + UISelectButton( const std::string& tag ); + virtual void onStateChange(); }; diff --git a/include/eepp/ui/uislider.hpp b/include/eepp/ui/uislider.hpp index 1f38de90a..d22e46dab 100644 --- a/include/eepp/ui/uislider.hpp +++ b/include/eepp/ui/uislider.hpp @@ -66,7 +66,7 @@ class EE_API UISlider : public UIWidget { void setPageStep( const Float & pageStep ); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); Sizef getMinimumSize(); protected: diff --git a/include/eepp/ui/uispinbox.hpp b/include/eepp/ui/uispinbox.hpp index 7a6fc3736..c81ce270b 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: UITextInput * mInput; UINode * mPushUp; diff --git a/include/eepp/ui/uisprite.hpp b/include/eepp/ui/uisprite.hpp index fbffe264b..785253cae 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: Graphics::Sprite * mSprite; RenderMode mRender; diff --git a/include/eepp/ui/uistate.hpp b/include/eepp/ui/uistate.hpp index 18accc530..758a44746 100644 --- a/include/eepp/ui/uistate.hpp +++ b/include/eepp/ui/uistate.hpp @@ -33,7 +33,7 @@ class EE_API UIState { StateFlagCount = StateCount }; - static const char * getSkinStateName( const Uint32& State ); + static const char * getStateName( const Uint32& State ); static int getStateNumber(const std::string & State); @@ -59,6 +59,8 @@ class EE_API UIState { Uint32 mCurrentState; void updateState(); + + virtual void onStateChange(); }; }} diff --git a/include/eepp/ui/uistyle.hpp b/include/eepp/ui/uistyle.hpp index f5f23c2d6..e9b2b2ff1 100644 --- a/include/eepp/ui/uistyle.hpp +++ b/include/eepp/ui/uistyle.hpp @@ -3,26 +3,36 @@ #include #include +#include using namespace EE::Scene; namespace EE { namespace UI { +class UIWidget; + class EE_API UIStyle : public UIState { public: - static UIStyle * New(); + static UIStyle * New( UIWidget * widget ); - explicit UIStyle(); + explicit UIStyle( UIWidget * widget ); virtual ~UIStyle(); bool stateExists( const Uint32& state ); void addAttribute( int state, NodeAttribute attribute ); + + void load(); protected: typedef std::map AttributesMap; + UIWidget * mWidget; std::map mStates; + + void addStyleSheetProperties( int state, const CSS::StyleSheetProperties& properties ); + + void onStateChange(); }; }} diff --git a/include/eepp/ui/uitab.hpp b/include/eepp/ui/uitab.hpp index 7021b53c0..0e34ccae8 100644 --- a/include/eepp/ui/uitab.hpp +++ b/include/eepp/ui/uitab.hpp @@ -29,7 +29,7 @@ class EE_API UITab : public UISelectButton { virtual UIPushButton * setText( const String& text ); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: Node * mControlOwned; std::string mOwnedName; diff --git a/include/eepp/ui/uitable.hpp b/include/eepp/ui/uitable.hpp index d2cf94a90..fdf817921 100644 --- a/include/eepp/ui/uitable.hpp +++ b/include/eepp/ui/uitable.hpp @@ -77,7 +77,7 @@ class EE_API UITable : public UITouchDragableWidget { Rectf getContainerPadding() const; - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: friend class UIItemContainer; friend class UITableCell; diff --git a/include/eepp/ui/uitabwidget.hpp b/include/eepp/ui/uitabwidget.hpp index f7c3c7e20..c2edd8090 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: friend class UITab; diff --git a/include/eepp/ui/uitextedit.hpp b/include/eepp/ui/uitextedit.hpp index a53113e8d..9bd1bb935 100644 --- a/include/eepp/ui/uitextedit.hpp +++ b/include/eepp/ui/uitextedit.hpp @@ -47,7 +47,7 @@ class EE_API UITextEdit : public UIWidget { void setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: UITextInput * mTextInput; UIScrollBar * mHScrollBar; diff --git a/include/eepp/ui/uitextinput.hpp b/include/eepp/ui/uitextinput.hpp index 5022d0d13..14d287a53 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 bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); virtual UIWidget * setPadding(const Rectf& padding); protected: @@ -58,6 +58,8 @@ class EE_API UITextInput : public UITextView { bool mAllowEditing; bool mShowingWait; + UITextInput( const std::string& tag ); + void resetWaitCursor(); virtual void alignFix(); diff --git a/include/eepp/ui/uitextureregion.hpp b/include/eepp/ui/uitextureregion.hpp index a60ab1762..a528a91c1 100644 --- a/include/eepp/ui/uitextureregion.hpp +++ b/include/eepp/ui/uitextureregion.hpp @@ -43,7 +43,7 @@ class EE_API UITextureRegion : public UIWidget { UITextureRegion * setScaleType(const Uint32 & scaleType); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: Uint32 mScaleType; Graphics::TextureRegion * mTextureRegion; diff --git a/include/eepp/ui/uitextview.hpp b/include/eepp/ui/uitextview.hpp index 6a54a6c91..00170408d 100644 --- a/include/eepp/ui/uitextview.hpp +++ b/include/eepp/ui/uitextview.hpp @@ -76,7 +76,7 @@ class EE_API UITextView : public UIWidget { UITooltipStyleConfig getFontStyleConfig() const; - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: Text * mTextCache; String mString; @@ -101,6 +101,8 @@ class EE_API UITextView : public UIWidget { Int32 mFontLineCenter; bool mSelecting; + UITextView( const std::string& tag ); + virtual void drawSelection(Text * textCache); virtual void onSizeChange(); diff --git a/include/eepp/ui/uitouchdragablewidget.hpp b/include/eepp/ui/uitouchdragablewidget.hpp index 2583de756..d7af7ac73 100644 --- a/include/eepp/ui/uitouchdragablewidget.hpp +++ b/include/eepp/ui/uitouchdragablewidget.hpp @@ -29,12 +29,14 @@ class EE_API UITouchDragableWidget : public UIWidget { UITouchDragableWidget * setTouchDragDeceleration( const Vector2f& touchDragDeceleration ); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: Vector2f mTouchDragPoint; Vector2f mTouchDragAcceleration; Vector2f mTouchDragDeceleration; + UITouchDragableWidget( const std::string& tag ); + virtual void onTouchDragValueChange( Vector2f diff ); virtual bool isTouchOverAllowedChilds(); diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index d305fb389..8953793fe 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace pugi { class xml_node; @@ -11,7 +12,9 @@ class xml_node; namespace EE { namespace UI { -class EE_API UIWidget : public UINode { +class UIStyle; + +class EE_API UIWidget : public UINode, public CSS::StyleSheetElement { public: static UIWidget * New(); @@ -85,18 +88,44 @@ class EE_API UIWidget : public UINode { void notifyLayoutAttrChangeParent(); - bool setAttribute( const std::string& name, const std::string& value ); + bool setAttribute( const std::string& name, const std::string& value, const Uint32& state = UIState::StateFlagNormal ); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); const Rectf& getPadding() const; UIWidget * setPadding(const Rectf& padding); + + const std::string& getStyleSheetTag() const; + + const std::string& getStyleSheetId() const; + + const std::vector& getStyleSheetClasses() const; + + StyleSheetElement * getStyleSheetParentElement(); + + void addClass( const std::string& cls ); + + void removeClass( const std::string& cls ); + + bool containsClass( const std::string& cls ); + + void setElementTag( const std::string& tag ); + + const std::string& getElementTag() const; + + virtual void pushState( const Uint32& State, bool emitEvent = true ); + + virtual void popState( const Uint32& State, bool emitEvent = true ); + + void reloadStyle(); protected: friend class UIManager; friend class UISceneNode; + std::string mTag; UITheme * mTheme; + UIStyle * mStyle; UITooltip * mTooltip; Sizef mMinControlSize; Rect mDistToBorder; @@ -111,6 +140,9 @@ class EE_API UIWidget : public UINode { UIWidget * mLayoutPositionRuleWidget; int mAttributesTransactionCount; std::string mSkinName; + std::vector mClasses; + + explicit UIWidget( const std::string& tag ); void createTooltip(); diff --git a/include/eepp/ui/uiwindow.hpp b/include/eepp/ui/uiwindow.hpp index 481529942..43d18d447 100644 --- a/include/eepp/ui/uiwindow.hpp +++ b/include/eepp/ui/uiwindow.hpp @@ -109,7 +109,7 @@ class EE_API UIWindow : public UIWidget { virtual void loadFromXmlNode( const pugi::xml_node& node ); - virtual bool setAttribute( const NodeAttribute& attribute ); + virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); virtual void internalDraw(); diff --git a/src/eepp/ui/css/stylesheet.cpp b/src/eepp/ui/css/stylesheet.cpp index 7c9ab3a49..7e1287ab9 100644 --- a/src/eepp/ui/css/stylesheet.cpp +++ b/src/eepp/ui/css/stylesheet.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace EE { namespace UI { namespace CSS { @@ -10,9 +11,13 @@ void StyleSheet::addNode( StyleSheetNode node ) { nodes.push_back( node ); } -StyleSheetProperties StyleSheet::find( const std::string& tagName, const std::string& id, const std::vector& classes, const std::string& pseudoClass ) { +bool StyleSheet::isEmpty() const { + return nodes.empty(); +} + +StyleSheetProperties StyleSheet::getElementProperties( StyleSheetElement * element, const std::string& pseudoClass ) { StyleSheetProperties propertiesSelected; - Uint32 lastSpecificity = -1; + Uint32 lastSpecificity = 0; for ( auto it = nodes.begin(); it != nodes.end(); ++it ) { StyleSheetNode& node = *it; @@ -20,17 +25,17 @@ StyleSheetProperties StyleSheet::find( const std::string& tagName, const std::st Uint32 flags = 0; - if ( selector.hasTagName() && !tagName.empty() && selector.getTagName() == tagName ) { + if ( selector.hasTagName() && !element->getStyleSheetTag().empty() && selector.getTagName() == element->getStyleSheetTag() ) { flags |= StyleSheetSelector::TagName; } - if ( selector.hasId() && !id.empty() && selector.getId() == id ) { + if ( selector.hasId() && !element->getStyleSheetId().empty() && selector.getId() == element->getStyleSheetId() ) { flags |= StyleSheetSelector::Id; } - if ( selector.hasClasses() && !classes.empty() ) { + if ( selector.hasClasses() && !element->getStyleSheetClasses().empty() ) { bool hasClasses = true; - for ( auto cit = classes.begin(); cit != classes.end(); ++cit ) { + for ( auto cit = element->getStyleSheetClasses().begin(); cit != element->getStyleSheetClasses().end(); ++cit ) { if ( !selector.hasClass( *cit ) ) { hasClasses = false; break; @@ -47,7 +52,9 @@ StyleSheetProperties StyleSheet::find( const std::string& tagName, const std::st } if ( flags == selector.getRequiredFlags() && selector.getSpecificity() > lastSpecificity ) { - propertiesSelected = node.properties; + for ( auto pit = node.properties.begin(); pit != node.properties.end(); ++pit ) + propertiesSelected[ pit->second.name ] = pit->second; + lastSpecificity = selector.getSpecificity(); } } diff --git a/src/eepp/ui/css/stylesheetparser.cpp b/src/eepp/ui/css/stylesheetparser.cpp index 07f784b62..558b350bd 100644 --- a/src/eepp/ui/css/stylesheetparser.cpp +++ b/src/eepp/ui/css/stylesheetparser.cpp @@ -2,14 +2,57 @@ #include #include #include +#include +#include +#include +#include + +using namespace EE::System; namespace EE { namespace UI { namespace CSS { StyleSheetParser::StyleSheetParser() { } -bool StyleSheetParser::loadFromFile( const std::string& file ) { - IOStreamFile stream( file ); +bool StyleSheetParser::loadFromStream( IOStream& stream ) { + mCSS.resize( stream.getSize(), '\0' ); + stream.read( &mCSS[0], stream.getSize() ); + return parse(); +} + +bool StyleSheetParser::loadFromFile( const std::string& filename ) { + if ( !FileSystem::fileExists( filename ) && PackManager::instance()->isFallbackToPacksActive() ) { + std::string path( filename ); + Pack * pack = PackManager::instance()->exists( path ); + + if ( NULL != pack ) { + return loadFromPack( pack, path ); + } + + return false; + } + + IOStreamFile stream( filename ); + return loadFromStream( stream ); +} + +bool StyleSheetParser::loadFromPack( Pack * pack, std::string filePackPath ) { + if ( NULL == pack ) + return false; + + bool Ret = false; + + SafeDataPointer PData; + + if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, PData ) ) { + Ret = loadFromMemory( PData.data, PData.size ); + } + + return Ret; +} + +bool StyleSheetParser::loadFromMemory( const Uint8* RAWData, const Uint32& size ) { + IOStreamMemory stream( (const char*)RAWData, size ); return loadFromStream( stream ); } @@ -143,10 +186,4 @@ int StyleSheetParser::readProperty( ReadState& rs, std::size_t pos, std::string& return pos; } -bool StyleSheetParser::loadFromStream( IOStream& stream ) { - mCSS.resize( stream.getSize(), '\0' ); - stream.read( &mCSS[0], stream.getSize() ); - return parse(); -} - }}} diff --git a/src/eepp/ui/css/stylesheetproperty.cpp b/src/eepp/ui/css/stylesheetproperty.cpp index a5f21fb14..35b11fff7 100644 --- a/src/eepp/ui/css/stylesheetproperty.cpp +++ b/src/eepp/ui/css/stylesheetproperty.cpp @@ -7,7 +7,7 @@ StyleSheetProperty::StyleSheetProperty() {} StyleSheetProperty::StyleSheetProperty( const std::string& name, const std::string& value ) : - name( String::trim( name ) ), + name( String::toLower( String::trim( name ) ) ), value( String::trim( value ) ) {} diff --git a/src/eepp/ui/css/stylesheetselector.cpp b/src/eepp/ui/css/stylesheetselector.cpp index aa7ba5c7c..ca4917a0d 100644 --- a/src/eepp/ui/css/stylesheetselector.cpp +++ b/src/eepp/ui/css/stylesheetselector.cpp @@ -5,7 +5,7 @@ namespace EE { namespace UI { namespace CSS { StyleSheetSelector::StyleSheetSelector( const std::string& selectorName ) : - name( selectorName ), + name( String::toLower( selectorName ) ), specificity(0) { auto parts = String::split( name, ' ' ); diff --git a/src/eepp/ui/uicheckbox.cpp b/src/eepp/ui/uicheckbox.cpp index 6fd2c3490..35d9dfc4b 100644 --- a/src/eepp/ui/uicheckbox.cpp +++ b/src/eepp/ui/uicheckbox.cpp @@ -10,7 +10,7 @@ UICheckBox * UICheckBox::New() { } UICheckBox::UICheckBox() : - UITextView(), + UITextView( "checkbox" ), mActive( false ), mTextSeparation( 4 ) { @@ -185,13 +185,13 @@ void UICheckBox::setTextSeparation(const Int32 & textSeparation) { setPadding( getPadding() ); } -bool UICheckBox::setAttribute( const NodeAttribute& attribute ) { +bool UICheckBox::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "selected" == name || "active" == name ) { setActive( attribute.asBool() ); } else { - return UITextView::setAttribute( attribute ); + return UITextView::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uicombobox.cpp b/src/eepp/ui/uicombobox.cpp index b03648525..fd0f773ef 100644 --- a/src/eepp/ui/uicombobox.cpp +++ b/src/eepp/ui/uicombobox.cpp @@ -8,7 +8,7 @@ UIComboBox * UIComboBox::New() { } UIComboBox::UIComboBox() : - UIWidget(), + UIWidget( "combobox" ), mDropDownList( NULL ), mButton( NULL ) { diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index 80353db6d..ac09583fb 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -12,7 +12,7 @@ UIDropDownList * UIDropDownList::New() { } UIDropDownList::UIDropDownList() : - UITextInput(), + UITextInput( "dropdownlist" ), mListBox( NULL ), mFriendCtrl( NULL ) { @@ -274,7 +274,7 @@ void UIDropDownList::destroyListBox() { } } -bool UIDropDownList::setAttribute( const NodeAttribute& attribute ) { +bool UIDropDownList::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "popuptomaincontrol" == name ) { @@ -282,7 +282,7 @@ bool UIDropDownList::setAttribute( const NodeAttribute& attribute ) { } else if ( "maxnumvisibleitems" == name ) { setMaxNumVisibleItems( attribute.asUint() ); } else { - return UITextInput::setAttribute( attribute ); + return UITextInput::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uigridlayout.cpp b/src/eepp/ui/uigridlayout.cpp index 449cabecc..f436e7985 100644 --- a/src/eepp/ui/uigridlayout.cpp +++ b/src/eepp/ui/uigridlayout.cpp @@ -8,7 +8,7 @@ UIGridLayout * UIGridLayout::New() { } UIGridLayout::UIGridLayout() : - UILayout(), + UILayout( "gridlayout" ), mColumnMode( Weight ), mRowMode( Weight ), mColumnWeight( 0.25f ), @@ -204,7 +204,7 @@ Sizef UIGridLayout::getTargetElementSize() { mRowMode == Size ? mRowHeight : ( ( getLayoutHeightRules() == WRAP_CONTENT ? getParent()->getSize().getHeight() : mDpSize.getHeight() ) - mPadding.Top - mPadding.Bottom ) * mRowWeight ); } -bool UIGridLayout::setAttribute( const NodeAttribute &attribute ) { +bool UIGridLayout::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "columnspan" == name ) { @@ -232,7 +232,7 @@ bool UIGridLayout::setAttribute( const NodeAttribute &attribute ) { } else if ( "reversedraw" == name ) { setReverseDraw( attribute.asBool() ); } else { - return UILayout::setAttribute( attribute ); + return UILayout::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index f3095647b..ecd8bda66 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -11,7 +11,7 @@ UIImage * UIImage::New() { } UIImage::UIImage() : - UIWidget(), + UIWidget( "image" ), mScaleType( UIScaleType::None ), mDrawable( NULL ), mColor(), @@ -183,7 +183,7 @@ const Vector2f& UIImage::getAlignOffset() const { return mAlignOffset; } -bool UIImage::setAttribute( const NodeAttribute& attribute ) { +bool UIImage::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "src" == name ) { @@ -209,7 +209,7 @@ bool UIImage::setAttribute( const NodeAttribute& attribute ) { } else if ( "tint" == name ) { setColor( attribute.asColor() ); } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uilayout.cpp b/src/eepp/ui/uilayout.cpp index 5edc6c9b5..38d52fe81 100644 --- a/src/eepp/ui/uilayout.cpp +++ b/src/eepp/ui/uilayout.cpp @@ -7,7 +7,12 @@ UILayout * UILayout::New() { } UILayout::UILayout() : - UIWidget() + UIWidget( "layout" ) +{ +} + +UILayout::UILayout( const std::string& tag ) : + UIWidget( tag ) { } diff --git a/src/eepp/ui/uilinearlayout.cpp b/src/eepp/ui/uilinearlayout.cpp index 225d873f4..dab22c0d0 100644 --- a/src/eepp/ui/uilinearlayout.cpp +++ b/src/eepp/ui/uilinearlayout.cpp @@ -16,7 +16,7 @@ UILinearLayout * UILinearLayout::NewHorizontal() { } UILinearLayout::UILinearLayout() : - UILayout(), + UILayout( "linearlayout" ), mOrientation( UI_VERTICAL ) { clipEnable(); @@ -336,7 +336,7 @@ Sizei UILinearLayout::getTotalUsedSize() { return size; } -bool UILinearLayout::setAttribute( const NodeAttribute& attribute ) { +bool UILinearLayout::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "orientation" == name ) { @@ -348,7 +348,7 @@ bool UILinearLayout::setAttribute( const NodeAttribute& attribute ) { else if ( "vertical" == val ) setOrientation( UI_VERTICAL ); } else { - return UILayout::setAttribute( attribute ); + return UILayout::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index df1a1f67e..99efaf6cb 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -16,7 +16,7 @@ UIListBox * UIListBox::New() { } UIListBox::UIListBox() : - UITouchDragableWidget(), + UITouchDragableWidget( "listbox" ), mRowHeight(0), mVScrollMode( UI_SCROLLBAR_AUTO ), mHScrollMode( UI_SCROLLBAR_AUTO ), @@ -983,7 +983,7 @@ void UIListBox::setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig) { setFontColor( mFontStyleConfig.FontColor ); } -bool UIListBox::setAttribute( const NodeAttribute& attribute ) { +bool UIListBox::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "rowheight" == name ) { @@ -1029,7 +1029,7 @@ bool UIListBox::setAttribute( const NodeAttribute& attribute ) { mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); } } else { - return UITouchDragableWidget::setAttribute( attribute ); + return UITouchDragableWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uilistboxitem.cpp b/src/eepp/ui/uilistboxitem.cpp index 54f3773ca..947b8c625 100644 --- a/src/eepp/ui/uilistboxitem.cpp +++ b/src/eepp/ui/uilistboxitem.cpp @@ -8,7 +8,7 @@ UIListBoxItem * UIListBoxItem::New() { } UIListBoxItem::UIListBoxItem() : - UITextView() + UITextView( "listboxitem" ) { setLayoutSizeRules( FIXED, FIXED ); applyDefaultTheme(); diff --git a/src/eepp/ui/uiloader.cpp b/src/eepp/ui/uiloader.cpp index b2d539574..b8b9aa4ab 100644 --- a/src/eepp/ui/uiloader.cpp +++ b/src/eepp/ui/uiloader.cpp @@ -9,7 +9,7 @@ UILoader * UILoader::New() { } UILoader::UILoader() : - UIWidget(), + UIWidget( "loader" ), mRadius(0), mOutlineThickness( PixelDensity::dpToPx(8) ), mColor( Color::Green ), @@ -184,7 +184,7 @@ UILoader * UILoader::setAnimationSpeed( const Float& animationSpeed ) { return this; } -bool UILoader::setAttribute( const NodeAttribute& attribute ) { +bool UILoader::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { std::string name = attribute.getName(); if ( "indeterminate" == name ) { @@ -204,7 +204,7 @@ bool UILoader::setAttribute( const NodeAttribute& attribute ) { } else if ( "arcstartangle" == name ) { setArcStartAngle( attribute.asFloat() ); } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 97093f396..714fbbeaa 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -13,7 +13,7 @@ UIMenu *UIMenu::New() { } UIMenu::UIMenu() : - UIWidget(), + UIWidget( "menu" ), mMaxWidth( 0 ), mNextPosY( 0 ), mBiggestIcon( 0 ), diff --git a/src/eepp/ui/uimenucheckbox.cpp b/src/eepp/ui/uimenucheckbox.cpp index 5b2f54abe..7c6810e3f 100644 --- a/src/eepp/ui/uimenucheckbox.cpp +++ b/src/eepp/ui/uimenucheckbox.cpp @@ -9,7 +9,7 @@ UIMenuCheckBox * UIMenuCheckBox::New() { } UIMenuCheckBox::UIMenuCheckBox() : - UIMenuItem(), + UIMenuItem( "menucheckbox" ), mActive( false ), mSkinActive( NULL ), mSkinInactive( NULL ) diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index 9582c067c..bd7744343 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -7,12 +7,16 @@ UIMenuItem * UIMenuItem::New() { return eeNew( UIMenuItem, () ); } -UIMenuItem::UIMenuItem() : - UIPushButton() +UIMenuItem::UIMenuItem( const std::string& tag ) : + UIPushButton( tag ) { applyDefaultTheme(); } +UIMenuItem::UIMenuItem() : + UIMenuItem( "menuitem" ) +{} + UIMenuItem::~UIMenuItem() { } diff --git a/src/eepp/ui/uimenuseparator.cpp b/src/eepp/ui/uimenuseparator.cpp index 0888b445b..e591bede6 100644 --- a/src/eepp/ui/uimenuseparator.cpp +++ b/src/eepp/ui/uimenuseparator.cpp @@ -8,7 +8,7 @@ UIMenuSeparator * UIMenuSeparator::New() { } UIMenuSeparator::UIMenuSeparator() : - UIWidget() + UIWidget( "menuseparator" ) { applyDefaultTheme(); } diff --git a/src/eepp/ui/uimenusubmenu.cpp b/src/eepp/ui/uimenusubmenu.cpp index 86f24d6ff..6471e8bfc 100644 --- a/src/eepp/ui/uimenusubmenu.cpp +++ b/src/eepp/ui/uimenusubmenu.cpp @@ -9,7 +9,7 @@ UIMenuSubMenu * UIMenuSubMenu::New() { } UIMenuSubMenu::UIMenuSubMenu() : - UIMenuItem(), + UIMenuItem( "menusubmenu" ), mSubMenu( NULL ), mArrow( NULL ), mTimeOver( 0.f ), diff --git a/src/eepp/ui/uipopupmenu.cpp b/src/eepp/ui/uipopupmenu.cpp index 49f9b2150..2b41b96c3 100644 --- a/src/eepp/ui/uipopupmenu.cpp +++ b/src/eepp/ui/uipopupmenu.cpp @@ -12,6 +12,7 @@ UIPopUpMenu * UIPopUpMenu::New() { UIPopUpMenu::UIPopUpMenu() : UIMenu() { + setElementTag( "popupmenu" ); setVisible( false ); setEnabled( false ); applyDefaultTheme(); diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index 186feb383..b12f7a144 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -10,7 +10,7 @@ UIProgressBar *UIProgressBar::New() { } UIProgressBar::UIProgressBar() : - UIWidget(), + UIWidget( "progressbar" ), mProgress( 0.f ), mTotalSteps( 100.f ), mFillerSkin( NULL ) @@ -213,7 +213,7 @@ UITextView * UIProgressBar::getTextBox() const { return mTextBox; } -bool UIProgressBar::setAttribute( const NodeAttribute& attribute ) { +bool UIProgressBar::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "totalsteps" == name ) { @@ -236,7 +236,7 @@ bool UIProgressBar::setAttribute( const NodeAttribute& attribute ) { } else if ( "fillerpaddingbottom" == name ) { setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, attribute.asDpDimension() ) ); } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 9c2d25ea3..d7f883361 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -11,8 +11,8 @@ UIPushButton * UIPushButton::New() { return eeNew( UIPushButton, () ); } -UIPushButton::UIPushButton() : - UIWidget(), +UIPushButton::UIPushButton( const std::string& tag ) : + UIWidget( tag ), mIcon( NULL ), mTextBox( NULL ) { @@ -61,6 +61,10 @@ UIPushButton::UIPushButton() : applyDefaultTheme(); } +UIPushButton::UIPushButton() : + UIPushButton( "pushbutton" ) +{} + UIPushButton::~UIPushButton() { } @@ -367,7 +371,7 @@ void UIPushButton::setStyleConfig(const UIPushButtonStyleConfig & styleConfig) { onStateChange(); } -bool UIPushButton::setAttribute( const NodeAttribute& attribute ) { +bool UIPushButton::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); bool attributeSet = true; @@ -387,7 +391,7 @@ bool UIPushButton::setAttribute( const NodeAttribute& attribute ) { setIcon( icon ); } } else { - attributeSet = UIWidget::setAttribute( attribute ); + attributeSet = UIWidget::setAttribute( attribute, state ); } if ( !attributeSet && ( String::startsWith( name, "text" ) || String::startsWith( name, "font" ) ) ) diff --git a/src/eepp/ui/uiradiobutton.cpp b/src/eepp/ui/uiradiobutton.cpp index 220712256..4b57f7b2e 100644 --- a/src/eepp/ui/uiradiobutton.cpp +++ b/src/eepp/ui/uiradiobutton.cpp @@ -10,7 +10,7 @@ UIRadioButton * UIRadioButton::New() { } UIRadioButton::UIRadioButton() : - UITextView(), + UITextView( "radiobutton" ), mActiveButton(NULL), mInactiveButton(NULL), mActive( false ), @@ -252,13 +252,13 @@ void UIRadioButton::setTextSeparation(const Int32 & textSeparation) { setPadding( getPadding() ); } -bool UIRadioButton::setAttribute( const NodeAttribute& attribute ) { +bool UIRadioButton::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "selected" == name || "active" == name ) { setActive( attribute.asBool() ); } else { - return UITextView::setAttribute( attribute ); + return UITextView::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uirelativelayout.cpp b/src/eepp/ui/uirelativelayout.cpp index ec7683cc9..0c080875a 100644 --- a/src/eepp/ui/uirelativelayout.cpp +++ b/src/eepp/ui/uirelativelayout.cpp @@ -7,7 +7,7 @@ UIRelativeLayout * UIRelativeLayout::New() { } UIRelativeLayout::UIRelativeLayout() : - UILayout() + UILayout( "relativelayout" ) { } diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 6102a73dc..773f1eee3 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -24,7 +24,7 @@ UISceneNode::UISceneNode( EE::Window::Window * window ) : resizeControl( mWindow ); } -void UISceneNode::resizeControl( EE::Window::Window * win ) { +void UISceneNode::resizeControl( EE::Window::Window * ) { setSize( (Float)mWindow->getWidth() / PixelDensity::getPixelDensity(), (Float)mWindow->getHeight() / PixelDensity::getPixelDensity() ); sendMsg( this, NodeMessage::WindowResize ); } @@ -98,6 +98,29 @@ UIWidget * UISceneNode::loadLayoutNodes( pugi::xml_node node, Node * parent ) { return firstWidget; } +void UISceneNode::setStyleSheet(CSS::StyleSheet styleSheet) { + mStyleSheet = styleSheet; + + if ( NULL != mChild ) { + Node * ChildLoop = mChild; + + while ( NULL != ChildLoop ) { + if ( ChildLoop->isWidget() ) + static_cast( ChildLoop )->reloadStyle(); + + ChildLoop = ChildLoop->getNextNode(); + } + } +} + +CSS::StyleSheet& UISceneNode::getStyleSheet() { + return mStyleSheet; +} + +bool UISceneNode::hasStyleSheet() { + return !mStyleSheet.isEmpty(); +} + UIWidget * UISceneNode::loadLayoutFromFile( const std::string& layoutPath, Node * parent ) { if ( FileSystem::fileExists( layoutPath ) ) { pugi::xml_document doc; diff --git a/src/eepp/ui/uiscrollbar.cpp b/src/eepp/ui/uiscrollbar.cpp index c98058057..632ccd7dc 100644 --- a/src/eepp/ui/uiscrollbar.cpp +++ b/src/eepp/ui/uiscrollbar.cpp @@ -16,7 +16,7 @@ UIScrollBar * UIScrollBar::NewVertical() { } UIScrollBar::UIScrollBar( const UI_ORIENTATION& orientation ) : - UIWidget(), + UIWidget( "scrollbar" ), #ifdef EE_PLATFORM_TOUCH mScrollBarType( NoButtons ) #else @@ -296,7 +296,7 @@ void UIScrollBar::setExpandBackground( bool expandBackground ) { adjustChilds(); } -bool UIScrollBar::setAttribute( const NodeAttribute & attribute ) { +bool UIScrollBar::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "orientation" == name ) { @@ -327,7 +327,7 @@ bool UIScrollBar::setAttribute( const NodeAttribute & attribute ) { setScrollBarType( TwoButtons ); } } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index 5a50fa9a7..253170c39 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -9,7 +9,7 @@ UIScrollView * UIScrollView::New() { } UIScrollView::UIScrollView() : - UITouchDragableWidget(), + UITouchDragableWidget( "scrollview" ), mViewType( Exclusive ), mVScrollMode( UI_SCROLLBAR_AUTO ), mHScrollMode( UI_SCROLLBAR_AUTO ), @@ -228,7 +228,7 @@ bool UIScrollView::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds() && mScrollView->isMouseOverMeOrChilds() && ret; } -bool UIScrollView::setAttribute( const NodeAttribute& attribute ) { +bool UIScrollView::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "type" == name ) { @@ -263,7 +263,7 @@ bool UIScrollView::setAttribute( const NodeAttribute& attribute ) { mHScroll->setScrollBarType( UIScrollBar::NoButtons ); } } else { - return UITouchDragableWidget::setAttribute( attribute ); + return UITouchDragableWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index 04553682c..6deb8d29b 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -4,14 +4,17 @@ namespace EE { namespace UI { -UISelectButton *UISelectButton::New() { +UISelectButton * UISelectButton::New() { return eeNew( UISelectButton, () ); } +UISelectButton::UISelectButton( const std::string& tag ) : + UIPushButton( tag ) +{} + UISelectButton::UISelectButton() : - UIPushButton() -{ -} + UISelectButton( "selectbutton" ) +{} UISelectButton::~UISelectButton() { } @@ -89,13 +92,13 @@ const Color &UISelectButton::getFontSelectedColor() const { return mStyleConfig.FontSelectedColor; } -bool UISelectButton::setAttribute( const NodeAttribute& attribute ) { +bool UISelectButton::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "textselectedcolor" == name ) { setFontSelectedColor( attribute.asColor() ); } else { - return UIPushButton::setAttribute( attribute ); + return UIPushButton::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 29a84d34f..93cbb935c 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -18,7 +18,7 @@ UISlider * UISlider::NewHorizontal() { } UISlider::UISlider( const UI_ORIENTATION& orientation ) : - UIWidget(), + UIWidget( "slider" ), mOrientation( orientation ), mBackSlider( NULL ), mSlider( NULL ), @@ -419,7 +419,7 @@ Uint32 UISlider::onMessage(const NodeMessage * Msg) { return 0; } -bool UISlider::setAttribute( const NodeAttribute& attribute ) { +bool UISlider::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "orientation" == name ) { @@ -443,7 +443,7 @@ bool UISlider::setAttribute( const NodeAttribute& attribute ) { } else if ( "halfslider" == name ) { setAllowHalfSliderOut( attribute.asBool() ); } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uisliderbutton.cpp b/src/eepp/ui/uisliderbutton.cpp index 9379d9d45..773ec2884 100644 --- a/src/eepp/ui/uisliderbutton.cpp +++ b/src/eepp/ui/uisliderbutton.cpp @@ -8,7 +8,7 @@ UISliderButton *UISliderButton::New() { } UISliderButton::UISliderButton() : - UIWidget() + UIWidget( "sliderbutton" ) { applyDefaultTheme(); } diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index bd8ffcb95..2bd59b038 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -9,7 +9,7 @@ UISpinBox * UISpinBox::New() { } UISpinBox::UISpinBox() : - UIWidget(), + UIWidget( "spinbox" ), mMinValue( 0.f ), mMaxValue( 1024.f ), mValue( 0 ), @@ -273,7 +273,7 @@ void UISpinBox::onPaddingChange() { UIWidget::onPaddingChange(); } -bool UISpinBox::setAttribute( const NodeAttribute& attribute ) { +bool UISpinBox::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); bool attributeSet = true; @@ -287,7 +287,7 @@ bool UISpinBox::setAttribute( const NodeAttribute& attribute ) { } else if ( "clickstep" == name ) { setClickStep(attribute.asFloat() ); } else { - attributeSet = UIWidget::setAttribute( attribute ); + attributeSet = UIWidget::setAttribute( attribute, state ); } mInput->setAttribute( attribute ); diff --git a/src/eepp/ui/uisprite.cpp b/src/eepp/ui/uisprite.cpp index 7e10722c0..00d8b5943 100644 --- a/src/eepp/ui/uisprite.cpp +++ b/src/eepp/ui/uisprite.cpp @@ -10,7 +10,7 @@ UISprite * UISprite::New() { } UISprite::UISprite() : - UIWidget(), + UIWidget( "sprite" ), mSprite( NULL ), mRender( RENDER_NORMAL ), mAlignOffset(0,0), @@ -185,7 +185,7 @@ void UISprite::onSizeChange() { UIWidget::onSizeChange(); } -bool UISprite::setAttribute( const NodeAttribute& attribute ) { +bool UISprite::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "src" == name ) { @@ -196,7 +196,7 @@ bool UISprite::setAttribute( const NodeAttribute& attribute ) { setSprite( Sprite::New( val ) ); } } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uistate.cpp b/src/eepp/ui/uistate.cpp index 1068bee7c..9c3d307d9 100644 --- a/src/eepp/ui/uistate.cpp +++ b/src/eepp/ui/uistate.cpp @@ -25,7 +25,7 @@ static const Uint32 UIStateFlags[] = { UIState::StateFlagDisabled }; -const char * UIState::getSkinStateName( const Uint32& State ) { +const char * UIState::getStateName( const Uint32& State ) { return UIStatesNames[ State ]; } @@ -95,12 +95,22 @@ void UIState::updateState() { if ( ( mState & UIStateFlags[i] ) == UIStateFlags[i] ) { if ( stateExists( UIStateFlags[i] ) ) { mCurrentState = UIStateFlags[i]; + onStateChange(); return; } } } + Uint32 currentState = mCurrentState; + mCurrentState = StateFlagNormal; + + if ( currentState != StateFlagNormal ) { + onStateChange(); + } +} + +void UIState::onStateChange() { } }} diff --git a/src/eepp/ui/uistyle.cpp b/src/eepp/ui/uistyle.cpp index 6fb5d0faa..014c4c638 100644 --- a/src/eepp/ui/uistyle.cpp +++ b/src/eepp/ui/uistyle.cpp @@ -1,25 +1,71 @@ #include +#include +#include namespace EE { namespace UI { -UIStyle * EE::UI::UIStyle::New() { - return eeNew( UIStyle, () ); +UIStyle * EE::UI::UIStyle::New( UIWidget * widget ) { + return eeNew( UIStyle, ( widget ) ); } -UIStyle::UIStyle() +UIStyle::UIStyle( UIWidget * widget ) : + mWidget( widget ) { + load(); } UIStyle::~UIStyle() -{ +{} + +bool UIStyle::stateExists( const EE::Uint32 & state ) { + return mStates.find( state ) != mStates.end(); } -bool UIStyle::stateExists( const EE::Uint32 & ) { - return false; -} - -void UIStyle::addAttribute(int state, NodeAttribute attribute) { +void UIStyle::addAttribute( int state, NodeAttribute attribute ) { mStates[ state ][ attribute.getName() ] = attribute; } +void UIStyle::load() { + UISceneNode * uiSceneNode = mWidget->getSceneNode()->isUISceneNode() ? static_cast( mWidget->getSceneNode() ) : NULL; + + if ( NULL != uiSceneNode ) { + CSS::StyleSheet& styleSheet = uiSceneNode->getStyleSheet(); + + if ( !styleSheet.isEmpty() ) { + addStyleSheetProperties( StateFlagNormal, styleSheet.getElementProperties( mWidget, "" ) ); + addStyleSheetProperties( StateFlagFocus, styleSheet.getElementProperties( mWidget, "focus" ) ); + addStyleSheetProperties( StateFlagSelected, styleSheet.getElementProperties( mWidget, "selected" ) ); + addStyleSheetProperties( StateFlagHover, styleSheet.getElementProperties( mWidget, "hover" ) ); + addStyleSheetProperties( StateFlagPressed, styleSheet.getElementProperties( mWidget, "pressed" ) ); + addStyleSheetProperties( StateFlagSelectedHover, styleSheet.getElementProperties( mWidget, "selectedhover" ) ); + addStyleSheetProperties( StateFlagSelectedPressed, styleSheet.getElementProperties( mWidget, "selectedpressed" ) ); + addStyleSheetProperties( StateFlagDisabled, styleSheet.getElementProperties( mWidget, "disabled" ) ); + + onStateChange(); + } + } +} + +void UIStyle::addStyleSheetProperties( int state, const CSS::StyleSheetProperties& properties ) { + if ( !properties.empty() ) { + for ( auto it = properties.begin(); it != properties.end(); ++it ) { + CSS::StyleSheetProperty property = it->second; + + addAttribute( state, NodeAttribute( property.name, property.value ) ); + } + } +} + +void UIStyle::onStateChange() { + if ( NULL != mWidget && stateExists( mCurrentState ) ) { + AttributesMap& attrs = mStates[ mCurrentState ]; + + for ( auto it = attrs.begin(); it != attrs.end(); ++it ) { + NodeAttribute& nodeAttr = it->second; + + mWidget->setAttribute( nodeAttr ); + } + } +} + }} diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 275bcebc4..29fa4dfa5 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -10,7 +10,7 @@ UITab *UITab::New() { } UITab::UITab() : - UISelectButton(), + UISelectButton( "tab" ), mControlOwned( NULL ) { applyDefaultTheme(); @@ -148,7 +148,7 @@ void UITab::onAutoSize() { } } -bool UITab::setAttribute( const NodeAttribute& attribute ) { +bool UITab::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { std::string name = attribute.getName(); if ( "name" == name || "text" == name ) { @@ -158,7 +158,7 @@ bool UITab::setAttribute( const NodeAttribute& attribute ) { mOwnedName = attribute.asString(); setOwnedControl(); } else { - return UISelectButton::setAttribute( attribute ); + return UISelectButton::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uitable.cpp b/src/eepp/ui/uitable.cpp index 485f97ad8..4b6883adc 100644 --- a/src/eepp/ui/uitable.cpp +++ b/src/eepp/ui/uitable.cpp @@ -8,7 +8,7 @@ UITable * UITable::New() { } UITable::UITable() : - UITouchDragableWidget(), + UITouchDragableWidget( "table" ), mContainerPadding(), mContainer( NULL ), mVScrollBar( NULL ), @@ -617,7 +617,7 @@ bool UITable::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds() && !mVScrollBar->isMouseOverMeOrChilds() && !mHScrollBar->isMouseOverMeOrChilds(); } -bool UITable::setAttribute( const NodeAttribute& attribute ) { +bool UITable::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "rowheight" == name ) { @@ -644,7 +644,7 @@ bool UITable::setAttribute( const NodeAttribute& attribute ) { mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); } } else { - return UITouchDragableWidget::setAttribute( attribute ); + return UITouchDragableWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uitablecell.cpp b/src/eepp/ui/uitablecell.cpp index 9c4322336..18058297d 100644 --- a/src/eepp/ui/uitablecell.cpp +++ b/src/eepp/ui/uitablecell.cpp @@ -8,7 +8,7 @@ UITableCell * UITableCell::New() { } UITableCell::UITableCell() : - UIWidget() + UIWidget( "tablecell" ) { applyDefaultTheme(); } diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index e45258391..b15b0f0a9 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -12,7 +12,7 @@ UITabWidget * UITabWidget::New() { } UITabWidget::UITabWidget() : - UIWidget(), + UIWidget( "tabwidget" ), mTabSelected( NULL ), mTabSelectedIndex( eeINDEX_NOT_FOUND ) { @@ -186,7 +186,7 @@ void UITabWidget::setStyleConfig(const UITabWidgetStyleConfig & styleConfig) { orderTabs(); } -bool UITabWidget::setAttribute( const NodeAttribute& attribute ) { +bool UITabWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "textcolor" == name ) { @@ -250,7 +250,7 @@ bool UITabWidget::setAttribute( const NodeAttribute& attribute ) { } else if ( "linebelowtabsyoffset" == name ) { setLineBelowTabsYOffset( attribute.asInt() ); } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uitextedit.cpp b/src/eepp/ui/uitextedit.cpp index c17429f3c..ac13ec03d 100644 --- a/src/eepp/ui/uitextedit.cpp +++ b/src/eepp/ui/uitextedit.cpp @@ -11,7 +11,7 @@ UITextEdit * UITextEdit::New() { } UITextEdit::UITextEdit() : - UIWidget(), + UIWidget( "textedit" ), mTextInput( NULL ), mHScrollBar( NULL ), mVScrollBar( NULL ), @@ -463,7 +463,7 @@ void UITextEdit::setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig) { } } -bool UITextEdit::setAttribute( const NodeAttribute &attribute ) { +bool UITextEdit::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); bool attributeSet = true; @@ -485,11 +485,11 @@ bool UITextEdit::setAttribute( const NodeAttribute &attribute ) { else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); } else { - attributeSet = UIWidget::setAttribute( attribute ); + attributeSet = UIWidget::setAttribute( attribute, state ); } if ( !attributeSet && ( String::startsWith( name, "text" ) || String::startsWith( name, "font" ) ) ) - mTextInput->setAttribute( attribute ); + mTextInput->setAttribute( attribute, state ); return attributeSet; } diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index db9ab1f56..804182c84 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -13,8 +13,8 @@ UITextInput * UITextInput::New() { return eeNew( UITextInput, () ); } -UITextInput::UITextInput() : - UITextView(), +UITextInput::UITextInput( const std::string& tag ) : + UITextView( tag ), mCursorPos(0), mAllowEditing( true ), mShowingWait( true ) @@ -31,6 +31,10 @@ UITextInput::UITextInput() : applyDefaultTheme(); } +UITextInput::UITextInput() : + UITextInput( "textinput" ) +{} + UITextInput::~UITextInput() { } @@ -344,7 +348,7 @@ bool UITextInput::isFreeEditingEnabled() { return mTextBuffer.isFreeEditingEnabled(); } -bool UITextInput::setAttribute( const NodeAttribute& attribute ) { +bool UITextInput::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "text" == name ) { @@ -362,7 +366,7 @@ bool UITextInput::setAttribute( const NodeAttribute& attribute ) { } else if ( "allowdot" == name ) { getInputTextBuffer()->setAllowOnlyNumbers( getInputTextBuffer()->onlyNumbersAllowed(), attribute.asBool() ); } else { - return UITextView::setAttribute( attribute ); + return UITextView::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uitextureregion.cpp b/src/eepp/ui/uitextureregion.cpp index cadd322ca..b1a6db481 100644 --- a/src/eepp/ui/uitextureregion.cpp +++ b/src/eepp/ui/uitextureregion.cpp @@ -11,7 +11,7 @@ UITextureRegion * UITextureRegion::New() { } UITextureRegion::UITextureRegion() : - UIWidget(), + UIWidget( "textureregion" ), mTextureRegion( NULL ), mColor(), mRender( RENDER_NORMAL ), @@ -192,7 +192,7 @@ const Vector2f& UITextureRegion::getAlignOffset() const { return mAlignOffset; } -bool UITextureRegion::setAttribute( const NodeAttribute& attribute ) { +bool UITextureRegion::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "src" == name || "textureregion" == name ) { @@ -215,7 +215,7 @@ bool UITextureRegion::setAttribute( const NodeAttribute& attribute ) { } else if ( "tint" == name ) { setColor( attribute.asColor() ); } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index 5319ff7d0..a87230191 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -13,8 +13,8 @@ UITextView * UITextView::New() { return eeNew( UITextView, () ); } -UITextView::UITextView() : - UIWidget(), +UITextView::UITextView( const std::string& tag ) : + UIWidget( tag ), mRealAlignOffset( 0.f, 0.f ), mSelCurInit( -1 ), mSelCurEnd( -1 ), @@ -37,6 +37,10 @@ UITextView::UITextView() : alignFix(); } +UITextView::UITextView() : + UITextView( "textview" ) +{} + UITextView::~UITextView() { eeSAFE_DELETE( mTextCache ); } @@ -532,7 +536,7 @@ void UITextView::setFontStyleConfig( const UITooltipStyleConfig& fontStyleConfig setOutlineColor( mFontStyleConfig.getOutlineColor() ); } -bool UITextView::setAttribute( const NodeAttribute& attribute ) { +bool UITextView::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "text" == name ) { @@ -591,7 +595,7 @@ bool UITextView::setAttribute( const NodeAttribute& attribute ) { } else if ( "textselection" == name ) { mFlags|= UI_TEXT_SELECTION_ENABLED; } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uitouchdragablewidget.cpp b/src/eepp/ui/uitouchdragablewidget.cpp index ce1d0fa88..3ffe3f913 100644 --- a/src/eepp/ui/uitouchdragablewidget.cpp +++ b/src/eepp/ui/uitouchdragablewidget.cpp @@ -7,11 +7,15 @@ UITouchDragableWidget * UITouchDragableWidget::New() { return eeNew( UITouchDragableWidget, () ); } -UITouchDragableWidget::UITouchDragableWidget() : - UIWidget(), +UITouchDragableWidget::UITouchDragableWidget( const std::string& tag ) : + UIWidget( tag ), mTouchDragDeceleration( 5.f, 5.f ) {} +UITouchDragableWidget::UITouchDragableWidget() : + UITouchDragableWidget( "touchdragablewidget" ) +{} + Uint32 UITouchDragableWidget::getType() const { return UI_TYPE_TOUCH_DRAGABLE_WIDGET; } @@ -136,7 +140,7 @@ bool UITouchDragableWidget::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds(); } -bool UITouchDragableWidget::setAttribute( const NodeAttribute& attribute ) { +bool UITouchDragableWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "touchdrag" == name ) { @@ -144,7 +148,7 @@ bool UITouchDragableWidget::setAttribute( const NodeAttribute& attribute ) { } else if ( "touchdragdeceleration" == name ) { setTouchDragDeceleration( Vector2f( attribute.asFloat(), attribute.asFloat() ) ); } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index d908395a5..859010f72 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -1,8 +1,10 @@ #include #include +#include #include -#include +#include #include +#include namespace EE { namespace UI { @@ -10,9 +12,11 @@ UIWidget * UIWidget::New() { return eeNew( UIWidget, () ); } -UIWidget::UIWidget() : +UIWidget::UIWidget( const std::string & tag ) : UINode(), + mTag( tag ), mTheme( NULL ), + mStyle( NULL ), mTooltip( NULL ), mMinControlSize(), mLayoutWeight(0), @@ -26,9 +30,18 @@ UIWidget::UIWidget() : mNodeFlags |= NODE_FLAG_WIDGET; updateAnchorsDistances(); + + if ( getSceneNode()->isUISceneNode() && static_cast( getSceneNode() )->hasStyleSheet() ) + mStyle = UIStyle::New( this ); +} + +UIWidget::UIWidget() : + UIWidget( "widget" ) +{ } UIWidget::~UIWidget() { + eeSAFE_DELETE( mStyle ); eeSAFE_DELETE( mTooltip ); } @@ -417,6 +430,77 @@ UIWidget * UIWidget::setPadding(const Rectf& padding) { return this; } +const std::string &UIWidget::getStyleSheetId() const { + return mId; +} + +const std::string& UIWidget::getStyleSheetTag() const { + return mTag; +} + +const std::vector &UIWidget::getStyleSheetClasses() const { + return mClasses; +} + +CSS::StyleSheetElement * UIWidget::getStyleSheetParentElement() { + return NULL != mParentCtrl && mParentCtrl->isWidget() ? reinterpret_cast( mParentCtrl ) : NULL; +} + +void UIWidget::addClass( const std::string& cls ) { + if ( !containsClass( cls ) ) + mClasses.push_back( cls ); +} + +void UIWidget::removeClass( const std::string& cls ) { + mClasses.erase( std::find( mClasses.begin(), mClasses.end(), cls ) ); +} + +bool UIWidget::containsClass( const std::string& cls ) { + return std::find( mClasses.begin(), mClasses.end(), cls ) != mClasses.end(); +} + +void UIWidget::setElementTag( const std::string& tag ) { + mTag = tag; +} + +const std::string& UIWidget::getElementTag() const { + return mTag; +} + +void UIWidget::pushState( const Uint32& State, bool emitEvent ) { + if ( NULL != mStyle ) + mStyle->pushState( State ); + + UINode::pushState( State, emitEvent ); +} + +void UIWidget::popState( const Uint32& State, bool emitEvent ) { + if ( NULL != mStyle ) + mStyle->popState( State ); + + UINode::popState( State, emitEvent ); +} + +void UIWidget::reloadStyle() { + if ( NULL == mStyle && getSceneNode()->isUISceneNode() && static_cast( getSceneNode() )->hasStyleSheet() ) + mStyle = UIStyle::New( this ); + + if ( NULL != mStyle ) { + mStyle->load(); + + if ( NULL != mChild ) { + Node * ChildLoop = mChild; + + while ( NULL != ChildLoop ) { + if ( ChildLoop->isWidget() ) + static_cast( ChildLoop )->reloadStyle(); + + ChildLoop = ChildLoop->getNextNode(); + } + } + } +} + void UIWidget::onPaddingChange() { invalidateDraw(); } @@ -433,11 +517,11 @@ void UIWidget::endAttributesTransaction() { } } -bool UIWidget::setAttribute( const std::string& name, const std::string& value ) { - return setAttribute( NodeAttribute( name, value ) ); +bool UIWidget::setAttribute( const std::string& name, const std::string& value, const Uint32& state ) { + return setAttribute( NodeAttribute( name, value ), state ); } -bool UIWidget::setAttribute(const NodeAttribute & attribute) { +bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { std::string name = attribute.getName(); bool attributeSet = true; @@ -460,32 +544,32 @@ bool UIWidget::setAttribute(const NodeAttribute & attribute) { const std::string attributeName( attribute.asString() ); if ( String::startsWith( attributeName, "#" ) ) { - setBackgroundColor( attribute.asColor() ); + setBackgroundColor( state, attribute.asColor() ); } else if ( NULL != ( res = DrawableSearcher::searchByName( attributeName ) ) ) { - setBackgroundDrawable( res, res->getDrawableType() == Drawable::SPRITE ); + setBackgroundDrawable( state, res, res->getDrawableType() == Drawable::SPRITE ); } } else if ( "backgroundcolor" == name ) { - setBackgroundColor( attribute.asColor() ); + setBackgroundColor( state, attribute.asColor() ); } else if ( "foreground" == name ) { Drawable * res = NULL; const std::string attributeName( attribute.asString() ); if ( String::startsWith( attributeName, "#" ) ) { - setForegroundColor( attribute.asColor() ); + setForegroundColor( state, attribute.asColor() ); } else if ( NULL != ( res = DrawableSearcher::searchByName( attributeName ) ) ) { - setForegroundDrawable( res, res->getDrawableType() == Drawable::SPRITE ); + setForegroundDrawable( state, res, res->getDrawableType() == Drawable::SPRITE ); } } else if ( "foregroundcolor" == name ) { - setForegroundColor( attribute.asColor() ); + setForegroundColor( state, attribute.asColor() ); } else if ( "foregroundcorners" == name ) { - setForegroundCorners( attribute.asUint() ); + setForegroundCorners( state, attribute.asUint() ); } else if ( "bordercolor" == name ) { - setBorderColor( attribute.asColor() ); + setBorderColor( state, attribute.asColor() ); } else if ( "borderwidth" == name ) { - setBorderWidth( attribute.asDpDimensionI("1") ); + setBorderWidth( state, attribute.asDpDimensionI("1") ); } else if ( "bordercorners" == name || "backgroundcorners" == name ) { - setBackgroundCorners( attribute.asUint() ); + setBackgroundCorners( state, attribute.asUint() ); } else if ( "visible" == name ) { setVisible( attribute.asBool() ); } else if ( "enabled" == name ) { diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 554b09e89..2d4a4406c 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -29,7 +29,7 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type ) : {} UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const UIWindowStyleConfig& windowStyleConfig ) : - UIWidget(), + UIWidget( "window" ), mFrameBuffer( NULL ), mStyleConfig( windowStyleConfig ), mWindowDecoration( NULL ), @@ -1412,7 +1412,7 @@ void UIWindow::resizeCursor() { } } -bool UIWindow::setAttribute( const NodeAttribute& attribute ) { +bool UIWindow::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); if ( "width" == name ) { @@ -1453,7 +1453,7 @@ bool UIWindow::setAttribute( const NodeAttribute& attribute ) { setWinFlags( winflags ); } } else { - return UIWidget::setAttribute( attribute ); + return UIWidget::setAttribute( attribute, state ); } return true; diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index efbf23947..e2053e4c5 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -12,7 +12,7 @@ UIWinMenu * UIWinMenu::New() { } UIWinMenu::UIWinMenu() : - UIWidget(), + UIWidget( "winmenu" ), mCurrentMenu( NULL ) { if ( !(mFlags & UI_ANCHOR_RIGHT) ) diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 6472e0694..39ec24e33 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -599,6 +599,12 @@ void EETest::createUI() { sceneNode->setTranslator( mTranslator ); + CSS::StyleSheetParser styleSheetParser; + + if ( styleSheetParser.loadFromFile( MyPath + "ui/css/style.css" ) ) { + sceneNode->setStyleSheet( styleSheetParser.getStyleSheet() ); + } + SceneManager::instance()->add( sceneNode ); eePRINTL("Node size: %d", sizeof(Node));