From da7d035a09fd3027900ee7e5598af66ef87f987c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 20 Dec 2018 18:42:37 -0300 Subject: [PATCH] UISkinState is now UIState. --HG-- branch : dev-stateful-drawable --- include/eepp/ui/uihelper.hpp | 2 +- include/eepp/ui/uinode.hpp | 11 +- include/eepp/ui/uiskin.hpp | 9 -- .../eepp/ui/{uiskinstate.hpp => uistate.hpp} | 24 ++-- projects/linux/ee.files | 8 +- src/eepp/ui/uilistboxitem.cpp | 16 +-- src/eepp/ui/uimenu.cpp | 6 +- src/eepp/ui/uimenucheckbox.cpp | 12 +- src/eepp/ui/uimenuitem.cpp | 4 +- src/eepp/ui/uinode.cpp | 43 ++++--- src/eepp/ui/uipopupmenu.cpp | 2 +- src/eepp/ui/uiprogressbar.cpp | 2 +- src/eepp/ui/uipushbutton.cpp | 6 +- src/eepp/ui/uiselectbutton.cpp | 16 +-- src/eepp/ui/uiskin.cpp | 38 +----- src/eepp/ui/uiskinstate.cpp | 73 ----------- src/eepp/ui/uistate.cpp | 114 ++++++++++++++++++ src/eepp/ui/uitab.cpp | 4 +- src/eepp/ui/uitablecell.cpp | 10 +- src/eepp/ui/uitabwidget.cpp | 2 +- src/eepp/ui/uitheme.cpp | 13 +- src/eepp/ui/uiwinmenu.cpp | 2 +- 22 files changed, 220 insertions(+), 197 deletions(-) rename include/eepp/ui/{uiskinstate.hpp => uistate.hpp} (60%) delete mode 100644 src/eepp/ui/uiskinstate.cpp create mode 100644 src/eepp/ui/uistate.cpp diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index a2a1b16ea..748e9499a 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -41,7 +41,7 @@ enum UI_FLAGS { UI_TEXT_SELECTION_ENABLED = (1 << 19) }; -enum UI_CONTROL_TYPES { +enum UI_NODE_TYPES { UI_TYPE_NODE = 0, UI_TYPE_UINODE, UI_TYPE_WIDGET, diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index f5303d758..002867ab9 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -140,9 +141,9 @@ class EE_API UINode : public Node { void removeSkin(); - void setSkinState( const Uint32& State, bool emitEvent = true ); + void pushState( const Uint32& State, bool emitEvent = true ); - void unsetSkinState( const Uint32& State, bool emitEvent = true ); + void popState( const Uint32& State, bool emitEvent = true ); Sizef getSkinSize(); @@ -173,7 +174,7 @@ class EE_API UINode : public Node { Vector2f mDpPos; Sizef mDpSize; Uint32 mFlags; - UISkinState * mSkinState; + UIState * mSkinState; UIBackground * mBackground; UIBackground * mForeground; UIBorder * mBorder; @@ -188,6 +189,8 @@ class EE_API UINode : public Node { virtual void onStateChange(); + virtual void onEnabledChange(); + virtual void onAlignChange(); virtual void drawSkin(); @@ -226,7 +229,7 @@ class EE_API UINode : public Node { Rectf makePadding( bool PadLeft = true, bool PadRight = true, bool PadTop = true, bool PadBottom = true, bool SkipFlags = false ); - Sizef getSkinSize( UISkin * Skin, const Uint32& State = UISkinState::StateNormal ); + Sizef getSkinSize( UISkin * Skin, const Uint32& State = UIState::StateNormal ); void drawHighlightFocus(); diff --git a/include/eepp/ui/uiskin.hpp b/include/eepp/ui/uiskin.hpp index 5d154c211..e9d9f6a9f 100644 --- a/include/eepp/ui/uiskin.hpp +++ b/include/eepp/ui/uiskin.hpp @@ -2,7 +2,6 @@ #define EE_UICUISKIN_HPP #include -#include #include namespace EE { namespace UI { @@ -11,12 +10,6 @@ class UITheme; class EE_API UISkin : public StateListDrawable { public: - static const char * getSkinStateName( const Uint32& State ); - - static int getStateNumber(const std::string & State); - - static bool isStateName( const std::string& State ); - static UISkin * New( const std::string& name ); explicit UISkin( const std::string& name ); @@ -45,8 +38,6 @@ class EE_API UISkin : public StateListDrawable { virtual Rectf getBorderSize(); protected: - friend class UISkinState; - std::string mName; Uint32 mNameHash; UITheme * mTheme; diff --git a/include/eepp/ui/uiskinstate.hpp b/include/eepp/ui/uistate.hpp similarity index 60% rename from include/eepp/ui/uiskinstate.hpp rename to include/eepp/ui/uistate.hpp index cb6ad4884..04f2adc20 100644 --- a/include/eepp/ui/uiskinstate.hpp +++ b/include/eepp/ui/uistate.hpp @@ -1,5 +1,5 @@ -#ifndef EE_UICUISKINSTATE_HPP -#define EE_UICUISKINSTATE_HPP +#ifndef EE_UI_UISTATE_HPP +#define EE_UI_UISTATE_HPP #include @@ -7,9 +7,9 @@ namespace EE { namespace UI { class UISkin; -class EE_API UISkinState { +class EE_API UIState { public: - enum UISkinStates { + enum UIStates { StateNormal = 0, StateFocus = 1, StateSelected = 2, @@ -19,17 +19,25 @@ class EE_API UISkinState { StateCount = 6 }; - static UISkinState * New( UISkin * skin ); + static const char * getSkinStateName( const Uint32& State ); - explicit UISkinState( UISkin * Skin ); + static int getStateNumber(const std::string & State); - ~UISkinState(); + static bool isStateName( const std::string& State ); + + static UIState * New( UISkin * skin ); + + explicit UIState( UISkin * Skin ); + + ~UIState(); const Uint32& getState() const; void setState( const Uint32& State ); - void unsetState( const Uint32& State ); + void pushState( const Uint32& State ); + + void popState( const Uint32& State ); UISkin * getSkin() const; diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 0d8c53e6d..68708447b 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -325,11 +325,11 @@ ../../include/eepp/ui/uiscrollview.hpp ../../include/eepp/ui/uiselectbutton.hpp ../../include/eepp/ui/uiskin.hpp -../../include/eepp/ui/uiskinstate.hpp ../../include/eepp/ui/uislider.hpp ../../include/eepp/ui/uisliderbutton.hpp ../../include/eepp/ui/uispinbox.hpp ../../include/eepp/ui/uisprite.hpp +../../include/eepp/ui/uistate.hpp ../../include/eepp/ui/uitab.hpp ../../include/eepp/ui/uitable.hpp ../../include/eepp/ui/uitablecell.hpp @@ -725,11 +725,11 @@ ../../src/eepp/ui/uiscrollview.cpp ../../src/eepp/ui/uiselectbutton.cpp ../../src/eepp/ui/uiskin.cpp -../../src/eepp/ui/uiskinstate.cpp ../../src/eepp/ui/uislider.cpp ../../src/eepp/ui/uisliderbutton.cpp ../../src/eepp/ui/uispinbox.cpp ../../src/eepp/ui/uisprite.cpp +../../src/eepp/ui/uistate.cpp ../../src/eepp/ui/uitab.cpp ../../src/eepp/ui/uitable.cpp ../../src/eepp/ui/uitablecell.cpp @@ -1221,7 +1221,7 @@ ../../include/eepp/ui/uispinbox.hpp ../../include/eepp/ui/uisliderbutton.hpp ../../include/eepp/ui/uislider.hpp -../../include/eepp/ui/uiskinstate.hpp +../../include/eepp/ui/uistate.hpp ../../include/eepp/ui/uiskin.hpp ../../include/eepp/ui/uiselectbutton.hpp ../../include/eepp/ui/uiscrollbar.hpp @@ -1262,7 +1262,7 @@ ../../src/eepp/ui/uispinbox.cpp ../../src/eepp/ui/uisliderbutton.cpp ../../src/eepp/ui/uislider.cpp -../../src/eepp/ui/uiskinstate.cpp +../../src/eepp/ui/uistate.cpp ../../src/eepp/ui/uiskin.cpp ../../src/eepp/ui/uiselectbutton.cpp ../../src/eepp/ui/uiscrollbar.cpp diff --git a/src/eepp/ui/uilistboxitem.cpp b/src/eepp/ui/uilistboxitem.cpp index fdf010ac3..fcc140101 100644 --- a/src/eepp/ui/uilistboxitem.cpp +++ b/src/eepp/ui/uilistboxitem.cpp @@ -57,7 +57,7 @@ void UIListBoxItem::select() { if ( LBParent->isMultiSelect() ) { if ( !wasSelected ) { - setSkinState( UISkinState::StateSelected ); + pushState( UIState::StateSelected ); mNodeFlags |= NODE_FLAG_SELECTED; @@ -70,7 +70,7 @@ void UIListBoxItem::select() { LBParent->mSelected.remove( LBParent->getItemIndex( this ) ); } } else { - setSkinState( UISkinState::StateSelected ); + pushState( UIState::StateSelected ); mNodeFlags |= NODE_FLAG_SELECTED; @@ -102,7 +102,7 @@ Uint32 UIListBoxItem::onMouseExit( const Vector2i& Pos, const Uint32 Flags ) { UINode::onMouseExit( Pos, Flags ); if ( mNodeFlags & NODE_FLAG_SELECTED ) - setSkinState( UISkinState::StateSelected ); + pushState( UIState::StateSelected ); return 1; } @@ -111,7 +111,7 @@ void UIListBoxItem::unselect() { if ( mNodeFlags & NODE_FLAG_SELECTED ) mNodeFlags &= ~NODE_FLAG_SELECTED; - unsetSkinState( UISkinState::StateSelected ); + popState( UIState::StateSelected ); } bool UIListBoxItem::isSelected() const { @@ -121,13 +121,13 @@ bool UIListBoxItem::isSelected() const { void UIListBoxItem::onStateChange() { UIListBox * LBParent = reinterpret_cast ( getParent()->getParent() ); - if ( isSelected() && mSkinState->getState() != UISkinState::StateSelected ) { - setSkinState( UISkinState::StateSelected, false ); + if ( isSelected() && mSkinState->getState() != UIState::StateSelected ) { + pushState( UIState::StateSelected, false ); } - if ( mSkinState->getState() & UISkinState::StateSelected ) { + if ( mSkinState->getState() & UIState::StateSelected ) { setFontColor( LBParent->getFontSelectedColor() ); - } else if ( mSkinState->getState() & UISkinState::StateHover ) { + } else if ( mSkinState->getState() & UIState::StateHover ) { setFontColor( LBParent->getFontOverColor() ); } else { setFontColor( LBParent->getFontColor() ); diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 463ae0a09..97093f396 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->unsetSkinState( UISkinState::StateSelected ); + mItemSelected->popState( UIState::StateSelected ); mItemSelected = NULL; mItemSelectedIndex = eeINDEX_NOT_FOUND; @@ -399,11 +399,11 @@ void UIMenu::setItemSelected( UINode * Item ) { tMenu->getSubMenu()->hide(); } - mItemSelected->unsetSkinState( UISkinState::StateSelected ); + mItemSelected->popState( UIState::StateSelected ); } if ( NULL != Item ) - Item->setSkinState( UISkinState::StateSelected ); + Item->pushState( UIState::StateSelected ); if ( mItemSelected != Item ) { mItemSelected = Item; diff --git a/src/eepp/ui/uimenucheckbox.cpp b/src/eepp/ui/uimenucheckbox.cpp index a9aa2eeff..0b37573ee 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::StateHover ); + if ( mSkinState->getState() & UIState::StateSelected ) + mIcon->pushState( UIState::StateHover ); else - mIcon->unsetSkinState( UISkinState::StateHover ); + mIcon->popState( UIState::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::StateHover ); + if ( mSkinState->getState() & UIState::StateSelected ) + mIcon->pushState( UIState::StateHover ); else - mIcon->unsetSkinState( UISkinState::StateHover ); + mIcon->popState( UIState::StateHover ); } else { mIcon->removeSkin(); } diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index bd9816307..01e855ff4 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() & UIState::StateSelected ) { mTextBox->setFontColor( tMenu->getFontStyleConfig().getFontSelectedColor() ); - } else if ( mSkinState->getState() & UISkinState::StateHover ) { + } else if ( mSkinState->getState() & UIState::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 ca600a263..62ed0ef96 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -311,7 +311,7 @@ Uint32 UINode::onMouseDown( const Vector2i& Pos, const Uint32 Flags ) { mDragPoint = Vector2f( Pos.x, Pos.y ); } - setSkinState( UISkinState::StatePressed ); + pushState( UIState::StatePressed ); return Node::onMouseDown( Pos, Flags ); } @@ -321,7 +321,7 @@ Uint32 UINode::onMouseUp( const Vector2i& Pos, const Uint32 Flags ) { setDragging( false ); } - unsetSkinState( UISkinState::StatePressed ); + popState( UIState::StatePressed ); return Node::onMouseUp( Pos, Flags ); } @@ -583,7 +583,7 @@ UINode * UINode::setSkin( const UISkin& Skin ) { UISkin * SkinCopy = const_cast( &Skin )->clone(); - mSkinState = UISkinState::New( SkinCopy ); + mSkinState = UIState::New( SkinCopy ); onThemeLoaded(); @@ -595,7 +595,7 @@ UINode * UINode::setSkin( UISkin * skin ) { if ( NULL != mSkinState && mSkinState->getSkin() == skin ) return this; - Uint32 InitialState = 1; + Uint32 InitialState = 1 << UIState::StateNormal; if ( NULL != mSkinState ) { InitialState = mSkinState->getState(); @@ -603,7 +603,7 @@ UINode * UINode::setSkin( UISkin * skin ) { removeSkin(); - mSkinState = UISkinState::New( skin ); + mSkinState = UIState::New( skin ); mSkinState->setState( InitialState ); onThemeLoaded(); @@ -626,13 +626,24 @@ void UINode::onStateChange() { invalidateDraw(); } +void UINode::onEnabledChange() { + if ( !mEnabled ) { + pushState( UIState::StateDisabled ); + } else if ( NULL != mSkinState && ( mSkinState->getState() & ( 1 << UIState::StateDisabled ) ) ) { + popState( UIState::StateDisabled ); + } + + Node::onEnabledChange(); + +} + void UINode::onAlignChange() { invalidateDraw(); } -void UINode::setSkinState(const Uint32& State , bool emitEvent) { +void UINode::pushState(const Uint32& State , bool emitEvent) { if ( NULL != mSkinState ) { - mSkinState->setState( State ); + mSkinState->pushState( State ); if ( emitEvent ) { onStateChange(); @@ -642,9 +653,9 @@ void UINode::setSkinState(const Uint32& State , bool emitEvent) { } } -void UINode::unsetSkinState(const Uint32& State , bool emitEvent) { +void UINode::popState(const Uint32& State , bool emitEvent) { if ( NULL != mSkinState ) { - mSkinState->unsetState( State ); + mSkinState->popState( State ); if ( emitEvent ) { onStateChange(); @@ -693,7 +704,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( 1 << UISkinState::StateNormal ); + Rectf rPadding = mSkinState->getSkin()->getBorderSize( 1 << UIState::StateNormal ); if ( PadLeft ) { tPadding.Left = rPadding.Left; @@ -799,14 +810,14 @@ Uint32 UINode::onDragStop( const Vector2i& Pos ) { } Uint32 UINode::onMouseEnter(const Vector2i & position, const Uint32 flags) { - setSkinState( UISkinState::StateHover ); + pushState( UIState::StateHover ); return Node::onMouseEnter( position, flags ); } Uint32 UINode::onMouseExit(const Vector2i & position, const Uint32 flags) { - unsetSkinState( UISkinState::StateHover ); - unsetSkinState( UISkinState::StatePressed ); + popState( UIState::StateHover ); + popState( UIState::StatePressed ); return Node::onMouseExit( position, flags ); } @@ -865,13 +876,13 @@ void UINode::setFocus() { } Uint32 UINode::onFocus() { - setSkinState( UISkinState::StateFocus ); + pushState( UIState::StateFocus ); return Node::onFocus(); } Uint32 UINode::onFocusLoss() { - unsetSkinState( UISkinState::StateFocus ); + popState( UIState::StateFocus ); return Node::onFocusLoss(); } diff --git a/src/eepp/ui/uipopupmenu.cpp b/src/eepp/ui/uipopupmenu.cpp index b219bd476..23e2a254a 100644 --- a/src/eepp/ui/uipopupmenu.cpp +++ b/src/eepp/ui/uipopupmenu.cpp @@ -63,7 +63,7 @@ bool UIPopUpMenu::hide() { if ( isVisible() ) { if ( !isActionManagerActive() ) { if ( NULL != mItemSelected ) - mItemSelected->unsetSkinState( UISkinState::StateSelected ); + mItemSelected->popState( UIState::StateSelected ); mItemSelected = NULL; mItemSelectedIndex = eeINDEX_NOT_FOUND; diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index 44579c4fd..8b4161732 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -70,7 +70,7 @@ void UIProgressBar::draw() { for ( int y = -1; y < numTiles.y; y++ ) { for ( int x = -1; x < numTiles.x; x++ ) { - mFillerSkin->setState( 1 << UISkinState::StateNormal ); + mFillerSkin->setState( 1 << UIState::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/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 0aa0ca8f0..e158f281d 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::StateHover ) { + if ( mSkinState->getState() & UIState::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::StatePressed ); + pushState( UIState::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 ) { - unsetSkinState( UISkinState::StatePressed ); + popState( UIState::StatePressed ); } return UIWidget::onKeyUp( Event ); diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index 8406d1048..3fe3aff71 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -27,7 +27,7 @@ bool UISelectButton::isType( const Uint32& type ) const { void UISelectButton::select() { bool wasSelected = selected(); - setSkinState( UISkinState::StateSelected ); + pushState( UIState::StateSelected ); mNodeFlags |= NODE_FLAG_SELECTED; @@ -41,7 +41,7 @@ void UISelectButton::unselect() { if ( mNodeFlags & NODE_FLAG_SELECTED ) mNodeFlags &= ~NODE_FLAG_SELECTED; - unsetSkinState( UISkinState::StateSelected ); + popState( UIState::StateSelected ); } bool UISelectButton::selected() const { @@ -52,24 +52,24 @@ void UISelectButton::onStateChange() { if ( NULL == mSkinState ) return; - if ( !( mSkinState->getState() & UISkinState::StateSelected ) && selected() && mSkinState->stateExists( UISkinState::StateSelected ) ) { - setSkinState( UISkinState::StateSelected, false ); + if ( !( mSkinState->getState() & UIState::StateSelected ) && selected() && mSkinState->stateExists( UIState::StateSelected ) ) { + pushState( UIState::StateSelected, false ); } if ( getParent()->isType( UI_TYPE_WINMENU ) ) { UIWinMenu * Menu = reinterpret_cast ( getParent() ); - if ( mSkinState->getState() & UISkinState::StateSelected ) { + if ( mSkinState->getState() & UIState::StateSelected ) { getTextBox()->setFontColor( Menu->getStyleConfig().getFontSelectedColor() ); - } else if ( mSkinState->getState() & UISkinState::StateHover ) { + } else if ( mSkinState->getState() & UIState::StateHover ) { getTextBox()->setFontColor( Menu->getStyleConfig().getFontOverColor() ); } else { getTextBox()->setFontColor( Menu->getStyleConfig().getFontColor() ); } } else { - if ( mSkinState->getState() & UISkinState::StateSelected ) { + if ( mSkinState->getState() & UIState::StateSelected ) { getTextBox()->setFontColor( mStyleConfig.FontSelectedColor ); - } else if ( mSkinState->getState() & UISkinState::StateHover ) { + } else if ( mSkinState->getState() & UIState::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 ddf7e2ccb..3ce9fcc8a 100644 --- a/src/eepp/ui/uiskin.cpp +++ b/src/eepp/ui/uiskin.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -8,39 +9,6 @@ UISkin * UISkin::New( const std::string& name ) { return eeNew( UISkin, ( name ) ); } -const char * UISkinStatesNames[] = { - "normal", - "focus", - "selected", - "hover", - "pressed", - "disabled" -}; - -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] ) { - return true; - } - } - - return false; -} - UISkin::UISkin( const std::string& name ) : mName( name ), mNameHash( String::hash( mName ) ), @@ -52,7 +20,7 @@ UISkin::~UISkin() { } Sizef UISkin::getSize() { - return getSize( 1 << UISkinState::StateNormal ); + return getSize( 1 << UIState::StateNormal ); } const std::string& UISkin::getName() const { @@ -77,7 +45,7 @@ void UISkin::setTheme( UITheme * theme ) { } Rectf UISkin::getBorderSize() { - return getBorderSize( 1 << UISkinState::StateNormal ); + return getBorderSize( 1 << UIState::StateNormal ); } UISkin * UISkin::clone( const std::string& NewName ) { diff --git a/src/eepp/ui/uiskinstate.cpp b/src/eepp/ui/uiskinstate.cpp deleted file mode 100644 index 1d316a4a0..000000000 --- a/src/eepp/ui/uiskinstate.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include - -namespace EE { namespace UI { - -UISkinState *UISkinState::New( UISkin * skin ) { - return eeNew( UISkinState, ( skin ) ); -} - -UISkinState::UISkinState( UISkin * Skin ) : - mSkin( Skin ), - mState(1 << StateNormal), - mCurrentState(StateNormal) -{ - eeASSERT( NULL != mSkin ); -} - -UISkinState::~UISkinState() { -} - -void UISkinState::draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha ) { - if ( NULL != mSkin ) { - mSkin->setState( 1 << mCurrentState ); - mSkin->setAlpha( Alpha ); - mSkin->draw( Vector2f( X, Y ), Sizef( Width, Height ) ); - } -} - -const Uint32& UISkinState::getState() const { - return mState; -} - -void UISkinState::setState( const Uint32& State ) { - if ( !( mState & ( 1 << State ) ) ) { - mState |= ( 1 << State ); - - updateState(); - } -} - -void UISkinState::unsetState(const Uint32 & State) { - if ( mState & ( 1 << State ) ) { - mState &= ~( 1 << State ); - - updateState(); - } -} - -UISkin * UISkinState::getSkin() const { - return mSkin; -} - -bool UISkinState::stateExists( const Uint32& State ) { - return mSkin->hasDrawableState( 1 << 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/uistate.cpp b/src/eepp/ui/uistate.cpp new file mode 100644 index 000000000..f752ec934 --- /dev/null +++ b/src/eepp/ui/uistate.cpp @@ -0,0 +1,114 @@ +#include +#include + +namespace EE { namespace UI { + +static const char * UIStatesNames[] = { + "normal", + "focus", + "selected", + "hover", + "pressed", + "disabled" +}; + +const char * UIState::getSkinStateName( const Uint32& State ) { + return UIStatesNames[ State ]; +} + +int UIState::getStateNumber( const std::string& State ) { + for ( int i = 0; i < UIState::StateCount; i++ ) { + if ( State == UIStatesNames[i] ) { + return i; + } + } + + return -1; +} + +bool UIState::isStateName( const std::string& State ) { + for ( int i = 0; i < UIState::StateCount; i++ ) { + if ( State == UIStatesNames[i] ) { + return true; + } + } + + return false; +} + +UIState * UIState::New( UISkin * skin ) { + return eeNew( UIState, ( skin ) ); +} + +UIState::UIState( UISkin * Skin ) : + mSkin( Skin ), + mState(1 << StateNormal), + mCurrentState(StateNormal) +{ + eeASSERT( NULL != mSkin ); +} + +UIState::~UIState() { +} + +void UIState::draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha ) { + if ( NULL != mSkin ) { + mSkin->setState( 1 << mCurrentState ); + mSkin->setAlpha( Alpha ); + mSkin->draw( Vector2f( X, Y ), Sizef( Width, Height ) ); + } +} + +const Uint32& UIState::getState() const { + return mState; +} + +void UIState::setState( const Uint32& State ) { + if ( mState != State ) { + mState |= State; + + updateState(); + } +} + +void UIState::pushState(const Uint32 & State) { + if ( !( mState & ( 1 << State ) ) ) { + mState |= ( 1 << State ); + + updateState(); + } +} + +void UIState::popState(const Uint32 & State) { + if ( mState & ( 1 << State ) ) { + mState &= ~( 1 << State ); + + updateState(); + } +} + +UISkin * UIState::getSkin() const { + return mSkin; +} + +bool UIState::stateExists( const Uint32& State ) { + return mSkin->hasDrawableState( 1 << State ); +} + +Uint32 UIState::getCurrentState() const { + return mCurrentState; +} + +void UIState::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 bbc987cd9..c37fea9be 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -90,9 +90,9 @@ void UITab::onStateChange() { setSize( mDpSize.getWidth(), skinSize ); - if ( mSkinState->getState() & UISkinState::StateSelected ) { + if ( mSkinState->getState() & UIState::StateSelected ) { mTextBox->setFontColor( tTabW->getFontSelectedColor() ); - } else if ( mSkinState->getState() & UISkinState::StateHover ) { + } else if ( mSkinState->getState() & UIState::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 7e6d0b2e4..30da77915 100644 --- a/src/eepp/ui/uitablecell.cpp +++ b/src/eepp/ui/uitablecell.cpp @@ -104,7 +104,7 @@ void UITableCell::select() { bool wasSelected = 0 != ( mNodeFlags & NODE_FLAG_SELECTED ); - setSkinState( UISkinState::StateSelected ); + pushState( UIState::StateSelected ); mNodeFlags |= NODE_FLAG_SELECTED; @@ -120,7 +120,7 @@ void UITableCell::unselect() { if ( mNodeFlags & NODE_FLAG_SELECTED ) mNodeFlags &= ~NODE_FLAG_SELECTED; - unsetSkinState( UISkinState::StateSelected); + popState( UIState::StateSelected); } bool UITableCell::isSelected() const { @@ -131,7 +131,7 @@ Uint32 UITableCell::onMouseExit( const Vector2i& Pos, const Uint32 Flags ) { UINode::onMouseExit( Pos, Flags ); if ( mNodeFlags & NODE_FLAG_SELECTED ) - setSkinState( UISkinState::StateSelected ); + pushState( UIState::StateSelected ); return 1; } @@ -174,8 +174,8 @@ void UITableCell::onAutoSize() { void UITableCell::onStateChange() { UIWidget::onStateChange(); - if ( isSelected() && !( mSkinState->getState() & UISkinState::StateSelected ) ) { - setSkinState( UISkinState::StateSelected, false ); + if ( isSelected() && !( mSkinState->getState() & UIState::StateSelected ) ) { + pushState( UIState::StateSelected, false ); } } diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index b001e7a3b..f4f8b0545 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -62,7 +62,7 @@ void UITabWidget::setTheme( UITheme * Theme ) { if ( NULL != tSkin ) { Sizef tSize1 = getSkinSize( tSkin ); - Sizef tSize2 = getSkinSize( tSkin, UISkinState::StateSelected ); + Sizef tSize2 = getSkinSize( tSkin, UIState::StateSelected ); mStyleConfig.TabWidgetHeight = eemax( tSize1.getHeight(), tSize2.getHeight() ); diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index 2e1864ff8..c80013308 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -87,7 +88,7 @@ UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtla if ( skins.find( skinName ) == skins.end() ) skins[ skinName ] = tTheme->add( UISkin::New( skinName ) ); - int stateNum = UISkin::getStateNumber( nameParts[ nameParts.size() - 1 ] ); + int stateNum = UIState::getStateNumber( nameParts[ nameParts.size() - 1 ] ); if ( -1 != stateNum ) skins[ skinName ]->setStateDrawable( 1 << stateNum, drawable ); @@ -97,9 +98,9 @@ UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtla if ( nameParts.size() >= 3 ) { int lPart = nameParts.size() - 1; - if ( UISkin::isStateName( nameParts[ lPart ] ) ) { + if ( UIState::isStateName( nameParts[ lPart ] ) ) { std::string skinName( elemNameFromSkin( nameParts ) ); - int stateNum = UISkin::getStateNumber( nameParts[ lPart ] ); + int stateNum = UIState::getStateNumber( nameParts[ lPart ] ); if ( skins.find( skinName ) == skins.end() ) skins[ skinName ] = tTheme->add( UISkin::New( skinName ) ); @@ -177,7 +178,7 @@ UITheme * UITheme::loadFromDirectroy( UITheme * tTheme, const std::string& Path if ( skins.find( skinName ) == skins.end() ) skins[ skinName ] = tTheme->add( UISkin::New( skinName ) ); - int stateNum = UISkin::getStateNumber( nameParts[ nameParts.size() - 1 ] ); + int stateNum = UIState::getStateNumber( nameParts[ nameParts.size() - 1 ] ); if ( -1 != stateNum ) skins[ skinName ]->setStateDrawable( 1 << stateNum, drawable ); @@ -187,11 +188,11 @@ UITheme * UITheme::loadFromDirectroy( UITheme * tTheme, const std::string& Path if ( nameParts.size() >= 3 ) { int lPart = nameParts.size() - 1; - if ( UISkin::isStateName( nameParts[ lPart ] ) ) { + if ( UIState::isStateName( nameParts[ lPart ] ) ) { TextureRegion * textureRegion = tSG->add( TextureRegion::New( TextureFactory::instance()->loadFromFile( fpath ), name ) ); std::string skinName( elemNameFromSkin( nameParts ) ); - int stateNum = UISkin::getStateNumber( nameParts[ lPart ] ); + int stateNum = UIState::getStateNumber( nameParts[ lPart ] ); if ( skins.find( skinName ) == skins.end() ) skins[ skinName ] = tTheme->add( UISkin::New( skinName ) ); diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index 3aec41df8..c6b692917 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( 1 << UISkinState::StateSelected ).getHeight(); + th = skin->getSize( 1 << UIState::StateSelected ).getHeight(); switch ( VAlignGet( getFlags() ) ) { case UI_VALIGN_CENTER: