Scale touch inputs based on the ratio of the stream size to the screen size

This commit is contained in:
Cameron Gutman 2014-11-19 23:26:50 -08:00
parent 307e807c8f
commit 848ed1ad72
2 changed files with 15 additions and 4 deletions

View File

@ -186,7 +186,9 @@ public class Game extends Activity implements SurfaceHolder.Callback,
// Initialize touch contexts // Initialize touch contexts
for (int i = 0; i < touchContextMap.length; i++) { for (int i = 0; i < touchContextMap.length; i++) {
touchContextMap[i] = new TouchContext(conn, i); touchContextMap[i] = new TouchContext(conn, i,
((double)prefConfig.width / (double)screenSize.x),
((double)prefConfig.height / (double)screenSize.y));
} }
if (LimelightBuildProps.ROOT_BUILD) { if (LimelightBuildProps.ROOT_BUILD) {

View File

@ -12,14 +12,17 @@ public class TouchContext {
private NvConnection conn; private NvConnection conn;
private int actionIndex; private int actionIndex;
private double xFactor, yFactor;
private static final int TAP_MOVEMENT_THRESHOLD = 10; private static final int TAP_MOVEMENT_THRESHOLD = 10;
private static final int TAP_TIME_THRESHOLD = 250; private static final int TAP_TIME_THRESHOLD = 250;
public TouchContext(NvConnection conn, int actionIndex) public TouchContext(NvConnection conn, int actionIndex, double xFactor, double yFactor)
{ {
this.conn = conn; this.conn = conn;
this.actionIndex = actionIndex; this.actionIndex = actionIndex;
this.xFactor = xFactor;
this.yFactor = yFactor;
} }
public int getActionIndex() public int getActionIndex()
@ -83,8 +86,14 @@ public class TouchContext {
{ {
// We only send moves for the primary touch point // We only send moves for the primary touch point
if (actionIndex == 0) { if (actionIndex == 0) {
conn.sendMouseMove((short)(eventX - lastTouchX), int deltaX = eventX - lastTouchX;
(short)(eventY - lastTouchY)); int deltaY = eventY - lastTouchY;
// Scale the deltas based on the factors passed to our constructor
deltaX = (int)Math.round((double)deltaX * xFactor);
deltaY = (int)Math.round((double)deltaY * yFactor);
conn.sendMouseMove((short)deltaX, (short)deltaY);
} }
lastTouchX = eventX; lastTouchX = eventX;