Fix mouse scaling to scale by stream view size rather than screen size for better behavior on N and in general

This commit is contained in:
Cameron Gutman 2016-04-19 19:13:57 -04:00
parent e0982d3961
commit 15fb3dd92c
2 changed files with 31 additions and 20 deletions

View File

@ -75,8 +75,8 @@ public class Game extends Activity implements SurfaceHolder.Callback,
private final TouchContext[] touchContextMap = new TouchContext[2]; private final TouchContext[] touchContextMap = new TouchContext[2];
private long threeFingerDownTime = 0; private long threeFingerDownTime = 0;
private static final double REFERENCE_HORIZ_RES = 1280; private static final int REFERENCE_HORIZ_RES = 1280;
private static final double REFERENCE_VERT_RES = 720; private static final int REFERENCE_VERT_RES = 720;
private static final int THREE_FINGER_TAP_THRESHOLD = 300; private static final int THREE_FINGER_TAP_THRESHOLD = 300;
@ -85,7 +85,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
private KeyboardTranslator keybTranslator; private KeyboardTranslator keybTranslator;
private PreferenceConfiguration prefConfig; private PreferenceConfiguration prefConfig;
private final Point screenSize = new Point(0, 0);
private NvConnection conn; private NvConnection conn;
private SpinnerDialog spinner; private SpinnerDialog spinner;
@ -97,6 +96,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
private int modifierFlags = 0; private int modifierFlags = 0;
private boolean grabbedInput = true; private boolean grabbedInput = true;
private boolean grabComboDown = false; private boolean grabComboDown = false;
private StreamView streamView;
private EnhancedDecoderRenderer decoderRenderer; private EnhancedDecoderRenderer decoderRenderer;
@ -175,13 +175,10 @@ public class Game extends Activity implements SurfaceHolder.Callback,
drFlags |= VideoDecoderRenderer.FLAG_FILL_SCREEN; drFlags |= VideoDecoderRenderer.FLAG_FILL_SCREEN;
} }
Display display = getWindowManager().getDefaultDisplay();
display.getSize(screenSize);
// Listen for events on the game surface // Listen for events on the game surface
StreamView sv = (StreamView) findViewById(R.id.surfaceView); streamView = (StreamView) findViewById(R.id.surfaceView);
sv.setOnGenericMotionListener(this); streamView.setOnGenericMotionListener(this);
sv.setOnTouchListener(this); streamView.setOnTouchListener(this);
// Warn the user if they're on a metered connection // Warn the user if they're on a metered connection
checkDataConnection(); checkDataConnection();
@ -258,6 +255,10 @@ public class Game extends Activity implements SurfaceHolder.Callback,
// >= 4K screens have exactly 4K screens, so we'll be able to hit this good path // >= 4K screens have exactly 4K screens, so we'll be able to hit this good path
// on these devices. On Marshmallow, we can start changing to 4K manually but no // on these devices. On Marshmallow, we can start changing to 4K manually but no
// 4K devices run 6.0 at the moment. // 4K devices run 6.0 at the moment.
Display display = getWindowManager().getDefaultDisplay();
Point screenSize = new Point(0, 0);
display.getSize(screenSize);
double screenAspectRatio = ((double)screenSize.y) / screenSize.x; double screenAspectRatio = ((double)screenSize.y) / screenSize.x;
double streamAspectRatio = ((double)prefConfig.height) / prefConfig.width; double streamAspectRatio = ((double)prefConfig.height) / prefConfig.width;
if (Math.abs(screenAspectRatio - streamAspectRatio) < 0.001) { if (Math.abs(screenAspectRatio - streamAspectRatio) < 0.001) {
@ -266,21 +267,21 @@ public class Game extends Activity implements SurfaceHolder.Callback,
} }
} }
SurfaceHolder sh = sv.getHolder(); SurfaceHolder sh = streamView.getHolder();
if (prefConfig.stretchVideo || aspectRatioMatch) { if (prefConfig.stretchVideo || aspectRatioMatch) {
// Set the surface to the size of the video // Set the surface to the size of the video
sh.setFixedSize(prefConfig.width, prefConfig.height); sh.setFixedSize(prefConfig.width, prefConfig.height);
} }
else { else {
// Set the surface to scale based on the aspect ratio of the stream // Set the surface to scale based on the aspect ratio of the stream
sv.setDesiredAspectRatio((double)prefConfig.width / (double)prefConfig.height); streamView.setDesiredAspectRatio((double)prefConfig.width / (double)prefConfig.height);
} }
// 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,
(REFERENCE_HORIZ_RES / (double)screenSize.x), REFERENCE_HORIZ_RES, REFERENCE_VERT_RES,
(REFERENCE_VERT_RES / (double)screenSize.y)); streamView);
} }
if (LimelightBuildProps.ROOT_BUILD) { if (LimelightBuildProps.ROOT_BUILD) {
@ -783,8 +784,8 @@ public class Game extends Activity implements SurfaceHolder.Callback,
// Scale the deltas if the device resolution is different // Scale the deltas if the device resolution is different
// than the stream resolution // than the stream resolution
deltaX = (int)Math.round((double)deltaX * (REFERENCE_HORIZ_RES / (double)screenSize.x)); deltaX = (int)Math.round((double)deltaX * (REFERENCE_HORIZ_RES / (double)streamView.getWidth()));
deltaY = (int)Math.round((double)deltaY * (REFERENCE_VERT_RES / (double)screenSize.y)); deltaY = (int)Math.round((double)deltaY * (REFERENCE_VERT_RES / (double)streamView.getHeight()));
conn.sendMouseMove((short)deltaX, (short)deltaY); conn.sendMouseMove((short)deltaX, (short)deltaY);
} }

