aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/iphone
diff options
context:
space:
mode:
authorJohannes Schickel2014-06-05 04:42:57 +0200
committerJohannes Schickel2014-06-05 04:42:57 +0200
commitc6a2d86be7097e8c86291c4b2b2b27218b34be9a (patch)
tree328c2e2fba31a37b8bacc9b37b51fcbb96cf6b9d /backends/platform/iphone
parent01c18c8f4051b39937d1f036283800a0e3973151 (diff)
downloadscummvm-rg350-c6a2d86be7097e8c86291c4b2b2b27218b34be9a.tar.gz
scummvm-rg350-c6a2d86be7097e8c86291c4b2b2b27218b34be9a.tar.bz2
scummvm-rg350-c6a2d86be7097e8c86291c4b2b2b27218b34be9a.zip
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...
Diffstat (limited to 'backends/platform/iphone')
-rw-r--r--backends/platform/iphone/iphone_video.h1
-rw-r--r--backends/platform/iphone/iphone_video.mm21
2 files changed, 21 insertions, 1 deletions
diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h
index 9b26ca9c5a..7dbf3c57ab 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 3178b38255..5048b57328 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;