From b4bad9100a07266b38a0adaa2efa597b362f027f Mon Sep 17 00:00:00 2001 From: Yoshi Sugawara Date: Thu, 11 Oct 2018 17:09:44 -1000 Subject: IOS: Support building in Xcode 10/iOS 12, and for iPhone X-like devices that have a "safe area" iOS 12 drops support for libstdc++, so the project needs to be compiled explicitly using libc++. Support the "safe area" when redrawing the view to leave space for the notch in portrait and landscape orientations. --- backends/platform/ios7/ios7_video.mm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'backends/platform/ios7') diff --git a/backends/platform/ios7/ios7_video.mm b/backends/platform/ios7/ios7_video.mm index 7ce19f1f4b..35df78ea51 100644 --- a/backends/platform/ios7/ios7_video.mm +++ b/backends/platform/ios7/ios7_video.mm @@ -776,6 +776,7 @@ uint getSizeNextPOT(uint size) { GLfloat ratio = adjustedHeight / adjustedWidth; int height = (int)(screenWidth * ratio); //printf("Making rect (%u, %u)\n", screenWidth, height); + _gameScreenRect = CGRectMake(0, 0, screenWidth, height); overlayPortraitRatio = (_videoContext.overlayHeight * ratio) / _videoContext.overlayWidth; @@ -792,6 +793,32 @@ uint getSizeNextPOT(uint size) { [self setViewTransformation]; [self updateMouseCursorScaling]; + [self adjustViewFrameForSafeArea]; +} + +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + +-(void)adjustViewFrameForSafeArea { +#if __has_builtin(__builtin_available) + if ( @available(iOS 11,*) ) { +#else + if ( [[UIApplication sharedApplication] keyWindow] respondsToSelector:@selector(safeAreaInsets) ) { +#endif + CGRect screenSize = [[UIScreen mainScreen] bounds]; + UIEdgeInsets inset = [[UIApplication sharedApplication] keyWindow].safeAreaInsets; + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + CGRect newFrame = screenSize; + if ( orientation == UIInterfaceOrientationPortrait ) { + newFrame = CGRectMake(screenSize.origin.x, screenSize.origin.y + inset.top, screenSize.size.width, screenSize.size.height - inset.top); + } else if ( orientation == UIInterfaceOrientationLandscapeLeft ) { + newFrame = CGRectMake(screenSize.origin.x, screenSize.origin.y, screenSize.size.width - inset.right, screenSize.size.height); + } else if ( orientation == UIInterfaceOrientationLandscapeRight ) { + newFrame = CGRectMake(screenSize.origin.x + inset.left, screenSize.origin.y, screenSize.size.width - inset.left, screenSize.size.height); + } + self.frame = newFrame; + } } - (void)setViewTransformation { -- cgit v1.2.3