Standardize mouse input scaling to avoid variance based on stream resolution

This commit is contained in:
Cameron Gutman
2020-04-18 14:33:55 -07:00
parent 10d2e1635b
commit bd5e0ecc40
3 changed files with 8 additions and 32 deletions
-1
View File
@@ -37,7 +37,6 @@
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
config:(StreamConfiguration*)streamConfig; config:(StreamConfiguration*)streamConfig;
- (void) showOnScreenControls; - (void) showOnScreenControls;
- (void) setMouseDeltaFactors:(float)x y:(float)y;
- (OnScreenControlsLevel) getCurrentOscState; - (OnScreenControlsLevel) getCurrentOscState;
@end @end
+8 -24
View File
@@ -15,6 +15,9 @@
static const double X1_MOUSE_SPEED_DIVISOR = 2.5; static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
static const int REFERENCE_WIDTH = 1280;
static const int REFERENCE_HEIGHT = 720;
@implementation StreamView { @implementation StreamView {
CGPoint touchLocation, originalLocation; CGPoint touchLocation, originalLocation;
BOOL touchMoved; BOOL touchMoved;
@@ -26,9 +29,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
NSTimer* dragTimer; NSTimer* dragTimer;
float streamAspectRatio; float streamAspectRatio;
float xDeltaFactor;
float yDeltaFactor;
float screenFactor;
NSInteger lastMouseButtonMask; NSInteger lastMouseButtonMask;
double mouseX; double mouseX;
@@ -46,19 +46,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
TextFieldKeyboardDelegate* textFieldDelegate; TextFieldKeyboardDelegate* textFieldDelegate;
} }
- (void) setMouseDeltaFactors:(float)x y:(float)y {
xDeltaFactor = x;
yDeltaFactor = y;
#if TARGET_OS_TV
// The Apple TV uses indirect touch devices, so they should
// not be scaled by the screen scaling factor.
screenFactor = 1.0f;
#else
screenFactor = [[UIScreen mainScreen] scale];
#endif
}
- (void) setupStreamView:(ControllerSupport*)controllerSupport - (void) setupStreamView:(ControllerSupport*)controllerSupport
swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
@@ -156,9 +143,9 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
} }
} }
- (Boolean)isConfirmedMove:(CGPoint)currentPoint from:(CGPoint)originalPoint { - (BOOL)isConfirmedMove:(CGPoint)currentPoint from:(CGPoint)originalPoint {
// Movements of greater than 10 pixels are considered confirmed // Movements of greater than 5 pixels are considered confirmed
return hypotf(originalPoint.x - currentPoint.x, originalPoint.y - currentPoint.y) >= 10; return hypotf(originalPoint.x - currentPoint.x, originalPoint.y - currentPoint.y) >= 5;
} }
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
@@ -256,11 +243,8 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
if (touchLocation.x != currentLocation.x || if (touchLocation.x != currentLocation.x ||
touchLocation.y != currentLocation.y) touchLocation.y != currentLocation.y)
{ {
int deltaX = currentLocation.x - touchLocation.x; int deltaX = (currentLocation.x - touchLocation.x) * (REFERENCE_WIDTH / self.bounds.size.width);
int deltaY = currentLocation.y - touchLocation.y; int deltaY = (currentLocation.y - touchLocation.y) * (REFERENCE_HEIGHT / self.bounds.size.height);
deltaX *= xDeltaFactor * screenFactor;
deltaY *= yDeltaFactor * screenFactor;
if (deltaX != 0 || deltaY != 0) { if (deltaX != 0 || deltaY != 0) {
LiSendMouseMoveEvent(deltaX, deltaY); LiSendMouseMoveEvent(deltaX, deltaY);
-7
View File
@@ -78,13 +78,6 @@
} }
} }
// Set mouse delta factors from the screen resolution and stream size
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
[((StreamView*)_renderView) setMouseDeltaFactors:_config.width / screenSize.width
y:_config.height / screenSize.height];
// Populate the config's version fields from serverinfo // Populate the config's version fields from serverinfo
_config.appVersion = appversion; _config.appVersion = appversion;
_config.gfeVersion = gfeVersion; _config.gfeVersion = gfeVersion;