View File

@ -1,5 +1,7 @@
package com.limelight.binding.input; package com.limelight.binding.input;
import android.view.View;
import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.NvConnection;
import com.limelight.nvstream.input.MouseButtonPacket; import com.limelight.nvstream.input.MouseButtonPacket;
@ -17,23 +19,27 @@ public class TouchContext {
private boolean confirmedDrag; private boolean confirmedDrag;
private Timer dragTimer; private Timer dragTimer;
private double distanceMoved; private double distanceMoved;
private double xFactor, yFactor;
private final NvConnection conn; private final NvConnection conn;
private final int actionIndex; private final int actionIndex;
private final double xFactor; private final int referenceWidth;
private final double yFactor; private final int referenceHeight;
private final View targetView;
private static final int TAP_MOVEMENT_THRESHOLD = 20; private static final int TAP_MOVEMENT_THRESHOLD = 20;
private static final int TAP_DISTANCE_THRESHOLD = 25; private static final int TAP_DISTANCE_THRESHOLD = 25;
private static final int TAP_TIME_THRESHOLD = 250; private static final int TAP_TIME_THRESHOLD = 250;
private static final int DRAG_TIME_THRESHOLD = 650; private static final int DRAG_TIME_THRESHOLD = 650;
public TouchContext(NvConnection conn, int actionIndex, double xFactor, double yFactor) public TouchContext(NvConnection conn, int actionIndex,
int referenceWidth, int referenceHeight, View view)
{ {
this.conn = conn; this.conn = conn;
this.actionIndex = actionIndex; this.actionIndex = actionIndex;
this.xFactor = xFactor; this.referenceWidth = referenceWidth;
this.yFactor = yFactor; this.referenceHeight = referenceHeight;
this.targetView = view;
} }
public int getActionIndex() public int getActionIndex()
@ -68,6 +74,10 @@ public class TouchContext {
public boolean touchDownEvent(int eventX, int eventY) public boolean touchDownEvent(int eventX, int eventY)
{ {
// Get the view dimensions to scale inputs on this touch
xFactor = referenceWidth / (double)targetView.getWidth();
yFactor = referenceHeight / (double)targetView.getHeight();
originalTouchX = lastTouchX = eventX; originalTouchX = lastTouchX = eventX;
originalTouchY = lastTouchY = eventY; originalTouchY = lastTouchY = eventY;
originalTouchTime = System.currentTimeMillis(); originalTouchTime = System.currentTimeMillis();