From 2bf7c0e13609ae6e54d2a93b41d641d01320fb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Mon, 30 Sep 2013 22:44:19 -0300 Subject: [PATCH] Some improvements to the UI. cTextCache setting Color by character fixed. cUIDropDownList now takes the UI_TOUCH_DRAG_ENABLED flag. cUIDropDownList shows the list above the control if the list can't be seen complete dropped below. cUIManager ignores clicks events when some UI_TOUCH_DRAG_ENABLED control was dragging before the click was released. --- include/eepp/ui/cuimanager.hpp | 11 +++++++++ src/eepp/graphics/ctextcache.cpp | 10 +++++--- src/eepp/ui/cuidropdownlist.cpp | 24 ++++++++++++++++++-- src/eepp/ui/cuigenericgrid.cpp | 4 ++++ src/eepp/ui/cuilistbox.cpp | 4 ++++ src/eepp/ui/cuimanager.cpp | 39 +++++++++++++++++++++++--------- 6 files changed, 76 insertions(+), 16 deletions(-) diff --git a/include/eepp/ui/cuimanager.hpp b/include/eepp/ui/cuimanager.hpp index 5e71e7cd5..8f71bfad0 100644 --- a/include/eepp/ui/cuimanager.hpp +++ b/include/eepp/ui/cuimanager.hpp @@ -84,6 +84,15 @@ class EE_API cUIManager { cUIControl * LossFocusControl() const; const bool& IsShootingDown() const; + + /** @return The position of the mouse when the event MouseDown was fired last time. + ** Useful to compare the mouse position of the MouseClick event + */ + const eeVector2i& GetMouseDownPos() const; + + void SetControlDragging( bool dragging ); + + const bool& IsControlDragging() const; protected: friend class cUIControl; friend class cUIWindow; @@ -105,10 +114,12 @@ class EE_API cUIManager { Uint32 mFlags; eeColorA mHighlightFocusColor; eeColorA mHighlightOverColor; + eeVector2i mMouseDownPos; bool mInit; bool mFirstPress; bool mShootingDown; + bool mControlDragging; cUIManager(); diff --git a/src/eepp/graphics/ctextcache.cpp b/src/eepp/graphics/ctextcache.cpp index 5f533c866..0c43af62a 100644 --- a/src/eepp/graphics/ctextcache.cpp +++ b/src/eepp/graphics/ctextcache.cpp @@ -95,10 +95,14 @@ void cTextCache::Color( const eeColorA& color ) { void cTextCache::Color( const eeColorA& color, Uint32 from, Uint32 to ) { std::size_t s = mText.size(); - if ( to >= s ) { to = s - 1; } + if ( to >= s ) { + to = s - 1; + } - if ( from <= to && from < s && to < s ) { - for ( Uint32 i = from * EE_QUAD_VERTEX; i < to * EE_QUAD_VERTEX; i++ ) { + if ( from <= to && from < s && to <= s ) { + size_t rto = ( to * EE_QUAD_VERTEX ) + EE_QUAD_VERTEX; + + for ( Uint32 i = from * EE_QUAD_VERTEX; i < rto; i++ ) { mColors[ i ] = color; } } diff --git a/src/eepp/ui/cuidropdownlist.cpp b/src/eepp/ui/cuidropdownlist.cpp index 46285f02f..96bb88253 100644 --- a/src/eepp/ui/cuidropdownlist.cpp +++ b/src/eepp/ui/cuidropdownlist.cpp @@ -14,14 +14,19 @@ cUIDropDownList::cUIDropDownList( cUIDropDownList::CreateParams& Params ) : ApplyDefaultTheme(); if ( NULL == mListBox ) { + Uint32 flags = UI_CLIP_ENABLE | UI_AUTO_PADDING; + + if ( Params.Flags & UI_TOUCH_DRAG_ENABLED ) + flags |= UI_TOUCH_DRAG_ENABLED; + cUITheme * Theme = cUIThemeManager::instance()->DefaultTheme(); if ( NULL != Theme ) { - mListBox = Theme->CreateListBox( NULL, eeSize( mSize.Width(), mMinNumVisibleItems * mSize.Height() ) ); + mListBox = Theme->CreateListBox( NULL, eeSize( mSize.Width(), mMinNumVisibleItems * mSize.Height() ),eeVector2i(), flags ); } else { cUIListBox::CreateParams LBParams; LBParams.Size = eeSize( mSize.Width(), mMinNumVisibleItems * mSize.Height() ); - LBParams.Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING; + LBParams.Flags = flags; LBParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 ); mListBox = eeNew( cUIListBox, ( LBParams ) ); } @@ -96,8 +101,11 @@ void cUIDropDownList::ShowListBox() { eeVector2i Pos = mScreenPos; Pos.y += mSize.Height(); + mListBox->UpdateScreenPos(); + mListBox->UpdateQuad(); mListBox->Parent()->ScreenToControl( Pos ); mListBox->Pos( Pos ); + mListBox->UpdateQuad(); if ( mListBox->Count() ) { eeRecti tPadding = mListBox->PaddingContainer(); @@ -108,6 +116,18 @@ void cUIDropDownList::ShowListBox() { mListBox->Size( mSize.Width(), (Int32)( mListBox->Count() * mListBox->RowHeight() ) + tPadding.Top + tPadding.Bottom ); } + eeRectf aabb( mListBox->GetPolygon().ToAABB() ); + eeRecti aabbi( aabb.Left, aabb.Top, aabb.Right, aabb.Bottom ); + + if ( !cUIManager::instance()->MainControl()->GetScreenRect().Contains( aabbi ) ) + { + Pos = mScreenPos; + Pos.y -= mListBox->Size().Height(); + + mListBox->Parent()->ScreenToControl( Pos ); + mListBox->Pos( Pos ); + } + Show(); mListBox->SetFocus(); diff --git a/src/eepp/ui/cuigenericgrid.cpp b/src/eepp/ui/cuigenericgrid.cpp index 5c6e5f96d..4620c5fb9 100644 --- a/src/eepp/ui/cuigenericgrid.cpp +++ b/src/eepp/ui/cuigenericgrid.cpp @@ -568,6 +568,7 @@ void cUIGenericGrid::Update() { // Mouse Not Down if ( !( Press & EE_BUTTON_LMASK ) ) { WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 ); + cUIManager::instance()->SetControlDragging( false ); return; } @@ -581,6 +582,8 @@ void cUIGenericGrid::Update() { mTouchDragAcceleration += Elapsed().AsMilliseconds() * diff.y * mTouchDragDeceleration; mTouchDragPoint = Pos; + + cUIManager::instance()->SetControlDragging( true ); } else { mTouchDragAcceleration -= Elapsed().AsMilliseconds() * mTouchDragAcceleration * 0.01f; } @@ -598,6 +601,7 @@ void cUIGenericGrid::Update() { // Mouse Up if ( ( LPress & EE_BUTTON_LMASK ) && !( Press & EE_BUTTON_LMASK ) ) { WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 ); + cUIManager::instance()->SetControlDragging( false ); } // Deaccelerate diff --git a/src/eepp/ui/cuilistbox.cpp b/src/eepp/ui/cuilistbox.cpp index 3074f4452..7b71da0d2 100644 --- a/src/eepp/ui/cuilistbox.cpp +++ b/src/eepp/ui/cuilistbox.cpp @@ -960,6 +960,7 @@ void cUIListBox::Update() { // Mouse Not Down if ( !( Press & EE_BUTTON_LMASK ) ) { WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 ); + cUIManager::instance()->SetControlDragging( false ); return; } @@ -973,6 +974,8 @@ void cUIListBox::Update() { mTouchDragAcceleration += Elapsed().AsMilliseconds() * diff.y * mTouchDragDeceleration; mTouchDragPoint = Pos; + + cUIManager::instance()->SetControlDragging( true ); } else { mTouchDragAcceleration -= Elapsed().AsMilliseconds() * mTouchDragAcceleration * 0.01f; } @@ -990,6 +993,7 @@ void cUIListBox::Update() { // Mouse Up if ( ( LPress & EE_BUTTON_LMASK ) && !( Press & EE_BUTTON_LMASK ) ) { WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 ); + cUIManager::instance()->SetControlDragging( false ); } // Deaccelerate diff --git a/src/eepp/ui/cuimanager.cpp b/src/eepp/ui/cuimanager.cpp index ba86ab096..3574e451e 100644 --- a/src/eepp/ui/cuimanager.cpp +++ b/src/eepp/ui/cuimanager.cpp @@ -181,6 +181,8 @@ void cUIManager::SendMsg( cUIControl * Ctrl, const Uint32& Msg, const Uint32& Fl void cUIManager::Update() { mElapsed = mWindow->Elapsed(); + bool wasDraggingControl = IsControlDragging(); + mControl->Update(); cUIControl * pOver = mControl->OverFind( mKM->GetMousePosf() ); @@ -204,15 +206,13 @@ void cUIManager::Update() { if ( mKM->PressTrigger() ) { if ( NULL != mOverControl ) { - if ( mOverControl != mFocusControl ) - FocusControl( mOverControl ); - mOverControl->OnMouseDown( mKM->GetMousePos(), mKM->PressTrigger() ); SendMsg( mOverControl, cUIMessage::MsgMouseDown, mKM->PressTrigger() ); } if ( !mFirstPress ) { mDownControl = mOverControl; + mMouseDownPos = mKM->GetMousePos(); mFirstPress = true; } @@ -220,16 +220,21 @@ void cUIManager::Update() { if ( mKM->ReleaseTrigger() ) { if ( NULL != mFocusControl ) { - mFocusControl->OnMouseUp( mKM->GetMousePos(), mKM->ReleaseTrigger() ); - SendMsg( mFocusControl, cUIMessage::MsgMouseUp, mKM->ReleaseTrigger() ); + if ( !wasDraggingControl ) { + if ( mOverControl != mFocusControl ) + FocusControl( mOverControl ); - if ( mDownControl == mOverControl && mKM->ClickTrigger() ) { - SendMsg( mFocusControl, cUIMessage::MsgClick, mKM->ClickTrigger() ); - mFocusControl->OnMouseClick( mKM->GetMousePos(), mKM->ClickTrigger() ); + mFocusControl->OnMouseUp( mKM->GetMousePos(), mKM->ReleaseTrigger() ); + SendMsg( mFocusControl, cUIMessage::MsgMouseUp, mKM->ReleaseTrigger() ); - if ( mKM->DoubleClickTrigger() ) { - SendMsg( mFocusControl, cUIMessage::MsgDoubleClick, mKM->DoubleClickTrigger() ); - mFocusControl->OnMouseDoubleClick( mKM->GetMousePos(), mKM->DoubleClickTrigger() ); + if ( mDownControl == mOverControl && mKM->ClickTrigger() ) { + SendMsg( mFocusControl, cUIMessage::MsgClick, mKM->ClickTrigger() ); + mFocusControl->OnMouseClick( mKM->GetMousePos(), mKM->ClickTrigger() ); + + if ( mKM->DoubleClickTrigger() ) { + SendMsg( mFocusControl, cUIMessage::MsgDoubleClick, mKM->DoubleClickTrigger() ); + mFocusControl->OnMouseDoubleClick( mKM->GetMousePos(), mKM->DoubleClickTrigger() ); + } } } } @@ -372,6 +377,10 @@ const bool& cUIManager::IsShootingDown() const { return mShootingDown; } +const eeVector2i &cUIManager::GetMouseDownPos() const { + return mMouseDownPos; +} + void cUIManager::AddToCloseQueue( cUIControl * Ctrl ) { eeASSERT( NULL != Ctrl ); @@ -425,4 +434,12 @@ void cUIManager::CheckClose() { } } +void cUIManager::SetControlDragging( bool dragging ) { + mControlDragging = dragging; +} + +const bool& cUIManager::IsControlDragging() const { + return mControlDragging; +} + }}