[Scummvm-cvs-logs] scummvm master -> c6a2d86be7097e8c86291c4b2b2b27218b34be9a

lordhoto lordhoto at gmail.com
Thu Jun 5 04:46:49 CEST 2014


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c6a2d86be7 IPHONE: Scale input according to content scale factor.


Commit: c6a2d86be7097e8c86291c4b2b2b27218b34be9a
    https://github.com/scummvm/scummvm/commit/c6a2d86be7097e8c86291c4b2b2b27218b34be9a
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2014-06-05T04:42:57+02:00

Commit Message:
IPHONE: Scale input according to content scale factor.

This hopefully fixes input positions in retina devices. The idea is stolen
from QT: https://qt.gitorious.org/qt/qt/source/0726127285413829f58618b5b82fb3e2da0c3a74:src/plugins/platforms/uikit/quikitwindow.mm#L261-296

Complicated way to retrieve scale's return value properly is taken from:
https://stackoverflow.com/questions/3130464 We sadly can't use the cleaner
solution since we don't want to require a newer SDK...

Changed paths:
    backends/platform/iphone/iphone_video.h
    backends/platform/iphone/iphone_video.mm



diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h
index 9b26ca9..7dbf3c5 100644
--- a/backends/platform/iphone/iphone_video.h
+++ b/backends/platform/iphone/iphone_video.h
@@ -70,6 +70,7 @@
 	GLfloat _mouseScaleX, _mouseScaleY;
 
 	int _scaledShakeOffsetY;
+	CGFloat _contentScaleFactor;
 
 	UITouch *_firstTouch;
 	UITouch *_secondTouch;
diff --git a/backends/platform/iphone/iphone_video.mm b/backends/platform/iphone/iphone_video.mm
index 3178b38..5048b57 100644
--- a/backends/platform/iphone/iphone_video.mm
+++ b/backends/platform/iphone/iphone_video.mm
@@ -161,9 +161,23 @@ const char *iPhone_getDocumentsDir() {
 - (id)initWithFrame:(struct CGRect)frame {
 	self = [super initWithFrame: frame];
 
+	_contentScaleFactor = 1;
 	if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
 		if ([self respondsToSelector:@selector(setContentScaleFactor:)]) {
-			[self setContentScaleFactor:[[UIScreen mainScreen] scale]];
+			// Horrible and crazy method to get the proper return value of
+			// scale when the SDK used for building does not know anything
+			// about the selector scale...
+			NSMethodSignature *scaleSignature = [UIScreen instanceMethodSignatureForSelector:@selector(scale)];
+			NSInvocation *scaleInvocation = [NSInvocation invocationWithMethodSignature:scaleSignature];
+			[scaleInvocation setTarget:[UIScreen mainScreen]];
+			[scaleInvocation setSelector:@selector(scale)];
+			[scaleInvocation invoke];
+
+			NSInteger returnLength = [[scaleInvocation methodSignature] methodReturnLength];
+			if (returnLength == sizeof(CGFloat)) {
+				[scaleInvocation getReturnValue:&_contentScaleFactor];
+				[self setContentScaleFactor:_contentScaleFactor];
+			}
 		}
 	}
 
@@ -613,6 +627,11 @@ const char *iPhone_getDocumentsDir() {
 }
 
 - (bool)getMouseCoords:(CGPoint)point eventX:(int *)x eventY:(int *)y {
+	// We scale the input according to our scale factor to get actual screen
+	// cooridnates.
+	point.x *= _contentScaleFactor;
+	point.y *= _contentScaleFactor;
+
 	if (![self convertToRotatedCoords:point result:&point])
 		return false;
 






More information about the Scummvm-git-logs mailing list