diff --git a/include/eepp/ui/cuigenericgrid.hpp b/include/eepp/ui/cuigenericgrid.hpp index 934dd559f..f1c8773d7 100644 --- a/include/eepp/ui/cuigenericgrid.hpp +++ b/include/eepp/ui/cuigenericgrid.hpp @@ -8,12 +8,12 @@ namespace EE { namespace UI { -class EE_API cUIGenericGrid : public cUIControlAnim { +class EE_API cUIGenericGrid : public cUIComplexControl { public: - class CreateParams : public cUIControlAnim::CreateParams { + class CreateParams : public cUIComplexControl::CreateParams { public: inline CreateParams() : - cUIControlAnim::CreateParams(), + cUIComplexControl::CreateParams(), SmoothScroll( true ), VScrollMode( UI_SCROLLBAR_AUTO ), HScrollMode( UI_SCROLLBAR_AUTO ), @@ -89,6 +89,16 @@ class EE_API cUIGenericGrid : public cUIControlAnim { Uint32 OnMessage( const cUIMessage * Msg ); tUIItemContainer * Container() const; + + virtual void Update(); + + bool TouchDragEnable() const; + + void TouchDragEnable( const bool& enable ); + + bool TouchDragging() const; + + void TouchDragging( const bool& dragging ); protected: friend class tUIItemContainer; friend class cUIGridCell; @@ -113,6 +123,10 @@ class EE_API cUIGenericGrid : public cUIControlAnim { Int32 mHScrollInit; Int32 mItemsNotVisible; Int32 mSelected; + + eeVector2i mTouchDragPoint; + eeFloat mTouchDragAcceleration; + bool mCollWidthAssigned; void UpdateCells(); diff --git a/include/eepp/ui/cuilistbox.hpp b/include/eepp/ui/cuilistbox.hpp index ead786f74..87fa2f22d 100644 --- a/include/eepp/ui/cuilistbox.hpp +++ b/include/eepp/ui/cuilistbox.hpp @@ -147,6 +147,16 @@ class EE_API cUIListBox : public cUIComplexControl { void HorizontalScrollMode( const UI_SCROLLBAR_MODE& Mode ); const UI_SCROLLBAR_MODE& HorizontalScrollMode(); + + virtual void Update(); + + bool TouchDragEnable() const; + + void TouchDragEnable( const bool& enable ); + + bool TouchDragging() const; + + void TouchDragging( const bool& dragging ); protected: friend class cUIListBoxItem; friend class tUIItemContainer; @@ -173,6 +183,9 @@ class EE_API cUIListBox : public cUIComplexControl { Uint32 mVisibleFirst; Uint32 mVisibleLast; + eeVector2i mTouchDragPoint; + eeFloat mTouchDragAcceleration; + std::list mSelected; std::vector mItems; std::vector mTexts; diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index c2bab743b..252165679 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -18,6 +18,7 @@ enum UI_CONTROL_FLAGS_VALUES { UI_CTRL_FLAG_DRAGABLE = (1<<9), UI_CTRL_FLAG_COMPLEX = (1<<10), UI_CTRL_FLAG_SKIN_OWNER = (1<<11), + UI_CTRL_FLAG_TOUCH_DRAGGING = (1<<12), UI_CTRL_FLAG_FREE_USE = (1<<31) }; @@ -56,7 +57,8 @@ enum UI_FLAGS { UI_ANCHOR_BOTTOM = (1 << 19), UI_ANCHOR_LEFT = (1 << 20), UI_ANCHOR_RIGHT = (1 << 21), - UI_AUTO_FIT = (1 << 22) + UI_AUTO_FIT = (1 << 22), + UI_TOUCH_DRAG_ENABLED = (1 << 23) }; enum UI_CONTROL_TYPES { diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 85188a5d5..1c7e80d53 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -48,7 +48,7 @@ Desktop Desktop {388e5431-b31b-42b3-b9ad-9002d279d75d} - 10 + 0 0 0 diff --git a/src/eepp/ui/cuigenericgrid.cpp b/src/eepp/ui/cuigenericgrid.cpp index 31e815d0d..9908e5644 100644 --- a/src/eepp/ui/cuigenericgrid.cpp +++ b/src/eepp/ui/cuigenericgrid.cpp @@ -4,7 +4,7 @@ namespace EE { namespace UI { cUIGenericGrid::cUIGenericGrid( const cUIGenericGrid::CreateParams& Params ) : - cUIControlAnim( Params ), + cUIComplexControl( Params ), mPadding( Params.PaddingContainer ), mSmoothScroll( Params.SmoothScroll ), mContainer( NULL ), @@ -21,6 +21,7 @@ cUIGenericGrid::cUIGenericGrid( const cUIGenericGrid::CreateParams& Params ) : mHScrollInit(0), mItemsNotVisible(0), mSelected(-1), + mTouchDragAcceleration(0), mCollWidthAssigned( false ) { mCollumnsWidth.resize( mCollumnsCount, 0 ); @@ -540,4 +541,76 @@ tUIItemContainer * cUIGenericGrid::Container() const { return mContainer; } + +bool cUIGenericGrid::TouchDragEnable() const { + return 0 != ( mFlags & UI_TOUCH_DRAG_ENABLED ); +} + +void cUIGenericGrid::TouchDragEnable( const bool& enable ) { + WriteFlag( UI_TOUCH_DRAG_ENABLED, true == enable ); +} + +bool cUIGenericGrid::TouchDragging() const { + return 0 != ( mControlFlags & UI_CTRL_FLAG_TOUCH_DRAGGING ); +} + +void cUIGenericGrid::TouchDragging( const bool& dragging ) { + WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, true == dragging ); +} + +void cUIGenericGrid::Update() { + if ( mEnabled && mVisible ) { + if ( mFlags & UI_TOUCH_DRAG_ENABLED ) { + Uint32 Press = cUIManager::instance()->PressTrigger(); + Uint32 LPress = cUIManager::instance()->LastPressTrigger(); + + if ( ( mControlFlags & UI_CTRL_FLAG_TOUCH_DRAGGING ) ) { + // Mouse Not Down + if ( !( Press & EE_BUTTON_LMASK ) ) { + WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 ); + return; + } + + eeVector2i Pos( cUIManager::instance()->GetMousePos() ); + + if ( mTouchDragPoint != Pos ) { + eeVector2i diff = -( mTouchDragPoint - Pos ); + + mVScrollBar->Value( mVScrollBar->Value() + ( -diff.y / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ) ); + + mTouchDragAcceleration += Elapsed() * diff.y * 0.01; + + mTouchDragPoint = Pos; + } else { + mTouchDragAcceleration -= Elapsed() * mTouchDragAcceleration * 0.01; + } + } else { + // Mouse Down + if ( IsMouseOverMeOrChilds() && !mVScrollBar->IsMouseOverMeOrChilds() && !mHScrollBar->IsMouseOverMeOrChilds() ) { + if ( !( LPress & EE_BUTTON_LMASK ) && ( Press & EE_BUTTON_LMASK ) ) { + WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 1 ); + + mTouchDragPoint = cUIManager::instance()->GetMousePos(); + mTouchDragAcceleration = 0; + } + } + + // Mouse Up + if ( ( LPress & EE_BUTTON_LMASK ) && !( Press & EE_BUTTON_LMASK ) ) { + WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 ); + } + + // Deaccelerate + if ( mTouchDragAcceleration > 0.01f || mTouchDragAcceleration < -0.01f ) { + mVScrollBar->Value( mVScrollBar->Value() + ( -mTouchDragAcceleration / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ) ); + + mTouchDragAcceleration -= mTouchDragAcceleration * 0.01 * Elapsed(); + } + } + } + } + + cUIComplexControl::Update(); +} + }} diff --git a/src/eepp/ui/cuilistbox.cpp b/src/eepp/ui/cuilistbox.cpp index 98a0dcd84..223244f41 100644 --- a/src/eepp/ui/cuilistbox.cpp +++ b/src/eepp/ui/cuilistbox.cpp @@ -25,7 +25,8 @@ cUIListBox::cUIListBox( cUIListBox::CreateParams& Params ) : mItemsNotVisible(0), mLastTickMove(0), mVisibleFirst(0), - mVisibleLast(0) + mVisibleLast(0), + mTouchDragAcceleration(0) { if ( NULL == Params.Font && NULL != cUIThemeManager::instance()->DefaultFont() ) mFont = cUIThemeManager::instance()->DefaultFont(); @@ -931,4 +932,75 @@ const UI_SCROLLBAR_MODE& cUIListBox::HorizontalScrollMode() { return mHScrollMode; } +bool cUIListBox::TouchDragEnable() const { + return 0 != ( mFlags & UI_TOUCH_DRAG_ENABLED ); +} + +void cUIListBox::TouchDragEnable( const bool& enable ) { + WriteFlag( UI_TOUCH_DRAG_ENABLED, true == enable ); +} + +bool cUIListBox::TouchDragging() const { + return 0 != ( mControlFlags & UI_CTRL_FLAG_TOUCH_DRAGGING ); +} + +void cUIListBox::TouchDragging( const bool& dragging ) { + WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, true == dragging ); +} + +void cUIListBox::Update() { + if ( mEnabled && mVisible ) { + if ( mFlags & UI_TOUCH_DRAG_ENABLED ) { + Uint32 Press = cUIManager::instance()->PressTrigger(); + Uint32 LPress = cUIManager::instance()->LastPressTrigger(); + + if ( ( mControlFlags & UI_CTRL_FLAG_TOUCH_DRAGGING ) ) { + // Mouse Not Down + if ( !( Press & EE_BUTTON_LMASK ) ) { + WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 ); + return; + } + + eeVector2i Pos( cUIManager::instance()->GetMousePos() ); + + if ( mTouchDragPoint != Pos ) { + eeVector2i diff = -( mTouchDragPoint - Pos ); + + mVScrollBar->Value( mVScrollBar->Value() + ( -diff.y / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ) ); + + mTouchDragAcceleration += Elapsed() * diff.y * 0.01; + + mTouchDragPoint = Pos; + } else { + mTouchDragAcceleration -= Elapsed() * mTouchDragAcceleration * 0.01; + } + } else { + // Mouse Down + if ( IsMouseOverMeOrChilds() && !mVScrollBar->IsMouseOverMeOrChilds() && !mHScrollBar->IsMouseOverMeOrChilds() ) { + if ( !( LPress & EE_BUTTON_LMASK ) && ( Press & EE_BUTTON_LMASK ) ) { + WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 1 ); + + mTouchDragPoint = cUIManager::instance()->GetMousePos(); + mTouchDragAcceleration = 0; + } + } + + // Mouse Up + if ( ( LPress & EE_BUTTON_LMASK ) && !( Press & EE_BUTTON_LMASK ) ) { + WriteCtrlFlag( UI_CTRL_FLAG_TOUCH_DRAGGING, 0 ); + } + + // Deaccelerate + if ( mTouchDragAcceleration > 0.01f || mTouchDragAcceleration < -0.01f ) { + mVScrollBar->Value( mVScrollBar->Value() + ( -mTouchDragAcceleration / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ) ); + + mTouchDragAcceleration -= mTouchDragAcceleration * 0.01 * Elapsed(); + } + } + } + } + + cUIComplexControl::Update(); +} + }} diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index fae24a211..fac2a98fd 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -414,7 +414,7 @@ void cEETest::CreateUI() { LBParams.Parent( C ); LBParams.PosSet( 325, 8 ); LBParams.Size = eeSize( 200, 240-16 ); - LBParams.Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING; // | UI_MULTI_SELECT + LBParams.Flags = UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_TOUCH_DRAG_ENABLED; // | UI_MULTI_SELECT mListBox = eeNew( cUIListBox, ( LBParams ) ); mListBox->Visible( true ); mListBox->Enabled( true ); @@ -516,7 +516,7 @@ void cEETest::CreateUI() { GridParams.Parent( C ); GridParams.PosSet( 325, 245 ); GridParams.SizeSet( 200, 130 ); - GridParams.Flags = UI_AUTO_PADDING; + GridParams.Flags = UI_AUTO_PADDING | UI_TOUCH_DRAG_ENABLED; GridParams.RowHeight = 24; GridParams.CollumnsCount = 3; cUIGenericGrid * mGenGrid = eeNew( cUIGenericGrid, ( GridParams ) );