A game framework written with osu! in mind.
at master 172 lines 5.9 kB view raw
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 4using System; 5using System.Collections.Generic; 6using System.Drawing; 7using JetBrains.Annotations; 8using osu.Framework.Bindables; 9using osu.Framework.Configuration; 10 11namespace osu.Framework.Platform 12{ 13 /// <summary> 14 /// Interface representation of the game window, intended to hide any implementation-specific code. 15 /// </summary> 16 public interface IWindow : IDisposable 17 { 18 /// <summary> 19 /// Cycles through the available <see cref="WindowMode"/>s as determined by <see cref="SupportedWindowModes"/>. 20 /// </summary> 21 void CycleMode(); 22 23 /// <summary> 24 /// Configures the <see cref="IWindow"/> based on the provided <see cref="FrameworkConfigManager"/>. 25 /// </summary> 26 /// <param name="config">The configuration manager to use.</param> 27 void SetupWindow(FrameworkConfigManager config); 28 29 /// <summary> 30 /// Creates the concrete window implementation. 31 /// </summary> 32 void Create(); 33 34 /// <summary> 35 /// Return value decides whether we should intercept and cancel this exit (if possible). 36 /// </summary> 37 [CanBeNull] 38 event Func<bool> ExitRequested; 39 40 /// <summary> 41 /// Invoked when the <see cref="IWindow"/> has closed. 42 /// </summary> 43 [CanBeNull] 44 event Action Exited; 45 46 /// <summary> 47 /// Invoked when the <see cref="IWindow"/> client size has changed. 48 /// </summary> 49 [CanBeNull] 50 event Action Resized; 51 52 /// <summary> 53 /// Whether the OS cursor is currently contained within the game window. 54 /// </summary> 55 IBindable<bool> CursorInWindow { get; } 56 57 /// <summary> 58 /// Controls the state of the OS cursor. 59 /// </summary> 60 CursorState CursorState { get; set; } 61 62 /// <summary> 63 /// Controls the state of the window. 64 /// </summary> 65 WindowState WindowState { get; set; } 66 67 /// <summary> 68 /// Controls the vertical sync mode of the screen. 69 /// </summary> 70 bool VerticalSync { get; set; } 71 72 /// <summary> 73 /// Returns the default <see cref="WindowMode"/> for the implementation. 74 /// </summary> 75 WindowMode DefaultWindowMode { get; } 76 77 /// <summary> 78 /// Whether this <see cref="IWindow"/> is active (in the foreground). 79 /// </summary> 80 IBindable<bool> IsActive { get; } 81 82 /// <summary> 83 /// Provides a <see cref="BindableSafeArea"/> that can be used to keep track of the "safe area" insets on mobile 84 /// devices. This usually corresponds to areas of the screen hidden under notches and rounded corners. 85 /// The safe area insets are provided by the operating system and dynamically change as the user rotates the device. 86 /// </summary> 87 BindableSafeArea SafeAreaPadding { get; } 88 89 /// <summary> 90 /// The <see cref="WindowMode"/>s supported by this <see cref="IWindow"/> implementation. 91 /// </summary> 92 IBindableList<WindowMode> SupportedWindowModes { get; } 93 94 /// <summary> 95 /// Provides a <see cref="Bindable{WindowMode}"/> that manages the current window mode. 96 /// Supported window modes for the current platform can be retrieved via <see cref="SupportedWindowModes"/>. 97 /// </summary> 98 Bindable<WindowMode> WindowMode { get; } 99 100 /// <summary> 101 /// Exposes the physical displays as an <see cref="IEnumerable{Display}"/>. 102 /// </summary> 103 IEnumerable<Display> Displays { get; } 104 105 /// <summary> 106 /// Gets the <see cref="Display"/> that has been set as "primary" or "default" in the operating system. 107 /// </summary> 108 Display PrimaryDisplay { get; } 109 110 /// <summary> 111 /// Exposes the <see cref="Display"/> that this window is currently on as a <see cref="Bindable{Display}"/>. 112 /// </summary> 113 Bindable<Display> CurrentDisplayBindable { get; } 114 115 /// <summary> 116 /// The <see cref="DisplayMode"/> for the display that this window is currently on. 117 /// </summary> 118 IBindable<DisplayMode> CurrentDisplayMode { get; } 119 120 /// <summary> 121 /// Makes this window the current graphics context, if appropriate for the driver. 122 /// </summary> 123 void MakeCurrent(); 124 125 /// <summary> 126 /// Clears the current graphics context, if appropriate for the driver. 127 /// </summary> 128 void ClearCurrent(); 129 130 /// <summary> 131 /// Request close. 132 /// </summary> 133 void Close(); 134 135 /// <summary> 136 /// Start the window's run loop. Is a blocking call. 137 /// </summary> 138 void Run(); 139 140 /// <summary> 141 /// Requests that the graphics backend perform a buffer swap. 142 /// </summary> 143 void SwapBuffers(); 144 145 /// <summary> 146 /// Whether the window currently has focus. 147 /// </summary> 148 bool Focused { get; } 149 150 /// <summary> 151 /// Convert a screen based coordinate to local window space. 152 /// </summary> 153 /// <param name="point"></param> 154 Point PointToClient(Point point); 155 156 /// <summary> 157 /// Convert a window based coordinate to global screen space. 158 /// </summary> 159 /// <param name="point"></param> 160 Point PointToScreen(Point point); 161 162 /// <summary> 163 /// The client size of the window (excluding any window decoration/border). 164 /// </summary> 165 Size ClientSize { get; } 166 167 /// <summary> 168 /// The window title. 169 /// </summary> 170 string Title { get; set; } 171 } 172}