mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
Solidify windowing API on iOS
This commit is contained in:
24
osu.Framework.iOS/IIOSWindow.cs
Normal file
24
osu.Framework.iOS/IIOSWindow.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Platform;
|
||||
using UIKit;
|
||||
|
||||
namespace osu.Framework.iOS
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface representation of the game window on the iOS platform.
|
||||
/// </summary>
|
||||
public interface IIOSWindow : IWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// The underlying <see cref="UIWindow"/> associated to this window.
|
||||
/// </summary>
|
||||
UIWindow UIWindow { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="UIViewController"/> presenting this window's content.
|
||||
/// </summary>
|
||||
UIViewController ViewController { get; }
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,12 @@ using UniformTypeIdentifiers;
|
||||
|
||||
namespace osu.Framework.iOS
|
||||
{
|
||||
internal class IOSFilePresenter : UIDocumentInteractionControllerDelegate
|
||||
public class IOSFilePresenter : UIDocumentInteractionControllerDelegate
|
||||
{
|
||||
private readonly IOSWindow window;
|
||||
private readonly IIOSWindow window;
|
||||
private readonly UIDocumentInteractionController viewController = new UIDocumentInteractionController();
|
||||
|
||||
internal IOSFilePresenter(IOSWindow window)
|
||||
public IOSFilePresenter(IIOSWindow window)
|
||||
{
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace osu.Framework.iOS
|
||||
{
|
||||
public event Action<FileInfo>? Selected;
|
||||
|
||||
private readonly UIWindow window;
|
||||
private readonly IIOSWindow window;
|
||||
|
||||
private readonly UIDocumentPickerViewController viewController;
|
||||
|
||||
public IOSFileSelector(UIWindow window, string[] allowedExtensions)
|
||||
public IOSFileSelector(IIOSWindow window, string[] allowedExtensions)
|
||||
{
|
||||
this.window = window;
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace osu.Framework.iOS
|
||||
{
|
||||
UIApplication.SharedApplication.InvokeOnMainThread(() =>
|
||||
{
|
||||
window.RootViewController!.PresentViewController(viewController, true, null);
|
||||
window.ViewController.PresentViewController(viewController, true, null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace osu.Framework.iOS
|
||||
{
|
||||
public class IOSGameHost : SDLGameHost
|
||||
{
|
||||
private IOSWindow iosWindow => (IOSWindow)Window;
|
||||
public new IIOSWindow Window => (IIOSWindow)base.Window;
|
||||
|
||||
private IOSFilePresenter presenter = null!;
|
||||
|
||||
public IOSGameHost()
|
||||
@@ -95,7 +96,7 @@ namespace osu.Framework.iOS
|
||||
if (!OperatingSystem.IsIOSVersionAtLeast(14))
|
||||
return;
|
||||
|
||||
selector = new IOSFileSelector(iosWindow.UIWindow, allowedExtensions);
|
||||
selector = new IOSFileSelector(Window, allowedExtensions);
|
||||
});
|
||||
|
||||
return selector;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -16,11 +15,11 @@ using UIKit;
|
||||
|
||||
namespace osu.Framework.iOS
|
||||
{
|
||||
internal class IOSWindow : SDL3MobileWindow
|
||||
internal class IOSWindow : SDL3MobileWindow, IIOSWindow
|
||||
{
|
||||
private UIWindow? uiWindow;
|
||||
public UIWindow UIWindow { get; private set; } = null!;
|
||||
|
||||
public UIWindow UIWindow => uiWindow!;
|
||||
public UIViewController ViewController => UIWindow.RootViewController!;
|
||||
|
||||
public override Size Size
|
||||
{
|
||||
@@ -28,9 +27,7 @@ namespace osu.Framework.iOS
|
||||
protected set
|
||||
{
|
||||
base.Size = value;
|
||||
|
||||
if (uiWindow != null)
|
||||
updateSafeArea();
|
||||
updateSafeArea();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +42,7 @@ namespace osu.Framework.iOS
|
||||
|
||||
base.Create();
|
||||
|
||||
uiWindow = Runtime.GetNSObject<UIWindow>(WindowHandle)!;
|
||||
UIWindow = Runtime.GetNSObject<UIWindow>(WindowHandle)!;
|
||||
updateSafeArea();
|
||||
|
||||
var appDelegate = (GameApplicationDelegate)UIApplication.SharedApplication.Delegate;
|
||||
@@ -76,14 +73,15 @@ namespace osu.Framework.iOS
|
||||
|
||||
private void updateSafeArea()
|
||||
{
|
||||
Debug.Assert(uiWindow != null);
|
||||
if (!Exists)
|
||||
return;
|
||||
|
||||
SafeAreaPadding.Value = new MarginPadding
|
||||
{
|
||||
Top = (float)uiWindow.SafeAreaInsets.Top * Scale,
|
||||
Left = (float)uiWindow.SafeAreaInsets.Left * Scale,
|
||||
Bottom = (float)uiWindow.SafeAreaInsets.Bottom * Scale,
|
||||
Right = (float)uiWindow.SafeAreaInsets.Right * Scale,
|
||||
Top = (float)UIWindow.SafeAreaInsets.Top * Scale,
|
||||
Left = (float)UIWindow.SafeAreaInsets.Left * Scale,
|
||||
Bottom = (float)UIWindow.SafeAreaInsets.Bottom * Scale,
|
||||
Right = (float)UIWindow.SafeAreaInsets.Right * Scale,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user