mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Implemented touch scrolling for cUIListBox and cUIGenericGrid, usefull for touch screens.
This commit is contained in:
@@ -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<cUIGenericGrid> * 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<cUIGenericGrid>;
|
||||
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();
|
||||
|
||||
@@ -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<cUIListBox>;
|
||||
@@ -173,6 +183,9 @@ class EE_API cUIListBox : public cUIComplexControl {
|
||||
Uint32 mVisibleFirst;
|
||||
Uint32 mVisibleLast;
|
||||
|
||||
eeVector2i mTouchDragPoint;
|
||||
eeFloat mTouchDragAcceleration;
|
||||
|
||||
std::list<Uint32> mSelected;
|
||||
std::vector<cUIListBoxItem *> mItems;
|
||||
std::vector<String> mTexts;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 2.7.0, 2013-05-15T12:35:22. -->
|
||||
<!-- Written by QtCreator 2.7.0, 2013-05-18T02:19:17. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
@@ -48,7 +48,7 @@
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">{388e5431-b31b-42b3-b9ad-9002d279d75d}</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">10</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
|
||||
@@ -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> * 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();
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -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 ) );
|
||||
|
||||
Reference in New Issue
Block a user