From 0e77e5e41d24f3bd8386a3074c2ff9c9e22fb978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Fri, 3 Mar 2017 00:34:49 -0300 Subject: [PATCH] Refactored UITextInput. --HG-- branch : dev --- include/eepp/ui/uitextinput.hpp | 25 +++--------------- include/eepp/ui/uitheme.hpp | 2 -- src/eepp/gaming/mapeditor/mapeditor.cpp | 24 +++++++---------- .../gaming/mapeditor/maplayerproperties.cpp | 3 ++- .../gaming/mapeditor/mapobjectproperties.cpp | 8 ++++-- src/eepp/gaming/mapeditor/uigotypenew.cpp | 3 ++- src/eepp/gaming/mapeditor/uimaplayernew.cpp | 3 ++- src/eepp/ui/tools/textureatlasnew.cpp | 3 ++- src/eepp/ui/uitextinput.cpp | 26 +++++-------------- src/eepp/ui/uitheme.cpp | 14 ---------- src/test/eetest.cpp | 1 + 11 files changed, 35 insertions(+), 77 deletions(-) diff --git a/include/eepp/ui/uitextinput.hpp b/include/eepp/ui/uitextinput.hpp index 14ce39b3b..65364e159 100644 --- a/include/eepp/ui/uitextinput.hpp +++ b/include/eepp/ui/uitextinput.hpp @@ -11,25 +11,6 @@ class EE_API UITextInput : public UITextBox { public: static UITextInput * New(); - class CreateParams : public UITextBox::CreateParams { - public: - inline CreateParams() : - UITextBox::CreateParams(), - SupportFreeEditing( true ), - MaxLength( 1024*8 ), - PassInput( false ) - { - } - - inline ~CreateParams() {} - - bool SupportFreeEditing; - Uint32 MaxLength; - bool PassInput; - }; - - UITextInput( const UITextInput::CreateParams& Params ); - UITextInput(); virtual ~UITextInput(); @@ -48,7 +29,7 @@ class EE_API UITextInput : public UITextBox { InputTextBuffer * getInputTextBuffer(); - void setAllowEditing( const bool& allow ); + UITextInput * setAllowEditing( const bool& allow ); const bool& getAllowEditing() const; @@ -58,11 +39,11 @@ class EE_API UITextInput : public UITextBox { virtual void shrinkText( const Uint32& MaxWidth ); - void setMaxLength( Uint32 maxLength ); + UITextInput * setMaxLength( Uint32 maxLength ); Uint32 getMaxLength(); - void setFreeEditing( bool support ); + UITextInput * setFreeEditing( bool support ); bool isFreeEditingEnabled(); protected: diff --git a/include/eepp/ui/uitheme.hpp b/include/eepp/ui/uitheme.hpp index ffca461fb..48727505b 100644 --- a/include/eepp/ui/uitheme.hpp +++ b/include/eepp/ui/uitheme.hpp @@ -85,8 +85,6 @@ class EE_API UITheme : protected ResourceManager { virtual UITextBox * createTextBox( const String& Text = "", UIControl * Parent = NULL, const Sizei& Size = Sizei(), const Vector2i& Pos = Vector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); - virtual UITextInput * createTextInput( UIControl * Parent = NULL, const Sizei& Size = Sizei(), const Vector2i& Pos = Vector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_TEXT_SELECTION_ENABLED, bool SupportFreeEditing = true, Uint32 MaxLength = 1024*8 ); - ColorA getTooltipFontColor() const; void setTooltipFontColor(const ColorA & tooltipFontColor); diff --git a/src/eepp/gaming/mapeditor/mapeditor.cpp b/src/eepp/gaming/mapeditor/mapeditor.cpp index 4cebffde0..778bab826 100644 --- a/src/eepp/gaming/mapeditor/mapeditor.cpp +++ b/src/eepp/gaming/mapeditor/mapeditor.cpp @@ -322,14 +322,11 @@ void MapEditor::CreateSubTextureContainer( Int32 Width ) { mChkDI->setParent( mSubTextureCont )->setPosition( TAB_CONT_X_DIST, Txt->getPosition().y + Txt->getSize().getHeight() + 4 )->resetFlags( ChkFlags )->setFlags( UI_DRAW_SHADOW );; mChkDI->setText( "Add as DataId" ); mChkDI->setTooltipText( "If the resource it's not a sprite,\nyou can reference it with a data id" ); - mChkDI->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapEditor::ChkClickDI ) ); + mChkDI->addEventListener( UIEvent::EventOnValueChange, cb::Make1( this, &MapEditor::ChkClickDI ) ); - UIComplexControl::CreateParams SGParams; - SGParams.setParent( mSubTextureCont ); - SGParams.setPosition( Vector2i( TAB_CONT_X_DIST, mChkDI->getPosition().y + mChkDI->getSize().getHeight() + 8 ) ); - SGParams.setSize( Sizei( Width, 400 ) ); - SGParams.Flags = UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP; - mSGCont = eeNew( UIComplexControl, ( SGParams ) ); + mSGCont = UIComplexControl::New(); + mSGCont->setParent( mSubTextureCont )->setPosition( TAB_CONT_X_DIST, mChkDI->getPosition().y + mChkDI->getSize().getHeight() + 8 )->setSize( Width, 400 ); + mSGCont->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); mSGCont->setEnabled( true ); mSGCont->setVisible( true ); @@ -353,18 +350,17 @@ void MapEditor::CreateSubTextureContainer( Int32 Width ) { mGfxPreview->setBorderEnabled( true )->setColor( ColorA( 0, 0, 0, 200 ) ); - UIComplexControl::CreateParams DIParams; - DIParams.setParent( mSubTextureCont ); - DIParams.setPosition( SGParams.Pos ); - DIParams.setSize( Sizei( Width, 400 ) ); - DIParams.Flags = UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP; - mDICont = eeNew( UIComplexControl, ( DIParams ) ); + mDICont = UIComplexControl::New(); + mDICont->setParent( mSubTextureCont )->setPosition( TAB_CONT_X_DIST, mChkDI->getPosition().y + mChkDI->getSize().getHeight() + 8 ); + mDICont->setSize( Width, 400 ); + mDICont->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); mDICont->setEnabled( false ); mDICont->setVisible( false ); Txt = mTheme->createTextBox( "DataId String:", mDICont, Sizei( Width, 16 ), Vector2i( TAB_CONT_X_DIST, 0 ), TxtFlags ); - mDataIdInput = mTheme->createTextInput( mDICont, Sizei( Width / 4 * 3, 21 ), Vector2i( TAB_CONT_X_DIST + 8, Txt->getPosition().y + Txt->getSize().getHeight() + 8 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE ); + mDataIdInput = UITextInput::New(); + mDataIdInput->setParent( mDICont )->setSize( Width / 4 * 3, 0 )->setPosition( TAB_CONT_X_DIST + 8, Txt->getPosition().y + Txt->getSize().getHeight() + 8 ); FillSGCombo(); } diff --git a/src/eepp/gaming/mapeditor/maplayerproperties.cpp b/src/eepp/gaming/mapeditor/maplayerproperties.cpp index b5545b24b..62a092f2f 100644 --- a/src/eepp/gaming/mapeditor/maplayerproperties.cpp +++ b/src/eepp/gaming/mapeditor/maplayerproperties.cpp @@ -30,7 +30,8 @@ MapLayerProperties::MapLayerProperties( MapLayer * Map, RefreshLayerListCb Cb ) Int32 DistFromTitle = 18; UITextBox * Txt = mUITheme->createTextBox( "Layer name:", mUIWindow->getContainer(), Sizei(), Vector2i( 50, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); - mUIInput = mUITheme->createTextInput( mUIWindow->getContainer(), Sizei( 120, 22 ), Vector2i( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); + mUIInput = UITextInput::New()->setMaxLength( 64 ); + mUIInput->setParent( mUIWindow->getContainer() )->setSize( 120, 0 )->setPosition( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ); mUIInput->setText( mLayer->getName() ); mUIInput->addEventListener( UIEvent::EventOnPressEnter, cb::Make1( this, &MapLayerProperties::onOKClick ) ); diff --git a/src/eepp/gaming/mapeditor/mapobjectproperties.cpp b/src/eepp/gaming/mapeditor/mapobjectproperties.cpp index c7123a660..31abf0277 100644 --- a/src/eepp/gaming/mapeditor/mapobjectproperties.cpp +++ b/src/eepp/gaming/mapeditor/mapobjectproperties.cpp @@ -29,12 +29,16 @@ MapObjectProperties::MapObjectProperties( GameObjectObject * Obj ) : Int32 DistFromTitle = 18; UITextBox * Txt = mUITheme->createTextBox( "Object name:", mUIWindow->getContainer(), Sizei(), Vector2i( 50, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); - mUIInput = mUITheme->createTextInput( mUIWindow->getContainer(), Sizei( 120, 22 ), Vector2i( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); + mUIInput = UITextInput::New(); + mUIInput->setParent( mUIWindow->getContainer() )->setSize( 120, 0 )->setPosition( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ); + mUIInput->setMaxLength( 64 ); mUIInput->setText( mObj->getName() ); mUIInput->addEventListener( UIEvent::EventOnPressEnter, cb::Make1( this, &MapObjectProperties::onOKClick ) ); UITextBox * Txt2 = mUITheme->createTextBox( "Object type:", mUIWindow->getContainer(), Sizei(), Vector2i( 50+192, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); - mUIInput2 = mUITheme->createTextInput( mUIWindow->getContainer(), Sizei( 120, 22 ), Vector2i( Txt2->getPosition().x + DistFromTitle, Txt2->getPosition().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); + mUIInput2 = UITextInput::New(); + mUIInput2->setParent( mUIWindow->getContainer() )->setSize( 120, 0 )->setPosition( Txt2->getPosition().x + DistFromTitle, Txt2->getPosition().y + DistFromTitle ); + mUIInput2->setMaxLength( 64 ); mUIInput2->setText( mObj->getTypeName() ); mUIInput2->addEventListener( UIEvent::EventOnPressEnter, cb::Make1( this, &MapObjectProperties::onOKClick ) ); diff --git a/src/eepp/gaming/mapeditor/uigotypenew.cpp b/src/eepp/gaming/mapeditor/uigotypenew.cpp index 4877bca41..a70307f52 100644 --- a/src/eepp/gaming/mapeditor/uigotypenew.cpp +++ b/src/eepp/gaming/mapeditor/uigotypenew.cpp @@ -25,7 +25,8 @@ UIGOTypeNew::UIGOTypeNew( cb::Callback2 Cb ) : UITextBox * Txt = mUITheme->createTextBox( "GameObject Type Name", mUIWindow->getContainer(), Sizei(), Vector2i( 16, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); - mUIInput = mUITheme->createTextInput( mUIWindow->getContainer(), Sizei( 120, 22 ), Vector2i( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); + mUIInput = UITextInput::New()->setMaxLength( 64 ); + mUIInput->setParent( mUIWindow->getContainer() )->setSize( 120, 0 )->setPosition( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ); UIPushButton * OKButton = UIPushButton::New(); OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); diff --git a/src/eepp/gaming/mapeditor/uimaplayernew.cpp b/src/eepp/gaming/mapeditor/uimaplayernew.cpp index d30953864..0908d59ca 100644 --- a/src/eepp/gaming/mapeditor/uimaplayernew.cpp +++ b/src/eepp/gaming/mapeditor/uimaplayernew.cpp @@ -31,7 +31,8 @@ UIMapLayerNew::UIMapLayerNew( UIMap * Map, EE_LAYER_TYPE Type, NewLayerCb newLay UITextBox * Txt = mTheme->createTextBox( "Layer Name", mUIWindow->getContainer(), Sizei(), Vector2i( 16, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); - mUILayerName = mTheme->createTextInput( mUIWindow->getContainer(), Sizei( 120, 22 ), Vector2i( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); + mUILayerName = UITextInput::New()->setMaxLength( 64 ); + mUILayerName->setParent( mUIWindow->getContainer() )->setSize( 120, 0 )->setPosition( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ); mUILayerName->setText( "Layer " + String::toStr( mUIMap->Map()->getLayerCount() + 1 ) ); UIPushButton * OKButton = UIPushButton::New(); diff --git a/src/eepp/ui/tools/textureatlasnew.cpp b/src/eepp/ui/tools/textureatlasnew.cpp index 339ed2ed6..e7b54519e 100644 --- a/src/eepp/ui/tools/textureatlasnew.cpp +++ b/src/eepp/ui/tools/textureatlasnew.cpp @@ -73,7 +73,8 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) : mPixelSpace->setParent( mUIWindow->getContainer() )->setSize( 100, 0 )->setPosition( PosX, 110 )->setVisible( true )->setEnabled( true ); createTxtBox( Vector2i( 10, 140 ), "Texture Atlas Folder Path:" ); - mTGPath = mTheme->createTextInput( mUIWindow->getContainer(), Sizei( mUIWindow->getContainer()->getSize().getWidth() - 60, 22 ), Vector2i( 10, 160 ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE , false, 512 ); + mTGPath = UITextInput::New()->setMaxLength( 512 ); + mTGPath->setParent( mUIWindow->getContainer() )->setSize( mUIWindow->getContainer()->getSize().getWidth() - 60, 0 )->setPosition( 10, 160 ); mTGPath->setAllowEditing( false ); mSetPathButton = UIPushButton::New(); diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 2524b4b0a..eb2729ceb 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -12,22 +12,6 @@ UITextInput * UITextInput::New() { return eeNew( UITextInput, () ); } -UITextInput::UITextInput( const UITextInput::CreateParams& Params ) : - UITextBox( Params ), - mCursorPos(0), - mAllowEditing( true ), - mShowingWait( true ) -{ - mTextBuffer.start(); - mTextBuffer.setActive( false ); - mTextBuffer.setFreeEditing( Params.SupportFreeEditing ); - mTextBuffer.setTextSelectionEnabled( isTextSelectionEnabled() ); - mTextBuffer.setMaxLength( Params.MaxLength ); - mTextBuffer.setReturnCallback( cb::Make0( this, &UITextInput::privOnPressEnter ) ); - - applyDefaultTheme(); -} - UITextInput::UITextInput() : UITextBox(), mCursorPos(0), @@ -214,11 +198,13 @@ InputTextBuffer * UITextInput::getInputTextBuffer() { return &mTextBuffer; } -void UITextInput::setAllowEditing( const bool& allow ) { +UITextInput * UITextInput::setAllowEditing( const bool& allow ) { mAllowEditing = allow; if ( !mAllowEditing && mTextBuffer.isActive() ) mTextBuffer.setActive( false ); + + return this; } const bool& UITextInput::getAllowEditing() const { @@ -306,16 +292,18 @@ Int32 UITextInput::selCurEnd() { return mTextBuffer.selCurEnd(); } -void UITextInput::setMaxLength( Uint32 maxLength ) { +UITextInput * UITextInput::setMaxLength( Uint32 maxLength ) { mTextBuffer.setMaxLength( maxLength ); + return this; } Uint32 UITextInput::getMaxLength() { return mTextBuffer.getMaxLength(); } -void UITextInput::setFreeEditing( bool support ) { +UITextInput * UITextInput::setFreeEditing( bool support ) { mTextBuffer.setFreeEditing( support ); + return this; } bool UITextInput::isFreeEditingEnabled() { diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index a013531a7..662579f8a 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -401,20 +401,6 @@ UITextBox * UITheme::createTextBox( const String& Text, UIControl * Parent, cons return Ctrl; } -UITextInput * UITheme::createTextInput( UIControl * Parent, const Sizei& Size, const Vector2i& Pos, const Uint32& Flags, bool SupportFreeEditing, Uint32 MaxLength ) { - UITextInput::CreateParams TextInputParams; - TextInputParams.setParent( Parent ); - TextInputParams.setPosition( Pos ); - TextInputParams.setSize( Size ); - TextInputParams.Flags = Flags; - TextInputParams.SupportFreeEditing = SupportFreeEditing; - TextInputParams.MaxLength = MaxLength; - UITextInput * Ctrl = eeNew( UITextInput, ( TextInputParams ) ); - Ctrl->setVisible( true ); - Ctrl->setEnabled( true ); - return Ctrl; -} - ColorA UITheme::getTooltipFontColor() const { return mTooltipFontColor; } diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 95f15e442..d0b8c7bcb 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -316,6 +316,7 @@ void EETest::createUI() { sprite->setSprite( eeNew( Sprite, ( "gn" ) ) ); sprite->setParent( C ); sprite->setPosition( 160, 100 ); + sprite->setDeallocSprite( true ); UITextBox * Text = UITextBox::New(); Text->setParent( C )->setEnabled( false )->setSize( 320, 240 )->setHorizontalAlign( UI_HALIGN_RIGHT )->setVerticalAlign( UI_VALIGN_TOP );