Added configurable deceleration for the touch scroll.

This commit is contained in:
Martín Lucas Golini
2013-05-18 02:36:10 -03:00
parent f8209dc7ef
commit a755cbc66b
5 changed files with 18 additions and 10 deletions

View File

@@ -19,7 +19,8 @@ class EE_API cUIGenericGrid : public cUIComplexControl {
HScrollMode( UI_SCROLLBAR_AUTO ),
CollumnsCount(1),
RowHeight( 24 ),
GridWidth( 0 )
GridWidth( 0 ),
TouchDragDeceleration( 0.01f )
{
}
@@ -32,6 +33,7 @@ class EE_API cUIGenericGrid : public cUIComplexControl {
Uint32 RowHeight;
Uint32 GridWidth;
eeRecti PaddingContainer;
eeFloat TouchDragDeceleration;
};
cUIGenericGrid( const cUIGenericGrid::CreateParams& Params );
@@ -126,6 +128,7 @@ class EE_API cUIGenericGrid : public cUIComplexControl {
eeVector2i mTouchDragPoint;
eeFloat mTouchDragAcceleration;
eeFloat mTouchDragDeceleration;
bool mCollWidthAssigned;

View File

@@ -22,7 +22,8 @@ class EE_API cUIListBox : public cUIComplexControl {
Font( NULL ),
FontColor( 0, 0, 0, 255 ),
FontOverColor( 0, 0, 0, 255 ),
FontSelectedColor( 0, 0, 0, 255 )
FontSelectedColor( 0, 0, 0, 255 ),
TouchDragDeceleration( 0.01f )
{
cUITheme * Theme = cUIThemeManager::instance()->DefaultTheme();
@@ -48,6 +49,7 @@ class EE_API cUIListBox : public cUIComplexControl {
eeColorA FontColor;
eeColorA FontOverColor;
eeColorA FontSelectedColor;
eeFloat TouchDragDeceleration;
};
cUIListBox( cUIListBox::CreateParams& Params );
@@ -185,6 +187,7 @@ class EE_API cUIListBox : public cUIComplexControl {
eeVector2i mTouchDragPoint;
eeFloat mTouchDragAcceleration;
eeFloat mTouchDragDeceleration;
std::list<Uint32> mSelected;
std::vector<cUIListBoxItem *> mItems;

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 2.7.0, 2013-05-18T02:19:17. -->
<!-- Written by QtCreator 2.7.0, 2013-05-18T02:35:40. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@@ -22,6 +22,7 @@ cUIGenericGrid::cUIGenericGrid( const cUIGenericGrid::CreateParams& Params ) :
mItemsNotVisible(0),
mSelected(-1),
mTouchDragAcceleration(0),
mTouchDragDeceleration( Params.TouchDragDeceleration ),
mCollWidthAssigned( false )
{
mCollumnsWidth.resize( mCollumnsCount, 0 );
@@ -578,11 +579,11 @@ void cUIGenericGrid::Update() {
mVScrollBar->Value( mVScrollBar->Value() + ( -diff.y / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ) );
mTouchDragAcceleration += Elapsed() * diff.y * 0.01;
mTouchDragAcceleration += Elapsed() * diff.y * mTouchDragDeceleration;
mTouchDragPoint = Pos;
} else {
mTouchDragAcceleration -= Elapsed() * mTouchDragAcceleration * 0.01;
mTouchDragAcceleration -= Elapsed() * mTouchDragAcceleration * 0.01f;
}
} else {
// Mouse Down
@@ -604,7 +605,7 @@ void cUIGenericGrid::Update() {
if ( mTouchDragAcceleration > 0.01f || mTouchDragAcceleration < -0.01f ) {
mVScrollBar->Value( mVScrollBar->Value() + ( -mTouchDragAcceleration / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ) );
mTouchDragAcceleration -= mTouchDragAcceleration * 0.01 * Elapsed();
mTouchDragAcceleration -= mTouchDragAcceleration * mTouchDragDeceleration * Elapsed();
}
}
}

View File

@@ -26,7 +26,8 @@ cUIListBox::cUIListBox( cUIListBox::CreateParams& Params ) :
mLastTickMove(0),
mVisibleFirst(0),
mVisibleLast(0),
mTouchDragAcceleration(0)
mTouchDragAcceleration(0),
mTouchDragDeceleration( Params.TouchDragDeceleration )
{
if ( NULL == Params.Font && NULL != cUIThemeManager::instance()->DefaultFont() )
mFont = cUIThemeManager::instance()->DefaultFont();
@@ -968,11 +969,11 @@ void cUIListBox::Update() {
mVScrollBar->Value( mVScrollBar->Value() + ( -diff.y / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ) );
mTouchDragAcceleration += Elapsed() * diff.y * 0.01;
mTouchDragAcceleration += Elapsed() * diff.y * mTouchDragDeceleration;
mTouchDragPoint = Pos;
} else {
mTouchDragAcceleration -= Elapsed() * mTouchDragAcceleration * 0.01;
mTouchDragAcceleration -= Elapsed() * mTouchDragAcceleration * 0.01f;
}
} else {
// Mouse Down
@@ -994,7 +995,7 @@ void cUIListBox::Update() {
if ( mTouchDragAcceleration > 0.01f || mTouchDragAcceleration < -0.01f ) {
mVScrollBar->Value( mVScrollBar->Value() + ( -mTouchDragAcceleration / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ) );
mTouchDragAcceleration -= mTouchDragAcceleration * 0.01 * Elapsed();
mTouchDragAcceleration -= mTouchDragAcceleration * mTouchDragDeceleration * Elapsed();
}
}
}