A game framework written with osu! in mind.

Introduce IWindow interface to hide GameWindow implementation

+65 -16
+2 -1
osu.Framework.Tests/Visual/Platform/TestSceneFullscreen.cs
··· 2 2 // See the LICENCE file in the repository root for full licence text. 3 3 4 4 using System.Drawing; 5 + using System.Linq; 5 6 using osu.Framework.Allocation; 6 7 using osu.Framework.Bindables; 7 8 using osu.Framework.Configuration; ··· 18 19 private readonly SpriteText currentDisplay = new SpriteText(); 19 20 private readonly SpriteText supportedWindowModes = new SpriteText(); 20 21 21 - private GameWindow window; 22 + private IWindow window; 22 23 private readonly BindableSize sizeFullscreen = new BindableSize(); 23 24 private readonly Bindable<WindowMode> windowMode = new Bindable<WindowMode>(); 24 25
+2 -3
osu.Framework.Tests/Visual/Platform/TestSceneSafeArea.cs
··· 11 11 using osu.Framework.Platform; 12 12 using osuTK; 13 13 using osuTK.Graphics; 14 - using GameWindow = osu.Framework.Platform.GameWindow; 15 14 16 15 namespace osu.Framework.Tests.Visual.Platform 17 16 { 18 17 public class TestSceneSafeArea : FrameworkTestScene 19 18 { 20 - private readonly BindableMarginPadding safeAreaPadding = new BindableMarginPadding(); 19 + private readonly IBindable<MarginPadding> safeAreaPadding = new BindableMarginPadding(); 21 20 private readonly Container container; 22 21 private readonly Box box; 23 22 private readonly SpriteText textbox; 24 23 25 - private GameWindow window; 24 + private IWindow window; 26 25 27 26 public TestSceneSafeArea() 28 27 {
+1 -2
osu.Framework/Game.cs
··· 20 20 using osu.Framework.IO.Stores; 21 21 using osu.Framework.Localisation; 22 22 using osu.Framework.Platform; 23 - using GameWindow = osu.Framework.Platform.GameWindow; 24 23 25 24 namespace osu.Framework 26 25 { 27 26 public abstract class Game : Container, IKeyBindingHandler<FrameworkAction> 28 27 { 29 - public GameWindow Window => Host?.Window; 28 + public IWindow Window => Host?.Window; 30 29 31 30 public ResourceStore<byte[]> Resources { get; private set; } 32 31
+3 -1
osu.Framework/Graphics/OpenGL/GLWrapper.cs
··· 18 18 using osu.Framework.Graphics.Primitives; 19 19 using osu.Framework.Graphics.Colour; 20 20 using osu.Framework.Platform; 21 + using GameWindow = osu.Framework.Platform.GameWindow; 21 22 22 23 namespace osu.Framework.Graphics.OpenGL 23 24 { ··· 65 66 { 66 67 if (IsInitialized) return; 67 68 68 - isEmbedded = host.Window.IsEmbedded; 69 + if (host.Window is GameWindow win) 70 + isEmbedded = win.IsEmbedded; 69 71 70 72 GLWrapper.host = new WeakReference<GameHost>(host); 71 73 reset_scheduler.SetCurrentThread();
+2 -2
osu.Framework/Input/GameWindowTextInput.cs
··· 8 8 { 9 9 public class GameWindowTextInput : ITextInputSource 10 10 { 11 - private readonly GameWindow window; 11 + private readonly IWindow window; 12 12 13 13 private string pending = string.Empty; 14 14 15 - public GameWindowTextInput(GameWindow window) 15 + public GameWindowTextInput(IWindow window) 16 16 { 17 17 this.window = window; 18 18 }
+2 -2
osu.Framework/Platform/GameHost.cs
··· 42 42 { 43 43 public abstract class GameHost : IIpcHost, IDisposable 44 44 { 45 - public GameWindow Window { get; protected set; } 45 + public IWindow Window { get; protected set; } 46 46 47 47 protected FrameworkDebugConfigManager DebugConfig { get; private set; } 48 48 49 49 protected FrameworkConfigManager Config { get; private set; } 50 50 51 51 /// <summary> 52 - /// Whether the <see cref="GameWindow"/> is active (in the foreground). 52 + /// Whether the <see cref="IWindow"/> is active (in the foreground). 53 53 /// </summary> 54 54 public readonly IBindable<bool> IsActive = new Bindable<bool>(true); 55 55
+9 -4
osu.Framework/Platform/GameWindow.cs
··· 15 15 using System.Drawing; 16 16 using JetBrains.Annotations; 17 17 using osu.Framework.Bindables; 18 + using osu.Framework.Graphics; 18 19 using Icon = osuTK.Icon; 19 20 20 21 namespace osu.Framework.Platform 21 22 { 22 - public abstract class GameWindow : IGameWindow 23 + public abstract class GameWindow : IWindow 23 24 { 24 25 /// <summary> 25 26 /// The <see cref="IGraphicsContext"/> associated with this <see cref="GameWindow"/>. ··· 86 87 87 88 FocusedChanged += (o, e) => isActive.Value = Focused; 88 89 89 - SupportedWindowModes.AddRange(DefaultSupportedWindowModes); 90 + supportedWindowModes.AddRange(DefaultSupportedWindowModes); 90 91 91 92 bool firstUpdate = true; 92 93 UpdateFrame += (o, e) => ··· 223 224 224 225 protected virtual void OnKeyDown(object sender, KeyboardKeyEventArgs e) => KeyDown?.Invoke(sender, e); 225 226 227 + private readonly BindableMarginPadding safeAreaPadding = new BindableMarginPadding(); 228 + 226 229 /// <summary> 227 230 /// Provides a <see cref="BindableMarginPadding"/> that can be used to keep track of the "safe area" insets on mobile 228 231 /// devices. This usually corresponds to areas of the screen hidden under notches and rounded corners. 229 232 /// The safe area insets are provided by the operating system and dynamically change as the user rotates the device. 230 233 /// </summary> 231 - public readonly BindableMarginPadding SafeAreaPadding = new BindableMarginPadding(); 234 + public IBindable<MarginPadding> SafeAreaPadding => safeAreaPadding; 232 235 233 - public readonly BindableList<WindowMode> SupportedWindowModes = new BindableList<WindowMode>(); 236 + private readonly BindableList<WindowMode> supportedWindowModes = new BindableList<WindowMode>(); 237 + 238 + public IBindableList<WindowMode> SupportedWindowModes => supportedWindowModes; 234 239 235 240 public virtual WindowMode DefaultWindowMode => SupportedWindowModes.First(); 236 241
+43
osu.Framework/Platform/IWindow.cs
··· 1 + // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2 + // See the LICENCE file in the repository root for full licence text. 3 + 4 + using System; 5 + using osu.Framework.Bindables; 6 + using osu.Framework.Configuration; 7 + using osu.Framework.Graphics; 8 + using osuTK; 9 + using osuTK.Platform; 10 + 11 + namespace osu.Framework.Platform 12 + { 13 + /// <summary> 14 + /// Interface representation of the game window, intended to hide any implementation-specific code. 15 + /// Currently inherits from osuTK; this will be removed as part of the <see cref="GameWindow"/> refactor. 16 + /// </summary> 17 + public interface IWindow : IGameWindow 18 + { 19 + void CycleMode(); 20 + 21 + void SetupWindow(FrameworkConfigManager config); 22 + 23 + event Func<bool> ExitRequested; 24 + 25 + event Action Exited; 26 + 27 + bool CursorInWindow { get; } 28 + 29 + CursorState CursorState { get; set; } 30 + 31 + VSyncMode VSync { get; set; } 32 + 33 + WindowMode DefaultWindowMode { get; } 34 + 35 + DisplayDevice CurrentDisplay { get; } 36 + 37 + IBindable<bool> IsActive { get; } 38 + 39 + IBindable<MarginPadding> SafeAreaPadding { get; } 40 + 41 + IBindableList<WindowMode> SupportedWindowModes { get; } 42 + } 43 + }
+1 -1
osu.Framework/Platform/MacOS/MacOSTextInput.cs
··· 16 16 17 17 private static bool isCapsLockOn => (Cocoa.CGEventSourceFlagsState(event_source_state_hid_system_state) & event_flag_mask_alpha_shift) != 0; 18 18 19 - public MacOSTextInput(GameWindow window) 19 + public MacOSTextInput(IWindow window) 20 20 : base(window) 21 21 { 22 22 }