From 63ec721aa181ce106936235aa8985c7367f919b4 Mon Sep 17 00:00:00 2001 From: MoonDroid <81515012+moondroidcoder@users.noreply.github.com> Date: Sat, 19 Apr 2025 16:06:57 +0700 Subject: [PATCH] Fix notch calculation for iOS. --- source/funkin/mobile/external/ScreenUtils.hx | 2 ++ .../mobile/external/project/ios/include/ScreenUtils.hpp | 1 + .../mobile/external/project/ios/src/ScreenUtils.mm | 9 +++++++++ source/funkin/mobile/util/ScreenUtil.hx | 7 ++++++- source/funkin/ui/FullScreenScaleMode.hx | 9 ++------- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/source/funkin/mobile/external/ScreenUtils.hx b/source/funkin/mobile/external/ScreenUtils.hx index d0868da88..cf262b178 100644 --- a/source/funkin/mobile/external/ScreenUtils.hx +++ b/source/funkin/mobile/external/ScreenUtils.hx @@ -10,4 +10,6 @@ extern class ScreenUtils { @:native('getSafeAreaInsets') static function getSafeAreaInsets(top:cpp.RawPointer, bottom:cpp.RawPointer, left:cpp.RawPointer, right:cpp.RawPointer):Void; + @:native('getScreenSize') + static function getScreenSize(width:cpp.RawPointer, height:cpp.RawPointer):Void; } diff --git a/source/funkin/mobile/external/project/ios/include/ScreenUtils.hpp b/source/funkin/mobile/external/project/ios/include/ScreenUtils.hpp index 158845401..b6036d8b8 100644 --- a/source/funkin/mobile/external/project/ios/include/ScreenUtils.hpp +++ b/source/funkin/mobile/external/project/ios/include/ScreenUtils.hpp @@ -1,3 +1,4 @@ #pragma once void getSafeAreaInsets(double* top, double* bottom, double* left, double* right); +void getScreenSize(double* width, double* height); diff --git a/source/funkin/mobile/external/project/ios/src/ScreenUtils.mm b/source/funkin/mobile/external/project/ios/src/ScreenUtils.mm index b0e72c21e..77fb6ed9b 100644 --- a/source/funkin/mobile/external/project/ios/src/ScreenUtils.mm +++ b/source/funkin/mobile/external/project/ios/src/ScreenUtils.mm @@ -25,3 +25,12 @@ void getSafeAreaInsets(double* top, double* bottom, double* left, double* right) (*left) = 0.0; (*right) = 0.0; } + +void getScreenSize(double* width, double* height) +{ + CGRect screenRect = [[UIScreen mainScreen] bounds]; + float scale = [UIScreen mainScreen].scale; + + (*width) = (double)screenRect.size.width * scale; + (*height) = (double)screenRect.size.height * scale; +} diff --git a/source/funkin/mobile/util/ScreenUtil.hx b/source/funkin/mobile/util/ScreenUtil.hx index e269849f9..05b7a7279 100644 --- a/source/funkin/mobile/util/ScreenUtil.hx +++ b/source/funkin/mobile/util/ScreenUtil.hx @@ -55,12 +55,17 @@ class ScreenUtil var left:Float = -1; var right:Float = -1; var bottom:Float = -1; + var width:Float = -1; + var height:Float = -1; ScreenUtils.getSafeAreaInsets(cpp.RawPointer.addressOf(top), cpp.RawPointer.addressOf(bottom), cpp.RawPointer.addressOf(left), cpp.RawPointer.addressOf(right)); + ScreenUtils.getScreenSize(cpp.RawPointer.addressOf(width), cpp.RawPointer.addressOf(height)); + // Calculate the rectangle dimensions for the notch - rectangle.width = flixel.FlxG.stage.stageWidth - left - right; + rectangle.width = -(width - left - right); + rectangle.width += width; rectangle.height = top; rectangle.x = left; // notchs are always at the top of the screen so they have 0 y position diff --git a/source/funkin/ui/FullScreenScaleMode.hx b/source/funkin/ui/FullScreenScaleMode.hx index a02429b1e..29a4937ca 100644 --- a/source/funkin/ui/FullScreenScaleMode.hx +++ b/source/funkin/ui/FullScreenScaleMode.hx @@ -239,13 +239,8 @@ class FullScreenScaleMode extends flixel.system.scaleModes.BaseScaleMode { notchPosition.set(enabled ? notch.x : 0, enabled ? notch.y : 0); notchSize.set(enabled ? notch.width : 0, enabled ? notch.height : 0); - #if android - gameNotchPosition.set(notchPosition.x / 2, notchPosition.y / 2); - gameNotchSize.set(notchSize.x / 2, notchSize.y / 2); - #else - gameNotchPosition.copyFrom(notchPosition); - gameNotchSize.copyFrom(notchSize); - #end + gameNotchPosition.set(notchPosition.x * scale.x, notchPosition.y * scale.y); + gameNotchSize.set(notchSize.x * scale.x, notchSize.y * scale.y); } #end