Fix notch calculation for iOS.

This commit is contained in:
MoonDroid
2025-04-19 16:06:57 +07:00
parent 2ac0627063
commit 63ec721aa1
5 changed files with 20 additions and 8 deletions
+2
View File
@@ -10,4 +10,6 @@ extern class ScreenUtils
{
@:native('getSafeAreaInsets')
static function getSafeAreaInsets(top:cpp.RawPointer<Float>, bottom:cpp.RawPointer<Float>, left:cpp.RawPointer<Float>, right:cpp.RawPointer<Float>):Void;
@:native('getScreenSize')
static function getScreenSize(width:cpp.RawPointer<Float>, height:cpp.RawPointer<Float>):Void;
}
@@ -1,3 +1,4 @@
#pragma once
void getSafeAreaInsets(double* top, double* bottom, double* left, double* right);
void getScreenSize(double* width, double* height);
@@ -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;
}
+6 -1
View File
@@ -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
+2 -7
View File
@@ -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