From c6a2d86be7097e8c86291c4b2b2b27218b34be9a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 5 Jun 2014 04:42:57 +0200 Subject: 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... --- backends/platform/iphone/iphone_video.h | 1 + backends/platform/iphone/iphone_video.mm | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'backends/platform/iphone') 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; -- cgit v1.2.3