From d72cdd9e1bbf5c557c744594024c50de23d8698b Mon Sep 17 00:00:00 2001 From: spartanj Date: Sat, 7 May 2011 20:44:56 -0300 Subject: [PATCH] Fixed anchors. Some minor changes to the UI. Added cUICommonDialog control. --- src/ee.h | 1 + src/test/eetest.cpp | 27 ++-- src/ui/cuicommondialog.cpp | 265 +++++++++++++++++++++++++++++++++++ src/ui/cuicommondialog.hpp | 69 +++++++++ src/ui/cuicomplexcontrol.cpp | 14 +- src/ui/cuicomplexcontrol.hpp | 6 +- src/ui/cuicontrol.cpp | 14 +- src/ui/cuicontrol.hpp | 6 +- src/ui/cuidropdownlist.cpp | 5 + src/ui/cuievent.hpp | 2 + src/ui/cuilistbox.cpp | 18 ++- src/ui/cuilistbox.hpp | 4 +- src/ui/cuilistboxitem.cpp | 2 + src/ui/cuitextbox.cpp | 15 +- src/ui/cuitextbox.hpp | 1 + src/ui/cuitextedit.cpp | 4 +- src/ui/cuitextedit.hpp | 2 +- src/ui/cuiwindow.cpp | 2 +- src/ui/uihelper.hpp | 31 ++-- src/utils/utils.cpp | 26 +++- src/utils/utils.hpp | 3 + 21 files changed, 461 insertions(+), 56 deletions(-) create mode 100644 src/ui/cuicommondialog.cpp create mode 100644 src/ui/cuicommondialog.hpp diff --git a/src/ee.h b/src/ee.h index 2f207b262..ab59097d7 100755 --- a/src/ee.h +++ b/src/ee.h @@ -194,6 +194,7 @@ #include "ui/cuiwindow.hpp" #include "ui/cuiselectbutton.hpp" #include "ui/cuiwinmenu.hpp" + #include "ui/cuicommondialog.hpp" using namespace EE::UI; #include "physics/cphysicsmanager.hpp" diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 54249ea21..9ed84d74d 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -548,6 +548,15 @@ void cEETest::CreateUI() { //mUIWindow->Show(); + cUICommonDialog::CreateParams CDParams; + CDParams.Flags = UI_HALIGN_CENTER; + CDParams.WinFlags |= cUIWindow::UI_WIN_MAXIMIZE_BUTTON; + CDParams.Size = eeSize( 420, 267 ); + cUICommonDialog * CDialog = eeNew( cUICommonDialog, ( CDParams ) ); + CDialog->AddFilePattern( "*.hpp;*.cpp", true ); + CDialog->Center(); + CDialog->Show(); + Log->Writef( "CreateUI time: %f", TE.ElapsedSinceStart() ); } @@ -595,11 +604,7 @@ void cEETest::CreateDecoratedWindow() { WinParams.WinFlags |= cUIWindow::UI_WIN_MAXIMIZE_BUTTON; WinParams.PosSet( 200, 50 ); WinParams.Size = eeSize( 530, 400 ); - WinParams.ButtonsPositionFixer.x = -4; - WinParams.ButtonsPositionFixer.y = -2; - //WinParams.BaseAlpha = 200; - //WinParams.BorderAutoSize = false; - //WinParams.BorderSize = eeSize( 8, 8 ); + WinParams.MinWindowSize = eeSize( 100, 200 ); mUIWindow = eeNew( cUIWindow, ( WinParams ) ); mUIWindow->AddEventListener( cUIEvent::EventOnWindowCloseClick, cb::Make1( this, &cEETest::CloseClick ) ); @@ -608,7 +613,7 @@ void cEETest::CreateDecoratedWindow() { cUIPushButton::CreateParams ButtonParams; ButtonParams.Parent( mUIWindow->Container() ); - ButtonParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_ANCHOR_RIGHT; + ButtonParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_ANCHOR_RIGHT | UI_ANCHOR_LEFT | UI_ANCHOR_TOP; ButtonParams.PosSet( 10, 28 ); ButtonParams.Size = eeSize( 510, 22 ); @@ -618,18 +623,18 @@ void cEETest::CreateDecoratedWindow() { Button->Text( "Click Me" ); Button->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cEETest::ButtonClick ) ); + mUIWindow->AddShortcut( KEY_C, KEYMOD_ALT, Button ); + cUITextEdit::CreateParams TEParams; TEParams.Parent( mUIWindow->Container() ); TEParams.PosSet( 10, 55 ); TEParams.Size = eeSize( 510, 300 ); - TEParams.Flags = UI_AUTO_PADDING | UI_CLIP_ENABLE | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM; + TEParams.Flags = UI_AUTO_PADDING | UI_CLIP_ENABLE | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM | UI_ANCHOR_LEFT | UI_ANCHOR_TOP; cUITextEdit * TextEdit = eeNew( cUITextEdit, ( TEParams ) ); TextEdit->Visible( true ); TextEdit->Enabled( true ); TextEdit->Text( mBuda ); - mUIWindow->AddShortcut( KEY_C, KEYMOD_ALT, Button ); - CreateWinMenu(); } @@ -1651,8 +1656,6 @@ cpBool cEETest::catcherBarBegin(cArbiter *arb, Physics::cSpace *space, void *unu return cpFalse; } -static cpFloat frand_unit(){return 2.0f*((cpFloat)rand()/(cpFloat)RAND_MAX) - 1.0f;} - void cEETest::Demo2Create() { mMouseJoint = NULL; mMouseBody = eeNew( cBody, ( INFINITY, INFINITY ) ); @@ -1702,7 +1705,7 @@ void cEETest::Demo2Update() { cBody * body = mSpace->AddBody( cBody::New( 1.0f, Moment::ForCircle(1.0f, 15.0f, 0.0f, cVectZero ) ) ); body->Pos( emitterInstance.position ); - body->Vel( cVectNew( frand_unit(), frand_unit() ) * (cpFloat)100 ); + body->Vel( cVectNew( eeRandf(-1,1), eeRandf(-1,1) ) * (cpFloat)100 ); Physics::cShape *shape = mSpace->AddShape( cShapeCircle::New( body, 15.0f, cVectZero ) ); shape->CollisionType( BALL_TYPE ); diff --git a/src/ui/cuicommondialog.cpp b/src/ui/cuicommondialog.cpp new file mode 100644 index 000000000..2d1687320 --- /dev/null +++ b/src/ui/cuicommondialog.cpp @@ -0,0 +1,265 @@ +#include "cuicommondialog.hpp" +#include "cuimanager.hpp" +#include "cuilistboxitem.hpp" + +namespace EE { namespace UI { + +#define CDLG_MIN_WIDTH 420 +#define CDLG_MIN_HEIGHT 267 + +cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) : + cUIWindow( Params ), + mCurPath( Params.DefaultDirectory ) +{ + if ( mSize.Width() < CDLG_MIN_WIDTH ) + mSize.x = CDLG_MIN_WIDTH; + + if ( mSize.Height() < CDLG_MIN_HEIGHT ) + mSize.y = CDLG_MIN_HEIGHT; + + if ( mMinWindowSize.Width() < CDLG_MIN_WIDTH ) + mMinWindowSize.Width( CDLG_MIN_WIDTH ); + + if ( mMinWindowSize.Height() < CDLG_MIN_HEIGHT ) + mMinWindowSize.Height( CDLG_MIN_HEIGHT ); + + Title( "Select a file" ); + + cUITextBox::CreateParams TxtBoxParams; + TxtBoxParams.Parent( Container() ); + TxtBoxParams.PosSet( 6, 13 ); + TxtBoxParams.Flags |= UI_AUTO_SIZE; + cUITextBox * TBox = eeNew( cUITextBox, ( TxtBoxParams ) ); + TBox->Visible( true ); + TBox->Enabled( false ); + TBox->Text( "Look in:" ); + + cUIPushButton::CreateParams ButtonParams; + ButtonParams.Parent( Container() ); + ButtonParams.PosSet( Container()->Size().Width() - 81, Container()->Size().Height() - 54 ); + ButtonParams.SizeSet( 75, 22 ); + ButtonParams.Flags = UI_HALIGN_CENTER | UI_ANCHOR_RIGHT | UI_VALIGN_CENTER; + mButtonOpen = eeNew( cUIPushButton, ( ButtonParams ) ); + mButtonOpen->Visible( true ); + mButtonOpen->Enabled( true ); + mButtonOpen->Text( "Open" ); + + ButtonParams.Pos.y = mButtonOpen->Pos().y + mButtonOpen->Size().Height() + 6; + mButtonCancel = eeNew( cUIPushButton, ( ButtonParams ) ); + mButtonCancel->Visible( true ); + mButtonCancel->Enabled( true ); + mButtonCancel->Text( "Cancel" ); + + cUITextInput::CreateParams TInputParams; + TInputParams.Parent( Container() ); + TInputParams.Flags = UI_AUTO_PADDING | UI_CLIP_ENABLE | UI_ANCHOR_RIGHT | UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_VALIGN_CENTER; + TInputParams.PosSet( 70, 6 ); + TInputParams.SizeSet( Container()->Size().Width() - TInputParams.Pos.x - 42, 22 ); + mPath = eeNew( cUITextInput, ( TInputParams ) ); + mPath->Visible( true ); + mPath->Enabled( true ); + mPath->Text( mCurPath ); + + ButtonParams.PosSet( TInputParams.Pos.x + TInputParams.Size.Width() + 6, TInputParams.Pos.y ); + ButtonParams.SizeSet( 24, 22 ); + ButtonParams.Flags |= UI_ANCHOR_TOP; + mButtonUp = eeNew( cUIPushButton, ( ButtonParams ) ); + mButtonUp->Visible( true ); + mButtonUp->Enabled( true ); + mButtonUp->Text( "Up" ); + + cUIListBox::CreateParams LBParams; + LBParams.Parent( Container() ); + LBParams.PosSet( 6, 33 ); + LBParams.Size = eeSize( Container()->Size().Width() - 12, Container()->Size().Height() - 92 ); + LBParams.Flags = UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_ANCHOR_BOTTOM | UI_CLIP_ENABLE; + LBParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 ); + mList = eeNew( cUIListBox, ( LBParams ) ); + mList->Visible( true ); + mList->Enabled( true ); + + TxtBoxParams.PosSet( 6, Container()->Size().Height() - 54 ); + TxtBoxParams.SizeSet( 74, 19 ); + TxtBoxParams.Flags = UI_ANCHOR_LEFT | UI_VALIGN_CENTER; + TBox = eeNew( cUITextBox, ( TxtBoxParams ) ); + TBox->Visible( true ); + TBox->Enabled( false ); + TBox->Text( "File Name:" ); + + TxtBoxParams.PosSet( TBox->Pos().x, TBox->Pos().y + TBox->Size().Height()+ 6 ); + cUITextBox * TBox2 = eeNew( cUITextBox, ( TxtBoxParams ) ); + TBox2->Visible( true ); + TBox2->Enabled( false ); + TBox2->Text( "Files of type:" ); + + TInputParams.Flags &= ~UI_ANCHOR_TOP; + TInputParams.PosSet( TBox->Pos().x + TBox->Size().Width(), TBox->Pos().y ); + TInputParams.SizeSet( Container()->Size().Width() - mButtonOpen->Size().Width() - TInputParams.Pos.x - 20, TInputParams.Size.Height() ); + mFile = eeNew( cUITextInput, ( TInputParams ) ); + mFile->Visible( true ); + mFile->Enabled( true ); + + cUIDropDownList::CreateParams DDLParams; + DDLParams.Parent( Container() ); + DDLParams.PosSet( TBox2->Pos().x + TBox2->Size().Width(), TBox2->Pos().y ); + DDLParams.SizeSet( Container()->Size().Width() - mButtonCancel->Size().Width() - DDLParams.Pos.x - 20, 22 ); + DDLParams.Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_VALIGN_CENTER | UI_HALIGN_LEFT | UI_ANCHOR_LEFT | UI_ANCHOR_RIGHT; + DDLParams.PopUpToMainControl = true; + mFiletype = eeNew( cUIDropDownList, ( DDLParams ) ); + mFiletype->Visible( true ); + mFiletype->Enabled( true ); + mFiletype->ListBox()->AddListBoxItem( "*" ); + mFiletype->ListBox()->SetSelected(0); + + ApplyDefaultTheme(); + + RefreshFolder(); +} + +void cUICommonDialog::RefreshFolder() { + std::vector flist = FilesGetInPath( String( mCurPath ) ); + std::vector files; + std::vector folders; + std::vector patterns; + bool accepted; + Uint32 i, z; + + if ( "*" != mFiletype->Text() ) { + patterns = SplitString( mFiletype->Text().ToUtf8(), ';' ); + + for ( i = 0; i < patterns.size(); i++ ) + patterns[i] = FileExtension( patterns[i] ); + } + + for ( i = 0; i < flist.size(); i++ ) { + if ( IsDirectory( mCurPath + flist[i] ) ) { + folders.push_back( flist[i] ); + } else { + accepted = false; + + if ( patterns.size() ) { + for ( z = 0; z < patterns.size(); z++ ) { + if ( patterns[z] == FileExtension( flist[i] ) ) { + accepted = true; + break; + } + } + } else { + accepted = true; + } + + if ( accepted ) + files.push_back( flist[i] ); + } + } + + std::sort( folders.begin(), folders.end() ); + std::sort( files.begin(), files.end() ); + + mList->Clear(); + mList->AddListBoxItems( folders ); + mList->AddListBoxItems( files ); +} + +Uint32 cUICommonDialog::OnMessage( const cUIMessage *Msg ) { + switch ( Msg->Msg() ) { + case cUIMessage::MsgClick: + { + if ( Msg->Sender() == mButtonOpen ) { + Open(); + } else if ( Msg->Sender() == mButtonCancel ) { + CloseWindow(); + } else if ( Msg->Sender() == mButtonUp ) { + mCurPath = RemoveLastFolderFromPath( mCurPath ); + mPath->Text( mCurPath ); + RefreshFolder(); + } + + break; + } + case cUIMessage::MsgDoubleClick: + { + if ( Msg->Sender()->IsType( UI_TYPE_LISTBOXITEM ) ) { + std::string newPath = mCurPath + mList->GetItemSelectedText(); + + if ( IsDirectory( newPath ) ) { + mCurPath = newPath + GetOSlash(); + mPath->Text( mCurPath ); + RefreshFolder(); + } else { + Open(); + } + } + + break; + } + case cUIMessage::MsgSelected: + { + if ( Msg->Sender() == mList ) { + mFile->Text( mList->GetItemSelectedText() ); + } else if ( Msg->Sender() == mFiletype ) { + RefreshFolder(); + } + + break; + } + } + + return cUIWindow::OnMessage( Msg ); +} + +void cUICommonDialog::Open() { + if ( "" != mList->GetItemSelectedText() ) { + SendCommonEvent( cUIEvent::EventOpenFile ); + + CloseWindow(); + } +} + +void cUICommonDialog::AddFilePattern( std::string pattern, bool select ) { + Uint32 index = mFiletype->ListBox()->AddListBoxItem( pattern ); + + if ( select ) { + mFiletype->ListBox()->SetSelected( index ); + + RefreshFolder(); + } +} + +std::string cUICommonDialog::GetCurPath() const { + return mCurPath; +} + +std::string cUICommonDialog::GetCurFile() const { + return mList->GetItemSelectedText().ToUtf8(); +} + +cUIPushButton * cUICommonDialog::GetButtonOpen() const { + return mButtonOpen; +} + +cUIPushButton * cUICommonDialog::GetButtonCancel() const { + return mButtonCancel; +} + +cUIPushButton * cUICommonDialog::GetButtonUp() const { + return mButtonUp; +} + +cUIListBox * cUICommonDialog::GetList() const { + return mList; +} + +cUITextInput * cUICommonDialog::GetPathInput() const { + return mPath; +} + +cUITextInput * cUICommonDialog::GetFileInput() const { + return mFile; +} + +cUIDropDownList * cUICommonDialog::GetFiletypeList() const { + return mFiletype; +} + +}} diff --git a/src/ui/cuicommondialog.hpp b/src/ui/cuicommondialog.hpp new file mode 100644 index 000000000..edb643546 --- /dev/null +++ b/src/ui/cuicommondialog.hpp @@ -0,0 +1,69 @@ +#ifndef EE_UICUICOMMONDIALOG_HPP +#define EE_UICUICOMMONDIALOG_HPP + +#include "base.hpp" +#include "cuicomplexcontrol.hpp" +#include "cuipushbutton.hpp" +#include "cuilistbox.hpp" +#include "cuitextinput.hpp" +#include "cuicombobox.hpp" +#include "cuiwindow.hpp" + +namespace EE { namespace UI { + +class cUICommonDialog : public cUIWindow { + public: + class CreateParams : public cUIWindow::CreateParams { + public: + inline CreateParams() : + cUIWindow::CreateParams(), + DefaultDirectory( GetProcessPath() ) + { + } + + inline ~CreateParams() {} + + std::string DefaultDirectory; + }; + + cUICommonDialog( const cUICommonDialog::CreateParams& Params ); + + void RefreshFolder(); + + virtual Uint32 OnMessage( const cUIMessage *Msg ); + + virtual void Open(); + + std::string GetCurPath() const; + + std::string GetCurFile() const; + + cUIPushButton * GetButtonOpen() const; + + cUIPushButton * GetButtonCancel() const; + + cUIPushButton * GetButtonUp() const; + + cUIListBox * GetList() const; + + cUITextInput * GetPathInput() const; + + cUITextInput * GetFileInput() const; + + cUIDropDownList * GetFiletypeList() const; + + void AddFilePattern( std::string pattern, bool select = false ); + protected: + std::string mCurPath; + cUIPushButton * mButtonOpen; + cUIPushButton * mButtonCancel; + cUIPushButton * mButtonUp; + cUIListBox * mList; + cUITextInput * mPath; + cUITextInput * mFile; + cUIDropDownList * mFiletype; +}; + +}} + +#endif diff --git a/src/ui/cuicomplexcontrol.cpp b/src/ui/cuicomplexcontrol.cpp index f5dc28990..1fca22b2a 100644 --- a/src/ui/cuicomplexcontrol.cpp +++ b/src/ui/cuicomplexcontrol.cpp @@ -21,7 +21,7 @@ cUIComplexControl::~cUIComplexControl() { void cUIComplexControl::CalcDistToBorder() { if ( NULL != mParentCtrl ) { - mDistToBorder = eeVector2i( mParentCtrl->Size().x - ( mPos.x + mSize.x ), mParentCtrl->Size().y - ( mPos.y + mSize.y ) ); + mDistToBorder = eeRecti( mPos.x, mPos.y, mParentCtrl->Size().x - ( mPos.x + mSize.x ), mParentCtrl->Size().y - ( mPos.y + mSize.y ) ); } } @@ -128,16 +128,18 @@ const eeSize& cUIComplexControl::Size() { return cUIControlAnim::Size(); } -void cUIComplexControl::OnParentSizeChange() { +void cUIComplexControl::OnParentSizeChange( const eeVector2i& SizeChange ) { eeSize newSize( mSize ); if ( mFlags & UI_ANCHOR_LEFT ) { // Nothing ? + } else { + Pos( mPos.x += SizeChange.x, mPos.y ); } if ( mFlags & UI_ANCHOR_RIGHT ) { if ( NULL != mParentCtrl ) { - newSize.x = mParentCtrl->Size().Width() - mPos.x - mDistToBorder.x; + newSize.x = mParentCtrl->Size().Width() - mPos.x - mDistToBorder.Right; if ( newSize.x < mMinControlSize.Width() ) newSize.y = mMinControlSize.Width(); @@ -146,11 +148,13 @@ void cUIComplexControl::OnParentSizeChange() { if ( mFlags & UI_ANCHOR_TOP ) { // Nothing ? + } else { + Pos( mPos.x, mPos.y += SizeChange.y ); } if ( mFlags & UI_ANCHOR_BOTTOM ) { if ( NULL != mParentCtrl ) { - newSize.y = mParentCtrl->Size().y - mPos.y - mDistToBorder.y; + newSize.y = mParentCtrl->Size().y - mPos.y - mDistToBorder.Bottom; if ( newSize.y < mMinControlSize.Height() ) newSize.y = mMinControlSize.Height(); @@ -159,7 +163,7 @@ void cUIComplexControl::OnParentSizeChange() { Size( newSize ); - cUIControlAnim::OnParentSizeChange(); + cUIControlAnim::OnParentSizeChange( SizeChange ); } }} diff --git a/src/ui/cuicomplexcontrol.hpp b/src/ui/cuicomplexcontrol.hpp index 0ae049125..b095d7a62 100644 --- a/src/ui/cuicomplexcontrol.hpp +++ b/src/ui/cuicomplexcontrol.hpp @@ -39,7 +39,7 @@ class EE_API cUIComplexControl : public cUIControlAnim { cUIComplexControl( const cUIComplexControl::CreateParams& Params ); - ~cUIComplexControl(); + virtual ~cUIComplexControl(); virtual void Update(); @@ -59,11 +59,11 @@ class EE_API cUIComplexControl : public cUIControlAnim { protected: cUITooltip * mTooltip; eeSize mMinControlSize; - eeVector2i mDistToBorder; + eeRecti mDistToBorder; void CreateTooltip(); - virtual void OnParentSizeChange(); + virtual void OnParentSizeChange( const eeVector2i& SizeChange ); void CalcDistToBorder(); }; diff --git a/src/ui/cuicontrol.cpp b/src/ui/cuicontrol.cpp index 676595735..2ccf0817f 100644 --- a/src/ui/cuicontrol.cpp +++ b/src/ui/cuicontrol.cpp @@ -132,9 +132,15 @@ const eeVector2i& cUIControl::Pos() const { void cUIControl::Size( const eeSize& Size ) { if ( Size != mSize ) { + eeVector2i sizeChange( Size.x - mSize.x, Size.y - mSize.y ); + mSize = Size; OnSizeChange(); + + if ( mFlags & UI_REPORT_SIZE_CHANGE_TO_CHILDS ) { + SendParentSizeChange( sizeChange ); + } } } @@ -477,8 +483,6 @@ void cUIControl::OnPosChange() { void cUIControl::OnSizeChange() { SendCommonEvent( cUIEvent::EventOnSizeChange ); - - SendParentSizeChange(); } void cUIControl::BackgroundDraw() { @@ -1030,18 +1034,18 @@ void cUIControl::SetFocus() { cUIManager::instance()->FocusControl( this ); } -void cUIControl::SendParentSizeChange() { +void cUIControl::SendParentSizeChange( const eeVector2i& SizeChange ) { if ( mFlags & UI_REPORT_SIZE_CHANGE_TO_CHILDS ) { cUIControl * ChildLoop = mChild; while( NULL != ChildLoop ) { - ChildLoop->OnParentSizeChange(); + ChildLoop->OnParentSizeChange( SizeChange ); ChildLoop = ChildLoop->mNext; } } } -void cUIControl::OnParentSizeChange( ) { +void cUIControl::OnParentSizeChange( const eeVector2i& SizeChange ) { SendCommonEvent( cUIEvent::EventOnParentSizeChange ); } diff --git a/src/ui/cuicontrol.hpp b/src/ui/cuicontrol.hpp index f918d721f..275a1b996 100644 --- a/src/ui/cuicontrol.hpp +++ b/src/ui/cuicontrol.hpp @@ -49,7 +49,7 @@ class EE_API cUIControl { ParentCtrl = NULL; Pos = eeVector2i( 0, 0 ); Size = eeSize( -1, -1 ); - Flags = UI_HALIGN_LEFT | UI_VALIGN_CENTER; + Flags = UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_HALIGN_LEFT | UI_VALIGN_CENTER; Blend = ALPHA_NORMAL; } @@ -293,7 +293,7 @@ class EE_API cUIControl { virtual void OnSizeChange(); - virtual void OnParentSizeChange(); + virtual void OnParentSizeChange( const eeVector2i& SizeChange ); virtual void OnStateChange(); @@ -355,7 +355,7 @@ class EE_API cUIControl { void ApplyDefaultTheme(); - void SendParentSizeChange(); + void SendParentSizeChange( const eeVector2i& SizeChange ); eeFloat Elapsed(); diff --git a/src/ui/cuidropdownlist.cpp b/src/ui/cuidropdownlist.cpp index a16345c0e..003569063 100644 --- a/src/ui/cuidropdownlist.cpp +++ b/src/ui/cuidropdownlist.cpp @@ -105,6 +105,11 @@ void cUIDropDownList::OnItemClicked( const cUIEvent * Event ) { void cUIDropDownList::OnItemSelected( const cUIEvent * Event ) { Text( mListBox->GetItemSelectedText() ); + + cUIMessage Msg( this, cUIMessage::MsgSelected, mListBox->GetItemSelectedIndex() ); + MessagePost( &Msg ); + + SendCommonEvent( cUIEvent::EventOnItemSelected ); } void cUIDropDownList::Show() { diff --git a/src/ui/cuievent.hpp b/src/ui/cuievent.hpp index 2b29476d6..57374c09a 100644 --- a/src/ui/cuievent.hpp +++ b/src/ui/cuievent.hpp @@ -38,11 +38,13 @@ class EE_API cUIEvent { EventOnHideByClick, EventOnItemKeyDown, EventOnItemKeyUp, + EventOnItemSelected, EventOnCursorPosChange, EventOnParentSizeChange, EventOnWindowCloseClick, EventOnWindowMaximizeClick, EventOnWindowMinimizeClick, + EventOpenFile, EventUser, EventForceDWord = 0xFFFFFFFF }; diff --git a/src/ui/cuilistbox.cpp b/src/ui/cuilistbox.cpp index ae87bde2e..1ab480e52 100644 --- a/src/ui/cuilistbox.cpp +++ b/src/ui/cuilistbox.cpp @@ -136,10 +136,6 @@ Uint32 cUIListBox::AddListBoxItem( cUIListBoxItem * Item ) { return (Uint32)(mItems.size() - 1); } -Uint32 cUIListBox::AddListBoxItem( const std::string& Text ) { - return AddListBoxItem( String( Text ) ); -} - Uint32 cUIListBox::AddListBoxItem( const String& Text ) { mTexts.push_back( Text ); mItems.push_back( NULL ); @@ -222,6 +218,17 @@ void cUIListBox::RemoveListBoxItems( std::vector ItemsIndex ) { } } +void cUIListBox::Clear() { + mTexts.clear(); + mItems.clear(); + mSelected.clear(); + mVScrollBar->Value(0); + + UpdateScroll(); + FindMaxWidth(); + UpdateListBoxItemsSize(); +} + Uint32 cUIListBox::RemoveListBoxItem( Uint32 ItemIndex ) { RemoveListBoxItems( std::vector( 1, ItemIndex ) ); @@ -561,6 +568,9 @@ void cUIListBox::ItemClicked( cUIListBoxItem * Item ) { } Uint32 cUIListBox::OnSelected() { + cUIMessage tMsg( this, cUIMessage::MsgSelected, 0 ); + MessagePost( &tMsg ); + SendCommonEvent( cUIEvent::EventOnSelected ); return 1; diff --git a/src/ui/cuilistbox.hpp b/src/ui/cuilistbox.hpp index 8e35e1c1e..4fe025e69 100644 --- a/src/ui/cuilistbox.hpp +++ b/src/ui/cuilistbox.hpp @@ -54,9 +54,9 @@ class EE_API cUIListBox : public cUIComplexControl { virtual ~cUIListBox(); - void AddListBoxItems( std::vector Texts ); + void Clear(); - Uint32 AddListBoxItem( const std::string& Text ); + void AddListBoxItems( std::vector Texts ); Uint32 AddListBoxItem( const String& Text ); diff --git a/src/ui/cuilistboxitem.cpp b/src/ui/cuilistboxitem.cpp index b7ab55bb4..feed3701e 100644 --- a/src/ui/cuilistboxitem.cpp +++ b/src/ui/cuilistboxitem.cpp @@ -7,6 +7,8 @@ namespace EE { namespace UI { cUIListBoxItem::cUIListBoxItem( const cUITextBox::CreateParams& Params ) : cUITextBox( Params ) { + mType |= UI_TYPE_GET( UI_TYPE_LISTBOXITEM ); + ApplyDefaultTheme(); } diff --git a/src/ui/cuitextbox.cpp b/src/ui/cuitextbox.cpp index a5e940702..184935043 100644 --- a/src/ui/cuitextbox.cpp +++ b/src/ui/cuitextbox.cpp @@ -69,11 +69,20 @@ void cUITextBox::Font( cFont * font ) { } const String& cUITextBox::Text() { + if ( mFlags & UI_AUTO_SHRINK_TEXT ) + return mString; + return mTextCache->Text(); } void cUITextBox::Text( const String& text ) { - mTextCache->Text( text ); + if ( mFlags & UI_AUTO_SHRINK_TEXT ) { + mString = text; + mTextCache->Text( mString ); + } else { + mTextCache->Text( text ); + } + AutoShrink(); AutoSize(); AutoAlign(); @@ -114,6 +123,10 @@ void cUITextBox::AutoShrink() { } void cUITextBox::ShrinkText( const Uint32& MaxWidth ) { + if ( mFlags & UI_AUTO_SHRINK_TEXT ) { + mTextCache->Text( mString ); + } + mTextCache->Font()->ShrinkText( mTextCache->Text(), MaxWidth ); } diff --git a/src/ui/cuitextbox.hpp b/src/ui/cuitextbox.hpp index 252218406..c01aab2d5 100644 --- a/src/ui/cuitextbox.hpp +++ b/src/ui/cuitextbox.hpp @@ -81,6 +81,7 @@ class EE_API cUITextBox : public cUIComplexControl { virtual void ShrinkText( const Uint32& MaxWidth ); protected: cTextCache * mTextCache; + String mString; eeColorA mFontColor; eeColorA mFontShadowColor; eeVector2f mAlignOffset; diff --git a/src/ui/cuitextedit.cpp b/src/ui/cuitextedit.cpp index 1fb443509..ee57ebdd2 100644 --- a/src/ui/cuitextedit.cpp +++ b/src/ui/cuitextedit.cpp @@ -102,8 +102,8 @@ void cUITextEdit::OnSizeChange() { FixScroll(); } -void cUITextEdit::OnParentSizeChange() { - cUIComplexControl::OnParentSizeChange(); +void cUITextEdit::OnParentSizeChange( const eeVector2i& SizeChange ) { + cUIComplexControl::OnParentSizeChange( SizeChange ); OnInputSizeChange( NULL ); } diff --git a/src/ui/cuitextedit.hpp b/src/ui/cuitextedit.hpp index 7d978cc8b..1708c0852 100644 --- a/src/ui/cuitextedit.hpp +++ b/src/ui/cuitextedit.hpp @@ -60,7 +60,7 @@ class EE_API cUITextEdit : public cUIComplexControl { virtual void OnAlphaChange(); - virtual void OnParentSizeChange(); + virtual void OnParentSizeChange( const eeVector2i& SizeChange ); void OnVScrollValueChange( const cUIEvent * Event ); diff --git a/src/ui/cuiwindow.cpp b/src/ui/cuiwindow.cpp index 9ad7e192b..65f70eb30 100644 --- a/src/ui/cuiwindow.cpp +++ b/src/ui/cuiwindow.cpp @@ -178,7 +178,7 @@ void cUIWindow::SetTheme( cUITheme *Theme ) { } void cUIWindow::GetMinWinSize() { - if ( NULL == mWindowDecoration ) + if ( NULL == mWindowDecoration || ( mMinWindowSize.x != 0 && mMinWindowSize.y != 0 ) ) return; eeSize tSize; diff --git a/src/ui/uihelper.hpp b/src/ui/uihelper.hpp index 83494795b..163972bf5 100644 --- a/src/ui/uihelper.hpp +++ b/src/ui/uihelper.hpp @@ -81,21 +81,22 @@ enum UI_CONTROL_TYPES { UI_TYPE_SCROLLBAR = 11, UI_TYPE_PROGRESSBAR = 12, UI_TYPE_LISTBOX = 13, - UI_TYPE_DROPDOWNLIST = 14, - UI_TYPE_SEPARATOR = 15, - UI_TYPE_COMBOBOX = 16, - UI_TYPE_MENU = 17, - UI_TYPE_MENUITEM = 18, - UI_TYPE_MENUCHECKBOX = 19, - UI_TYPE_MENUSUBMENU = 20, - UI_TYPE_SPRITE = 21, - UI_TYPE_TEXTEDIT = 22, - UI_TYPE_TOOLTIP = 23, - UI_TYPE_GENERICGRID = 24, - UI_TYPE_WINDOW = 25, - UI_TYPE_WINMENU = 26, - UI_TYPE_SELECTBUTTON = 27, - UI_TYPE_POPUPMENU = 28 + UI_TYPE_LISTBOXITEM = 14, + UI_TYPE_DROPDOWNLIST = 15, + UI_TYPE_SEPARATOR = 16, + UI_TYPE_COMBOBOX = 17, + UI_TYPE_MENU = 18, + UI_TYPE_MENUITEM = 19, + UI_TYPE_MENUCHECKBOX = 20, + UI_TYPE_MENUSUBMENU = 21, + UI_TYPE_SPRITE = 22, + UI_TYPE_TEXTEDIT = 23, + UI_TYPE_TOOLTIP = 24, + UI_TYPE_GENERICGRID = 25, + UI_TYPE_WINDOW = 26, + UI_TYPE_WINMENU = 27, + UI_TYPE_SELECTBUTTON = 28, + UI_TYPE_POPUPMENU = 29 }; #define UI_TYPE_GET(X) ( 1 << (X) ) diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 18e4c9649..c615a859e 100755 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -801,7 +801,7 @@ std::string SaveTypeToExtension( const Uint32& Format ) { } void DirPathAddSlashAtEnd( std::string& path ) { - if ( path[ path.size() - 1 ] != '/' && path[ path.size() - 1 ] != '\\' ) + if ( path.size() && path[ path.size() - 1 ] != '/' && path[ path.size() - 1 ] != '\\' ) path += GetOSlash(); } @@ -809,10 +809,32 @@ std::string GetOSlash() { #if EE_PLATFORM == EE_PLATFORM_WIN return std::string( "\\" ); #else - return std::string( "/" ); + return std::string( "/" ); #endif } +std::string RemoveLastFolderFromPath( std::string path ) { + if ( path.size() > 1 && ( path[ path.size() - 1 ] == '/' || path[ path.size() - 1 ] == '\\' ) ) { + path.resize( path.size() - 1 ); + } + + std::size_t pos = path.find_last_of( GetOSlash() ); + + if ( std::string::npos != pos ) { + std::size_t pos2 = path.find_first_of( GetOSlash() ); + + if ( pos2 != pos ) { + return path.substr(0,pos) + GetOSlash(); + } else { + if ( pos == pos2 ) { + return path.substr(0,pos2+1); + } + } + } + + return path; +} + std::string SizeToString( const Uint32& MemSize ) { std::string size = " bytes"; eeDouble mem = static_cast( MemSize ); diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index f6a1cc52e..a919b6d08 100755 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -93,6 +93,9 @@ namespace EE { namespace Utils { /** If the directory path not end with a slash, it will add it. */ void EE_API DirPathAddSlashAtEnd( std::string& path ); + /** Move up from directory tree */ + std::string RemoveLastFolderFromPath( std::string path ); + /** @return The default slash path code of the current OS */ std::string EE_API GetOSlash();