mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-07-20 17:52:50 +03:00
UISkinState is now UIState.
--HG-- branch : dev-stateful-drawable
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <eepp/ui/uihelper.hpp>
|
||||
#include <eepp/ui/uibackground.hpp>
|
||||
#include <eepp/ui/uiborder.hpp>
|
||||
#include <eepp/ui/uistate.hpp>
|
||||
#include <eepp/ui/uiskin.hpp>
|
||||
#include <eepp/scene/node.hpp>
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define EE_UICUISKIN_HPP
|
||||
|
||||
#include <eepp/ui/base.hpp>
|
||||
#include <eepp/ui/uiskinstate.hpp>
|
||||
#include <eepp/graphics/statelistdrawable.hpp>
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef EE_UICUISKINSTATE_HPP
|
||||
#define EE_UICUISKINSTATE_HPP
|
||||
#ifndef EE_UI_UISTATE_HPP
|
||||
#define EE_UI_UISTATE_HPP
|
||||
|
||||
#include <eepp/ui/base.hpp>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<UIListBox*> ( 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() );
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <eepp/ui/uinode.hpp>
|
||||
#include <eepp/ui/uitheme.hpp>
|
||||
#include <eepp/ui/uiwindow.hpp>
|
||||
#include <eepp/ui/uiskinstate.hpp>
|
||||
#include <eepp/ui/uistate.hpp>
|
||||
#include <eepp/ui/uithememanager.hpp>
|
||||
#include <eepp/graphics/primitives.hpp>
|
||||
#include <eepp/graphics/textureregion.hpp>
|
||||
@@ -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<UISkin*>( &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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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<UIWinMenu*> ( 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 );
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <eepp/ui/uiskin.hpp>
|
||||
#include <eepp/ui/uistate.hpp>
|
||||
#include <eepp/graphics/textureregion.hpp>
|
||||
#include <eepp/graphics/ninepatch.hpp>
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
#include <eepp/ui/uiskinstate.hpp>
|
||||
#include <eepp/ui/uiskin.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
114
src/eepp/ui/uistate.cpp
Normal file
114
src/eepp/ui/uistate.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#include <eepp/ui/uistate.hpp>
|
||||
#include <eepp/ui/uiskin.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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() );
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <eepp/ui/uitheme.hpp>
|
||||
#include <eepp/ui/uithememanager.hpp>
|
||||
#include <eepp/ui/uistate.hpp>
|
||||
#include <eepp/graphics/sprite.hpp>
|
||||
#include <eepp/graphics/drawable.hpp>
|
||||
#include <eepp/graphics/textureatlas.hpp>
|
||||
@@ -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 ) );
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user