diff --git a/include/eepp/ui/css/stylesheetselectorrule.hpp b/include/eepp/ui/css/stylesheetselectorrule.hpp index 5bddc40c1..8674f94b6 100644 --- a/include/eepp/ui/css/stylesheetselectorrule.hpp +++ b/include/eepp/ui/css/stylesheetselectorrule.hpp @@ -26,6 +26,8 @@ class StyleSheetSelectorRule { }; enum SpecificityVal { + SpecificityImportant = UINT32_MAX, + SpecificityInline = UINT32_MAX - 1, SpecificityId = 1000000, SpecificityClass = 100000, SpecificityTag = 10000, diff --git a/include/eepp/ui/uiscenenode.hpp b/include/eepp/ui/uiscenenode.hpp index 5efa9dd1c..ac73484c4 100644 --- a/include/eepp/ui/uiscenenode.hpp +++ b/include/eepp/ui/uiscenenode.hpp @@ -44,8 +44,12 @@ class EE_API UISceneNode : public SceneNode { void setStyleSheet( const CSS::StyleSheet& styleSheet ); + void setStyleSheet( const std::string& inlineStyleSheet ); + void combineStyleSheet( const CSS::StyleSheet& styleSheet ); + void combineStyleSheet( const std::string& inlineStyleSheet ); + CSS::StyleSheet& getStyleSheet(); bool hasStyleSheet(); diff --git a/include/eepp/ui/uiscrollview.hpp b/include/eepp/ui/uiscrollview.hpp index 7767f2da8..e7fc5e044 100644 --- a/include/eepp/ui/uiscrollview.hpp +++ b/include/eepp/ui/uiscrollview.hpp @@ -38,7 +38,7 @@ class EE_API UIScrollView : public UITouchDragableWidget { UIScrollBar * getHorizontalScrollBar() const; - UINode * getContainer() const; + UIWidget * getContainer() const; virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); protected: @@ -47,7 +47,7 @@ class EE_API UIScrollView : public UITouchDragableWidget { UI_SCROLLBAR_MODE mHScrollMode; UIScrollBar * mVScroll; UIScrollBar * mHScroll; - UINode * mContainer; + UIWidget * mContainer; Node * mScrollView; Uint32 mSizeChangeCb; diff --git a/include/eepp/ui/uistyle.hpp b/include/eepp/ui/uistyle.hpp index 8848ce7ba..812387880 100644 --- a/include/eepp/ui/uistyle.hpp +++ b/include/eepp/ui/uistyle.hpp @@ -61,9 +61,9 @@ class EE_API UIStyle : public UIState { NodeAttribute getNodeAttribute(const std::string& attributeName ) const; - void addStyleSheetProperties( const CSS::StyleSheetProperties& properties ); + void setStyleSheetProperties( const CSS::StyleSheetProperties& properties ); - void addStyleSheetProperty( const CSS::StyleSheetProperty& property ); + void setStyleSheetProperty( const CSS::StyleSheetProperty& property ); bool hasTransition( const std::string& propertyName ); diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index 6ab3e9b97..9463425d6 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -92,7 +92,7 @@ class EE_API UIWidget : public UINode, public CSS::StyleSheetElement { void notifyLayoutAttrChangeParent(); - bool setAttribute( const std::string& name, const std::string& value, const Uint32& state = UIState::StateFlagNormal ); + void setStyleSheetProperty( const std::string& name, const std::string& value, const Uint32& specificity = UINT32_MAX - 1/*SpecificityInline*/ ); virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal ); diff --git a/src/eepp/scene/scenemanager.cpp b/src/eepp/scene/scenemanager.cpp index 87f821f3d..f43c3ddf7 100644 --- a/src/eepp/scene/scenemanager.cpp +++ b/src/eepp/scene/scenemanager.cpp @@ -22,8 +22,7 @@ SceneManager::~SceneManager() { mResources.clear(); } -void SceneManager::draw() -{ +void SceneManager::draw() { for ( auto it = mResources.begin() ; it != mResources.end(); it++ ) { SceneNode * sceneNode = (*it); @@ -43,8 +42,7 @@ void SceneManager::update() { update( mClock.getElapsed() ); } -bool SceneManager::isShootingDown() const -{ +bool SceneManager::isShootingDown() const { return mIsShootingDown; } diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index c54062c31..0a28b34c3 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -57,6 +57,9 @@ UINode::~UINode() { eeSAFE_DELETE( mBackgroundState ); eeSAFE_DELETE( mForegroundState ); eeSAFE_DELETE( mBorder ); + + if ( isDragging() ) + getEventDispatcher()->setNodeDragging( NULL ); } void UINode::worldToNodeTranslation( Vector2f& Pos ) const { diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index c2d3b50a8..b258db4db 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace EE { namespace UI { @@ -123,12 +124,26 @@ void UISceneNode::setStyleSheet( const CSS::StyleSheet& styleSheet ) { reloadStyle(); } -void UISceneNode::combineStyleSheet(const CSS::StyleSheet & styleSheet) { +void UISceneNode::setStyleSheet( const std::string& inlineStyleSheet ) { + CSS::StyleSheetParser parser; + + if ( parser.loadFromString( inlineStyleSheet ) ) + setStyleSheet( parser.getStyleSheet() ); +} + +void UISceneNode::combineStyleSheet( const CSS::StyleSheet& styleSheet ) { mStyleSheet.combineStyleSheet( styleSheet ); reloadStyle(); } +void UISceneNode::combineStyleSheet( const std::string& inlineStyleSheet ) { + CSS::StyleSheetParser parser; + + if ( parser.loadFromString( inlineStyleSheet ) ) + combineStyleSheet( parser.getStyleSheet() ); +} + CSS::StyleSheet& UISceneNode::getStyleSheet() { return mStyleSheet; } diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index ab8ac9bc5..15598d19d 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -15,7 +15,7 @@ UIScrollView::UIScrollView() : mHScrollMode( UI_SCROLLBAR_AUTO ), mVScroll( UIScrollBar::NewVertical() ), mHScroll( UIScrollBar::NewHorizontal() ), - mContainer( UINode::New() ), + mContainer( UIWidget::NewWithTag( "scrollview::container" ) ), mScrollView( NULL ), mSizeChangeCb( 0 ) { @@ -131,7 +131,7 @@ UIScrollBar * UIScrollView::getHorizontalScrollBar() const { return mHScroll; } -UINode * UIScrollView::getContainer() const { +UIWidget * UIScrollView::getContainer() const { return mContainer; } diff --git a/src/eepp/ui/uistyle.cpp b/src/eepp/ui/uistyle.cpp index ddc8cf2bb..6730ba65c 100644 --- a/src/eepp/ui/uistyle.cpp +++ b/src/eepp/ui/uistyle.cpp @@ -27,7 +27,7 @@ bool UIStyle::stateExists( const EE::Uint32& ) const { return true; } -void UIStyle::addStyleSheetProperty( const StyleSheetProperty& attribute ) { +void UIStyle::setStyleSheetProperty( const StyleSheetProperty& attribute ) { if ( attribute.getName() == "padding" ) { Rectf rect( NodeAttribute( attribute.getName(), attribute.getValue() ).asRectf() ); mElementStyle.setProperty( StyleSheetProperty( "paddingleft", String::toStr( rect.Left ), attribute.getSpecificity(), attribute.isVolatile() ) ); @@ -74,10 +74,10 @@ void UIStyle::load() { } } -void UIStyle::addStyleSheetProperties( const CSS::StyleSheetProperties& properties ) { +void UIStyle::setStyleSheetProperties( const CSS::StyleSheetProperties& properties ) { if ( !properties.empty() ) { for ( const auto& it : properties ) { - addStyleSheetProperty( it.second ); + setStyleSheetProperty( it.second ); } } } diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index b9f4c3c38..a35f9bb69 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -557,11 +557,12 @@ void UITextView::resetSelCache() { } #define SAVE_NORMAL_STATE_ATTR( ATTR_FORMATED ) \ - if ( state != UIState::StateFlagNormal ) { \ - CSS::StyleSheetProperty oldAttribute = mStyle->getStatelessStyleSheetProperty( attribute.getName() ); \ - if ( oldAttribute.isEmpty() && mStyle->getPreviousState() == UIState::StateFlagNormal ) \ - mStyle->addStyleSheetProperty( CSS::StyleSheetProperty( attribute.getName(), ATTR_FORMATED ) ); \ - } \ + if ( state != UIState::StateFlagNormal || ( state == UIState::StateFlagNormal && attribute.isVolatile() ) ) { \ + CSS::StyleSheetProperty oldAttribute = mStyle->getStatelessStyleSheetProperty( attribute.getName() ); \ + if ( oldAttribute.isEmpty() && mStyle->getPreviousState() == UIState::StateFlagNormal ) { \ + mStyle->setStyleSheetProperty( CSS::StyleSheetProperty( attribute.getName(), ATTR_FORMATED ) ); \ + } \ + } bool UITextView::setAttribute( const NodeAttribute& attribute, const Uint32& state ) { const std::string& name = attribute.getName(); diff --git a/src/eepp/ui/uitouchdragablewidget.cpp b/src/eepp/ui/uitouchdragablewidget.cpp index 57368d794..6a129dbfd 100644 --- a/src/eepp/ui/uitouchdragablewidget.cpp +++ b/src/eepp/ui/uitouchdragablewidget.cpp @@ -20,6 +20,8 @@ UITouchDragableWidget::UITouchDragableWidget() : {} UITouchDragableWidget::~UITouchDragableWidget() { + if ( isTouchDragging() ) + getEventDispatcher()->setNodeDragging( NULL ); } Uint32 UITouchDragableWidget::getType() const { diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index d399ce237..c2407e8b9 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -652,15 +652,16 @@ const Uint32& UIWidget::getStylePreviousState() const { return NULL != mStyle ? mStyle->getPreviousState() : mState; } -bool UIWidget::setAttribute( const std::string& name, const std::string& value, const Uint32& state ) { - return setAttribute( NodeAttribute( name, value, false ), state ); +void UIWidget::setStyleSheetProperty( const std::string& name, const std::string& value, const Uint32& specificity ) { + if ( mStyle != NULL ) + mStyle->setStyleSheetProperty( CSS::StyleSheetProperty( name, value, specificity ) ); } #define SAVE_NORMAL_STATE_ATTR( ATTR_FORMATED ) \ if ( state != UIState::StateFlagNormal || ( state == UIState::StateFlagNormal && attribute.isVolatile() ) ) { \ CSS::StyleSheetProperty oldAttribute = mStyle->getStatelessStyleSheetProperty( attribute.getName() ); \ if ( oldAttribute.isEmpty() && mStyle->getPreviousState() == UIState::StateFlagNormal ) { \ - mStyle->addStyleSheetProperty( CSS::StyleSheetProperty( attribute.getName(), ATTR_FORMATED ) ); \ + mStyle->setStyleSheetProperty( CSS::StyleSheetProperty( attribute.getName(), ATTR_FORMATED ) ); \ } \ } @@ -814,7 +815,7 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state rectColors.BottomLeft = rectColors.BottomRight = Color::fromString( params.at(2) ); } } else { - return setAttribute( "backgroundcolor", params.at(0) ); + return setAttribute( NodeAttribute( "backgroundcolor", params.at(0) ) ); } drawable->setRectColors( rectColors ); @@ -1232,7 +1233,7 @@ void UIWidget::loadFromXmlNode( const pugi::xml_node& node ) { beginAttributesTransaction(); for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { - setAttribute( ait->name(), ait->value() ); + setAttribute( NodeAttribute( ait->name(), ait->value() ) ); } endAttributesTransaction(); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 376aa7100..f853f4601 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -626,7 +626,7 @@ void EETest::createNewUI() { relLay = UIRelativeLayout::New(); relLay->setLayoutSizeRules( MATCH_PARENT, MATCH_PARENT ); - UINode * container = UINode::New(); + UIWidget * container = UIWidget::New(); container->setSize( relLay->getSize() - 32.f ); UIScrollView * scrollView = UIScrollView::New(); @@ -645,6 +645,7 @@ void EETest::createNewUI() { loader->setBackgroundColor( 0xCCCCCCCC ); UIRadioButton * ctrl = UIRadioButton::New(); + ctrl->setId( "happy_radio" ); ctrl->setLayoutSizeRules( FIXED, FIXED )->setPosition( 50, 100 )->setSize( 200, 32 )->setParent( container ); ctrl->setBackgroundColor( 0x33333333 ); ctrl->setBorderColor( 0x66666666 ); @@ -652,12 +653,20 @@ void EETest::createNewUI() { ctrl->setFontColor( Color::Black ); UICheckBox * cbox = UICheckBox::New(); + cbox->setId( "happy_check" ); cbox->setLayoutSizeRules( FIXED, FIXED )->setPosition( 50, 164 )->setSize( 200, 32 )->setParent( container ); cbox->setBackgroundColor( 0x33333333 ); cbox->setBorderColor( 0x66666666 ); cbox->setText( "Happy CheckBox :)" ); cbox->setFontColor( Color::Black ); + SceneManager::instance()->getUISceneNode()->combineStyleSheet( R"css( + #happy_check, + #happy_radio { + textColor: black; + } + )css"); + UIImage * gfx = UIImage::New(); gfx->setPosition( 50, 140 )->setSize( 16, 16 )->setParent( container ); gfx->setBackgroundColor( 0x33333333 ); @@ -1144,7 +1153,7 @@ void EETest::onQuitClick( const Event * event ) { } void EETest::showMenu() { - if ( Menu->show() ) { + if ( NULL != Menu && Menu->show() ) { Vector2f Pos = mWindow->getInput()->getMousePosf(); UIMenu::fixMenuPos( Pos , Menu ); Menu->setPosition( Vector2f( Pos.x / PixelDensity::getPixelDensity(), Pos.y / PixelDensity::getPixelDensity() ) );