From 7fa61de408b54aa7225c15cc417838c16d88acd6 Mon Sep 17 00:00:00 2001 From: spartanj Date: Mon, 11 Oct 2010 03:34:05 -0300 Subject: [PATCH] Added cUISlider ( horizontal and vertical ). Fixed some critical bugs on the UI. --- src/ee.h | 1 + src/test/ee.cpp | 39 ++++++- src/ui/cuicontrol.cpp | 29 +++-- src/ui/cuicontrol.hpp | 2 + src/ui/cuidragable.cpp | 4 +- src/ui/cuimanager.cpp | 8 ++ src/ui/cuimanager.hpp | 4 + src/ui/cuipushbutton.hpp | 4 +- src/ui/cuiradiobutton.cpp | 13 ++- src/ui/cuiskincomplex.cpp | 14 ++- src/ui/cuislider.cpp | 223 +++++++++++++++++++++++++++++++++++++ src/ui/cuislider.hpp | 69 ++++++++++++ src/ui/cuisliderbutton.cpp | 21 ++++ src/ui/cuisliderbutton.hpp | 19 ++++ src/ui/cuitextinput.cpp | 2 +- src/ui/uihelper.hpp | 47 ++++---- 16 files changed, 458 insertions(+), 41 deletions(-) create mode 100644 src/ui/cuislider.cpp create mode 100644 src/ui/cuislider.hpp create mode 100644 src/ui/cuisliderbutton.cpp create mode 100644 src/ui/cuisliderbutton.hpp diff --git a/src/ee.h b/src/ee.h index 973b14610..78afad2a1 100755 --- a/src/ee.h +++ b/src/ee.h @@ -155,5 +155,6 @@ #include "ui/cuipushbutton.hpp" #include "ui/cuicheckbox.hpp" #include "ui/cuiradiobutton.hpp" + #include "ui/cuislider.hpp" using namespace EE::UI; #endif diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 2c2c3df63..a228eac25 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -357,7 +357,7 @@ void cEETest::CreateUI() { C->Enabled( true ); C->Pos( 320, 240 ); C->DragEnable( true ); - C->StartRotation( 0.f, 360.f, 2500.f ); + //C->StartRotation( 0.f, 360.f, 2500.f ); Params.Flags &= ~UI_CLIP_ENABLE; Params.Background.Corners(0); @@ -444,12 +444,28 @@ void cEETest::CreateUI() { TextParams.PosSet( 120, 60 ); RadioButton = eeNew( cUIRadioButton, ( TextParams ) ); RadioButton->Visible( true ); - RadioButton->Text( L"Check Me" ); + RadioButton->Text( L"Check Me 2" ); RadioButton->Enabled( true ); + cUISlider::CreateParams SliderParams; + SliderParams.Parent( C ); + SliderParams.PosSet( 220, 80 ); + SliderParams.Size = eeSize( 80, 24 ); + cUISlider * mSlider = eeNew( cUISlider, ( SliderParams ) ); + mSlider->Visible( true ); + mSlider->Enabled( true ); + + SliderParams.PosSet( 60, 120 ); + SliderParams.Size = eeSize( 24, 80 ); + SliderParams.VerticalSlider = true; + mSlider = eeNew( cUISlider, ( SliderParams ) ); + mSlider->Visible( true ); + mSlider->Enabled( true ); + mBuda = L"El mono ve el pez en el agua y sufre. Piensa que su mundo es el único que existe, el mejor, el real. Sufre porque es bueno y tiene compasión, lo ve y piensa: \"Pobre se está ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salvé. Pero el pez se retuerce de dolor y muere. Por eso te mostré el sueño, es imposible meter el mar en tu cabeza, que es un balde.\nPowered by Text Shrinker =)"; TTF->ShrinkText( mBuda, 400 ); + /** Replace this with the texture atlas and an auto theme loader */ cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal.png" ), "aqua_textinput_normal" ) ) ); cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_focus.png" ), "aqua_textinput_focus" ) ) ); cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_textinput_normal_dl.png" ), "aqua_textinput_normal_dl" ) ) ); @@ -469,6 +485,16 @@ void cEETest::CreateUI() { cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_radiobutton_active_normal.png" ), "aqua_radiobutton_active_normal" ) ) ); cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_radiobutton_inactive_menter.png" ), "aqua_radiobutton_inactive_menter" ) ) ); cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_radiobutton_inactive_normal.png" ), "aqua_radiobutton_inactive_normal" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_button_normal.png" ), "aqua_hslider_button_normal" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_button_menter.png" ), "aqua_hslider_button_menter" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_bg_normal_m.png" ), "aqua_hslider_bg_normal_m" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_bg_normal_ml.png" ), "aqua_hslider_bg_normal_ml" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_hslider_bg_normal_mr.png" ), "aqua_hslider_bg_normal_mr" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_button_normal.png" ), "aqua_vslider_button_normal" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_button_menter.png" ), "aqua_vslider_button_menter" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_bg_normal_m.png" ), "aqua_vslider_bg_normal_m" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_bg_normal_u.png" ), "aqua_vslider_bg_normal_u" ) ) ); + cGlobalShapeGroup::instance()->Add( eeNew( cShape, ( TF->Load( MyPath + "data/aqua/aqua_vslider_bg_normal_d.png" ), "aqua_vslider_bg_normal_d" ) ) ); cUITheme * AquaTheme = eeNew( cUITheme, ( "aqua", "aqua" ) ); @@ -478,6 +504,10 @@ void cEETest::CreateUI() { cUISkinSimple * AquaCheckboxInactive = eeNew( cUISkinSimple, ( "aqua_checkbox_inactive" ) ); cUISkinSimple * AquaRadioButtonActive = eeNew( cUISkinSimple, ( "aqua_radiobutton_active" ) ); cUISkinSimple * AquaRadioButtonInactive = eeNew( cUISkinSimple, ( "aqua_radiobutton_inactive" ) ); + cUISkinComplex * AquaSliderBg = eeNew( cUISkinComplex, ( "aqua_hslider_bg" ) ); + cUISkinSimple * AquaSliderButton = eeNew( cUISkinSimple, ( "aqua_hslider_button" ) ); + cUISkinComplex * AquaVSliderBg = eeNew( cUISkinComplex, ( "aqua_vslider_bg" ) ); + cUISkinSimple * AquaVSliderButton = eeNew( cUISkinSimple, ( "aqua_vslider_button" ) ); AquaTextInput->SetColor ( cUISkin::StateNormal , eeColorA( 240, 240, 255, 255 ) ); AquaTextInput->SetColor ( cUISkin::StateFocus , eeColorA( 250, 250, 255, 255 ) ); @@ -490,6 +520,11 @@ void cEETest::CreateUI() { AquaTheme->Add( AquaCheckboxInactive ); AquaTheme->Add( AquaRadioButtonActive ); AquaTheme->Add( AquaRadioButtonInactive ); + AquaTheme->Add( AquaSliderBg ); + AquaTheme->Add( AquaSliderButton ); + AquaTheme->Add( AquaVSliderBg ); + AquaTheme->Add( AquaVSliderButton ); + /***************/ cUIThemeManager::instance()->Add( AquaTheme ); diff --git a/src/ui/cuicontrol.cpp b/src/ui/cuicontrol.cpp index 056c4a773..0e400ce15 100644 --- a/src/ui/cuicontrol.cpp +++ b/src/ui/cuicontrol.cpp @@ -10,7 +10,8 @@ cUIControl::cUIControl( const CreateParams& Params ) : mSize( Params.Size ), mParentCtrl( Params.ParentCtrl ), mFlags( Params.Flags ), - mData( 0xFFFFFFFF ), + mType( 0 ), + mData( 0 ), mChild( NULL ), mNext( NULL ), mBackground( Params.Background ), @@ -230,17 +231,17 @@ void cUIControl::SendCommonEvent( const Uint32& Event ) { Uint32 cUIControl::OnKeyDown( const cUIEventKey& Event ) { SendEvent( &Event ); - return 0; + return 1; } Uint32 cUIControl::OnKeyUp( const cUIEventKey& Event ) { SendEvent( &Event ); - return 0; + return 1; } Uint32 cUIControl::OnMouseMove( const eeVector2i& Pos, const Uint32 Flags ) { SendMouseEvent( cUIEvent::EventMouseMove, Pos, Flags ); - return 0; + return 1; } Uint32 cUIControl::OnMouseDown( const eeVector2i& Pos, const Uint32 Flags ) { @@ -248,7 +249,7 @@ Uint32 cUIControl::OnMouseDown( const eeVector2i& Pos, const Uint32 Flags ) { SetSkinState( cUISkin::StateMouseDown ); - return 0; + return 1; } Uint32 cUIControl::OnMouseUp( const eeVector2i& Pos, const Uint32 Flags ) { @@ -256,20 +257,26 @@ Uint32 cUIControl::OnMouseUp( const eeVector2i& Pos, const Uint32 Flags ) { SetPrevSkinState(); - return 0; + return 1; } Uint32 cUIControl::OnMouseClick( const eeVector2i& Pos, const Uint32 Flags ) { SendMouseEvent( cUIEvent::EventMouseClick, Pos, Flags ); - return 0; + return 1; +} + +bool cUIControl::IsMouseOver() { + return 0 != Read32BitKey( &mControlFlags, UI_CTRL_FLAG_MOUSEOVER_POS ); } Uint32 cUIControl::OnMouseDoubleClick( const eeVector2i& Pos, const Uint32 Flags ) { SendMouseEvent( cUIEvent::EventMouseDoubleClick, Pos, Flags ); - return 0; + return 1; } Uint32 cUIControl::OnMouseEnter( const eeVector2i& Pos, const Uint32 Flags ) { + Write32BitKey( &mControlFlags, UI_CTRL_FLAG_MOUSEOVER_POS, 1 ); + SendMouseEvent( cUIEvent::EventMouseEnter, Pos, Flags ); SetSkinState( cUISkin::StateMouseEnter ); @@ -278,6 +285,8 @@ Uint32 cUIControl::OnMouseEnter( const eeVector2i& Pos, const Uint32 Flags ) { } Uint32 cUIControl::OnMouseExit( const eeVector2i& Pos, const Uint32 Flags ) { + Write32BitKey( &mControlFlags, UI_CTRL_FLAG_MOUSEOVER_POS, 0 ); + SendMouseEvent( cUIEvent::EventMouseExit, Pos, Flags ); SetSkinState( cUISkin::StateMouseExit ); @@ -290,7 +299,7 @@ Uint32 cUIControl::OnFocus() { SetSkinState( cUISkin::StateFocus ); - return 0; + return 1; } Uint32 cUIControl::OnFocusLoss() { @@ -298,7 +307,7 @@ Uint32 cUIControl::OnFocusLoss() { SetSkinState( cUISkin::StateLostFocus ); - return 0; + return 1; } Uint32 cUIControl::HAlign() const { diff --git a/src/ui/cuicontrol.hpp b/src/ui/cuicontrol.hpp index 113d1f0eb..ffc01d64d 100644 --- a/src/ui/cuicontrol.hpp +++ b/src/ui/cuicontrol.hpp @@ -212,6 +212,8 @@ class EE_API cUIControl { void ForceThemeSkin( cUITheme * Theme, const std::string& ControlName ); cUIControl * ChildGetFirst() const; + + bool IsMouseOver(); protected: friend class cUIManager; friend class cUIDragable; diff --git a/src/ui/cuidragable.cpp b/src/ui/cuidragable.cpp index 5441975f2..a56a672d0 100644 --- a/src/ui/cuidragable.cpp +++ b/src/ui/cuidragable.cpp @@ -6,7 +6,7 @@ cUIDragable::cUIDragable( const cUIControl::CreateParams& Params ) : cUIControl( Params ), mDragEnable( false ), mDragging( false ), - mDragButton(EE_BUTTON_LEFT) + mDragButton( EE_BUTTON_LMASK ) { } @@ -62,7 +62,7 @@ void cUIDragable::Update() { return; if ( mDragging ) { - if ( !( cInput::instance()->PressTrigger() & EE_BUTTON( mDragButton ) ) ) { + if ( !( cInput::instance()->PressTrigger() & mDragButton ) ) { mDragging = false; return; } diff --git a/src/ui/cuimanager.cpp b/src/ui/cuimanager.cpp index b60fa55cf..299cf263a 100644 --- a/src/ui/cuimanager.cpp +++ b/src/ui/cuimanager.cpp @@ -179,6 +179,10 @@ const eeFloat& cUIManager::Elapsed() const { return mElapsed; } +eeVector2i cUIManager::GetMousePos() { + return mKM->GetMousePos(); +} + void cUIManager::ClipEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) { GLdouble tX = (GLdouble)x; GLdouble tY = (GLdouble)y; @@ -227,4 +231,8 @@ void cUIManager::SetTheme( cUITheme * Theme ) { } } +cInput * cUIManager::GetInput() const { + return mKM; +} + }} diff --git a/src/ui/cuimanager.hpp b/src/ui/cuimanager.hpp index 19fcb57a6..e583861ed 100644 --- a/src/ui/cuimanager.hpp +++ b/src/ui/cuimanager.hpp @@ -45,6 +45,10 @@ class EE_API cUIManager : public tSingleton { void SetTheme( const std::string& Theme ); void SetTheme( cUITheme * Theme ); + + eeVector2i GetMousePos(); + + cInput * GetInput() const; protected: cEngine * mEE; cInput * mKM; diff --git a/src/ui/cuipushbutton.hpp b/src/ui/cuipushbutton.hpp index 3024d039c..feeeab7af 100644 --- a/src/ui/cuipushbutton.hpp +++ b/src/ui/cuipushbutton.hpp @@ -1,5 +1,5 @@ -#ifndef EE_UICUIPUSHBUTTON_H -#define EE_UICUIPUSHBUTTON_H +#ifndef EE_UICUIPUSHBUTTON_HPP +#define EE_UICUIPUSHBUTTON_HPP #include "cuitextbox.hpp" diff --git a/src/ui/cuiradiobutton.cpp b/src/ui/cuiradiobutton.cpp index 99085d646..8028d8a03 100644 --- a/src/ui/cuiradiobutton.cpp +++ b/src/ui/cuiradiobutton.cpp @@ -4,6 +4,8 @@ namespace EE { namespace UI { cUIRadioButton::cUIRadioButton( const cUITextBox::CreateParams& Params ) : cUITextBox( Params ), + mActiveButton(NULL), + mInactiveButton(NULL), mActive( false ) { mType |= UI_TYPE_GET(UI_TYPE_RADIOBUTTON); @@ -21,7 +23,7 @@ cUIRadioButton::cUIRadioButton( const cUITextBox::CreateParams& Params ) : mInactiveButton = eeNew( cUIPushButton, ( ButtonParams ) ); mInactiveButton->Visible( true ); mInactiveButton->Enabled( true ); - + Padding( eeRectf(0,0,0,0) ); AutoActivate(); @@ -134,6 +136,8 @@ bool cUIRadioButton::CheckActives() { } void cUIRadioButton::AutoActivate() { + eeASSERT( NULL != mParentCtrl ); + if ( NULL != mParentCtrl ) { cUIControl * tChild = mParentCtrl->ChildGetFirst(); @@ -141,12 +145,13 @@ void cUIRadioButton::AutoActivate() { if ( tChild->Type() & UI_TYPE_GET( UI_TYPE_RADIOBUTTON ) ) { if ( tChild != this ) { cUIRadioButton * tRB = reinterpret_cast ( tChild ); - - if ( tRB->Active() ) + + if ( tRB->Active() ) { return; + } } } - + tChild = tChild->NextGet(); } } diff --git a/src/ui/cuiskincomplex.cpp b/src/ui/cuiskincomplex.cpp index 384a1248d..15eb4a9fa 100644 --- a/src/ui/cuiskincomplex.cpp +++ b/src/ui/cuiskincomplex.cpp @@ -70,6 +70,9 @@ void cUISkinComplex::Draw( const eeFloat& X, const eeFloat& Y, const eeFloat& Wi tShape->Draw( X, Y + uls.Height(), mColor[ mCurState ] ); tShape->ResetDestWidthAndHeight(); + + if ( uls.Width() == 0 ) + uls.x = tShape->RealSize().Width(); } tShape = mShape[ mCurState ][ Up ]; @@ -80,11 +83,20 @@ void cUISkinComplex::Draw( const eeFloat& X, const eeFloat& Y, const eeFloat& Wi tShape->Draw( X + uls.Width(), Y, mColor[ mCurState ] ); tShape->ResetDestWidthAndHeight(); + + if ( urs.Height() == 0 ) + urs.y = tShape->RealSize().Height(); + + if ( uls.Height() == 0 ) + uls.y = tShape->RealSize().Height(); } tShape = mShape[ mCurState ][ Right ]; if ( NULL != tShape ) { + if ( urs.Width() == 0 ) + urs.x = tShape->RealSize().Width(); + tShape->DestHeight( Height - urs.Height() - drs.Height() ); tShape->Draw( X + Width - urs.Width(), Y + urs.Height(), mColor[ mCurState ] ); @@ -129,7 +141,7 @@ void cUISkinComplex::SetSkin( const Uint32& State ) { cShape * cUISkinComplex::GetShape( const Uint32& State ) const { eeASSERT ( State < cUISkin::StateCount ); - return mShape[ State ][ 0 ]; + return mShape[ State ][ Center ]; } void cUISkinComplex::SetState( const Uint32& State ) { diff --git a/src/ui/cuislider.cpp b/src/ui/cuislider.cpp new file mode 100644 index 000000000..6eb3183a3 --- /dev/null +++ b/src/ui/cuislider.cpp @@ -0,0 +1,223 @@ +#include "cuislider.hpp" +#include "cuimanager.hpp" + +namespace EE { namespace UI { + +cUISlider::cUISlider( const cUISlider::CreateParams& Params ) : + cUIControlAnim( Params ), + mVertical( Params.VerticalSlider ), + mBackSlider( NULL ), + mSlider( NULL ), + mMinValue( 0.f ), + mMaxValue( 1.f ), + mValue( 0.f ), + mClickStep( 0.1f ), + mOnPosChange( false ) +{ + mType |= UI_TYPE_GET(UI_TYPE_SLIDER); + + cUIControl::CreateParams BgParams; + BgParams.Parent( this ); + + if ( !mVertical ) + BgParams.Size = eeSize( mSize.Width() - 16, 8 ); + else + BgParams.Size = eeSize( 8, mSize.Width() - 16 ); + + mBackSlider = eeNew( cUIControl, ( BgParams ) ); + mBackSlider->Visible( true ); + mBackSlider->Enabled( true ); + mBackSlider->Center(); + + cUIDragable::CreateParams SlideParams; + SlideParams.Parent( this ); + SlideParams.Size = eeSize( 16, 16 ); + SlideParams.PosSet( eeVector2i( 0, 0 ) ); + + mSlider = eeNew( Private::cUISliderButton, ( SlideParams ) ); + mSlider->Enabled( true ); + mSlider->Visible( true ); + mSlider->DragEnable( true ); + + if ( !mVertical ) + mSlider->CenterVertical(); + else + mSlider->CenterHorizontal(); +} + +cUISlider::~cUISlider() { +} + +void cUISlider::SetTheme( cUITheme * Theme ) { + if ( !mVertical ) { + cUIControl::SetTheme( Theme, "hslider" ); + + mBackSlider->ForceThemeSkin( Theme, "hslider_bg" ); + mSlider->ForceThemeSkin( Theme, "hslider_button" ); + } else { + cUIControl::SetTheme( Theme, "vslider" ); + + mBackSlider->ForceThemeSkin( Theme, "vslider_bg" ); + mSlider->ForceThemeSkin( Theme, "vslider_button" ); + } + + cShape * tShape = NULL; + cUISkin * tSkin = NULL; + + tSkin = mSlider->GetSkin(); + + if ( NULL != tSkin ) { + tShape = tSkin->GetShape( cUISkin::StateNormal ); + + if ( NULL != tShape ) { + mSlider->Size( tShape->RealSize() ); + + if ( !mVertical ) + mSlider->CenterVertical(); + else + mSlider->CenterHorizontal(); + } + } + + tSkin = mBackSlider->GetSkin(); + + if ( NULL != tSkin ) { + tShape = tSkin->GetShape( cUISkin::StateNormal ); + + if ( NULL != tShape ) { + if ( !mVertical ) + mBackSlider->Size( eeSize( mSize.Width() - mSlider->Size().Width(), tShape->RealSize().Height() ) ); + else + mBackSlider->Size( eeSize( tShape->RealSize().Width(), mSize.Height() - mSlider->Size().Height() ) ); + + mBackSlider->Center(); + } + } + + Value( mValue ); +} + +void cUISlider::FixSliderPos() { + if ( !mOnPosChange ) { + mOnPosChange = true; + + if ( !mVertical ) { + mSlider->Pos( mSlider->Pos().x, 0 ); + + if ( mSlider->Pos().x < 0 ) + mSlider->Pos( 0, 0 ); + + if ( mSlider->Pos().x > mBackSlider->Size().Width() ) + mSlider->Pos( mBackSlider->Size().Width(), 0 ); + + mSlider->CenterVertical(); + + Value( mMinValue + (eeFloat)mSlider->Pos().x * ( mMaxValue - mMinValue ) / (eeFloat)mBackSlider->Size().Width() ); + } else { + mSlider->Pos( 0, mSlider->Pos().y ); + + if ( mSlider->Pos().y < 0 ) + mSlider->Pos( 0, 0 ); + + if ( mSlider->Pos().y > mBackSlider->Size().Height() ) + mSlider->Pos( 0, mBackSlider->Size().Height() ); + + mSlider->CenterHorizontal(); + + Value( mMinValue + (eeFloat)mSlider->Pos().y * ( mMaxValue - mMinValue ) / (eeFloat)mBackSlider->Size().Height() ); + } + + mOnPosChange = false; + } +} + +void cUISlider::Value( const eeFloat& Val ) { + if ( Val >= mMinValue && Val <= mMaxValue ) { + mValue = Val; + + if ( !mOnPosChange ) { + if ( !mVertical ) + mSlider->Pos( mBackSlider->Size().Width() * ( Val - mMinValue ), mSlider->Pos().y ); + else + mSlider->Pos( mSlider->Pos().x, mBackSlider->Size().Height() * ( Val - mMinValue ) ); + } + } +} + +const eeFloat& cUISlider::Value() const { + return mValue; +} + +void cUISlider::MinValue( const eeFloat& MinVal ) { + mMinValue = MinVal; + + if ( mValue < mMinValue ) + mValue = mMinValue; + + FixSliderPos(); +} + +const eeFloat& cUISlider::MinValue() const { + return mMinValue; +} + +void cUISlider::MaxValue( const eeFloat& MaxVal ) { + mMaxValue = MaxVal; + + if ( mValue > mMaxValue ) + mValue = mMaxValue; + + FixSliderPos(); +} + +const eeFloat& cUISlider::MaxValue() const { + return mMaxValue; +} + +void cUISlider::ClickStep( const eeFloat& step ) { + mClickStep = step; +} + +const eeFloat& cUISlider::ClickStep() const { + return mClickStep; +} + +const bool& cUISlider::IsVertical() const { + return mVertical; +} + +void cUISlider::Update() { + cUIControlAnim::Update(); + + if ( IsMouseOver() || mBackSlider->IsMouseOver() || mSlider->IsMouseOver() ) { + ManageClick( cUIManager::instance()->GetInput()->ClickTrigger() ); + } +} + +void cUISlider::ManageClick( const Uint32& Flags ) { + if ( Flags ) { + eeVector2i ControlPos = cUIManager::instance()->GetMousePos(); + mSlider->ScreenToControl( ControlPos ); + + if ( Flags & EE_BUTTON_LMASK && !mSlider->IsMouseOver() ) { + if ( !mVertical ) { + if ( ControlPos.x < 0 ) + Value( Value() - ClickStep() ); + else + Value( Value() + ClickStep() ); + } else { + if ( ControlPos.y < 0 ) + Value( Value() - ClickStep() ); + else + Value( Value() + ClickStep() ); + } + } else if ( Flags & EE_BUTTONS_WUWD ) { + if ( Flags & EE_BUTTON( EE_BUTTON_WHEELUP ) ) + Value( Value() - ClickStep() ); + else + Value( Value() + ClickStep() ); + } + } +} + +}} diff --git a/src/ui/cuislider.hpp b/src/ui/cuislider.hpp new file mode 100644 index 000000000..fdb8c260b --- /dev/null +++ b/src/ui/cuislider.hpp @@ -0,0 +1,69 @@ +#ifndef EE_UIcUISlider_HPP +#define EE_UIcUISlider_HPP + +#include "cuicontrolanim.hpp" +#include "cuisliderbutton.hpp" + +namespace EE { namespace UI { + +class EE_API cUISlider : public cUIControlAnim { + public: + class CreateParams : public cUIControl::CreateParams { + public: + inline CreateParams() : cUIControl::CreateParams() { + VerticalSlider = false; + } + + inline ~CreateParams() {} + + bool VerticalSlider; + }; + + cUISlider( const cUISlider::CreateParams& Params ); + + ~cUISlider(); + + virtual void SetTheme( cUITheme * Theme ); + + virtual void Value( const eeFloat& Val ); + + const eeFloat& Value() const; + + virtual void MinValue( const eeFloat& MinVal ); + + const eeFloat& MinValue() const; + + virtual void MaxValue( const eeFloat& MaxVal ); + + const eeFloat& MaxValue() const; + + virtual void ClickStep( const eeFloat& step ); + + const eeFloat& ClickStep() const; + + const bool& IsVertical() const; + + virtual void Update(); + protected: + friend class Private::cUISliderButton; + + bool mVertical; + cUIControl * mBackSlider; + cUIDragable * mSlider; + eeFloat mMinValue; + eeFloat mMaxValue; + eeFloat mValue; + eeFloat mClickStep; + + bool mOnPosChange; + + void FixSliderPos(); + + void ManageClick( const Uint32& Flags ); +}; + +}} + +#endif + + diff --git a/src/ui/cuisliderbutton.cpp b/src/ui/cuisliderbutton.cpp new file mode 100644 index 000000000..86afc10da --- /dev/null +++ b/src/ui/cuisliderbutton.cpp @@ -0,0 +1,21 @@ +#include "cuisliderbutton.hpp" +#include "cuislider.hpp" + +namespace EE { namespace UI { namespace Private { + +cUISliderButton::cUISliderButton( const cUIDragable::CreateParams& Params ) : + cUIDragable( Params ) +{ +} + +cUISliderButton::~cUISliderButton() { +} + +void cUISliderButton::OnPosChange() { + cUIDragable::OnPosChange(); + + cUISlider * Slider = reinterpret_cast ( mParentCtrl ); + Slider->FixSliderPos(); +} + +}}} diff --git a/src/ui/cuisliderbutton.hpp b/src/ui/cuisliderbutton.hpp new file mode 100644 index 000000000..931810c7c --- /dev/null +++ b/src/ui/cuisliderbutton.hpp @@ -0,0 +1,19 @@ +#ifndef EE_UICUISLIDERBUTTON_HPP +#define EE_UICUISLIDERBUTTON_HPP + +#include "cuidragable.hpp" + +namespace EE { namespace UI { namespace Private { + +class cUISliderButton : public cUIDragable { + public: + cUISliderButton( const cUIDragable::CreateParams& Params ); + + ~cUISliderButton(); + protected: + virtual void OnPosChange(); +}; + +}}} + +#endif diff --git a/src/ui/cuitextinput.cpp b/src/ui/cuitextinput.cpp index 7318eee0e..4333aacc2 100644 --- a/src/ui/cuitextinput.cpp +++ b/src/ui/cuitextinput.cpp @@ -8,7 +8,7 @@ cUITextInput::cUITextInput( const cUITextInput::CreateParams& Params ) : mCursorPos(0) { mType |= UI_TYPE_GET(UI_TYPE_TEXTINPUT); - + mTextBuffer.Start(); mTextBuffer.Active( false ); mTextBuffer.SupportNewLine( Params.SupportNewLine ); diff --git a/src/ui/uihelper.hpp b/src/ui/uihelper.hpp index fb2bf7644..131140ade 100644 --- a/src/ui/uihelper.hpp +++ b/src/ui/uihelper.hpp @@ -19,28 +19,37 @@ Uint32 EE_API HAlignGet( Uint32 Flags ); Uint32 EE_API VAlignGet( Uint32 Flags ); -#define UI_CTRL_FLAG_CLOSE (1 << 0) -#define UI_CTRL_FLAG_CLOSE_FO (1 << 1) -#define UI_CTRL_FLAG_ANIM (1 << 2) +#define UI_CTRL_FLAG_CLOSE_POS (0) +#define UI_CTRL_FLAG_CLOSE (1 << UI_CTRL_FLAG_CLOSE_POS) -#define UI_TEXT_DRAW_SHADOW FONT_DRAW_SHADOW -#define UI_AUTO_SIZE (1 << 6) -#define UI_INGORE_FOCUS (1 << 7) -#define UI_FILL_BACKGROUND (1 << 8) -#define UI_BORDER (1 << 9) -#define UI_TAB_STOP (1 << 10) -#define UI_FIT_TO_CONTROL (1 << 11) -#define UI_CLIP_ENABLE (1 << 12) -#define UI_AUTO_SHRINK_TEXT (1 << 13) +#define UI_CTRL_FLAG_CLOSE_FO_POS (1) +#define UI_CTRL_FLAG_CLOSE_FO (1 << UI_CTRL_FLAG_CLOSE_FO_POS) -#define UI_TYPE_CONTROL (0) -#define UI_TYPE_CONTROL_ANIM (1) -#define UI_TYPE_GFX (2) +#define UI_CTRL_FLAG_ANIM_POS (2) +#define UI_CTRL_FLAG_ANIM (1 << UI_CTRL_FLAG_ANIM_POS) + +#define UI_CTRL_FLAG_MOUSEOVER_POS (3) +#define UI_CTRL_FLAG_MOUSEOVER (1 << UI_CTRL_FLAG_MOUSEOVER_POS) + +#define UI_TEXT_DRAW_SHADOW FONT_DRAW_SHADOW +#define UI_AUTO_SIZE (1 << 6) +#define UI_INGORE_FOCUS (1 << 7) +#define UI_FILL_BACKGROUND (1 << 8) +#define UI_BORDER (1 << 9) +#define UI_TAB_STOP (1 << 10) +#define UI_FIT_TO_CONTROL (1 << 11) +#define UI_CLIP_ENABLE (1 << 12) +#define UI_AUTO_SHRINK_TEXT (1 << 13) + +#define UI_TYPE_CONTROL (0) +#define UI_TYPE_CONTROL_ANIM (1) +#define UI_TYPE_GFX (2) #define UI_TYPE_TEXTBOX (3) -#define UI_TYPE_TEXTINPUT (4) -#define UI_TYPE_PUSHBUTTON (5) -#define UI_TYPE_CHECKBOX (6) -#define UI_TYPE_RADIOBUTTON (7) +#define UI_TYPE_TEXTINPUT (4) +#define UI_TYPE_PUSHBUTTON (5) +#define UI_TYPE_CHECKBOX (6) +#define UI_TYPE_RADIOBUTTON (7) +#define UI_TYPE_SLIDER (8) #define UI_TYPE_GET(X) ( 1 << (X) )