diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index 724940689..4830b2e97 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -143,6 +143,11 @@ enum UI_MSGBOX_TYPE { MSGBOX_OK }; +enum UI_ORIENTATION { + UI_VERTICAL, + UI_HORIZONTAL +}; + static const Uint32 UI_CONTROL_DEFAULT_ALIGN = UI_HALIGN_LEFT | UI_VALIGN_CENTER; static const Uint32 UI_CONTROL_ALIGN_CENTER = UI_HALIGN_CENTER | UI_VALIGN_CENTER; diff --git a/include/eepp/ui/uiscrollbar.hpp b/include/eepp/ui/uiscrollbar.hpp index 53bb2ed69..6a5890136 100644 --- a/include/eepp/ui/uiscrollbar.hpp +++ b/include/eepp/ui/uiscrollbar.hpp @@ -49,7 +49,7 @@ class EE_API UIScrollBar : public UIComplexControl { virtual void setTheme( UITheme * Theme ); - const bool& isVertical() const; + bool isVertical() const; virtual void update(); diff --git a/include/eepp/ui/uislider.hpp b/include/eepp/ui/uislider.hpp index d3d05cfbe..57c69be83 100644 --- a/include/eepp/ui/uislider.hpp +++ b/include/eepp/ui/uislider.hpp @@ -53,7 +53,7 @@ class EE_API UISlider : public UIComplexControl { const Float& getClickStep() const; - const bool& isVertical() const; + bool isVertical() const; virtual void update(); @@ -68,10 +68,22 @@ class EE_API UISlider : public UIComplexControl { const bool& isBackgroundExpanded() const; void manageClick( const Uint32& flags ); + + UI_ORIENTATION getOrientation() const; + + void setOrientation( const UI_ORIENTATION & orientation ); + + bool getAllowHalfSliderOut() const; + + void setAllowHalfSliderOut( bool allowHalfSliderOut ); + + bool getExpandBackground() const; + + void setExpandBackground( bool expandBackground ); protected: friend class Private::UISliderButton; - bool mVertical; + UI_ORIENTATION mOrientation; bool mAllowHalfSliderOut; bool mExpandBackground; UIControlAnim * mBackSlider; diff --git a/src/eepp/ui/uiscrollbar.cpp b/src/eepp/ui/uiscrollbar.cpp index 1a4e30848..0d4adafbb 100644 --- a/src/eepp/ui/uiscrollbar.cpp +++ b/src/eepp/ui/uiscrollbar.cpp @@ -229,7 +229,7 @@ const Float& UIScrollBar::getClickStep() const { return mSlider->getClickStep(); } -const bool& UIScrollBar::isVertical() const { +bool UIScrollBar::isVertical() const { return mSlider->isVertical(); } diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 67f824b42..37d9404c9 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -6,7 +6,7 @@ namespace EE { namespace UI { UISlider::UISlider( const UISlider::CreateParams& Params ) : UIComplexControl( Params ), - mVertical( Params.VerticalSlider ), + mOrientation( Params.VerticalSlider ? UI_VERTICAL : UI_HORIZONTAL ), mAllowHalfSliderOut( Params.AllowHalfSliderOut ), mExpandBackground( Params.ExpandBackground ), mBackSlider( NULL ), @@ -20,7 +20,7 @@ UISlider::UISlider( const UISlider::CreateParams& Params ) : UIControl::CreateParams BgParams; BgParams.setParent( this ); - if ( !mVertical ) + if ( !mOrientation ) BgParams.Size = Sizei( mSize.getWidth() - 16, 8 ); else BgParams.Size = Sizei( 8, mSize.getHeight() - 16 ); @@ -40,7 +40,7 @@ UISlider::UISlider( const UISlider::CreateParams& Params ) : mSlider->setVisible( true ); mSlider->setDragEnabled( true ); - if ( !mVertical ) + if ( !mOrientation ) mSlider->centerVertical(); else mSlider->centerHorizontal(); @@ -50,7 +50,7 @@ UISlider::UISlider( const UISlider::CreateParams& Params ) : UISlider::UISlider() : UIComplexControl(), - mVertical( true ), + mOrientation( UI_VERTICAL ), mAllowHalfSliderOut( false ), mExpandBackground( false ), mBackSlider( NULL ), @@ -63,7 +63,7 @@ UISlider::UISlider() : { Sizei bgSize; - if ( !mVertical ) + if ( UI_HORIZONTAL == mOrientation ) bgSize = dpToPxI( Sizei( mSize.getWidth() - 16, 8 ) ); else bgSize = dpToPxI( Sizei( 8, mSize.getHeight() - 16 ) ); @@ -83,7 +83,7 @@ UISlider::UISlider() : mSlider->setSize( dpToPxI( 16 ), dpToPxI( 16 ) ); mSlider->setPosition( 0, 0 ); - if ( !mVertical ) + if ( UI_HORIZONTAL == mOrientation ) mSlider->centerVertical(); else mSlider->centerHorizontal(); @@ -103,7 +103,7 @@ bool UISlider::isType( const Uint32& type ) const { } void UISlider::setTheme( UITheme * Theme ) { - if ( !mVertical ) { + if ( UI_HORIZONTAL == mOrientation ) { UIControl::setThemeControl( Theme, "hslider" ); mBackSlider->setThemeControl( Theme, "hslider_bg" ); @@ -133,7 +133,7 @@ void UISlider::adjustChilds() { if ( NULL != tSkin ) { mSlider->setPixelsSize( tSkin->getSize() ); - if ( !mVertical ) + if ( UI_HORIZONTAL == mOrientation ) mSlider->centerVertical(); else mSlider->centerHorizontal(); @@ -142,7 +142,7 @@ void UISlider::adjustChilds() { tSkin = mBackSlider->getSkin(); if ( NULL != tSkin ) { - if ( !mVertical ) { + if ( UI_HORIZONTAL == mOrientation ) { Int32 Height; if ( mExpandBackground ) @@ -178,7 +178,7 @@ void UISlider::fixSliderPos() { if ( !mOnPosChange ) { mOnPosChange = true; - if ( !mVertical ) { + if ( UI_HORIZONTAL == mOrientation ) { mSlider->setPosition( mSlider->getPosition().x, 0 ); if ( mSlider->getPosition().x < 0 ) @@ -237,7 +237,7 @@ void UISlider::setValue( Float Val ) { mOnPosChange = true; - if ( !mVertical ) { + if ( UI_HORIZONTAL == mOrientation ) { if ( mAllowHalfSliderOut ) mSlider->setPosition( (Int32)( (Float)mBackSlider->getSize().getWidth() * Percent ), mSlider->getPosition().y ); else @@ -294,8 +294,8 @@ const Float& UISlider::getClickStep() const { return mClickStep; } -const bool& UISlider::isVertical() const { - return mVertical; +bool UISlider::isVertical() const { + return mOrientation == UI_VERTICAL; } void UISlider::update() { @@ -336,7 +336,7 @@ void UISlider::manageClick( const Uint32& Flags ) { mSlider->worldToControl( ControlPos ); if ( Flags & EE_BUTTON_LMASK && !mSlider->isMouseOver() ) { - if ( !mVertical ) { + if ( UI_HORIZONTAL == mOrientation ) { if ( ControlPos.x < 0 ) setValue( mValue - mClickStep ); else @@ -356,6 +356,53 @@ void UISlider::manageClick( const Uint32& Flags ) { } } +UI_ORIENTATION UISlider::getOrientation() const { + return mOrientation; +} + +void UISlider::setOrientation( const UI_ORIENTATION & orientation ) { + mOrientation = orientation; + + Sizei bgSize; + + if ( UI_HORIZONTAL == mOrientation ) + bgSize = dpToPxI( Sizei( mSize.getWidth() - 16, 8 ) ); + else + bgSize = dpToPxI( Sizei( 8, mSize.getHeight() - 16 ) ); + + mBackSlider->setSize( bgSize ); + + applyDefaultTheme(); +} + +bool UISlider::getAllowHalfSliderOut() const +{ + return mAllowHalfSliderOut; +} + +void UISlider::setAllowHalfSliderOut( bool allowHalfSliderOut ) +{ + mAllowHalfSliderOut = allowHalfSliderOut; + + adjustChilds(); + + setValue( mValue ); +} + +bool UISlider::getExpandBackground() const +{ + return mExpandBackground; +} + +void UISlider::setExpandBackground( bool expandBackground ) +{ + mExpandBackground = expandBackground; + + adjustChilds(); + + setValue( mValue ); +} + UIControl * UISlider::getBackSlider() const { return mBackSlider; } diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 0a05de9c2..1f9972dec 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -617,9 +617,19 @@ void EETest::createUI() { UISlider * slider = eeNew( UISlider, () ); slider->setPosition( 50, 100 ); - slider->setSize( 16, 100 ); + slider->setSize( 100, 100 ); slider->setVisible( true ); slider->setEnabled( true ); + slider->setOrientation( UI_HORIZONTAL ); + slider->setAllowHalfSliderOut( true ); + + UISlider * slider2 = eeNew( UISlider, () ); + slider2->setPosition( 50, 25 ); + slider2->setSize( 100, 100 ); + slider2->setVisible( true ); + slider2->setEnabled( true ); + slider2->setOrientation( UI_VERTICAL ); + slider2->setAllowHalfSliderOut( true ); UITextInput * textInput = eeNew( UITextInput, () ); textInput->setPosition( 50, 210 );