mirror of
https://github.com/jamessanford/kegs.git
synced 2025-02-13 04:31:01 +00:00
Touch movements scaled to match screen scaling.
This commit is contained in:
parent
19dfbdd245
commit
2726b3f2c7
@ -391,6 +391,8 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S
|
|||||||
|
|
||||||
mKegsView.updateScreenSize(bitmapSize);
|
mKegsView.updateScreenSize(bitmapSize);
|
||||||
|
|
||||||
|
// Update scale of mouse movements.
|
||||||
|
mKegsTouch.updateScale(bitmapSize.getScaleX(), bitmapSize.getScaleY());
|
||||||
|
|
||||||
// Update special click zone that toggles the ActionBar.
|
// Update special click zone that toggles the ActionBar.
|
||||||
final TouchSpecialZone zone = new TouchSpecialZone(getSpecialActionBarRect(bitmapSize)) {
|
final TouchSpecialZone zone = new TouchSpecialZone(getSpecialActionBarRect(bitmapSize)) {
|
||||||
|
@ -21,13 +21,16 @@ class KegsTouch {
|
|||||||
|
|
||||||
private boolean mPrimaryPastSlop = false;
|
private boolean mPrimaryPastSlop = false;
|
||||||
private boolean mPrimaryLongPress = false;
|
private boolean mPrimaryLongPress = false;
|
||||||
private int mPrimaryX = -1; // original X
|
private float mPrimaryX = -1.0f; // original X
|
||||||
private int mPrimaryY = -1; // original Y
|
private float mPrimaryY = -1.0f; // original Y
|
||||||
private int mPrimaryLastX = -1; // last seen X
|
private float mPrimaryLastX = -1.0f; // last seen X
|
||||||
private int mPrimaryLastY = -1; // last seen Y
|
private float mPrimaryLastY = -1.0f; // last seen Y
|
||||||
|
|
||||||
private int mSecondaryX = -1; // in case of promotion to primary
|
private float mSecondaryX = -1.0f; // in case of promotion to primary
|
||||||
private int mSecondaryY = -1; // in case of promotion to primary
|
private float mSecondaryY = -1.0f; // in case of promotion to primary
|
||||||
|
|
||||||
|
private float mScaleX = 1.0f;
|
||||||
|
private float mScaleY = 1.0f;
|
||||||
|
|
||||||
private static final int LONG_PRESS = 1;
|
private static final int LONG_PRESS = 1;
|
||||||
private static final int LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();
|
private static final int LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();
|
||||||
@ -42,6 +45,11 @@ class KegsTouch {
|
|||||||
mTouchSlopSquare = touchSlop * touchSlop;
|
mTouchSlopSquare = touchSlop * touchSlop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateScale(float x, float y) {
|
||||||
|
mScaleX = x;
|
||||||
|
mScaleY = y;
|
||||||
|
}
|
||||||
|
|
||||||
public void setSpecialZone(TouchSpecialZone zone) {
|
public void setSpecialZone(TouchSpecialZone zone) {
|
||||||
mSpecialZone = zone;
|
mSpecialZone = zone;
|
||||||
}
|
}
|
||||||
@ -60,8 +68,8 @@ class KegsTouch {
|
|||||||
|
|
||||||
// For promotion of secondary to primary. Crazy stuff.
|
// For promotion of secondary to primary. Crazy stuff.
|
||||||
private boolean checkSecondarySlop(MotionEvent newPoint, int index) {
|
private boolean checkSecondarySlop(MotionEvent newPoint, int index) {
|
||||||
final int deltaX = (int)newPoint.getX(index) - mSecondaryX;
|
final int deltaX = (int)newPoint.getX(index) - (int)mSecondaryX;
|
||||||
final int deltaY = (int)newPoint.getY(index) - mSecondaryY;
|
final int deltaY = (int)newPoint.getY(index) - (int)mSecondaryY;
|
||||||
final int distance = (deltaX * deltaX) + (deltaY * deltaY);
|
final int distance = (deltaX * deltaX) + (deltaY * deltaY);
|
||||||
if (distance > mTouchSlopSquare) {
|
if (distance > mTouchSlopSquare) {
|
||||||
return true;
|
return true;
|
||||||
@ -75,8 +83,8 @@ class KegsTouch {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int deltaX = (int)newPoint.getX(index) - mPrimaryX;
|
final int deltaX = (int)newPoint.getX(index) - (int)mPrimaryX;
|
||||||
final int deltaY = (int)newPoint.getY(index) - mPrimaryY;
|
final int deltaY = (int)newPoint.getY(index) - (int)mPrimaryY;
|
||||||
final int distance = (deltaX * deltaX) + (deltaY * deltaY);
|
final int distance = (deltaX * deltaX) + (deltaY * deltaY);
|
||||||
if (distance > mTouchSlopSquare) {
|
if (distance > mTouchSlopSquare) {
|
||||||
mPrimaryPastSlop = true;
|
mPrimaryPastSlop = true;
|
||||||
@ -96,8 +104,8 @@ class KegsTouch {
|
|||||||
if (mPrimaryId == -1 && mSecondaryId != pointerId) {
|
if (mPrimaryId == -1 && mSecondaryId != pointerId) {
|
||||||
// First new finger down becomes movement.
|
// First new finger down becomes movement.
|
||||||
mPrimaryId = pointerId;
|
mPrimaryId = pointerId;
|
||||||
mPrimaryX = (int)event.getX(pointerIndex);
|
mPrimaryX = event.getX(pointerIndex);
|
||||||
mPrimaryY = (int)event.getY(pointerIndex);
|
mPrimaryY = event.getY(pointerIndex);
|
||||||
mPrimaryLastX = mPrimaryX;
|
mPrimaryLastX = mPrimaryX;
|
||||||
mPrimaryLastY = mPrimaryY;
|
mPrimaryLastY = mPrimaryY;
|
||||||
mPrimaryPastSlop = false;
|
mPrimaryPastSlop = false;
|
||||||
@ -109,8 +117,8 @@ class KegsTouch {
|
|||||||
} else {
|
} else {
|
||||||
// Any subequent fingers become the mouse button.
|
// Any subequent fingers become the mouse button.
|
||||||
mSecondaryId = pointerId;
|
mSecondaryId = pointerId;
|
||||||
mSecondaryX = (int)event.getX(pointerIndex);
|
mSecondaryX = event.getX(pointerIndex);
|
||||||
mSecondaryY = (int)event.getY(pointerIndex);
|
mSecondaryY = event.getY(pointerIndex);
|
||||||
mButton1 = 1;
|
mButton1 = 1;
|
||||||
mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1));
|
mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1));
|
||||||
}
|
}
|
||||||
@ -144,8 +152,8 @@ class KegsTouch {
|
|||||||
mButton1 = 0;
|
mButton1 = 0;
|
||||||
mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1));
|
mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1));
|
||||||
mSecondaryId = -1;
|
mSecondaryId = -1;
|
||||||
mSecondaryX = -1;
|
mSecondaryX = -1.0f;
|
||||||
mSecondaryY = -1;
|
mSecondaryY = -1.0f;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (action == MotionEvent.ACTION_CANCEL) {
|
} else if (action == MotionEvent.ACTION_CANCEL) {
|
||||||
@ -161,8 +169,8 @@ class KegsTouch {
|
|||||||
return true;
|
return true;
|
||||||
} else if (pointerId == mSecondaryId) {
|
} else if (pointerId == mSecondaryId) {
|
||||||
mSecondaryId = -1;
|
mSecondaryId = -1;
|
||||||
mSecondaryX = -1;
|
mSecondaryX = -1.0f;
|
||||||
mSecondaryY = -1;
|
mSecondaryY = -1.0f;
|
||||||
if ((mButton1 & 1) == 1) {
|
if ((mButton1 & 1) == 1) {
|
||||||
mButton1 = 0;
|
mButton1 = 0;
|
||||||
mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1));
|
mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1));
|
||||||
@ -176,7 +184,7 @@ class KegsTouch {
|
|||||||
for(moveIndex = 0; moveIndex < event.getPointerCount(); moveIndex++) {
|
for(moveIndex = 0; moveIndex < event.getPointerCount(); moveIndex++) {
|
||||||
moveId = event.getPointerId(moveIndex);
|
moveId = event.getPointerId(moveIndex);
|
||||||
|
|
||||||
if (moveId == mSecondaryId && mPrimaryId != -1 && !mPrimaryPastSlop && mSecondaryX != -1 && mSecondaryY != -1) {
|
if (moveId == mSecondaryId && mPrimaryId != -1 && !mPrimaryPastSlop && mSecondaryX != -1.0f && mSecondaryY != -1.0f) {
|
||||||
// If the secondary goes past slop now, swap primary and secondary...
|
// If the secondary goes past slop now, swap primary and secondary...
|
||||||
// This allows you to click with one finger, and then drag the next
|
// This allows you to click with one finger, and then drag the next
|
||||||
// and that drag becomes the primary finger.
|
// and that drag becomes the primary finger.
|
||||||
@ -189,24 +197,31 @@ class KegsTouch {
|
|||||||
mPrimaryY = mSecondaryY;
|
mPrimaryY = mSecondaryY;
|
||||||
mPrimaryLastX = mSecondaryX;
|
mPrimaryLastX = mSecondaryX;
|
||||||
mPrimaryLastY = mSecondaryY;
|
mPrimaryLastY = mSecondaryY;
|
||||||
mSecondaryX = -1;
|
mSecondaryX = -1.0f;
|
||||||
mSecondaryY = -1;
|
mSecondaryY = -1.0f;
|
||||||
}
|
}
|
||||||
// Let this fall through to process the event.
|
// Let this fall through to process the event.
|
||||||
}
|
}
|
||||||
if (moveId == mPrimaryId) {
|
if (moveId == mPrimaryId) {
|
||||||
if (checkPrimarySlop(event, moveIndex)) {
|
if (checkPrimarySlop(event, moveIndex)) {
|
||||||
mHandler.removeMessages(LONG_PRESS);
|
mHandler.removeMessages(LONG_PRESS);
|
||||||
final int currentX = (int)event.getX(moveIndex);
|
final float currentX = event.getX(moveIndex);
|
||||||
final int currentY = (int)event.getY(moveIndex);
|
final float currentY = event.getY(moveIndex);
|
||||||
final int changeX = currentX - mPrimaryLastX;
|
int changeX = (int)((currentX - mPrimaryLastX) / mScaleX);
|
||||||
final int changeY = currentY - mPrimaryLastY;
|
int changeY = (int)((currentY - mPrimaryLastY) / mScaleY);
|
||||||
|
// Only track the last value when we send a change.
|
||||||
|
// That way if it keeps moving 'one' point at a time,
|
||||||
|
// it will 'eventually' cause a change.
|
||||||
|
if (changeX != 0) {
|
||||||
mPrimaryLastX = currentX;
|
mPrimaryLastX = currentX;
|
||||||
|
}
|
||||||
|
if (changeY != 0) {
|
||||||
mPrimaryLastY = currentY;
|
mPrimaryLastY = currentY;
|
||||||
|
}
|
||||||
mEventQueue.add(new Event.MouseKegsEvent(changeX, changeY, mButton1, 1));
|
mEventQueue.add(new Event.MouseKegsEvent(changeX, changeY, mButton1, 1));
|
||||||
// Once we have had an active primary, don't allow promotions.
|
// Once we have had an active primary, don't allow promotions.
|
||||||
mSecondaryX = -1;
|
mSecondaryX = -1.0f;
|
||||||
mSecondaryY = -1;
|
mSecondaryY = -1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user