From 7a759fce0b0d0fb718bc06051d7f84c75a0e28ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Mon, 27 Feb 2017 13:24:43 -0300 Subject: [PATCH] UITab and UITabWidget WIP. --HG-- branch : dev --- include/eepp/ui/uiselectbutton.hpp | 6 + include/eepp/ui/uitab.hpp | 9 +- include/eepp/ui/uitabwidget.hpp | 72 +++++++++- src/eepp/ui/uiselectbutton.cpp | 16 +++ src/eepp/ui/uitab.cpp | 27 +++- src/eepp/ui/uitabwidget.cpp | 218 +++++++++++++++++++++++++++-- src/test/eetest.cpp | 7 + 7 files changed, 331 insertions(+), 24 deletions(-) diff --git a/include/eepp/ui/uiselectbutton.hpp b/include/eepp/ui/uiselectbutton.hpp index 7f31521a9..6c75fa2f5 100644 --- a/include/eepp/ui/uiselectbutton.hpp +++ b/include/eepp/ui/uiselectbutton.hpp @@ -22,8 +22,14 @@ class EE_API UISelectButton : public UIPushButton { virtual void unselect(); virtual void select(); + + ColorA getFontSelectedColor() const; + + void setFontSelectedColor(const ColorA & fontSelectedColor); protected: virtual void onStateChange(); + + ColorA mFontSelectedColor; }; }} diff --git a/include/eepp/ui/uitab.hpp b/include/eepp/ui/uitab.hpp index d02cb6165..92e68bbf8 100644 --- a/include/eepp/ui/uitab.hpp +++ b/include/eepp/ui/uitab.hpp @@ -11,8 +11,12 @@ class EE_API UITab : public UISelectButton { public: UITab( UISelectButton::CreateParams& Params, UIControl * controlOwned ); + UITab(); + UIControl * getControlOwned() const; + void setControlOwned( UIControl * controlOwned ); + virtual ~UITab(); virtual Uint32 getType() const; @@ -26,8 +30,9 @@ class EE_API UITab : public UISelectButton { virtual void setText( const String& text ); virtual void update(); + protected: - UIControl * mCtrlOwned; + UIControl * mControlOwned; virtual Uint32 onMouseClick( const Vector2i &position, const Uint32 flags ); @@ -36,6 +41,8 @@ class EE_API UITab : public UISelectButton { void autoSize(); UITabWidget * getTabWidget(); + + virtual void onParentChange(); }; }} diff --git a/include/eepp/ui/uitabwidget.hpp b/include/eepp/ui/uitabwidget.hpp index 75b7d6fb8..442747956 100644 --- a/include/eepp/ui/uitabwidget.hpp +++ b/include/eepp/ui/uitabwidget.hpp @@ -67,6 +67,8 @@ class EE_API UITabWidget : public UIComplexControl { UITabWidget( UITabWidget::CreateParams& Params ); + UITabWidget(); + virtual ~UITabWidget(); virtual Uint32 getType() const; @@ -106,16 +108,74 @@ class EE_API UITabWidget : public UIComplexControl { UIComplexControl * getControlContainer() const; virtual void draw(); + + Font * getFont() const; + + void setFont(Font * font); + + ColorA getFontColor() const; + + void setFontColor(const ColorA & fontColor); + + ColorA getFontShadowColor() const; + + void setFontShadowColor(const ColorA & fontShadowColor); + + ColorA getFontOverColor() const; + + void setFontOverColor(const ColorA & fontOverColor); + + ColorA getFontSelectedColor() const; + + void setFontSelectedColor(const ColorA & fontSelectedColor); + + Int32 getTabSeparation() const; + + void setTabSeparation(const Int32 & tabSeparation); + + Uint32 getMaxTextLength() const; + + void setMaxTextLength(const Uint32 & maxTextLength); + + Uint32 getTabWidgetHeight() const; + + Uint32 getMinTabWidth() const; + + void setMinTabWidth(const Uint32 & minTabWidth); + + Uint32 getMaxTabWidth() const; + + void setMaxTabWidth(const Uint32 & maxTabWidth); + + bool getTabsClosable() const; + + void setTabsClosable(bool tabsClosable); + + bool getSpecialBorderTabs() const; + + void setSpecialBorderTabs(bool specialBorderTabs); + + bool getDrawLineBelowTabs() const; + + void setDrawLineBelowTabs(bool drawLineBelowTabs); + + ColorA getLineBelowTabsColor() const; + + void setLineBelowTabsColor(const ColorA & lineBelowTabsColor); + + Int32 getLineBewowTabsYOffset() const; + + void setLineBewowTabsYOffset(const Int32 & lineBewowTabsYOffset); protected: friend class UITab; UIComplexControl * mCtrlContainer; UIComplexControl * mTabContainer; Font * mFont; - ColorA mFontColor; - ColorA mFontShadowColor; - ColorA mFontOverColor; - ColorA mFontSelectedColor; + ColorA mFontColor; + ColorA mFontShadowColor; + ColorA mFontOverColor; + ColorA mFontSelectedColor; Int32 mTabSeparation; Uint32 mMaxTextLength; Uint32 mTabWidgetHeight; @@ -124,11 +184,11 @@ class EE_API UITabWidget : public UIComplexControl { bool mTabsClosable; bool mSpecialBorderTabs; bool mDrawLineBelowTabs; - ColorA mLineBelowTabsColor; + ColorA mLineBelowTabsColor; Int32 mLineBewowTabsYOffset; std::deque mTabs; - UITab * mTabSelected; + UITab * mTabSelected; Uint32 mTabSelectedIndex; void doAftersetTheme(); diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index 2e4ddaf4e..b65b5927d 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -65,7 +65,23 @@ void UISelectButton::onStateChange() { } else { getTextBox()->setFontColor( Menu->getFontColor() ); } + } else { + if ( mSkinState->getState() == UISkinState::StateSelected ) { + getTextBox()->setFontColor( mFontSelectedColor ); + } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { + getTextBox()->setFontColor( mFontOverColor ); + } else { + getTextBox()->setFontColor( mFontColor ); + } } } +ColorA UISelectButton::getFontSelectedColor() const { + return mFontSelectedColor; +} + +void UISelectButton::setFontSelectedColor(const ColorA & fontSelectedColor) { + mFontSelectedColor = fontSelectedColor; +} + }} diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 9890e2fe1..2aeb3ae3c 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -6,7 +6,14 @@ namespace EE { namespace UI { UITab::UITab( UISelectButton::CreateParams& Params, UIControl * controlOwned ) : UISelectButton( Params ), - mCtrlOwned( controlOwned ) + mControlOwned( controlOwned ) +{ + applyDefaultTheme(); +} + +UITab::UITab() : + UISelectButton(), + mControlOwned( NULL ) { applyDefaultTheme(); } @@ -23,13 +30,17 @@ bool UITab::isType( const Uint32& type ) const { } UITabWidget * UITab::getTabWidget() { - if ( getParent()->getParent()->isType( UI_TYPE_TABWIDGET ) ) { + if ( NULL != getParent() && NULL != getParent()->getParent() && getParent()->getParent()->isType( UI_TYPE_TABWIDGET ) ) { return reinterpret_cast ( getParent()->getParent() ); } return NULL; } +void UITab::onParentChange() { + applyDefaultTheme(); +} + void UITab::setTheme( UITheme * Theme ) { std::string tabPos = "tab"; @@ -125,10 +136,6 @@ void UITab::autoSize() { } } -UIControl * UITab::getControlOwned() const { - return mCtrlOwned; -} - void UITab::update() { UISelectButton::update(); @@ -153,4 +160,12 @@ void UITab::update() { } } +UIControl * UITab::getControlOwned() const { + return mControlOwned; +} + +void UITab::setControlOwned(UIControl * controlOwned) { + mControlOwned = controlOwned; +} + }} diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 496ecc302..4543331c9 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -50,6 +50,53 @@ UITabWidget::UITabWidget( UITabWidget::CreateParams& Params ) : applyDefaultTheme(); } +UITabWidget::UITabWidget() : + UIComplexControl(), + mFont( NULL ), + mFontColor(), + mFontShadowColor(), + mFontOverColor(), + mFontSelectedColor(), + mTabSeparation( 0 ), + mMaxTextLength( 32 ), + mTabWidgetHeight( 64 ), + mMinTabWidth( 32 ), + mMaxTabWidth( 210 ), + mTabsClosable( false ), + mSpecialBorderTabs( false ), + mDrawLineBelowTabs( false ), + mLineBelowTabsColor( ColorA::Black ), + mLineBewowTabsYOffset( 0 ), + mTabSelected( NULL ), + mTabSelectedIndex( eeINDEX_NOT_FOUND ) +{ + UITheme * Theme = UIThemeManager::instance()->getDefaultTheme(); + + if ( NULL != Theme ) { + mFont = Theme->getFont(); + mFontColor = Theme->getFontColor(); + mFontShadowColor = Theme->getFontShadowColor(); + mFontOverColor = Theme->getFontOverColor(); + mFontSelectedColor = Theme->getFontSelectedColor(); + } + + if ( NULL == mFont ) + mFont = UIThemeManager::instance()->getDefaultFont(); + + mTabContainer = eeNew( UIComplexControl, ( ) ); + mTabContainer->setParent( this )->setPosition( 0, 0 )->setSize( mSize.getWidth(), mTabWidgetHeight )->setVisible( true )->setEnabled( true ); + mTabContainer->setFlags( UI_CLIP_ENABLE | UI_ANCHOR_RIGHT ); + + mCtrlContainer = eeNew( UIComplexControl, ( ) ); + mCtrlContainer->setParent( this )->setPosition( 0, mTabWidgetHeight ) + ->setSize( mSize.getWidth(), mSize.getHeight() - mTabWidgetHeight )->setVisible( true )->setEnabled( true ) + ->setFlags( UI_CLIP_ENABLE | UI_ANCHOR_BOTTOM | UI_ANCHOR_RIGHT ); + + onSizeChange(); + + applyDefaultTheme(); +} + UITabWidget::~UITabWidget() { } @@ -121,6 +168,156 @@ void UITabWidget::draw() { } } +Font * UITabWidget::getFont() const { + return mFont; +} + +void UITabWidget::setFont(Font * font) { + mFont = font; + + if ( mTabs.size() > 0 ) { + for ( Uint32 i = 0; i < mTabs.size(); i++ ) { + ((UITab*)mTabs[ i ])->setFont( mFont ); + } + } +} + +ColorA UITabWidget::getFontColor() const { + return mFontColor; +} + +void UITabWidget::setFontColor(const ColorA & fontColor) { + mFontColor = fontColor; + + if ( mTabs.size() > 0 ) { + for ( Uint32 i = 0; i < mTabs.size(); i++ ) { + ((UITab*)mTabs[ i ])->setFontColor( mFontColor ); + } + } +} + +ColorA UITabWidget::getFontShadowColor() const { + return mFontShadowColor; +} + +void UITabWidget::setFontShadowColor(const ColorA & fontShadowColor) { + mFontShadowColor = fontShadowColor; + + if ( mTabs.size() > 0 ) { + for ( Uint32 i = 0; i < mTabs.size(); i++ ) { + ((UITab*)mTabs[ i ])->setFontShadowColor( mFontShadowColor ); + } + } +} + +ColorA UITabWidget::getFontOverColor() const { + return mFontOverColor; +} + +void UITabWidget::setFontOverColor(const ColorA & fontOverColor) { + mFontOverColor = fontOverColor; + + if ( mTabs.size() > 0 ) { + for ( Uint32 i = 0; i < mTabs.size(); i++ ) { + ((UITab*)mTabs[ i ])->setFontOverColor( mFontOverColor ); + } + } +} + +ColorA UITabWidget::getFontSelectedColor() const { + return mFontSelectedColor; +} + +void UITabWidget::setFontSelectedColor(const ColorA & fontSelectedColor) { + mFontSelectedColor = fontSelectedColor; + + if ( mTabs.size() > 0 ) { + for ( Uint32 i = 0; i < mTabs.size(); i++ ) { + ((UITab*)mTabs[ i ])->setFontSelectedColor( mFontSelectedColor ); + } + } +} + +Int32 UITabWidget::getTabSeparation() const { + return mTabSeparation; +} + +void UITabWidget::setTabSeparation(const Int32 & tabSeparation) { + mTabSeparation = tabSeparation; + setTabContainerSize(); + posTabs(); +} + +Uint32 UITabWidget::getMaxTextLength() const { + return mMaxTextLength; +} + +void UITabWidget::setMaxTextLength(const Uint32 & maxTextLength) { + mMaxTextLength = maxTextLength; +} + +Uint32 UITabWidget::getTabWidgetHeight() const { + return mTabWidgetHeight; +} + +Uint32 UITabWidget::getMinTabWidth() const +{ + return mMinTabWidth; +} + +void UITabWidget::setMinTabWidth(const Uint32 & minTabWidth) { + mMinTabWidth = minTabWidth; +} + +Uint32 UITabWidget::getMaxTabWidth() const { + return mMaxTabWidth; +} + +void UITabWidget::setMaxTabWidth(const Uint32 & maxTabWidth) { + mMaxTabWidth = maxTabWidth; +} + +bool UITabWidget::getTabsClosable() const { + return mTabsClosable; +} + +void UITabWidget::setTabsClosable(bool tabsClosable) { + mTabsClosable = tabsClosable; +} + +bool UITabWidget::getSpecialBorderTabs() const { + return mSpecialBorderTabs; +} + +void UITabWidget::setSpecialBorderTabs(bool specialBorderTabs) { + mSpecialBorderTabs = specialBorderTabs; + applyThemeToTabs(); +} + +bool UITabWidget::getDrawLineBelowTabs() const { + return mDrawLineBelowTabs; +} + +void UITabWidget::setDrawLineBelowTabs(bool drawLineBelowTabs) { + mDrawLineBelowTabs = drawLineBelowTabs; +} + +ColorA UITabWidget::getLineBelowTabsColor() const { + return mLineBelowTabsColor; +} + +void UITabWidget::setLineBelowTabsColor(const ColorA & lineBelowTabsColor) { + mLineBelowTabsColor = lineBelowTabsColor; +} + +Int32 UITabWidget::getLineBewowTabsYOffset() const { + return mLineBewowTabsYOffset; +} + +void UITabWidget::setLineBewowTabsYOffset(const Int32 & lineBewowTabsYOffset) { + mLineBewowTabsYOffset = lineBewowTabsYOffset; +} + void UITabWidget::setTabContainerSize() { Uint32 s = 0; @@ -194,20 +391,19 @@ void UITabWidget::orderTabs() { } UITab * UITabWidget::createTab( const String& Text, UIControl * CtrlOwned, SubTexture * Icon ) { - UITab::CreateParams Params; - Params.setParent( mTabContainer ); - Params.Font = mFont; - Params.FontColor = mFontColor; - Params.FontShadowColor = mFontShadowColor; - Params.FontOverColor = mFontOverColor; - Params.Icon = Icon; - Params.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_AUTO_SIZE; - - UITab * tCtrl = eeNew( UITab, ( Params, CtrlOwned ) ); - + UITab * tCtrl = eeNew( UITab, ( ) ); + tCtrl->setParent( mTabContainer ); + tCtrl->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_AUTO_SIZE ); + tCtrl->setFont( mFont ); + tCtrl->setFontColor( mFontColor ); + tCtrl->setFontShadowColor( mFontShadowColor ); + tCtrl->setFontOverColor( mFontOverColor ); + tCtrl->setFontSelectedColor( mFontSelectedColor ); + tCtrl->setIcon( Icon ); tCtrl->setText( Text ); tCtrl->setVisible( true ); tCtrl->setEnabled( true ); + tCtrl->setControlOwned( CtrlOwned ); CtrlOwned->setParent( mCtrlContainer ); CtrlOwned->setVisible( false ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index ef0e6e21d..4a1da07f2 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -723,6 +723,13 @@ void EETest::createNewUI() { WinMenu->addMenuButton( "File", PopMenu ); WinMenu->addMenuButton( "Edit", PopMenu2 ); /**/ + + UITabWidget * TabWidget = eeNew( UITabWidget, () ); + TabWidget->setPosition( 350, 550 )->setSize( 200, 100 ); + + TabWidget->add( "Tab 1", eeNew( UIControl, () ) ); + TabWidget->add( "Tab 2", eeNew( UIControl, () ) ); + TabWidget->add( "Tab 3", eeNew( UIControl, () ) ); } void EETest::createMapEditor() {