|
|
@@ -730,22 +730,28 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
|
|
|
switch(evt)
|
|
|
{
|
|
|
case Touch::TOUCH_PRESS:
|
|
|
- _scrollingLastX = _scrollingFirstX = x;
|
|
|
- _scrollingLastY = _scrollingFirstY = y;
|
|
|
- _scrollingVelocity.set(0, 0);
|
|
|
- _scrolling = true;
|
|
|
- _scrollingStartTimeX = _scrollingStartTimeY = 0;
|
|
|
-
|
|
|
- if (_scrollBarOpacityClip && _scrollBarOpacityClip->isPlaying())
|
|
|
- {
|
|
|
- _scrollBarOpacityClip->stop();
|
|
|
- _scrollBarOpacityClip = NULL;
|
|
|
- }
|
|
|
- _scrollBarOpacity = 1.0f;
|
|
|
- return _consumeInputEvents;
|
|
|
-
|
|
|
+ if (_contactIndex == INVALID_CONTACT_INDEX)
|
|
|
+ {
|
|
|
+ _contactIndex = (int) contactIndex;
|
|
|
+ _contactIndices++;
|
|
|
+ _scrollingLastX = _scrollingFirstX = x;
|
|
|
+ _scrollingLastY = _scrollingFirstY = y;
|
|
|
+ _scrollingVelocity.set(0, 0);
|
|
|
+ _scrolling = true;
|
|
|
+ _scrollingStartTimeX = _scrollingStartTimeY = 0;
|
|
|
+
|
|
|
+ if (_scrollBarOpacityClip && _scrollBarOpacityClip->isPlaying())
|
|
|
+ {
|
|
|
+ _scrollBarOpacityClip->stop();
|
|
|
+ _scrollBarOpacityClip = NULL;
|
|
|
+ }
|
|
|
+ _scrollBarOpacity = 1.0f;
|
|
|
+
|
|
|
+ return _consumeInputEvents;
|
|
|
+ }
|
|
|
+ break;
|
|
|
case Touch::TOUCH_MOVE:
|
|
|
- if (_scrolling)
|
|
|
+ if (_scrolling && _contactIndex == (int) contactIndex)
|
|
|
{
|
|
|
double gameTime = Game::getAbsoluteTime();
|
|
|
|
|
|
@@ -808,50 +814,57 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
|
|
|
break;
|
|
|
|
|
|
case Touch::TOUCH_RELEASE:
|
|
|
- _scrolling = false;
|
|
|
- double gameTime = Game::getAbsoluteTime();
|
|
|
- float timeSinceLastMove = (float)(gameTime - _scrollingLastTime);
|
|
|
- if (timeSinceLastMove > SCROLL_INERTIA_DELAY)
|
|
|
- {
|
|
|
- _scrollingVelocity.set(0, 0);
|
|
|
- _scrollingMouseVertically = _scrollingMouseHorizontally = false;
|
|
|
- return _consumeInputEvents;
|
|
|
- }
|
|
|
-
|
|
|
- int dx = _scrollingLastX - _scrollingFirstX;
|
|
|
- int dy = _scrollingLastY - _scrollingFirstY;
|
|
|
-
|
|
|
- float timeTakenX = (float)(gameTime - _scrollingStartTimeX);
|
|
|
- float elapsedSecsX = timeTakenX * 0.001f;
|
|
|
- float timeTakenY = (float)(gameTime - _scrollingStartTimeY);
|
|
|
- float elapsedSecsY = timeTakenY * 0.001f;
|
|
|
-
|
|
|
- float vx = dx;
|
|
|
- float vy = dy;
|
|
|
- if (elapsedSecsX > 0)
|
|
|
- vx = (float)dx / elapsedSecsX;
|
|
|
- if (elapsedSecsY > 0)
|
|
|
- vy = (float)dy / elapsedSecsY;
|
|
|
-
|
|
|
- if (_scrollingMouseVertically)
|
|
|
- {
|
|
|
- float yRatio = _totalHeight / _absoluteBounds.height;
|
|
|
- vy *= yRatio;
|
|
|
- _scrollingVelocity.set(0, -vy);
|
|
|
- }
|
|
|
- else if (_scrollingMouseHorizontally)
|
|
|
- {
|
|
|
- float xRatio = _totalWidth / _absoluteBounds.width;
|
|
|
- vx *= xRatio;
|
|
|
- _scrollingVelocity.set(-vx, 0);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _scrollingVelocity.set(vx, vy);
|
|
|
- }
|
|
|
-
|
|
|
- _scrollingMouseVertically = _scrollingMouseHorizontally = false;
|
|
|
- return _consumeInputEvents;
|
|
|
+ if (_contactIndex == (int) contactIndex)
|
|
|
+ {
|
|
|
+ _contactIndex = INVALID_CONTACT_INDEX;
|
|
|
+ _contactIndices--;
|
|
|
+ _scrolling = false;
|
|
|
+ double gameTime = Game::getAbsoluteTime();
|
|
|
+ float timeSinceLastMove = (float)(gameTime - _scrollingLastTime);
|
|
|
+ if (timeSinceLastMove > SCROLL_INERTIA_DELAY)
|
|
|
+ {
|
|
|
+ _scrollingVelocity.set(0, 0);
|
|
|
+ _scrollingMouseVertically = _scrollingMouseHorizontally = false;
|
|
|
+ return _consumeInputEvents;
|
|
|
+ }
|
|
|
+
|
|
|
+ int dx = _scrollingLastX - _scrollingFirstX;
|
|
|
+ int dy = _scrollingLastY - _scrollingFirstY;
|
|
|
+
|
|
|
+ float timeTakenX = (float)(gameTime - _scrollingStartTimeX);
|
|
|
+ float elapsedSecsX = timeTakenX * 0.001f;
|
|
|
+ float timeTakenY = (float)(gameTime - _scrollingStartTimeY);
|
|
|
+ float elapsedSecsY = timeTakenY * 0.001f;
|
|
|
+
|
|
|
+ float vx = dx;
|
|
|
+ float vy = dy;
|
|
|
+ if (elapsedSecsX > 0)
|
|
|
+ vx = (float)dx / elapsedSecsX;
|
|
|
+ if (elapsedSecsY > 0)
|
|
|
+ vy = (float)dy / elapsedSecsY;
|
|
|
+
|
|
|
+ if (_scrollingMouseVertically)
|
|
|
+ {
|
|
|
+ float yRatio = _totalHeight / _absoluteBounds.height;
|
|
|
+ vy *= yRatio;
|
|
|
+ _scrollingVelocity.set(0, -vy);
|
|
|
+ }
|
|
|
+ else if (_scrollingMouseHorizontally)
|
|
|
+ {
|
|
|
+ float xRatio = _totalWidth / _absoluteBounds.width;
|
|
|
+ vx *= xRatio;
|
|
|
+ _scrollingVelocity.set(-vx, 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _scrollingVelocity.set(vx, vy);
|
|
|
+ }
|
|
|
+
|
|
|
+ _scrollingMouseVertically = _scrollingMouseHorizontally = false;
|
|
|
+
|
|
|
+ return _consumeInputEvents;
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
@@ -997,6 +1010,7 @@ bool Container::pointerEvent(bool mouse, char evt, int x, int y, int data)
|
|
|
return (_consumeInputEvents | eventConsumed);
|
|
|
}
|
|
|
|
|
|
+ bool withinClipBounds = false;
|
|
|
switch (evt)
|
|
|
{
|
|
|
case Touch::TOUCH_PRESS:
|
|
|
@@ -1004,12 +1018,14 @@ bool Container::pointerEvent(bool mouse, char evt, int x, int y, int data)
|
|
|
y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
|
|
|
{
|
|
|
setState(Control::FOCUS);
|
|
|
+ withinClipBounds = true;
|
|
|
if (eventConsumed)
|
|
|
_contactIndices++;
|
|
|
}
|
|
|
else if (_contactIndices == 0)
|
|
|
{
|
|
|
setState(Control::NORMAL);
|
|
|
+ _contactIndex = INVALID_CONTACT_INDEX;
|
|
|
return false;
|
|
|
}
|
|
|
break;
|
|
|
@@ -1024,7 +1040,7 @@ bool Container::pointerEvent(bool mouse, char evt, int x, int y, int data)
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if (!eventConsumed && _scroll != SCROLL_NONE && getState() == Control::FOCUS)
|
|
|
+ if (!eventConsumed && _scroll != SCROLL_NONE && getState() == Control::FOCUS && (evt != Touch::TOUCH_PRESS || withinClipBounds))
|
|
|
{
|
|
|
if ((mouse && mouseEventScroll((Mouse::MouseEvent)evt, x - xPos, y - yPos, data)) ||
|
|
|
(!mouse && touchEventScroll((Touch::TouchEvent)evt, x - xPos, y - yPos, (unsigned int)data)))
|