From 3ba966eebd322c84a015efd78e5d65af2c95c02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 20 Dec 2018 03:11:34 -0300 Subject: [PATCH] UISkin is now a StateListDrawable --HG-- branch : dev-stateful-drawable --- include/eepp/graphics/statelistdrawable.hpp | 2 +- include/eepp/ui.hpp | 1 - include/eepp/ui/uiskin.hpp | 32 +++----- include/eepp/ui/uiskinsimple.hpp | 41 ---------- projects/linux/ee.files | 4 - src/eepp/graphics/statelistdrawable.cpp | 10 ++- src/eepp/ui/uinode.cpp | 19 +++-- src/eepp/ui/uiprogressbar.cpp | 3 +- src/eepp/ui/uiskin.cpp | 62 ++++++++++++--- src/eepp/ui/uiskinsimple.cpp | 83 --------------------- src/eepp/ui/uiskinstate.cpp | 9 ++- src/eepp/ui/uitheme.cpp | 60 ++++++++++----- src/eepp/ui/uiwinmenu.cpp | 2 +- 13 files changed, 133 insertions(+), 195 deletions(-) delete mode 100644 include/eepp/ui/uiskinsimple.hpp delete mode 100644 src/eepp/ui/uiskinsimple.cpp diff --git a/include/eepp/graphics/statelistdrawable.hpp b/include/eepp/graphics/statelistdrawable.hpp index 12a1547ad..7523f8e79 100644 --- a/include/eepp/graphics/statelistdrawable.hpp +++ b/include/eepp/graphics/statelistdrawable.hpp @@ -6,7 +6,7 @@ namespace EE { namespace Graphics { -class EE_API StateListDrawable : StatefulDrawable { +class EE_API StateListDrawable : public StatefulDrawable { public: static StateListDrawable * New(); diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index f12e88731..bdda0e7d6 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/include/eepp/ui/uiskin.hpp b/include/eepp/ui/uiskin.hpp index f68380d60..5d154c211 100644 --- a/include/eepp/ui/uiskin.hpp +++ b/include/eepp/ui/uiskin.hpp @@ -3,38 +3,30 @@ #include #include +#include namespace EE { namespace UI { class UITheme; -class EE_API UISkin { +class EE_API UISkin : public StateListDrawable { public: - enum UISkinType { - SkinSimple, - SkinTypeCount - }; - static const char * getSkinStateName( const Uint32& State ); + static int getStateNumber(const std::string & State); + static bool isStateName( const std::string& State ); - UISkin( const std::string& name, const Uint32& Type ); + static UISkin * New( const std::string& name ); + + explicit UISkin( const std::string& name ); virtual ~UISkin(); - virtual void draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha, const Uint32& State ) = 0; - - virtual void setSkin( const Uint32& State ) = 0; - - virtual Sizef getSize( const Uint32& state ) = 0; + virtual Sizef getSize( const Uint32& state ); virtual Sizef getSize(); - virtual bool stateExists( const Uint32& State ) = 0; - - virtual void setSkins(); - const std::string& getName() const; void setName( const std::string& name ); @@ -45,18 +37,16 @@ class EE_API UISkin { void setTheme( UITheme * theme ); - virtual UISkin * clone() = 0; + virtual UISkin * clone(); - const Uint32& getType() const; + virtual UISkin * clone( const std::string& NewName ); - virtual Rectf getBorderSize( const Uint32 & state ) = 0; + virtual Rectf getBorderSize( const Uint32 & state ); virtual Rectf getBorderSize(); protected: - friend class UIControl; friend class UISkinState; - Uint32 mType; std::string mName; Uint32 mNameHash; UITheme * mTheme; diff --git a/include/eepp/ui/uiskinsimple.hpp b/include/eepp/ui/uiskinsimple.hpp deleted file mode 100644 index 429e860c0..000000000 --- a/include/eepp/ui/uiskinsimple.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef EE_UICUISKINSIMPLE_HPP -#define EE_UICUISKINSIMPLE_HPP - -#include -#include - -namespace EE { namespace Graphics { -class Drawable; -}} - -namespace EE { namespace UI { - -class EE_API UISkinSimple : public UISkin { - public: - static UISkinSimple * New( const std::string& name ); - - explicit UISkinSimple( const std::string& name ); - - virtual ~UISkinSimple(); - - virtual void draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha, const Uint32& State ); - - void setSkin( const Uint32& State ); - - bool stateExists( const Uint32& state ); - - UISkinSimple * clone( const std::string& NewName ); - - virtual UISkin * clone(); - - Sizef getSize( const Uint32& state ); - - Rectf getBorderSize( const Uint32 & state ); - protected: - Drawable * mDrawable[ UISkinState::StateCount ]; - Color mTempColor; -}; - -}} - -#endif diff --git a/projects/linux/ee.files b/projects/linux/ee.files index fcf624626..b5ddbfc15 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -321,7 +321,6 @@ ../../include/eepp/ui/uiscrollview.hpp ../../include/eepp/ui/uiselectbutton.hpp ../../include/eepp/ui/uiskin.hpp -../../include/eepp/ui/uiskinsimple.hpp ../../include/eepp/ui/uiskinstate.hpp ../../include/eepp/ui/uislider.hpp ../../include/eepp/ui/uisliderbutton.hpp @@ -719,7 +718,6 @@ ../../src/eepp/ui/uiscrollview.cpp ../../src/eepp/ui/uiselectbutton.cpp ../../src/eepp/ui/uiskin.cpp -../../src/eepp/ui/uiskinsimple.cpp ../../src/eepp/ui/uiskinstate.cpp ../../src/eepp/ui/uislider.cpp ../../src/eepp/ui/uisliderbutton.cpp @@ -1217,7 +1215,6 @@ ../../include/eepp/ui/uisliderbutton.hpp ../../include/eepp/ui/uislider.hpp ../../include/eepp/ui/uiskinstate.hpp -../../include/eepp/ui/uiskinsimple.hpp ../../include/eepp/ui/uiskin.hpp ../../include/eepp/ui/uiselectbutton.hpp ../../include/eepp/ui/uiscrollbar.hpp @@ -1259,7 +1256,6 @@ ../../src/eepp/ui/uisliderbutton.cpp ../../src/eepp/ui/uislider.cpp ../../src/eepp/ui/uiskinstate.cpp -../../src/eepp/ui/uiskinsimple.cpp ../../src/eepp/ui/uiskin.cpp ../../src/eepp/ui/uiselectbutton.cpp ../../src/eepp/ui/uiscrollbar.cpp diff --git a/src/eepp/graphics/statelistdrawable.cpp b/src/eepp/graphics/statelistdrawable.cpp index 7b7494c44..8244279e5 100644 --- a/src/eepp/graphics/statelistdrawable.cpp +++ b/src/eepp/graphics/statelistdrawable.cpp @@ -43,8 +43,10 @@ void StateListDrawable::draw( const Vector2f& position ) { } void StateListDrawable::draw( const Vector2f & position, const Sizef & size ) { - if ( NULL != mCurrentDrawable ) + if ( NULL != mCurrentDrawable ) { + mCurrentDrawable->setAlpha( getAlpha() ); mCurrentDrawable->draw( position, size ); + } } bool StateListDrawable::isStateful() { @@ -52,7 +54,7 @@ bool StateListDrawable::isStateful() { } StatefulDrawable * StateListDrawable::setState( Uint32 state ) { - if ( state != mCurrentState ) { + if ( state != mCurrentState || mCurrentDrawable == NULL ) { mCurrentState = state; auto it = mDrawables.find( state ); @@ -73,6 +75,10 @@ const Uint32& StateListDrawable::getState() const { StateListDrawable * StateListDrawable::setStateDrawable(Uint32 state, Drawable * drawable) { mDrawables[ state ] = drawable; + + if ( state == mCurrentState ) + setState( state ); + return this; } diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 96f0f1d6d..0c4451767 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -252,7 +252,7 @@ void UINode::drawBox() { void UINode::drawSkin() { if ( NULL != mSkinState ) { if ( mFlags & UI_SKIN_KEEP_SIZE_ON_DRAW ) { - Sizef rSize = PixelDensity::dpToPx( mSkinState->getSkin()->getSize( mSkinState->getCurrentState() ) ); + Sizef rSize = PixelDensity::dpToPx( getSkinSize( getSkin(), mSkinState->getCurrentState() ) ); Sizef diff = ( mSize - rSize ) * 0.5f; mSkinState->draw( mScreenPosi.x + eefloor(diff.x), mScreenPosi.y + eefloor(diff.y), eefloor(rSize.getWidth()), eefloor(rSize.getHeight()), (Uint32)mAlpha ); @@ -595,7 +595,7 @@ UINode * UINode::setSkin( UISkin * skin ) { if ( NULL != mSkinState && mSkinState->getSkin() == skin ) return this; - Uint32 InitialState = 1 << UISkinState::StateNormal; + Uint32 InitialState = 1; if ( NULL != mSkinState ) { InitialState = mSkinState->getState(); @@ -634,8 +634,11 @@ void UINode::setSkinState(const Uint32& State , bool emitEvent) { if ( NULL != mSkinState ) { mSkinState->setState( State ); - if ( emitEvent ) + if ( emitEvent ) { onStateChange(); + } else { + invalidateDraw(); + } } } @@ -643,8 +646,11 @@ void UINode::unsetSkinState(const Uint32& State , bool emitEvent) { if ( NULL != mSkinState ) { mSkinState->unsetState( State ); - if ( emitEvent ) + if ( emitEvent ) { onStateChange(); + } else { + invalidateDraw(); + } } } @@ -687,7 +693,7 @@ Rectf UINode::makePadding( bool PadLeft, bool PadRight, bool PadTop, bool PadBot if ( mFlags & UI_AUTO_PADDING || SkipFlags ) { if ( NULL != mSkinState && NULL != mSkinState->getSkin() ) { - Rectf rPadding = mSkinState->getSkin()->getBorderSize( UISkinState::StateNormal ); + Rectf rPadding = mSkinState->getSkin()->getBorderSize( 1 << UISkinState::StateNormal ); if ( PadLeft ) { tPadding.Left = rPadding.Left; @@ -712,7 +718,7 @@ Rectf UINode::makePadding( bool PadLeft, bool PadRight, bool PadTop, bool PadBot Sizef UINode::getSkinSize( UISkin * Skin, const Uint32& State ) { if ( NULL != Skin ) { - return Skin->getSize( State ); + return Skin->getSize( 1 << State ); } return Sizef::Zero; @@ -800,6 +806,7 @@ Uint32 UINode::onMouseEnter(const Vector2i & position, const Uint32 flags) { Uint32 UINode::onMouseExit(const Vector2i & position, const Uint32 flags) { unsetSkinState( UISkinState::StateHover ); + unsetSkinState( UISkinState::StatePressed ); return Node::onMouseExit( position, flags ); } diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index b32d70823..44579c4fd 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -70,7 +70,8 @@ void UIProgressBar::draw() { for ( int y = -1; y < numTiles.y; y++ ) { for ( int x = -1; x < numTiles.x; x++ ) { - mFillerSkin->draw( (Int32)mOffset.x + mScreenPosi.x + fillerPadding.Left + x * rSize.getWidth(), mOffset.y + mScreenPosi.y + fillerPadding.Top + y * rSize.getHeight(), rSize.getWidth(), rSize.getHeight(), 255, UISkinState::StateNormal ); + mFillerSkin->setState( 1 << UISkinState::StateNormal ); + mFillerSkin->draw( Vector2f( (Int32)mOffset.x + mScreenPosi.x + fillerPadding.Left + x * rSize.getWidth(), mOffset.y + mScreenPosi.y + fillerPadding.Top + y * rSize.getHeight() ), Sizef( rSize.getWidth(), rSize.getHeight() ) ); } } diff --git a/src/eepp/ui/uiskin.cpp b/src/eepp/ui/uiskin.cpp index 830a5b109..ddf7e2ccb 100644 --- a/src/eepp/ui/uiskin.cpp +++ b/src/eepp/ui/uiskin.cpp @@ -1,8 +1,13 @@ #include #include +#include namespace EE { namespace UI { +UISkin * UISkin::New( const std::string& name ) { + return eeNew( UISkin, ( name ) ); +} + const char * UISkinStatesNames[] = { "normal", "focus", @@ -16,6 +21,16 @@ const char * UISkin::getSkinStateName( const Uint32& State ) { return UISkinStatesNames[ State ]; } +int UISkin::getStateNumber( const std::string& State ) { + for ( int i = 0; i < UISkinState::StateCount; i++ ) { + if ( State == UISkinStatesNames[i] ) { + return i; + } + } + + return -1; +} + bool UISkin::isStateName( const std::string& State ) { for ( int i = 0; i < UISkinState::StateCount; i++ ) { if ( State == UISkinStatesNames[i] ) { @@ -26,8 +41,7 @@ bool UISkin::isStateName( const std::string& State ) { return false; } -UISkin::UISkin( const std::string& name, const Uint32& Type ) : - mType( Type ), +UISkin::UISkin( const std::string& name ) : mName( name ), mNameHash( String::hash( mName ) ), mTheme(NULL) @@ -38,7 +52,7 @@ UISkin::~UISkin() { } Sizef UISkin::getSize() { - return getSize( UISkinState::StateNormal ); + return getSize( 1 << UISkinState::StateNormal ); } const std::string& UISkin::getName() const { @@ -54,11 +68,6 @@ const Uint32& UISkin::getId() const { return mNameHash; } -void UISkin::setSkins() { - for ( Int32 i = 0; i < UISkinState::StateCount; i++ ) - setSkin( i ); -} - UITheme * UISkin::getTheme() const { return mTheme; } @@ -67,12 +76,41 @@ void UISkin::setTheme( UITheme * theme ) { mTheme = theme; } -const Uint32& UISkin::getType() const { - return mType; +Rectf UISkin::getBorderSize() { + return getBorderSize( 1 << UISkinState::StateNormal ); } -Rectf UISkin::getBorderSize() { - return getBorderSize( UISkinState::StateNormal ); +UISkin * UISkin::clone( const std::string& NewName ) { + UISkin * SkinS = UISkin::New( NewName ); + + + return SkinS; +} + +UISkin * UISkin::clone() { + return clone( mName ); +} + +Sizef UISkin::getSize( const Uint32 & state ) { + if ( NULL != mDrawables[ state ] ) { + return mDrawables[ state ]->getSize(); + } + + return Sizef(); +} + +Rectf UISkin::getBorderSize( const Uint32 & state ) { + if ( NULL != mDrawables[ state ] && mDrawables[ state ]->getDrawableType() == EE::Graphics::Drawable::Type::NINEPATCH ) { + NinePatch * ninePatch( static_cast( mDrawables[ state ] ) ); + TextureRegion * stl( ninePatch->getTextureRegion( NinePatch::Left ) ); + TextureRegion * str( ninePatch->getTextureRegion( NinePatch::Right ) ); + TextureRegion * stt( ninePatch->getTextureRegion( NinePatch::Up ) ); + TextureRegion * stb( ninePatch->getTextureRegion( NinePatch::Down ) ); + Rectf size( stl->getPxSize().getWidth(), stt->getPxSize().getHeight(), str->getPxSize().getWidth(), stb->getPxSize().getHeight() ); + return size; + } + + return Rectf(); } }} diff --git a/src/eepp/ui/uiskinsimple.cpp b/src/eepp/ui/uiskinsimple.cpp deleted file mode 100644 index 13f8a2579..000000000 --- a/src/eepp/ui/uiskinsimple.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -#include -#include - -namespace EE { namespace UI { - -UISkinSimple * UISkinSimple::New( const std::string& name ) { - return eeNew( UISkinSimple, ( name ) ); -} - -UISkinSimple::UISkinSimple(const std::string& name ) : - UISkin( name, SkinSimple ) -{ - for ( Int32 i = 0; i < UISkinState::StateCount; i++ ) - mDrawable[ i ] = NULL; - - setSkins(); -} - -UISkinSimple::~UISkinSimple() { -} - -void UISkinSimple::draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha, const Uint32& State ) { - if ( 0 == Alpha ) - return; - - Drawable * tDrawable = mDrawable[ State ]; - - if ( NULL != tDrawable ) { - tDrawable->setAlpha( Alpha ); - tDrawable->draw( Vector2f( X, Y ), Sizef( Width, Height ) ); - tDrawable->clearColor(); - } -} - -void UISkinSimple::setSkin( const Uint32& State ) { - eeASSERT ( State < UISkinState::StateCount ); - - std::string Name( mName + "_" + UISkin::getSkinStateName( State ) ); - - mDrawable[ State ] = DrawableSearcher::searchByName( Name ); -} - -bool UISkinSimple::stateExists( const Uint32 & state ) { - return NULL != mDrawable[ state ]; -} - -UISkinSimple * UISkinSimple::clone( const std::string& NewName ) { - UISkinSimple * SkinS = UISkinSimple::New( NewName ); - - memcpy( &SkinS->mDrawable[0], &mDrawable[0], UISkinState::StateCount * sizeof(Drawable*) ); - - return SkinS; -} - -UISkin * UISkinSimple::clone() { - return clone( mName ); -} - -Sizef UISkinSimple::getSize( const Uint32 & state ) { - if ( NULL != mDrawable[ state ] ) { - return mDrawable[ state ]->getSize(); - } - - return Sizef(); -} - -Rectf UISkinSimple::getBorderSize( const Uint32 & state ) { - if ( NULL != mDrawable[ state ] && mDrawable[ state ]->getDrawableType() == Drawable::NINEPATCH ) { - NinePatch * ninePatch( static_cast( mDrawable[ state ] ) ); - TextureRegion * stl( ninePatch->getTextureRegion( NinePatch::Left ) ); - TextureRegion * str( ninePatch->getTextureRegion( NinePatch::Right ) ); - TextureRegion * stt( ninePatch->getTextureRegion( NinePatch::Up ) ); - TextureRegion * stb( ninePatch->getTextureRegion( NinePatch::Down ) ); - Rectf size( stl->getPxSize().getWidth(), stt->getPxSize().getHeight(), str->getPxSize().getWidth(), stb->getPxSize().getHeight() ); - return size; - } - - return Rectf(); -} - -}} diff --git a/src/eepp/ui/uiskinstate.cpp b/src/eepp/ui/uiskinstate.cpp index 42030a192..1d316a4a0 100644 --- a/src/eepp/ui/uiskinstate.cpp +++ b/src/eepp/ui/uiskinstate.cpp @@ -19,8 +19,11 @@ UISkinState::~UISkinState() { } void UISkinState::draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha ) { - if ( NULL != mSkin ) - mSkin->draw( X, Y, Width, Height, Alpha, mCurrentState ); + if ( NULL != mSkin ) { + mSkin->setState( 1 << mCurrentState ); + mSkin->setAlpha( Alpha ); + mSkin->draw( Vector2f( X, Y ), Sizef( Width, Height ) ); + } } const Uint32& UISkinState::getState() const { @@ -48,7 +51,7 @@ UISkin * UISkinState::getSkin() const { } bool UISkinState::stateExists( const Uint32& State ) { - return mSkin->stateExists( State ); + return mSkin->hasDrawableState( 1 << State ); } Uint32 UISkinState::getCurrentState() const { diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index f24be46d4..2e1864ff8 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -9,11 +8,12 @@ #include #include #include +#include #include namespace EE { namespace UI { -static std::string elemNameFromSkinSimple( const std::vector& nameParts ) { +static std::string elemNameFromSkin( const std::vector& nameParts ) { std::string str; int lPart = (int)nameParts.size() - 1; @@ -47,7 +47,7 @@ UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtla std::list& resources = TextureAtlas->getResources(); std::list::iterator it; std::string sAbbr( tTheme->getAbbr() + "_" ); - std::vector elemFound; + std::map skins; for ( it = resources.begin(); it != resources.end(); ++it ) { TextureRegion* TextureRegion = *it; @@ -80,9 +80,17 @@ UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtla String::fromString( b, srcRect[3] ); } - elemFound.push_back( elemNameFromSkinSimple( nameParts ) ); + std::string skinName( elemNameFromSkin( nameParts ) ); - NinePatchManager::instance()->add( NinePatch::New( TextureRegion, l, t, r, b, realName ) ); + Drawable * drawable = NinePatchManager::instance()->add( NinePatch::New( TextureRegion, l, t, r, b, realName ) ); + + if ( skins.find( skinName ) == skins.end() ) + skins[ skinName ] = tTheme->add( UISkin::New( skinName ) ); + + int stateNum = UISkin::getStateNumber( nameParts[ nameParts.size() - 1 ] ); + + if ( -1 != stateNum ) + skins[ skinName ]->setStateDrawable( 1 << stateNum, drawable ); } else { std::vector nameParts = String::split( name, '_' ); @@ -90,17 +98,20 @@ UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtla int lPart = nameParts.size() - 1; if ( UISkin::isStateName( nameParts[ lPart ] ) ) { - elemFound.push_back( elemNameFromSkinSimple( nameParts ) ); + std::string skinName( elemNameFromSkin( nameParts ) ); + int stateNum = UISkin::getStateNumber( nameParts[ lPart ] ); + + if ( skins.find( skinName ) == skins.end() ) + skins[ skinName ] = tTheme->add( UISkin::New( skinName ) ); + + if ( -1 != stateNum ) + skins[ skinName ]->setStateDrawable( 1 << stateNum, TextureRegion ); } } } } } - for ( auto it = elemFound.begin(); it != elemFound.end(); ++it ) { - tTheme->add( UISkinSimple::New( *it ) ); - } - eePRINTL( "UI Theme Loaded in: %4.3f ms ( from TextureAtlas )", TE.getElapsed().asMilliseconds() ); return tTheme; @@ -124,7 +135,7 @@ UITheme * UITheme::loadFromDirectroy( UITheme * tTheme, const std::string& Path std::vector::iterator it; std::string sAbbr( tTheme->getAbbr() + "_" ); std::string sAbbrIcon( tTheme->getAbbr() + "_icon_" ); - std::vector elemFound; + std::map skins; for ( it = resources.begin(); it != resources.end(); ++it ) { std::string fpath( RPath + (*it) ); @@ -159,9 +170,17 @@ UITheme * UITheme::loadFromDirectroy( UITheme * tTheme, const std::string& Path String::fromString( b, srcRect[3] ); } - elemFound.push_back( elemNameFromSkinSimple( nameParts ) ); + std::string skinName( elemNameFromSkin( nameParts ) ); - NinePatchManager::instance()->add( NinePatch::New( TextureFactory::instance()->loadFromFile( fpath ), l, t, r, b, pixelDensity, realName ) ); + Drawable * drawable = NinePatchManager::instance()->add( NinePatch::New( TextureFactory::instance()->loadFromFile( fpath ), l, t, r, b, pixelDensity, realName ) ); + + if ( skins.find( skinName ) == skins.end() ) + skins[ skinName ] = tTheme->add( UISkin::New( skinName ) ); + + int stateNum = UISkin::getStateNumber( nameParts[ nameParts.size() - 1 ] ); + + if ( -1 != stateNum ) + skins[ skinName ]->setStateDrawable( 1 << stateNum, drawable ); } else { std::vector nameParts = String::split( name, '_' ); @@ -169,9 +188,16 @@ UITheme * UITheme::loadFromDirectroy( UITheme * tTheme, const std::string& Path int lPart = nameParts.size() - 1; if ( UISkin::isStateName( nameParts[ lPart ] ) ) { - elemFound.push_back( elemNameFromSkinSimple( nameParts ) ); + TextureRegion * textureRegion = tSG->add( TextureRegion::New( TextureFactory::instance()->loadFromFile( fpath ), name ) ); - tSG->add( TextureRegion::New( TextureFactory::instance()->loadFromFile( fpath ), name ) ); + std::string skinName( elemNameFromSkin( nameParts ) ); + int stateNum = UISkin::getStateNumber( nameParts[ lPart ] ); + + if ( skins.find( skinName ) == skins.end() ) + skins[ skinName ] = tTheme->add( UISkin::New( skinName ) ); + + if ( -1 != stateNum ) + skins[ skinName ]->setStateDrawable( 1 << stateNum, textureRegion ); } } } @@ -184,10 +210,6 @@ UITheme * UITheme::loadFromDirectroy( UITheme * tTheme, const std::string& Path else eeSAFE_DELETE( tSG ); - for ( auto it = elemFound.begin(); it != elemFound.end(); ++it ) { - tTheme->add( UISkinSimple::New( *it ) ); - } - eePRINTL( "UI Theme Loaded in: %4.3f ms ( from path )", TE.getElapsed().asMilliseconds() ); return tTheme; diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index e65b9c1bd..3aec41df8 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -150,7 +150,7 @@ void UIWinMenu::refreshButtons() { skin = tbut->getSkin(); if ( NULL != skin ) { - th = skin->getSize( UISkinState::StateSelected ).getHeight(); + th = skin->getSize( 1 << UISkinState::StateSelected ).getHeight(); switch ( VAlignGet( getFlags() ) ) { case UI_VALIGN_CENTER: