From e0b77d3821ccaa83f07549df0621a661dd040e97 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 20 Jan 2023 00:58:47 +0200 Subject: [PATCH] Can't permanently disable the Home Bar, so the Safe Area must be followed :( --- iOS/GBHorizontalLayout.m | 8 ++++---- iOS/GBLayout.h | 1 + iOS/GBLayout.m | 4 ++++ iOS/GBViewController.m | 14 ++++++++++---- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/iOS/GBHorizontalLayout.m b/iOS/GBHorizontalLayout.m index ab50399..e82c7f4 100644 --- a/iOS/GBHorizontalLayout.m +++ b/iOS/GBHorizontalLayout.m @@ -11,13 +11,13 @@ CGSize resolution = {self.resolution.height - self.cutout, self.resolution.width}; CGRect screenRect = {0,}; - screenRect.size.height = self.hasFractionalPixels? resolution.height : floor(resolution.height / 144) * 144; + screenRect.size.height = self.hasFractionalPixels? resolution.height : floor((resolution.height - self.homeBar) / 144) * 144; screenRect.size.width = screenRect.size.height / 144 * 160; double horizontalMargin, verticalMargin; while (true) { horizontalMargin = (resolution.width - screenRect.size.width) / 2; - verticalMargin = (resolution.height - screenRect.size.height) / 2; + verticalMargin = (resolution.height - self.homeBar - screenRect.size.height) / 2; if (horizontalMargin / self.factor < 164) { if (self.hasFractionalPixels) { screenRect.size.width = resolution.width - 164 * self.factor * 2; @@ -37,10 +37,10 @@ bool drawSameBoyLogo = false; if (verticalMargin * 2 > screenBorderWidth * 7) { drawSameBoyLogo = true; - screenRect.origin.y = (resolution.height - screenRect.size.height - screenBorderWidth * 5) / 2; + screenRect.origin.y = (resolution.height - self.homeBar - screenRect.size.height - screenBorderWidth * 5) / 2; } else { - screenRect.origin.y = (resolution.height - screenRect.size.height) / 2; + screenRect.origin.y = (resolution.height - self.homeBar - screenRect.size.height) / 2; } self.screenRect = screenRect; diff --git a/iOS/GBLayout.h b/iOS/GBLayout.h index 01a9f90..dd2228c 100644 --- a/iOS/GBLayout.h +++ b/iOS/GBLayout.h @@ -24,6 +24,7 @@ @property (readonly) CGSize resolution; @property (readonly) unsigned factor; @property (readonly) unsigned minY; +@property (readonly) unsigned homeBar; @property (readonly) unsigned cutout; @property (readonly) bool hasFractionalPixels; diff --git a/iOS/GBLayout.m b/iOS/GBLayout.m index de99ba7..6850015 100644 --- a/iOS/GBLayout.m +++ b/iOS/GBLayout.m @@ -21,6 +21,10 @@ ignoreHidden:true] * _factor; _cutout = _minY <= 24 * _factor? 0 : _minY; + if ([UIApplication sharedApplication].windows[0].safeAreaInsets.bottom) { + _homeBar = 21 * _factor; + } + // The Plus series will scale things lossily anyway, so no need to bother with integer scale things // This also "catches" zoomed display modes _hasFractionalPixels = _factor != [UIScreen mainScreen].nativeScale; diff --git a/iOS/GBViewController.m b/iOS/GBViewController.m index bcbd7d0..9d1d68f 100644 --- a/iOS/GBViewController.m +++ b/iOS/GBViewController.m @@ -271,10 +271,16 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) - (BOOL)prefersHomeIndicatorAutoHidden { - UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; - if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { - return false; - } + return true; +} + +- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures +{ + return UIRectEdgeTop; +} + +- (BOOL)prefersStatusBarHidden +{ return true; }