Reimplementing how skins and skins states are managed.

--HG--
branch : dev-stateful-drawable
This commit is contained in:
Martín Lucas Golini
2018-12-19 01:45:02 -03:00
parent 02cf8773ed
commit f5f6ed577c
24 changed files with 123 additions and 244 deletions

View File

@@ -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;

View File

@@ -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;
};
}}

View File

@@ -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<int,Drawable*> mDrawables;
std::map<Uint32,Drawable*> mDrawables;
};
}}

View File

@@ -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 );

View File

@@ -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;
};
}}

View File

@@ -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 );
};
}}

View File

@@ -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 );
};
}}

View File

@@ -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();
};
}}

View File

@@ -1,4 +1,6 @@
#include <eepp/graphics/drawable.hpp>
#include <eepp/graphics/statefuldrawable.hpp>
#include <eepp/core/debug.hpp>
namespace EE { namespace Graphics {
@@ -87,6 +89,11 @@ void Drawable::setPosition( const Vector2f& position ) {
}
}
StatefulDrawable * Drawable::asStatefulDrawable() {
eeASSERT( isStateful() );
return static_cast<StatefulDrawable*>( this );
}
void Drawable::onAlphaChange() {
}

View File

@@ -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();
}

View File

@@ -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<UIListBox*> ( 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() );

View File

@@ -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 )

View File

@@ -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();
}

View File

@@ -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() );

View File

@@ -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();
}
}}

View File

@@ -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;

View File

@@ -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 );

View File

@@ -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<UIWinMenu*> ( 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 );

View File

@@ -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 );
}
}}

View File

@@ -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 ) {

View File

@@ -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 ) {

View File

@@ -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;
}
}}

View File

@@ -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() );

View File

@@ -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 );
}
}