Make tests work use ISDLWindow interface

This commit is contained in:
Dan Balasescu
2024-05-21 19:17:21 +09:00
parent 58c99580af
commit 7bfc9fe532
7 changed files with 16 additions and 15 deletions

View File

@@ -11,7 +11,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Platform;
using osu.Framework.Platform.SDL3;
namespace osu.Framework.Tests.Visual.Platform
{
@@ -25,7 +24,7 @@ namespace osu.Framework.Tests.Visual.Platform
private readonly SpriteText currentWindowMode = new SpriteText();
private readonly SpriteText currentDisplay = new SpriteText();
private SDL3Window? window;
private ISDLWindow? window;
private readonly Bindable<WindowMode> windowMode = new Bindable<WindowMode>();
public TestSceneBorderless()
@@ -58,7 +57,7 @@ namespace osu.Framework.Tests.Visual.Platform
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager config, GameHost host)
{
window = host.Window as SDL3Window;
window = host.Window as ISDLWindow;
config.BindWith(FrameworkSetting.WindowMode, windowMode);
windowMode.BindValueChanged(mode => currentWindowMode.Text = $"Window Mode: {mode.NewValue}", true);

View File

@@ -19,7 +19,6 @@ using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Platform.SDL3;
using osuTK;
using WindowState = osu.Framework.Platform.WindowState;
@@ -130,7 +129,7 @@ namespace osu.Framework.Tests.Visual.Platform
if (window.SupportedWindowModes.Contains(WindowMode.Fullscreen))
{
AddStep("change to fullscreen", () => windowMode.Value = WindowMode.Fullscreen);
AddAssert("window position updated", () => ((SDL3Window)window).Position, () => Is.EqualTo(window.CurrentDisplayBindable.Value.Bounds.Location));
AddAssert("window position updated", () => ((ISDLWindow)window).Position, () => Is.EqualTo(window.CurrentDisplayBindable.Value.Bounds.Location));
testResolution(1920, 1080);
testResolution(1280, 960);
testResolution(9999, 9999);

View File

@@ -12,7 +12,6 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Platform;
using osu.Framework.Platform.SDL3;
using osuTK;
using WindowState = osu.Framework.Platform.WindowState;
@@ -32,12 +31,12 @@ namespace osu.Framework.Tests.Visual.Platform
[Resolved]
private FrameworkConfigManager config { get; set; }
private SDL3Window sdlWindow;
private ISDLWindow sdlWindow;
[BackgroundDependencyLoader]
private void load()
{
sdlWindow = (SDL3Window)host.Window;
sdlWindow = (ISDLWindow)host.Window;
Children = new Drawable[]
{
new FillFlowContainer

View File

@@ -14,7 +14,6 @@ using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Platform;
using osu.Framework.Platform.SDL3;
using osuTK;
using osuTK.Graphics;
@@ -37,7 +36,7 @@ namespace osu.Framework.Tests.Visual.Platform
private static readonly Color4 window_fill = new Color4(95, 113, 197, 255);
private static readonly Color4 window_stroke = new Color4(36, 59, 166, 255);
private SDL3Window? window;
private ISDLWindow? window;
private readonly Bindable<WindowMode> windowMode = new Bindable<WindowMode>();
private readonly Bindable<Display> currentDisplay = new Bindable<Display>();
@@ -91,7 +90,7 @@ namespace osu.Framework.Tests.Visual.Platform
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager config, GameHost host)
{
window = host.Window as SDL3Window;
window = host.Window as ISDLWindow;
config.BindWith(FrameworkSetting.WindowMode, windowMode);
if (window != null)

View File

@@ -33,6 +33,9 @@ namespace osu.Framework.Platform
Point Position { get; }
Size Size { get; }
float Scale { get; }
bool Resizable { get; set; }
bool MouseAutoCapture { set; }
bool RelativeMouseMode { get; set; }
bool CapsLockPressed { get; }

View File

@@ -277,7 +277,7 @@ namespace osu.Framework.Platform.SDL2
/// </summary>
public Size ClientSize => new Size((int)(Size.Width * Scale), (int)(Size.Height * Scale));
public float Scale = 1;
public float Scale { get; private set; } = 1;
#region Displays (mostly self-contained)

View File

@@ -284,7 +284,7 @@ namespace osu.Framework.Platform.SDL3
/// </summary>
public Size ClientSize => new Size((int)(Size.Width * Scale), (int)(Size.Height * Scale));
public float Scale = 1;
public float Scale { get; private set; } = 1;
#region Displays (mostly self-contained)
@@ -876,14 +876,16 @@ namespace osu.Framework.Platform.SDL3
if (mode != null)
return *mode;
else
Logger.Log($"Unable to get preferred display mode (try #1/2). Target display: {display.Index}, mode: {size.Width}x{size.Height}@{requestedMode.RefreshRate}. SDL error: {SDL3Extensions.GetAndClearError()}");
Logger.Log(
$"Unable to get preferred display mode (try #1/2). Target display: {display.Index}, mode: {size.Width}x{size.Height}@{requestedMode.RefreshRate}. SDL error: {SDL3Extensions.GetAndClearError()}");
// fallback to current display's native bounds
mode = SDL_GetClosestFullscreenDisplayMode(displayID, display.Bounds.Width, display.Bounds.Height, 0f, SDL_bool.SDL_TRUE);
if (mode != null)
return *mode;
else
Logger.Log($"Unable to get preferred display mode (try #2/2). Target display: {display.Index}, mode: {display.Bounds.Width}x{display.Bounds.Height}@default. SDL error: {SDL3Extensions.GetAndClearError()}");
Logger.Log(
$"Unable to get preferred display mode (try #2/2). Target display: {display.Index}, mode: {display.Bounds.Width}x{display.Bounds.Height}@default. SDL error: {SDL3Extensions.GetAndClearError()}");
// try the display's native display mode.
mode = SDL_GetDesktopDisplayMode(displayID);