diff --git a/src/test/ee.cpp b/src/test/ee.cpp index db4437dcf..e9a8d3d31 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -377,8 +377,20 @@ void cEETest::CreateShaders() { void cEETest::CreateUI() { cUIManager::instance()->Init(); cUIThemeManager::instance()->DefaultFont( TTF ); - //eeSize( 530, 240 ) - cUIControl::CreateParams Params( cUIManager::instance()->MainControl(), eeVector2i(0,0), eeSize( 640, 480 ), UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER ); + + cUIControl::CreateParams Params( cUIManager::instance()->MainControl(), eeVector2i(0,0), eeSize( 530, 240 ), UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER ); + + + cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); + + CreateAquaTextureAtlas(); + + cTextureGroupLoader tgl( MyPath + "data/aqua.etg" ); + TF->GetByName( "data/aqua.png" )->TextureFilter( TEX_FILTER_NEAREST ); + cUIThemeManager::instance()->Add( cUITheme::LoadFromShapeGroup( cShapeGroupManager::instance()->GetByName( "aqua" ), "aqua", "aqua" ) ); + + //cUIManager::instance()->SetTheme( "aqua" ); + cUIManager::instance()->DefaultTheme( "aqua" ); Params.Border.Width( 2 ); Params.Border.Color( 0xFF979797 ); @@ -442,9 +454,8 @@ void cEETest::CreateUI() { InputParams.Background.Colors( eeColorA(0x99AAAAAA), eeColorA(0x99CCCCCC), eeColorA(0x99CCCCCC), eeColorA(0x99AAAAAA) ); InputParams.PosSet( 20, 216 ); InputParams.Size = eeSize( 200, 22 ); - InputParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT | UI_CLIP_ENABLE; // | UI_BORDER | UI_FILL_BACKGROUND + InputParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT | UI_CLIP_ENABLE | UI_AUTO_PADDING; cUITextInput * Input = eeNew( cUITextInput, ( InputParams ) ); - Input->Padding( eeRectf( 4, -2, 8, 0 ) ); Input->Visible( true ); Input->Enabled( true ); @@ -458,7 +469,6 @@ void cEETest::CreateUI() { Button->Visible( true ); Button->Enabled( true ); Button->Text( L"Click Me" ); - Button->Padding( eeRectf( 0, -1, 0, 0 ) ); Button->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cEETest::ButtonClick ) ); TextParams.PosSet( 120, 20 ); @@ -510,7 +520,6 @@ void cEETest::CreateUI() { cUISpinBox * mSpinBox = eeNew( cUISpinBox, ( SpinBoxParams ) ); mSpinBox->Visible( true ); mSpinBox->Enabled( true ); - mSpinBox->Padding( eeRectf( 3, -1, 0, 0 ) ); cUIScrollBar::CreateParams ScrollBarP; ScrollBarP.Parent( C ); @@ -531,7 +540,6 @@ void cEETest::CreateUI() { mProgressBar = eeNew( cUIProgressBar, ( PBParams ) ); mProgressBar->Visible( true ); mProgressBar->Enabled( true ); - mProgressBar->TextBox()->Padding( eeRectf( 0, -1, 0, 0 ) ); TextParams.PosSet( 20, 5 ); mTextBoxValue = eeNew( cUITextBox, ( TextParams ) ); @@ -541,30 +549,18 @@ void cEETest::CreateUI() { LBParams.Parent( C ); LBParams.PosSet( 325, 8 ); LBParams.Size = eeSize( 200, 240-16 ); - LBParams.Flags = UI_CLIP_ENABLE | UI_MULTI_SELECT; - LBParams.PaddingContainer = eeRecti( 2, 2, 2, 2 ); + LBParams.Flags = UI_CLIP_ENABLE | UI_MULTI_SELECT | UI_AUTO_PADDING; LBParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 ); mListBox = eeNew( cUIListBox, ( LBParams ) ); mListBox->Visible( true ); mListBox->Enabled( true ); - for ( Int32 i = 1; i <= 15; i++ ) + for ( Int32 i = 1; i <= 25; i++ ) mListBox->AddListBoxItem( L"Test ListBox " + toWStr(i) + L" testing it right now!" ); 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."; TTFB->ShrinkText( mBuda, 400 ); - cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); - - CreateAquaTextureAtlas(); - - cTextureGroupLoader tgl( MyPath + "data/aqua.etg" ); - TF->GetByName( "data/aqua.png" )->TextureFilter( TEX_FILTER_NEAREST ); - cUIThemeManager::instance()->Add( cUITheme::LoadFromShapeGroup( cShapeGroupManager::instance()->GetByName( "aqua" ), "aqua", "aqua" ) ); - - - cUIManager::instance()->SetTheme( "aqua" ); - mBudaTC.Create( TTFB, mBuda, eeColorA(255,255,255,255) ); mEEText.Create( TTFB, L"Entropia Engine++\nCTRL + 1 = Screen 1 - CTRL + 2 = Screen 2\nCTRL + 3 = Screen 3" ); mFBOText.Create( TTFB, L"This is a VBO\nInside of a FBO" ); diff --git a/src/ui/cuicheckbox.cpp b/src/ui/cuicheckbox.cpp index 31569d262..da94cb47d 100644 --- a/src/ui/cuicheckbox.cpp +++ b/src/ui/cuicheckbox.cpp @@ -22,7 +22,9 @@ cUICheckBox::cUICheckBox( const cUITextBox::CreateParams& Params ) : mInactiveButton->Visible( true ); mInactiveButton->Enabled( true ); - Padding( eeRectf(0,0,0,0) ); + Padding( eeRecti(0,0,0,0) ); + + ApplyDefaultTheme(); } cUICheckBox::~cUICheckBox() { @@ -57,12 +59,12 @@ void cUICheckBox::SetTheme( cUITheme * Theme ) { } } - Padding( eeRectf(0,0,0,0) ); + Padding( eeRecti(0,0,0,0) ); } void cUICheckBox::OnSizeChange() { cUITextBox::OnSizeChange(); - + mActiveButton->CenterVertical(); mInactiveButton->CenterVertical(); } @@ -96,7 +98,7 @@ void cUICheckBox::Active( const bool& active ) { mActive = true; } - + OnValueChange(); } @@ -108,7 +110,7 @@ const bool& cUICheckBox::IsActive() const { return Active(); } -void cUICheckBox::Padding( const eeRectf& padding ) { +void cUICheckBox::Padding( const eeRecti& padding ) { mPadding = padding; mPadding.Left = mPadding.Left + mActiveButton->Size().Width(); } diff --git a/src/ui/cuicheckbox.hpp b/src/ui/cuicheckbox.hpp index ded3547a9..6b909303c 100644 --- a/src/ui/cuicheckbox.hpp +++ b/src/ui/cuicheckbox.hpp @@ -22,18 +22,18 @@ class EE_API cUICheckBox : public cUITextBox { const bool& Active() const; - virtual void Padding( const eeRectf& padding ); - + virtual void Padding( const eeRecti& padding ); + cUIControlAnim * ActiveButton() const; - + cUIControlAnim * InactiveButton() const; protected: cUIControlAnim * mActiveButton; cUIControlAnim * mInactiveButton; bool mActive; - + virtual void OnSizeChange(); - + void SwitchState(); }; diff --git a/src/ui/cuicontrol.cpp b/src/ui/cuicontrol.cpp index 6d702621a..c3a20a3ec 100644 --- a/src/ui/cuicontrol.cpp +++ b/src/ui/cuicontrol.cpp @@ -891,4 +891,52 @@ void cUIControl::WriteCtrlFlag( const Uint32& Pos, const Uint32& Val ) { Write32BitKey( &mControlFlags, Pos, Val ); } +void cUIControl::ApplyDefaultTheme() { + cUIManager::instance()->ApplyDefaultTheme( this ); +} + +eeRecti cUIControl::MakePadding( bool PadLeft, bool PadRight, bool PadTop, bool PadBottom ) { + eeRecti tPadding( 0, 0, 0, 0 ); + + if ( mFlags & UI_AUTO_PADDING ) { + if ( NULL != mSkinState && NULL != mSkinState->GetSkin() ) { + if ( mSkinState->GetSkin()->GetType() == cUISkin::UISkinComplex ) { + cUISkinComplex * tComplex = reinterpret_cast ( mSkinState->GetSkin() ); + + cShape * tShape = NULL; + + if ( PadLeft ) { + tShape = tComplex->GetShapeSide( cUISkinState::StateNormal, cUISkinComplex::Left ); + + if ( NULL != tShape ) + tPadding.Left = tShape->RealSize().Width(); + } + + if ( PadRight ) { + tShape = tComplex->GetShapeSide( cUISkinState::StateNormal, cUISkinComplex::Right ); + + if ( NULL != tShape ) + tPadding.Right = tShape->RealSize().Width(); + } + + if ( PadTop ) { + tShape = tComplex->GetShapeSide( cUISkinState::StateNormal, cUISkinComplex::Up ); + + if ( NULL != tShape ) + tPadding.Top = tShape->RealSize().Height(); + } + + if ( PadBottom ) { + tShape = tComplex->GetShapeSide( cUISkinState::StateNormal, cUISkinComplex::Down ); + + if ( NULL != tShape ) + tPadding.Bottom = tShape->RealSize().Height(); + } + } + } + } + + return tPadding; +} + }} diff --git a/src/ui/cuicontrol.hpp b/src/ui/cuicontrol.hpp index d2aa71c0a..23cbb7a71 100644 --- a/src/ui/cuicontrol.hpp +++ b/src/ui/cuicontrol.hpp @@ -11,6 +11,8 @@ #include "cuieventmouse.hpp" #include "cuiskin.hpp" #include "cuiskinstate.hpp" +#include "cuiskinsimple.hpp" +#include "cuiskincomplex.hpp" #include "cuitheme.hpp" #include "cuithememanager.hpp" @@ -319,6 +321,10 @@ class EE_API cUIControl { void UpdateChildsScreenPos(); void WriteCtrlFlag( const Uint32& Pos, const Uint32& Val ); + + void ApplyDefaultTheme(); + + eeRecti MakePadding( bool PadLeft = true, bool PadRight = true, bool PadTop = true, bool PadBottom = true ); }; }} diff --git a/src/ui/cuilistbox.cpp b/src/ui/cuilistbox.cpp index d29842a4b..516fd6779 100644 --- a/src/ui/cuilistbox.cpp +++ b/src/ui/cuilistbox.cpp @@ -61,6 +61,8 @@ cUIListBox::cUIListBox( cUIListBox::CreateParams& Params ) : mHScrollBar->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIListBox::OnHScrollValueChange ) ); SetRowHeight(); + + ApplyDefaultTheme(); } cUIListBox::~cUIListBox() { @@ -69,9 +71,17 @@ cUIListBox::~cUIListBox() { void cUIListBox::SetTheme( cUITheme * Theme ) { cUIControl::SetTheme( Theme, "listbox" ); + AutoPadding(); + OnSizeChange(); } +void cUIListBox::AutoPadding() { + if ( mFlags & UI_AUTO_PADDING ) { + mPaddingContainer = MakePadding(); + } +} + cUIScrollBar * cUIListBox::ScrollBar() const { return mScrollBar; } @@ -280,6 +290,8 @@ void cUIListBox::ItemUpdateSize( cUIListBoxItem * Item ) { } void cUIListBox::ContainerResize() { + mContainer->Pos( mPaddingContainer.Left, mPaddingContainer.Top ); + if( mHScrollBar->Visible() ) mContainer->Size( mSize.Width() - mPaddingContainer.Right - mPaddingContainer.Left, mSize.Height() - mPaddingContainer.Top - mPaddingContainer.Bottom - mHScrollBar->Size().Height() ); else diff --git a/src/ui/cuilistbox.hpp b/src/ui/cuilistbox.hpp index 88c1be8ee..40c317635 100644 --- a/src/ui/cuilistbox.hpp +++ b/src/ui/cuilistbox.hpp @@ -161,6 +161,8 @@ class EE_API cUIListBox : public cUIControlAnim { void ContainerResize(); void ItemUpdateSize( cUIListBoxItem * Item ); + + void AutoPadding(); }; }} diff --git a/src/ui/cuilistboxitem.cpp b/src/ui/cuilistboxitem.cpp index 0c01c9bfd..5088b0a11 100644 --- a/src/ui/cuilistboxitem.cpp +++ b/src/ui/cuilistboxitem.cpp @@ -9,6 +9,8 @@ cUIListBoxItem::cUIListBoxItem( cUITextBox::CreateParams& Params ) : mSelected( false ) { mType |= UI_TYPE_LISTBOXITEM; + + ApplyDefaultTheme(); } cUIListBoxItem::~cUIListBoxItem() { diff --git a/src/ui/cuimanager.cpp b/src/ui/cuimanager.cpp index 937dc7a1f..92097c8f1 100644 --- a/src/ui/cuimanager.cpp +++ b/src/ui/cuimanager.cpp @@ -11,7 +11,9 @@ cUIManager::cUIManager() : mOverControl( NULL ), mDownControl( NULL ), mFirstPress( false ), - mCbId(-1) + mCbId(-1), + mThemeDefault( NULL ), + mAutoApplyDefaultTheme( true ) { mEE = cEngine::instance(); mKM = cInput::instance(); @@ -250,4 +252,29 @@ cInput * cUIManager::GetInput() const { return mKM; } +void cUIManager::DefaultTheme( cUITheme * Theme ) { + mThemeDefault = Theme; +} + +void cUIManager::DefaultTheme( const std::string& Theme ) { + DefaultTheme( cUIThemeManager::instance()->GetByName( Theme ) ); +} + +cUITheme * cUIManager::DefaultTheme() const { + return mThemeDefault; +} + +void cUIManager::ApplyDefaultTheme( cUIControl * Control ) { + if ( mAutoApplyDefaultTheme && NULL != mThemeDefault && NULL != Control ) + Control->SetTheme( mThemeDefault ); +} + +void cUIManager::AutoApplyDefaultTheme( const bool& apply ) { + mAutoApplyDefaultTheme = apply; +} + +const bool& cUIManager::AutoApplyDefaultTheme() const { + return mAutoApplyDefaultTheme; +} + }} diff --git a/src/ui/cuimanager.hpp b/src/ui/cuimanager.hpp index e96135623..ce954d83f 100644 --- a/src/ui/cuimanager.hpp +++ b/src/ui/cuimanager.hpp @@ -49,6 +49,18 @@ class EE_API cUIManager : public tSingleton { eeVector2i GetMousePos(); cInput * GetInput() const; + + void DefaultTheme( cUITheme * Theme ); + + void DefaultTheme( const std::string& Theme ); + + cUITheme * DefaultTheme() const; + + void ApplyDefaultTheme( cUIControl * Control ); + + void AutoApplyDefaultTheme( const bool& apply ); + + const bool& AutoApplyDefaultTheme() const; protected: cEngine * mEE; cInput * mKM; @@ -64,6 +76,9 @@ class EE_API cUIManager : public tSingleton { Int32 mCbId; + cUITheme * mThemeDefault; + bool mAutoApplyDefaultTheme; + void InputCallback( EE_Event * Event ); void SendKeyUp( EE_Event * Event ); void SendKeyDown( EE_Event * Event ); diff --git a/src/ui/cuiprogressbar.cpp b/src/ui/cuiprogressbar.cpp index 531c03940..4950d47b7 100644 --- a/src/ui/cuiprogressbar.cpp +++ b/src/ui/cuiprogressbar.cpp @@ -13,7 +13,7 @@ cUIProgressBar::cUIProgressBar( const cUIProgressBar::CreateParams& Params ) : mParallax( NULL ) { mType |= UI_TYPE_GET(UI_TYPE_PROGRESSBAR); - + cUITextBox::CreateParams TxtBoxParams = Params; TxtBoxParams.Parent( this ); @@ -24,6 +24,8 @@ cUIProgressBar::cUIProgressBar( const cUIProgressBar::CreateParams& Params ) : mTextBox->Enabled( false ); UpdateTextBox(); + + ApplyDefaultTheme(); } cUIProgressBar::~cUIProgressBar() { diff --git a/src/ui/cuipushbutton.cpp b/src/ui/cuipushbutton.cpp index 0af7d7904..6489f0530 100644 --- a/src/ui/cuipushbutton.cpp +++ b/src/ui/cuipushbutton.cpp @@ -28,6 +28,8 @@ cUIPushButton::cUIPushButton( const cUIPushButton::CreateParams& Params ) : mTextBox->Enabled( false ); OnSizeChange(); + + ApplyDefaultTheme(); } void cUIPushButton::OnSizeChange() { @@ -42,6 +44,14 @@ cUIPushButton::~cUIPushButton() { void cUIPushButton::SetTheme( cUITheme * Theme ) { cUIControl::SetTheme( Theme, "button" ); + + AutoPadding(); +} + +void cUIPushButton::AutoPadding() { + if ( mFlags & UI_AUTO_PADDING ) { + Padding( MakePadding( true, false, true, false ) ); + } } void cUIPushButton::Icon( cShape * Icon ) { @@ -64,11 +74,11 @@ void cUIPushButton::Text( const std::string& text ) { OnSizeChange(); } -void cUIPushButton::Padding( const eeRectf& padding ) { +void cUIPushButton::Padding( const eeRecti& padding ) { mTextBox->Padding( padding ); } -const eeRectf& cUIPushButton::Padding() const { +const eeRecti& cUIPushButton::Padding() const { return mTextBox->Padding(); } diff --git a/src/ui/cuipushbutton.hpp b/src/ui/cuipushbutton.hpp index 5211f3b02..f58c879eb 100644 --- a/src/ui/cuipushbutton.hpp +++ b/src/ui/cuipushbutton.hpp @@ -45,9 +45,9 @@ class EE_API cUIPushButton : public cUIControlAnim { void Text( const std::string& text ); - void Padding( const eeRectf& padding ); + void Padding( const eeRecti& padding ); - const eeRectf& Padding() const; + const eeRecti& Padding() const; void IconHorizontalMargin( Int32 margin ); @@ -60,6 +60,8 @@ class EE_API cUIPushButton : public cUIControlAnim { Int32 mIconSpace; virtual void OnSizeChange(); + + void AutoPadding(); }; }} diff --git a/src/ui/cuiradiobutton.cpp b/src/ui/cuiradiobutton.cpp index 06aaafb03..3522b55f5 100644 --- a/src/ui/cuiradiobutton.cpp +++ b/src/ui/cuiradiobutton.cpp @@ -23,10 +23,12 @@ cUIRadioButton::cUIRadioButton( const cUITextBox::CreateParams& Params ) : mInactiveButton = eeNew( cUIControlAnim, ( ButtonParams ) ); mInactiveButton->Visible( true ); mInactiveButton->Enabled( true ); - - Padding( eeRectf(0,0,0,0) ); + + Padding( eeRecti(0,0,0,0) ); AutoActivate(); + + ApplyDefaultTheme(); } cUIRadioButton::~cUIRadioButton() { @@ -61,12 +63,12 @@ void cUIRadioButton::SetTheme( cUITheme * Theme ) { } } - Padding( eeRectf(0,0,0,0) ); + Padding( eeRecti(0,0,0,0) ); } void cUIRadioButton::OnSizeChange() { cUITextBox::OnSizeChange(); - + mActiveButton->CenterVertical(); mInactiveButton->CenterVertical(); } @@ -95,7 +97,7 @@ void cUIRadioButton::Active( const bool& active ) { mInactiveButton->Visible( true ); mActive = false; - + OnValueChange(); } } else { @@ -103,7 +105,7 @@ void cUIRadioButton::Active( const bool& active ) { mInactiveButton->Visible( false ); mActive = true; - + OnValueChange(); } @@ -148,7 +150,7 @@ bool cUIRadioButton::CheckActives() { void cUIRadioButton::AutoActivate() { eeASSERT( NULL != mParentCtrl ); - + if ( NULL != mParentCtrl ) { cUIControl * tChild = mParentCtrl->ChildGetFirst(); @@ -156,13 +158,13 @@ void cUIRadioButton::AutoActivate() { if ( tChild->IsType( UI_TYPE_RADIOBUTTON ) ) { if ( tChild != this ) { cUIRadioButton * tRB = reinterpret_cast ( tChild ); - + if ( tRB->Active() ) { return; } } } - + tChild = tChild->NextGet(); } } @@ -178,7 +180,7 @@ const bool& cUIRadioButton::IsActive() const { return Active(); } -void cUIRadioButton::Padding( const eeRectf& padding ) { +void cUIRadioButton::Padding( const eeRecti& padding ) { mPadding = padding; mPadding.Left = mPadding.Left + mActiveButton->Size().Width(); } diff --git a/src/ui/cuiradiobutton.hpp b/src/ui/cuiradiobutton.hpp index 93aec1cbf..dbcdf93c4 100644 --- a/src/ui/cuiradiobutton.hpp +++ b/src/ui/cuiradiobutton.hpp @@ -22,16 +22,16 @@ class EE_API cUIRadioButton : public cUITextBox { const bool& Active() const; - virtual void Padding( const eeRectf& padding ); - + virtual void Padding( const eeRecti& padding ); + cUIControlAnim * ActiveButton() const; - + cUIControlAnim * InactiveButton() const; protected: cUIControlAnim * mActiveButton; cUIControlAnim * mInactiveButton; bool mActive; - + virtual void OnSizeChange(); void SwitchState(); diff --git a/src/ui/cuiscrollbar.cpp b/src/ui/cuiscrollbar.cpp index de25dd1a1..66f73953b 100644 --- a/src/ui/cuiscrollbar.cpp +++ b/src/ui/cuiscrollbar.cpp @@ -39,6 +39,8 @@ cUIScrollBar::cUIScrollBar( const cUIScrollBar::CreateParams& Params ) : mSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIScrollBar::OnValueChangeCb ) ); AdjustChilds(); + + ApplyDefaultTheme(); } cUIScrollBar::~cUIScrollBar() { diff --git a/src/ui/cuiskincomplex.cpp b/src/ui/cuiskincomplex.cpp index 478fbcaff..ce29715bb 100644 --- a/src/ui/cuiskincomplex.cpp +++ b/src/ui/cuiskincomplex.cpp @@ -150,6 +150,12 @@ cShape * cUISkinComplex::GetShape( const Uint32& State ) const { return mShape[ State ][ Center ]; } +cShape * cUISkinComplex::GetShapeSide( const Uint32& State, const Uint32& Side ) { + eeASSERT ( State < cUISkinState::StateCount && Side < cUISkinComplex::SideCount ); + + return mShape[ State ][ Side ]; +} + void cUISkinComplex::StateNormalToState( const Uint32& State ) { if ( NULL == mShape[ State ][ 0 ] ) { for ( Uint32 Side = 0; Side < SideCount; Side++ ) { diff --git a/src/ui/cuiskincomplex.hpp b/src/ui/cuiskincomplex.hpp index 328f8db09..e5d70a7f2 100644 --- a/src/ui/cuiskincomplex.hpp +++ b/src/ui/cuiskincomplex.hpp @@ -33,6 +33,8 @@ class EE_API cUISkinComplex : public cUISkin { cShape * GetShape( const Uint32& State ) const; + cShape * GetShapeSide( const Uint32& State, const Uint32& Side ); + cUISkinComplex * Copy( const std::string& NewName, const bool& CopyColorsState = true ); virtual cUISkin * Copy(); diff --git a/src/ui/cuislider.cpp b/src/ui/cuislider.cpp index 1d17d1dad..15ebae295 100644 --- a/src/ui/cuislider.cpp +++ b/src/ui/cuislider.cpp @@ -45,6 +45,8 @@ cUISlider::cUISlider( const cUISlider::CreateParams& Params ) : mSlider->CenterVertical(); else mSlider->CenterHorizontal(); + + ApplyDefaultTheme(); } cUISlider::~cUISlider() { @@ -62,7 +64,7 @@ void cUISlider::SetTheme( cUITheme * Theme ) { mBackSlider->ForceThemeSkin( Theme, "vslider_bg" ); mSlider->ForceThemeSkin( Theme, "vslider_button" ); } - + AdjustChilds(); Value( mValue ); @@ -99,30 +101,30 @@ void cUISlider::AdjustChilds() { if ( NULL != tShape ) { if ( !mVertical ) { Int32 Height; - + if ( mExpandBackground ) Height = mSize.Height(); else Height = tShape->RealSize().Height(); - + if ( mAllowHalfSliderOut ) mBackSlider->Size( eeSize( mSize.Width() - mSlider->Size().Width(), Height ) ); else mBackSlider->Size( eeSize( mSize.Width(), Height ) ); } else { Int32 Width; - + if ( mExpandBackground ) Width = mSize.Width(); else Width = tShape->RealSize().Width(); - + if ( mAllowHalfSliderOut ) mBackSlider->Size( eeSize( Width, mSize.Height() - mSlider->Size().Height() ) ); else mBackSlider->Size( eeSize( Width, mSize.Height() ) ); } - + mBackSlider->Center(); } } @@ -137,7 +139,7 @@ void cUISlider::FixSliderPos() { if ( mSlider->Pos().x < 0 ) mSlider->Pos( 0, 0 ); - + if ( mAllowHalfSliderOut ) { if ( mSlider->Pos().x > mBackSlider->Size().Width() ) mSlider->Pos( mBackSlider->Size().Width(), 0 ); @@ -145,9 +147,9 @@ void cUISlider::FixSliderPos() { if ( mSlider->Pos().x > mBackSlider->Size().Width() - mSlider->Size().Width() ) mSlider->Pos( mBackSlider->Size().Width() - mSlider->Size().Width(), 0 ); } - + mSlider->CenterVertical(); - + if ( mAllowHalfSliderOut ) Value( mMinValue + (eeFloat)mSlider->Pos().x * ( mMaxValue - mMinValue ) / (eeFloat)mBackSlider->Size().Width() ); else @@ -157,7 +159,7 @@ void cUISlider::FixSliderPos() { if ( mSlider->Pos().y < 0 ) mSlider->Pos( 0, 0 ); - + if ( mAllowHalfSliderOut ) { if ( mSlider->Pos().y > mBackSlider->Size().Height() ) mSlider->Pos( 0, mBackSlider->Size().Height() ); @@ -165,9 +167,9 @@ void cUISlider::FixSliderPos() { if ( mSlider->Pos().y > mBackSlider->Size().Height() - mSlider->Size().Height() ) mSlider->Pos( 0, mBackSlider->Size().Height() - mSlider->Size().Height() ); } - + mSlider->CenterHorizontal(); - + if ( mAllowHalfSliderOut ) Value( mMinValue + (eeFloat)mSlider->Pos().y * ( mMaxValue - mMinValue ) / (eeFloat)mBackSlider->Size().Height() ); else @@ -181,13 +183,13 @@ void cUISlider::FixSliderPos() { void cUISlider::Value( eeFloat Val ) { if ( Val < mMinValue ) Val = mMinValue; if ( Val > mMaxValue ) Val = mMaxValue; - + if ( Val >= mMinValue && Val <= mMaxValue ) { mValue = Val; if ( !mOnPosChange ) { mOnPosChange = true; - + if ( !mVertical ) { if ( mAllowHalfSliderOut ) mSlider->Pos( (Int32)( (eeFloat)mBackSlider->Size().Width() * ( Val - mMinValue ) ), mSlider->Pos().y ); @@ -199,7 +201,7 @@ void cUISlider::Value( eeFloat Val ) { else mSlider->Pos( mSlider->Pos().x, (Int32)( ( (eeFloat)mSize.Height() - mSlider->Size().Height() ) * ( Val - mMinValue ) ) ); } - + mOnPosChange = false; } diff --git a/src/ui/cuisliderbutton.cpp b/src/ui/cuisliderbutton.cpp index 86afc10da..e995ecb86 100644 --- a/src/ui/cuisliderbutton.cpp +++ b/src/ui/cuisliderbutton.cpp @@ -6,6 +6,7 @@ namespace EE { namespace UI { namespace Private { cUISliderButton::cUISliderButton( const cUIDragable::CreateParams& Params ) : cUIDragable( Params ) { + ApplyDefaultTheme(); } cUISliderButton::~cUISliderButton() { diff --git a/src/ui/cuispinbox.cpp b/src/ui/cuispinbox.cpp index 9fbfc407e..e280f161e 100644 --- a/src/ui/cuispinbox.cpp +++ b/src/ui/cuispinbox.cpp @@ -14,6 +14,7 @@ cUISpinBox::cUISpinBox( const cUISpinBox::CreateParams& Params ) : cUITextInput::CreateParams InputParams( Params ); InputParams.PosSet( 0, 0 ); InputParams.Parent( this ); + InputParams.Flags |= UI_AUTO_PADDING; mInput = eeNew( cUITextInput, ( InputParams ) ); @@ -36,6 +37,8 @@ cUISpinBox::cUISpinBox( const cUISpinBox::CreateParams& Params ) : InternalValue( mValue, true ); AdjustChilds(); + + ApplyDefaultTheme(); } cUISpinBox::~cUISpinBox() { @@ -81,11 +84,11 @@ void cUISpinBox::AdjustChilds() { mInput->Size( mSize.Width() - mPushUp->Size().Width(), mSize.Height() ); } -void cUISpinBox::Padding( const eeRectf& padding ) { +void cUISpinBox::Padding( const eeRecti& padding ) { mInput->Padding( padding ); } -const eeRectf& cUISpinBox::Padding() const { +const eeRecti& cUISpinBox::Padding() const { return mInput->Padding(); } @@ -141,7 +144,7 @@ void cUISpinBox::InternalValue( const eeFloat& Val, const bool& Force ) { } mValue = Val; - + mInput->GetInputTextBuffer()->ChangedSinceLastUpdate( false ); OnValueChange(); diff --git a/src/ui/cuispinbox.hpp b/src/ui/cuispinbox.hpp index 11f7f87b7..ce80501c6 100644 --- a/src/ui/cuispinbox.hpp +++ b/src/ui/cuispinbox.hpp @@ -18,7 +18,7 @@ class EE_API cUISpinBox : public cUIControlAnim { } inline ~CreateParams() {} - + eeFloat DefaultValue; bool AllowDotsInNumbers; }; @@ -28,19 +28,19 @@ class EE_API cUISpinBox : public cUIControlAnim { ~cUISpinBox(); virtual void SetTheme( cUITheme * Theme ); - - virtual void Padding( const eeRectf& padding ); - const eeRectf& Padding() const; - + virtual void Padding( const eeRecti& padding ); + + const eeRecti& Padding() const; + virtual void ClickStep( const eeFloat& step ); const eeFloat& ClickStep() const; - + virtual Uint32 OnMessage( const cUIMessage * Msg ); - + void AddValue( const eeFloat& value ); - + virtual void MinValue( const eeFloat& MinVal ); const eeFloat& MinValue() const; @@ -48,17 +48,17 @@ class EE_API cUISpinBox : public cUIControlAnim { virtual void MaxValue( const eeFloat& MaxVal ); const eeFloat& MaxValue() const; - + virtual void Value( const eeFloat& Val ); const eeFloat& Value() const; - + virtual void Update(); - + cUIControlAnim * ButtonPushUp() const; - + cUIControlAnim * ButtonPushDown() const; - + cUITextInput * TextInput() const; protected: cUITextInput * mInput; @@ -68,9 +68,9 @@ class EE_API cUISpinBox : public cUIControlAnim { eeFloat mMaxValue; eeFloat mValue; eeFloat mClickStep; - + void AdjustChilds(); - + void InternalValue( const eeFloat& Val, const bool& Force = false ); }; diff --git a/src/ui/cuitextbox.cpp b/src/ui/cuitextbox.cpp index 0a28f88cf..bb4729a16 100644 --- a/src/ui/cuitextbox.cpp +++ b/src/ui/cuitextbox.cpp @@ -34,9 +34,9 @@ void cUITextBox::Draw() { if ( mTextCache.GetTextWidth() ) { if ( mFlags & UI_CLIP_ENABLE ) - cUIManager::instance()->ClipEnable( mScreenPos.x + (Int32)mPadding.Left, mScreenPos.y + (Int32)mPadding.Top, mSize.Width() - (Int32)mPadding.Right, mSize.Height() - (Int32)mPadding.Bottom ); + cUIManager::instance()->ClipEnable( mScreenPos.x + mPadding.Left, mScreenPos.y + mPadding.Top, mSize.Width() - mPadding.Left - mPadding.Right, mSize.Height() - mPadding.Bottom ); - mTextCache.Draw( (eeFloat)mScreenPos.x + mAlignOffset.x + mPadding.Left + 1.f, (eeFloat)mScreenPos.y + mAlignOffset.y + mPadding.Top, Flags(), 1.f, 0.f, mBlend ); + mTextCache.Draw( (eeFloat)mScreenPos.x + mAlignOffset.x + (eeFloat)mPadding.Left + 1.f, (eeFloat)mScreenPos.y + mAlignOffset.y + (eeFloat)mPadding.Top, Flags(), 1.f, 0.f, mBlend ); if ( mFlags & UI_CLIP_ENABLE ) cUIManager::instance()->ClipDisable(); @@ -154,11 +154,11 @@ void cUITextBox::OnFontChanged() { SendCommonEvent( cUIEvent::EventOnFontChanged ); } -void cUITextBox::Padding( const eeRectf& padding ) { +void cUITextBox::Padding( const eeRecti& padding ) { mPadding = padding; } -const eeRectf& cUITextBox::Padding() const { +const eeRecti& cUITextBox::Padding() const { return mPadding; } diff --git a/src/ui/cuitextbox.hpp b/src/ui/cuitextbox.hpp index 1ace565d0..ed849b67e 100644 --- a/src/ui/cuitextbox.hpp +++ b/src/ui/cuitextbox.hpp @@ -54,9 +54,9 @@ class EE_API cUITextBox : public cUIControlAnim { virtual void OnFontChanged(); - virtual void Padding( const eeRectf& padding ); + virtual void Padding( const eeRecti& padding ); - const eeRectf& Padding() const; + const eeRecti& Padding() const; virtual void SetTheme( cUITheme * Theme ); @@ -66,7 +66,7 @@ class EE_API cUITextBox : public cUIControlAnim { eeColorA mFontColor; eeColorA mFontShadowColor; eeVector2f mAlignOffset; - eeRectf mPadding; + eeRecti mPadding; virtual void OnSizeChange(); diff --git a/src/ui/cuitextinput.cpp b/src/ui/cuitextinput.cpp index b62465ce7..ed7852482 100644 --- a/src/ui/cuitextinput.cpp +++ b/src/ui/cuitextinput.cpp @@ -5,7 +5,8 @@ namespace EE { namespace UI { cUITextInput::cUITextInput( const cUITextInput::CreateParams& Params ) : cUITextBox( Params ), - mCursorPos(0) + mCursorPos(0), + mAllowEditing( true ) { mType |= UI_TYPE_GET(UI_TYPE_TEXTINPUT); @@ -14,6 +15,8 @@ cUITextInput::cUITextInput( const cUITextInput::CreateParams& Params ) : mTextBuffer.SupportFreeEditing( Params.SupportFreeEditing ); mTextBuffer.MaxLenght( Params.MaxLenght ); mTextBuffer.SetReturnCallback( cb::Make0( this, &cUITextInput::PrivOnPressEnter ) ); + + ApplyDefaultTheme(); } cUITextInput::~cUITextInput() { @@ -33,6 +36,8 @@ void cUITextInput::Update() { AlignFix(); + mCursorPos = mTextBuffer.CurPos(); + return; } @@ -126,31 +131,36 @@ void cUITextInput::AlignFix() { if ( tX < 0.f ) mAlignOffset.x = -( mAlignOffset.x + ( tW - mAlignOffset.x ) ); - else if ( tX > mSize.Width() - mPadding.Right ) - mAlignOffset.x = mSize.Width() - mPadding.Right - ( mAlignOffset.x + ( tW - mAlignOffset.x ) ); + else if ( tX > mSize.Width() - mPadding.Left - mPadding.Right ) + mAlignOffset.x = mSize.Width() - mPadding.Left - mPadding.Right - ( mAlignOffset.x + ( tW - mAlignOffset.x ) ); } void cUITextInput::SetTheme( cUITheme * Theme ) { cUIControl::SetTheme( Theme, "textinput" ); + + AutoPadding(); +} + +void cUITextInput::AutoPadding() { + if ( mFlags & UI_AUTO_PADDING ) { + mPadding = MakePadding( true, true, false, false ); + } } cInputTextBuffer * cUITextInput::GetInputTextBuffer() { return &mTextBuffer; } -void cUITextInput::Text( const std::wstring& text ) { - cUITextBox::Text( text ); +void cUITextInput::AllowEditing( const bool& allow ) { + mAllowEditing = allow; - mTextBuffer.Buffer( text ); + if ( !mAllowEditing && mTextBuffer.Active() ) + mTextBuffer.Active( false ); } -void cUITextInput::Text( const std::string& text ) { - cUITextBox::Text( text ); -} - -const std::wstring& cUITextInput::Text() { - return cUITextBox::Text(); +const bool& cUITextInput::AllowEditing() const { + return mAllowEditing; } }} diff --git a/src/ui/cuitextinput.hpp b/src/ui/cuitextinput.hpp index d7cf4286f..34c68a8ef 100644 --- a/src/ui/cuitextinput.hpp +++ b/src/ui/cuitextinput.hpp @@ -37,27 +37,27 @@ class EE_API cUITextInput : public cUITextBox { virtual Uint32 OnPressEnter(); - virtual void Text( const std::wstring& text ); - - virtual void Text( const std::string& text ); - - virtual const std::wstring& Text(); - void PushIgnoredChar( const Uint32& ch ); virtual void SetTheme( cUITheme * Theme ); cInputTextBuffer * GetInputTextBuffer(); + + void AllowEditing( const bool& allow ); + + const bool& AllowEditing() const; protected: cInputTextBuffer mTextBuffer; bool mShowingWait; eeFloat mWaitCursorTime; eeVector2f mCurPos; eeInt mCursorPos; + bool mAllowEditing; void ResetWaitCursor(); void AlignFix(); void PrivOnPressEnter(); + void AutoPadding(); }; }} diff --git a/src/ui/uihelper.hpp b/src/ui/uihelper.hpp index 854d6c44a..bb220d8ab 100644 --- a/src/ui/uihelper.hpp +++ b/src/ui/uihelper.hpp @@ -41,6 +41,7 @@ Uint32 EE_API VAlignGet( Uint32 Flags ); #define UI_CLIP_ENABLE (1 << 12) #define UI_AUTO_SHRINK_TEXT (1 << 13) #define UI_MULTI_SELECT (1 << 14) +#define UI_AUTO_PADDING (1 << 15) #define UI_TYPE_CONTROL (0) #define UI_TYPE_CONTROL_ANIM (1)