From f5f6ed577c8c8a2abf70e97692b1e6f2adab278c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 19 Dec 2018 01:45:02 -0300 Subject: [PATCH] Reimplementing how skins and skins states are managed. --HG-- branch : dev-stateful-drawable --- include/eepp/graphics/drawable.hpp | 4 + include/eepp/graphics/statefuldrawable.hpp | 4 +- include/eepp/graphics/statelistdrawable.hpp | 12 +-- include/eepp/ui/uinode.hpp | 8 +- include/eepp/ui/uiskin.hpp | 14 ---- include/eepp/ui/uiskincomplex.hpp | 4 +- include/eepp/ui/uiskinsimple.hpp | 4 +- include/eepp/ui/uiskinstate.hpp | 29 +++---- src/eepp/graphics/drawable.cpp | 7 ++ src/eepp/graphics/statelistdrawable.cpp | 8 +- src/eepp/ui/uilistboxitem.cpp | 8 +- src/eepp/ui/uimenu.cpp | 4 +- src/eepp/ui/uimenucheckbox.cpp | 12 +-- src/eepp/ui/uimenuitem.cpp | 4 +- src/eepp/ui/uinode.cpp | 30 ++++--- src/eepp/ui/uipopupmenu.cpp | 2 +- src/eepp/ui/uipushbutton.cpp | 6 +- src/eepp/ui/uiselectbutton.cpp | 16 ++-- src/eepp/ui/uiskin.cpp | 26 ------ src/eepp/ui/uiskincomplex.cpp | 43 +--------- src/eepp/ui/uiskinsimple.cpp | 22 +----- src/eepp/ui/uiskinstate.cpp | 88 +++++++-------------- src/eepp/ui/uitab.cpp | 6 +- src/eepp/ui/uitablecell.cpp | 6 +- 24 files changed, 123 insertions(+), 244 deletions(-) diff --git a/include/eepp/graphics/drawable.hpp b/include/eepp/graphics/drawable.hpp index 16b559df7..8dc50f8f5 100644 --- a/include/eepp/graphics/drawable.hpp +++ b/include/eepp/graphics/drawable.hpp @@ -10,6 +10,8 @@ using namespace EE::System; namespace EE { namespace Graphics { +class StatefulDrawable; + class EE_API Drawable { public: enum Type { @@ -60,6 +62,8 @@ class EE_API Drawable { const Vector2f& getPosition() const; void setPosition( const Vector2f& position ); + + StatefulDrawable * asStatefulDrawable(); protected: Type mDrawableType; Color mColor; diff --git a/include/eepp/graphics/statefuldrawable.hpp b/include/eepp/graphics/statefuldrawable.hpp index 92cf56beb..77e9431eb 100644 --- a/include/eepp/graphics/statefuldrawable.hpp +++ b/include/eepp/graphics/statefuldrawable.hpp @@ -9,9 +9,9 @@ class EE_API StatefulDrawable : public Drawable { public: StatefulDrawable( Type drawableType ) : Drawable( drawableType ) {} - virtual StatefulDrawable * setState( int state ) = 0; + virtual StatefulDrawable * setState( Uint32 state ) = 0; - virtual const int& getState() const = 0; + virtual const Uint32& getState() const = 0; }; }} diff --git a/include/eepp/graphics/statelistdrawable.hpp b/include/eepp/graphics/statelistdrawable.hpp index 7ea69ac72..2bfe59dfc 100644 --- a/include/eepp/graphics/statelistdrawable.hpp +++ b/include/eepp/graphics/statelistdrawable.hpp @@ -22,13 +22,13 @@ class EE_API StateListDrawable : StatefulDrawable { virtual bool isStateful(); - virtual StatefulDrawable * setState( int state ); + virtual StatefulDrawable * setState( Uint32 state ); - virtual const int& getState() const; + virtual const Uint32& getState() const; - virtual StateListDrawable * setStateDrawable( int state, Drawable * drawable ); + virtual StateListDrawable * setStateDrawable( Uint32 state, Drawable * drawable ); - bool hasDrawableState( int state ); + bool hasDrawableState( Uint32 state ); void setIsDrawableOwner( const bool& isOwner ); @@ -37,9 +37,9 @@ class EE_API StateListDrawable : StatefulDrawable { void clearDrawables(); protected: bool mDrawableOwner; - int mCurrentState; + Uint32 mCurrentState; Drawable * mCurrentDrawable; - std::map mDrawables; + std::map mDrawables; }; }} diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index 0a60862e4..c06c56348 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -140,7 +140,9 @@ class EE_API UINode : public Node { void removeSkin(); - void setSkinState( const Uint32& State ); + void setSkinState( const Uint32& State, bool emitEvent = true ); + + void unsetSkinState( const Uint32& State, bool emitEvent = true ); Sizef getSkinSize(); @@ -242,14 +244,14 @@ class EE_API UINode : public Node { virtual Uint32 onFocus(); + virtual Uint32 onFocusLoss(); + void checkClose(); virtual void internalDraw(); virtual void onWidgetFocusLoss(); - void setPrevSkinState(); - void writeFlag( const Uint32& Flag, const Uint32& Val ); Rectf makePadding( bool PadLeft = true, bool PadRight = true, bool PadTop = true, bool PadBottom = true, bool SkipFlags = false ); diff --git a/include/eepp/ui/uiskin.hpp b/include/eepp/ui/uiskin.hpp index 46bfd5d5a..67ce39807 100644 --- a/include/eepp/ui/uiskin.hpp +++ b/include/eepp/ui/uiskin.hpp @@ -34,10 +34,6 @@ class EE_API UISkin { virtual bool stateExists( const Uint32& State ) = 0; - virtual void setColor( const Uint32& State, const Color& Color ); - - virtual const Color& getColor( const Uint32& State ) const; - virtual void setSkins(); const std::string& getName() const; @@ -64,17 +60,7 @@ class EE_API UISkin { Uint32 mType; std::string mName; Uint32 mNameHash; - Uint32 mColorDefault; - Color mColor[ UISkinState::StateCount ]; UITheme * mTheme; - - void stateBack( const Uint32& State ); - - void setPrevState(); - - bool getColorDefault( const Uint32& State ); - - virtual void stateNormalToState( const Uint32& State ) = 0; }; }} diff --git a/include/eepp/ui/uiskincomplex.hpp b/include/eepp/ui/uiskincomplex.hpp index ee3117030..014cd86af 100644 --- a/include/eepp/ui/uiskincomplex.hpp +++ b/include/eepp/ui/uiskincomplex.hpp @@ -43,7 +43,7 @@ class EE_API UISkinComplex : public UISkin { Sizef getSideSize( const Uint32& State, const Uint32& Side ); - UISkinComplex * clone( const std::string& NewName, const bool& CopyColorsState = true ); + UISkinComplex * clone( const std::string& NewNamee ); virtual UISkin * clone(); @@ -57,8 +57,6 @@ class EE_API UISkinComplex : public UISkin { Rectf mBorderSize[ UISkinState::StateCount ]; void cacheSize(); - - void stateNormalToState( const Uint32& State ); }; }} diff --git a/include/eepp/ui/uiskinsimple.hpp b/include/eepp/ui/uiskinsimple.hpp index f4293ec6e..146735a6a 100644 --- a/include/eepp/ui/uiskinsimple.hpp +++ b/include/eepp/ui/uiskinsimple.hpp @@ -24,7 +24,7 @@ class EE_API UISkinSimple : public UISkin { bool stateExists( const Uint32& state ); - UISkinSimple * clone( const std::string& NewName, const bool& CopyColorsState = true ); + UISkinSimple * clone( const std::string& NewName ); virtual UISkin * clone(); @@ -34,8 +34,6 @@ class EE_API UISkinSimple : public UISkin { protected: Drawable * mDrawable[ UISkinState::StateCount ]; Color mTempColor; - - void stateNormalToState( const Uint32& State ); }; }} diff --git a/include/eepp/ui/uiskinstate.hpp b/include/eepp/ui/uiskinstate.hpp index eb0efe039..227520af8 100644 --- a/include/eepp/ui/uiskinstate.hpp +++ b/include/eepp/ui/uiskinstate.hpp @@ -10,13 +10,12 @@ class UISkin; class EE_API UISkinState { public: enum UISkinStates { - StateNormal = 0, - StateFocus, - StateSelected, - StateMouseEnter, - StateMouseExit, - StateMouseDown, - StateCount + StateNormal = 0, + StateFocus = 1, + StateSelected = 2, + StateHover = 3, + StatePressed = 4, + StateCount = 5 }; static UISkinState * New( UISkin * skin ); @@ -29,27 +28,23 @@ class EE_API UISkinState { void setState( const Uint32& State ); + void unsetState( const Uint32& State ); + UISkin * getSkin() const; void draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha ); bool stateExists( const Uint32& State ); - const Uint32& getPrevState() const; + Uint32 getCurrentState() const; protected: friend class UINode; UISkin * mSkin; - Uint32 mCurState; - Uint32 mLastState; + Uint32 mState; + Uint32 mCurrentState; - void stateBack( const Uint32& State ); - - void setPrevState(); - - void setStateTypeSimple( const Uint32& State ); - - void setStateTypeDefault( const Uint32& State ); + void updateState(); }; }} diff --git a/src/eepp/graphics/drawable.cpp b/src/eepp/graphics/drawable.cpp index d811dfb1d..711a9b67e 100644 --- a/src/eepp/graphics/drawable.cpp +++ b/src/eepp/graphics/drawable.cpp @@ -1,4 +1,6 @@ #include +#include +#include namespace EE { namespace Graphics { @@ -87,6 +89,11 @@ void Drawable::setPosition( const Vector2f& position ) { } } +StatefulDrawable * Drawable::asStatefulDrawable() { + eeASSERT( isStateful() ); + return static_cast( this ); +} + void Drawable::onAlphaChange() { } diff --git a/src/eepp/graphics/statelistdrawable.cpp b/src/eepp/graphics/statelistdrawable.cpp index 0cb5f7a8b..0243caf6e 100644 --- a/src/eepp/graphics/statelistdrawable.cpp +++ b/src/eepp/graphics/statelistdrawable.cpp @@ -47,7 +47,7 @@ bool StateListDrawable::isStateful() { return true; } -StatefulDrawable * StateListDrawable::setState( int state ) { +StatefulDrawable * StateListDrawable::setState( Uint32 state ) { if ( state != mCurrentState ) { mCurrentState = state; @@ -63,16 +63,16 @@ StatefulDrawable * StateListDrawable::setState( int state ) { return this; } -const int& StateListDrawable::getState() const { +const Uint32& StateListDrawable::getState() const { return mCurrentState; } -StateListDrawable * StateListDrawable::setStateDrawable(int state, Drawable * drawable) { +StateListDrawable * StateListDrawable::setStateDrawable(Uint32 state, Drawable * drawable) { mDrawables[ state ] = drawable; return this; } -bool StateListDrawable::hasDrawableState( int state ) { +bool StateListDrawable::hasDrawableState(Uint32 state ) { return mDrawables.find( state ) != mDrawables.end(); } diff --git a/src/eepp/ui/uilistboxitem.cpp b/src/eepp/ui/uilistboxitem.cpp index c2be48f61..fdf010ac3 100644 --- a/src/eepp/ui/uilistboxitem.cpp +++ b/src/eepp/ui/uilistboxitem.cpp @@ -111,7 +111,7 @@ void UIListBoxItem::unselect() { if ( mNodeFlags & NODE_FLAG_SELECTED ) mNodeFlags &= ~NODE_FLAG_SELECTED; - setSkinState( UISkinState::StateNormal ); + unsetSkinState( UISkinState::StateSelected ); } bool UIListBoxItem::isSelected() const { @@ -122,12 +122,12 @@ void UIListBoxItem::onStateChange() { UIListBox * LBParent = reinterpret_cast ( getParent()->getParent() ); if ( isSelected() && mSkinState->getState() != UISkinState::StateSelected ) { - setSkinState( UISkinState::StateSelected ); + setSkinState( UISkinState::StateSelected, false ); } - if ( mSkinState->getState() == UISkinState::StateSelected ) { + if ( mSkinState->getState() & UISkinState::StateSelected ) { setFontColor( LBParent->getFontSelectedColor() ); - } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { + } else if ( mSkinState->getState() & UISkinState::StateHover ) { setFontColor( LBParent->getFontOverColor() ); } else { setFontColor( LBParent->getFontColor() ); diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 1717f664e..463ae0a09 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -382,7 +382,7 @@ bool UIMenu::hide() { setVisible( false ); if ( NULL != mItemSelected ) - mItemSelected->setSkinState( UISkinState::StateNormal ); + mItemSelected->unsetSkinState( UISkinState::StateSelected ); mItemSelected = NULL; mItemSelectedIndex = eeINDEX_NOT_FOUND; @@ -399,7 +399,7 @@ void UIMenu::setItemSelected( UINode * Item ) { tMenu->getSubMenu()->hide(); } - mItemSelected->setSkinState( UISkinState::StateNormal ); + mItemSelected->unsetSkinState( UISkinState::StateSelected ); } if ( NULL != Item ) diff --git a/src/eepp/ui/uimenucheckbox.cpp b/src/eepp/ui/uimenucheckbox.cpp index 2e11643db..a9aa2eeff 100644 --- a/src/eepp/ui/uimenucheckbox.cpp +++ b/src/eepp/ui/uimenucheckbox.cpp @@ -55,10 +55,10 @@ void UIMenuCheckBox::setActive( const bool& active ) { if ( NULL == mIcon->getSkin() || mIcon->getSkin()->getName() != mSkinActive->getName() ) mIcon->setSkin( mSkinActive ); - if ( mSkinState->getState() == UISkinState::StateSelected ) - mIcon->setSkinState( UISkinState::StateMouseEnter ); + if ( mSkinState->getState() & UISkinState::StateSelected ) + mIcon->setSkinState( UISkinState::StateHover ); else - mIcon->setSkinState( UISkinState::StateNormal ); + mIcon->unsetSkinState( UISkinState::StateHover ); } else { mIcon->removeSkin(); } @@ -67,10 +67,10 @@ void UIMenuCheckBox::setActive( const bool& active ) { if ( NULL == mIcon->getSkin() || mIcon->getSkin()->getName() != mSkinInactive->getName() ) mIcon->setSkin( mSkinInactive ); - if ( mSkinState->getState() == UISkinState::StateSelected ) - mIcon->setSkinState( UISkinState::StateMouseEnter ); + if ( mSkinState->getState() & UISkinState::StateSelected ) + mIcon->setSkinState( UISkinState::StateHover ); else - mIcon->setSkinState( UISkinState::StateNormal ); + mIcon->unsetSkinState( UISkinState::StateHover ); } else { mIcon->removeSkin(); } diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index cba08c9a2..bd9816307 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -44,9 +44,9 @@ void UIMenuItem::onStateChange() { if ( NULL == mSkinState ) return; - if ( mSkinState->getState() == UISkinState::StateSelected ) { + if ( mSkinState->getState() & UISkinState::StateSelected ) { mTextBox->setFontColor( tMenu->getFontStyleConfig().getFontSelectedColor() ); - } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { + } else if ( mSkinState->getState() & UISkinState::StateHover ) { mTextBox->setFontColor( tMenu->getFontStyleConfig().getFontOverColor() ); } else { mTextBox->setFontColor( tMenu->getFontStyleConfig().getFontColor() ); diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 259fb7d44..c140e4cc7 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -254,7 +254,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->getState() ) ); + Sizef rSize = PixelDensity::dpToPx( mSkinState->getSkin()->getSize( 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 ); @@ -313,7 +313,7 @@ Uint32 UINode::onMouseDown( const Vector2i& Pos, const Uint32 Flags ) { mDragPoint = Vector2f( Pos.x, Pos.y ); } - setSkinState( UISkinState::StateMouseDown ); + setSkinState( UISkinState::StatePressed ); return Node::onMouseDown( Pos, Flags ); } @@ -323,7 +323,7 @@ Uint32 UINode::onMouseUp( const Vector2i& Pos, const Uint32 Flags ) { setDragging( false ); } - setPrevSkinState(); + unsetSkinState( UISkinState::StatePressed ); return Node::onMouseUp( Pos, Flags ); } @@ -597,7 +597,7 @@ UINode * UINode::setSkin( UISkin * skin ) { if ( NULL != mSkinState && mSkinState->getSkin() == skin ) return this; - Uint32 InitialState = UISkinState::StateNormal; + Uint32 InitialState = 1 << UISkinState::StateNormal; if ( NULL != mSkinState ) { InitialState = mSkinState->getState(); @@ -632,19 +632,21 @@ void UINode::onAlignChange() { invalidateDraw(); } -void UINode::setSkinState( const Uint32& State ) { +void UINode::setSkinState(const Uint32& State , bool emitEvent) { if ( NULL != mSkinState ) { mSkinState->setState( State ); - onStateChange(); + if ( emitEvent ) + onStateChange(); } } -void UINode::setPrevSkinState() { +void UINode::unsetSkinState(const Uint32& State , bool emitEvent) { if ( NULL != mSkinState ) { - mSkinState->setPrevState(); + mSkinState->unsetState( State ); - onStateChange(); + if ( emitEvent ) + onStateChange(); } } @@ -793,13 +795,13 @@ Uint32 UINode::onDragStop( const Vector2i& Pos ) { } Uint32 UINode::onMouseEnter(const Vector2i & position, const Uint32 flags) { - setSkinState( UISkinState::StateMouseEnter ); + setSkinState( UISkinState::StateHover ); return Node::onMouseEnter( position, flags ); } Uint32 UINode::onMouseExit(const Vector2i & position, const Uint32 flags) { - setSkinState( UISkinState::StateMouseExit ); + unsetSkinState( UISkinState::StateHover ); return Node::onMouseExit( position, flags ); } @@ -970,4 +972,10 @@ Uint32 UINode::onFocus() { return Node::onFocus(); } +Uint32 UINode::onFocusLoss() { + unsetSkinState( UISkinState::StateFocus ); + + return Node::onFocusLoss(); +} + }} diff --git a/src/eepp/ui/uipopupmenu.cpp b/src/eepp/ui/uipopupmenu.cpp index 8decb6c2c..17f880ff0 100644 --- a/src/eepp/ui/uipopupmenu.cpp +++ b/src/eepp/ui/uipopupmenu.cpp @@ -61,7 +61,7 @@ bool UIPopUpMenu::hide() { if ( isVisible() ) { if ( !isFadingOut() ) { if ( NULL != mItemSelected ) - mItemSelected->setSkinState( UISkinState::StateNormal ); + mItemSelected->unsetSkinState( UISkinState::StateSelected ); mItemSelected = NULL; mItemSelectedIndex = eeINDEX_NOT_FOUND; diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 6cffb0e57..0aa0ca8f0 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -236,7 +236,7 @@ void UIPushButton::onAlphaChange() { } void UIPushButton::onStateChange() { - if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { + if ( mSkinState->getState() & UISkinState::StateHover ) { mTextBox->setFontColor( mStyleConfig.FontOverColor ); } else { mTextBox->setFontColor( mStyleConfig.FontColor ); @@ -260,7 +260,7 @@ Uint32 UIPushButton::onKeyDown( const KeyEvent& Event ) { messagePost( &Msg ); onMouseClick( Vector2i(0,0), EE_BUTTON_LMASK ); - setSkinState( UISkinState::StateMouseDown ); + setSkinState( UISkinState::StatePressed ); } return UIWidget::onKeyDown( Event ); @@ -268,7 +268,7 @@ Uint32 UIPushButton::onKeyDown( const KeyEvent& Event ) { Uint32 UIPushButton::onKeyUp( const KeyEvent& Event ) { if ( Event.getKeyCode() == KEY_RETURN ) { - setPrevSkinState(); + unsetSkinState( UISkinState::StatePressed ); } return UIWidget::onKeyUp( Event ); diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index c6d9873aa..8406d1048 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -41,7 +41,7 @@ void UISelectButton::unselect() { if ( mNodeFlags & NODE_FLAG_SELECTED ) mNodeFlags &= ~NODE_FLAG_SELECTED; - setSkinState( UISkinState::StateNormal ); + unsetSkinState( UISkinState::StateSelected ); } bool UISelectButton::selected() const { @@ -52,26 +52,24 @@ void UISelectButton::onStateChange() { if ( NULL == mSkinState ) return; - if ( mSkinState->getState() != UISkinState::StateSelected && selected() ) { - if ( mSkinState->stateExists( UISkinState::StateSelected ) ) { - setSkinState( UISkinState::StateSelected ); - } + if ( !( mSkinState->getState() & UISkinState::StateSelected ) && selected() && mSkinState->stateExists( UISkinState::StateSelected ) ) { + setSkinState( UISkinState::StateSelected, false ); } if ( getParent()->isType( UI_TYPE_WINMENU ) ) { UIWinMenu * Menu = reinterpret_cast ( getParent() ); - if ( mSkinState->getState() == UISkinState::StateSelected ) { + if ( mSkinState->getState() & UISkinState::StateSelected ) { getTextBox()->setFontColor( Menu->getStyleConfig().getFontSelectedColor() ); - } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { + } else if ( mSkinState->getState() & UISkinState::StateHover ) { getTextBox()->setFontColor( Menu->getStyleConfig().getFontOverColor() ); } else { getTextBox()->setFontColor( Menu->getStyleConfig().getFontColor() ); } } else { - if ( mSkinState->getState() == UISkinState::StateSelected ) { + if ( mSkinState->getState() & UISkinState::StateSelected ) { getTextBox()->setFontColor( mStyleConfig.FontSelectedColor ); - } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { + } else if ( mSkinState->getState() & UISkinState::StateHover ) { getTextBox()->setFontColor( mStyleConfig.FontOverColor ); } else { getTextBox()->setFontColor( mStyleConfig.FontColor ); diff --git a/src/eepp/ui/uiskin.cpp b/src/eepp/ui/uiskin.cpp index baae1db82..e9e81d223 100644 --- a/src/eepp/ui/uiskin.cpp +++ b/src/eepp/ui/uiskin.cpp @@ -8,7 +8,6 @@ const char * UISkinStatesNames[] = { "focus", "selected", "menter", - "mexit", "mdown" }; @@ -32,13 +31,6 @@ UISkin::UISkin( const std::string& name, const Uint32& Type ) : mNameHash( String::hash( mName ) ), mTheme(NULL) { - Color tColor( 255, 255, 255, 255 ); - - mColorDefault = tColor.getValue(); - - for ( Int32 i = 0; i < UISkinState::StateCount; i++ ) { - mColor[ i ] = tColor; - } } UISkin::~UISkin() { @@ -48,20 +40,6 @@ Sizef UISkin::getSize() { return getSize( UISkinState::StateNormal ); } -void UISkin::setColor( const Uint32& State, const Color& Color ) { - eeASSERT ( State < UISkinState::StateCount ); - - BitOp::writeBitKey( &mColorDefault, State, 0 ); - - mColor[ State ] = Color; -} - -const Color& UISkin::getColor( const Uint32& State ) const { - eeASSERT ( State < UISkinState::StateCount ); - - return mColor[ State ]; -} - const std::string& UISkin::getName() const { return mName; } @@ -96,8 +74,4 @@ Rectf UISkin::getBorderSize() { return getBorderSize( UISkinState::StateNormal ); } -bool UISkin::getColorDefault( const Uint32& State ) { - return BitOp::readBitKey( &mColorDefault, State ); -} - }} diff --git a/src/eepp/ui/uiskincomplex.cpp b/src/eepp/ui/uiskincomplex.cpp index e3e0e1593..9466376d5 100644 --- a/src/eepp/ui/uiskincomplex.cpp +++ b/src/eepp/ui/uiskincomplex.cpp @@ -49,12 +49,6 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co if ( 0 == Alpha ) return; - mTempColor = mColor[ State ]; - - if ( mTempColor.a != Alpha ) { - mTempColor.a = (Uint8)( (Float)mTempColor.a * ( (Float)Alpha / 255.f ) ); - } - Drawable * tDrawable = mDrawable[ State ][ UpLeft ]; Sizef uls; @@ -62,9 +56,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co if ( NULL != tDrawable ) { uls = DRAWABLE_PX_SIZE; - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X, Y ), uls ); - tDrawable->clearColor(); } tDrawable = mDrawable[ State ][ DownLeft ]; @@ -74,9 +66,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co if ( NULL != tDrawable ) { dls = DRAWABLE_PX_SIZE; - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X, Y + Height - dls.getHeight() ), dls ); - tDrawable->clearColor(); } tDrawable = mDrawable[ State ][ UpRight ]; @@ -86,9 +76,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co if ( NULL != tDrawable ) { urs = DRAWABLE_PX_SIZE; - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X + Width - urs.getWidth() , Y ), urs ); - tDrawable->clearColor(); } tDrawable = mDrawable[ State ][ DownRight ]; @@ -98,9 +86,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co if ( NULL != tDrawable ) { drs = DRAWABLE_PX_SIZE; - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X + Width - drs.getWidth(), Y + Height - drs.getHeight() ), drs ); - tDrawable->clearColor(); } tDrawable = mDrawable[ State ][ Left ]; @@ -109,9 +95,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co Sizef dpxs( DRAWABLE_PX_SIZE ); Sizef ns( dpxs.getWidth(), Height - uls.getHeight() - dls.getHeight() ); - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X, Y + uls.getHeight() ), ns ); - tDrawable->clearColor(); if ( uls.getWidth() == 0 ) uls.x = dpxs.getWidth(); @@ -123,9 +107,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co Sizef dpxs( DRAWABLE_PX_SIZE ); Sizef ns( Width - uls.getWidth() - urs.getWidth(), dpxs.getHeight() ); - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X + uls.getWidth(), Y ), ns ); - tDrawable->clearColor(); if ( urs.getHeight() == 0 ) urs.y = dpxs.getHeight(); @@ -144,9 +126,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co Sizef ns( dpxs.x, Height - urs.getHeight() - drs.getHeight() ); - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X + Width - dpxs.getWidth(), Y + urs.getHeight() ), ns ); - tDrawable->clearColor(); } tDrawable = mDrawable[ State ][ Down ]; @@ -155,9 +135,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co Sizef dpxs( DRAWABLE_PX_SIZE ); Sizef ns( Width - dls.getWidth() - drs.getWidth(), dpxs.getHeight() ); - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X + dls.getWidth(), Y + Height - dpxs.getHeight() ), ns ); - tDrawable->clearColor(); if ( dls.getHeight() == 0 && drs.getHeight() == 0 ) dls.setHeight( dpxs.getHeight() ); @@ -168,9 +146,7 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co if ( NULL != tDrawable ) { Sizef ns( Width - uls.getWidth() - urs.getWidth(), Height - uls.getHeight() - dls.getHeight() ); - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X + uls.getWidth(), Y + uls.getHeight() ), ns ); - tDrawable->clearColor(); } } @@ -198,31 +174,16 @@ Sizef UISkinComplex::getSideSize( const Uint32& State, const Uint32& Side ) { return Sizef(); } -void UISkinComplex::stateNormalToState( const Uint32& State ) { - if ( NULL == mDrawable[ State ][ Center ] ) { - for ( Uint32 Side = 0; Side < SideCount; Side++ ) { - mDrawable[ State ][ Side ] = mDrawable[ UISkinState::StateNormal ][ Side ]; - } - } -} - -UISkinComplex * UISkinComplex::clone( const std::string& NewName, const bool& CopyColorsState ) { +UISkinComplex * UISkinComplex::clone( const std::string& NewName ) { UISkinComplex * SkinC = UISkinComplex::New( NewName ); - if ( CopyColorsState ) { - SkinC->mColorDefault = mColorDefault; - - for ( size_t i = 0; i < UISkinState::StateCount; i++ ) - SkinC->mColor[i] = mColor[i]; - } - memcpy( &SkinC->mDrawable[0], &mDrawable[0], UISkinState::StateCount * SideCount * sizeof(Drawable*) ); return SkinC; } UISkin * UISkinComplex::clone() { - return clone( mName, true ); + return clone( mName ); } Sizef UISkinComplex::getSize( const Uint32 & state ) { diff --git a/src/eepp/ui/uiskinsimple.cpp b/src/eepp/ui/uiskinsimple.cpp index 6c2484443..6ea5b0e10 100644 --- a/src/eepp/ui/uiskinsimple.cpp +++ b/src/eepp/ui/uiskinsimple.cpp @@ -26,14 +26,8 @@ void UISkinSimple::draw( const Float& X, const Float& Y, const Float& Width, con return; Drawable * tDrawable = mDrawable[ State ]; - mTempColor = mColor[ State ]; if ( NULL != tDrawable ) { - if ( mTempColor.a != Alpha ) { - mTempColor.a = (Uint8)( (Float)mTempColor.a * ( (Float)Alpha / 255.f ) ); - } - - tDrawable->setColor( mTempColor ); tDrawable->draw( Vector2f( X, Y ), Sizef( Width, Height ) ); tDrawable->clearColor(); } @@ -51,28 +45,16 @@ bool UISkinSimple::stateExists( const Uint32 & state ) { return NULL != mDrawable[ state ]; } -void UISkinSimple::stateNormalToState( const Uint32& State ) { - if ( NULL == mDrawable[ State ] ) - mDrawable[ State ] = mDrawable[ UISkinState::StateNormal ]; -} - -UISkinSimple * UISkinSimple::clone( const std::string& NewName, const bool& CopyColorsState ) { +UISkinSimple * UISkinSimple::clone( const std::string& NewName ) { UISkinSimple * SkinS = UISkinSimple::New( NewName ); - if ( CopyColorsState ) { - SkinS->mColorDefault = mColorDefault; - - for ( size_t i = 0; i < UISkinState::StateCount; i++ ) - SkinS->mColor[i] = mColor[i]; - } - memcpy( &SkinS->mDrawable[0], &mDrawable[0], UISkinState::StateCount * sizeof(Drawable*) ); return SkinS; } UISkin * UISkinSimple::clone() { - return clone( mName, true ); + return clone( mName ); } Sizef UISkinSimple::getSize( const Uint32 & state ) { diff --git a/src/eepp/ui/uiskinstate.cpp b/src/eepp/ui/uiskinstate.cpp index 7e9799316..42030a192 100644 --- a/src/eepp/ui/uiskinstate.cpp +++ b/src/eepp/ui/uiskinstate.cpp @@ -9,8 +9,8 @@ UISkinState *UISkinState::New( UISkin * skin ) { UISkinState::UISkinState( UISkin * Skin ) : mSkin( Skin ), - mCurState(0), - mLastState(0) + mState(1 << StateNormal), + mCurrentState(StateNormal) { eeASSERT( NULL != mSkin ); } @@ -20,76 +20,27 @@ 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, mCurState ); -} - -void UISkinState::stateBack( const Uint32& State ) { - if ( ( StateFocus == State ) && StateMouseEnter == mCurState && StateNormal == mLastState ) { - return; - } - - if ( mCurState == StateSelected && ( State == StateMouseDown || State == StateFocus ) ) { - return; - } - - if ( !( mCurState == StateFocus && ( State == StateMouseEnter || State == StateMouseExit || State == StateMouseDown ) ) ) { - mLastState = mCurState; - mCurState = StateNormal; - } -} - -void UISkinState::setPrevState() { - if ( StateMouseDown == mCurState ) { - Uint32 State = mCurState; - mCurState = mLastState; - mLastState = State; - } -} - -const Uint32& UISkinState::getPrevState() const { - return mLastState; + mSkin->draw( X, Y, Width, Height, Alpha, mCurrentState ); } const Uint32& UISkinState::getState() const { - return mCurState; + return mState; } void UISkinState::setState( const Uint32& State ) { - eeASSERT ( State < UISkinState::StateCount ); + if ( !( mState & ( 1 << State ) ) ) { + mState |= ( 1 << State ); - switch ( mSkin->getType() ) - { - case UISkin::SkinSimple: - case UISkin::SkinComplex: - setStateTypeSimple( State ); - break; - default: - setStateTypeDefault( State ); + updateState(); } } -void UISkinState::setStateTypeSimple( const Uint32& State ) { - eeASSERT ( State < UISkinState::StateCount ); +void UISkinState::unsetState(const Uint32 & State) { + if ( mState & ( 1 << State ) ) { + mState &= ~( 1 << State ); - if ( mCurState == State ) - return; - - if ( !mSkin->getColorDefault( State ) || stateExists( State ) ) { - mSkin->stateNormalToState( State ); - - mLastState = mCurState; - mCurState = State; - } else - stateBack( State ); -} - -void UISkinState::setStateTypeDefault( const Uint32& State ) { - eeASSERT ( State < UISkinState::StateCount ); - - if ( !mSkin->getColorDefault( State ) ) - mCurState = State; - else - stateBack( State ); + updateState(); + } } UISkin * UISkinState::getSkin() const { @@ -100,5 +51,20 @@ bool UISkinState::stateExists( const Uint32& State ) { return mSkin->stateExists( State ); } +Uint32 UISkinState::getCurrentState() const { + return mCurrentState; +} + +void UISkinState::updateState() { + for ( int i = StateCount - 1; i >= 0; i-- ) { + if ( ( mState & ( 1 << i ) ) && stateExists( i ) ) { + mCurrentState = i; + return; + } + } + + mCurrentState = 0; +} + }} diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 6000676fa..bbc987cd9 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -82,7 +82,7 @@ void UITab::onStateChange() { UITabWidget * tTabW = getTabWidget(); if ( NULL != tTabW && NULL != mSkinState ) { - Int32 skinSize = getSkinSize( getSkin(), mSkinState->getState() ).getHeight(); + Int32 skinSize = getSkinSize( getSkin(), mSkinState->getCurrentState() ).getHeight(); if ( 0 == skinSize ) { skinSize = getSkinSize().getHeight(); @@ -90,9 +90,9 @@ void UITab::onStateChange() { setSize( mDpSize.getWidth(), skinSize ); - if ( mSkinState->getState() == UISkinState::StateSelected ) { + if ( mSkinState->getState() & UISkinState::StateSelected ) { mTextBox->setFontColor( tTabW->getFontSelectedColor() ); - } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { + } else if ( mSkinState->getState() & UISkinState::StateHover ) { mTextBox->setFontColor( tTabW->getFontOverColor() ); } else { mTextBox->setFontColor( tTabW->getFontColor() ); diff --git a/src/eepp/ui/uitablecell.cpp b/src/eepp/ui/uitablecell.cpp index 766a6c25b..7e6d0b2e4 100644 --- a/src/eepp/ui/uitablecell.cpp +++ b/src/eepp/ui/uitablecell.cpp @@ -120,7 +120,7 @@ void UITableCell::unselect() { if ( mNodeFlags & NODE_FLAG_SELECTED ) mNodeFlags &= ~NODE_FLAG_SELECTED; - setSkinState( UISkinState::StateNormal ); + unsetSkinState( UISkinState::StateSelected); } bool UITableCell::isSelected() const { @@ -174,8 +174,8 @@ void UITableCell::onAutoSize() { void UITableCell::onStateChange() { UIWidget::onStateChange(); - if ( isSelected() && mSkinState->getState() != UISkinState::StateSelected ) { - setSkinState( UISkinState::StateSelected ); + if ( isSelected() && !( mSkinState->getState() & UISkinState::StateSelected ) ) { + setSkinState( UISkinState::StateSelected, false ); } }