From 392703fb2e1c0a334594aa574fdcfbd9a63b1d1b Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 3 Mar 2024 15:58:27 +0100 Subject: [PATCH 01/45] Convert SDL2 usages to `using static` This helps with migrating enums, as ClangSharp doesn't put them in the `SDL3` class. --- osu.Framework.iOS/GameApplication.cs | 8 +- osu.Framework.iOS/IOSWindow.cs | 10 +- osu.Framework/Platform/Linux/LinuxGameHost.cs | 4 +- .../LinuxReadableKeyCombinationProvider.cs | 8 +- .../MacOSReadableKeyCombinationProvider.cs | 12 +- osu.Framework/Platform/SDL2/SDL2Clipboard.cs | 6 +- .../Platform/SDL2/SDL2ControllerBindings.cs | 26 +- osu.Framework/Platform/SDL2/SDL2Extensions.cs | 692 +++++++++--------- .../Platform/SDL2/SDL2GraphicsSurface.cs | 64 +- .../SDL2ReadableKeyCombinationProvider.cs | 96 +-- osu.Framework/Platform/SDL2/SDL2Structs.cs | 8 +- osu.Framework/Platform/SDL2DesktopWindow.cs | 8 +- osu.Framework/Platform/SDL2Window.cs | 214 +++--- osu.Framework/Platform/SDL2Window_Input.cs | 148 ++-- .../Platform/SDL2Window_Windowing.cs | 124 ++-- .../Platform/Windows/WindowsMouseHandler.cs | 6 +- .../WindowsReadableKeyCombinationProvider.cs | 8 +- .../Platform/Windows/WindowsWindow.cs | 24 +- 18 files changed, 733 insertions(+), 733 deletions(-) diff --git a/osu.Framework.iOS/GameApplication.cs b/osu.Framework.iOS/GameApplication.cs index e5d8b00905..b0f9a15333 100644 --- a/osu.Framework.iOS/GameApplication.cs +++ b/osu.Framework.iOS/GameApplication.cs @@ -9,7 +9,7 @@ using ManagedBass.Fx; using ManagedBass.Mix; using ObjCRuntime; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.iOS { @@ -30,11 +30,11 @@ public static void Main(Game target) game = target; - SDL.PrepareLibraryForIOS(); - SDL.SDL_UIKitRunApp(0, IntPtr.Zero, main); + PrepareLibraryForIOS(); + SDL_UIKitRunApp(0, IntPtr.Zero, main); } - [MonoPInvokeCallback(typeof(SDL.SDL_main_func))] + [MonoPInvokeCallback(typeof(SDL_main_func))] private static int main(int argc, IntPtr argv) { var audioSession = AVAudioSession.SharedInstance(); diff --git a/osu.Framework.iOS/IOSWindow.cs b/osu.Framework.iOS/IOSWindow.cs index 1e0e404ff3..40a4801a1b 100644 --- a/osu.Framework.iOS/IOSWindow.cs +++ b/osu.Framework.iOS/IOSWindow.cs @@ -8,8 +8,8 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Platform; -using SDL2; using UIKit; +using static SDL2.SDL; namespace osu.Framework.iOS { @@ -37,7 +37,7 @@ public IOSWindow(GraphicsSurfaceType surfaceType) protected override void UpdateWindowStateAndSize(WindowState state, Display display, DisplayMode displayMode) { // This sets the status bar to hidden. - SDL.SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN); + SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL_WindowFlags.SDL_WINDOW_FULLSCREEN); // Don't run base logic at all. Let's keep things simple. } @@ -60,11 +60,11 @@ protected override void RunMainLoop() // iOS may be a good forward direction if this ever comes up, as a user may see a potentially higher // frame rate with multi-threaded mode turned on, but it is going to give them worse input latency // and higher power usage. - SDL.SDL_iPhoneSetEventPump(SDL.SDL_bool.SDL_FALSE); - SDL.SDL_iPhoneSetAnimationCallback(SDLWindowHandle, 1, runFrame, ObjectHandle.Handle); + SDL_iPhoneSetEventPump(SDL_bool.SDL_FALSE); + SDL_iPhoneSetAnimationCallback(SDLWindowHandle, 1, runFrame, ObjectHandle.Handle); } - [ObjCRuntime.MonoPInvokeCallback(typeof(SDL.SDL_iPhoneAnimationCallback))] + [ObjCRuntime.MonoPInvokeCallback(typeof(SDL_iPhoneAnimationCallback))] private static void runFrame(IntPtr userdata) { var handle = new ObjectHandle(userdata); diff --git a/osu.Framework/Platform/Linux/LinuxGameHost.cs b/osu.Framework/Platform/Linux/LinuxGameHost.cs index 03a94ab3f9..835ee56814 100644 --- a/osu.Framework/Platform/Linux/LinuxGameHost.cs +++ b/osu.Framework/Platform/Linux/LinuxGameHost.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.Linq; -using SDL2; using osu.Framework.Input; using osu.Framework.Input.Handlers; using osu.Framework.Input.Handlers.Mouse; +using static SDL2.SDL; namespace osu.Framework.Platform.Linux { @@ -29,7 +29,7 @@ internal LinuxGameHost(string gameName, HostOptions? options) protected override void SetupForRun() { - SDL.SDL_SetHint(SDL.SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, BypassCompositor ? "1" : "0"); + SDL_SetHint(SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, BypassCompositor ? "1" : "0"); base.SetupForRun(); } diff --git a/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs b/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs index 532ac01df9..d83dc9554b 100644 --- a/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs @@ -3,7 +3,7 @@ using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform.Linux { @@ -21,15 +21,15 @@ protected override string GetReadableKey(InputKey key) } } - protected override bool TryGetNameFromKeycode(SDL.SDL_Keycode keycode, out string name) + protected override bool TryGetNameFromKeycode(SDL_Keycode keycode, out string name) { switch (keycode) { - case SDL.SDL_Keycode.SDLK_LGUI: + case SDL_Keycode.SDLK_LGUI: name = "LSuper"; return true; - case SDL.SDL_Keycode.SDLK_RGUI: + case SDL_Keycode.SDLK_RGUI: name = "RSuper"; return true; diff --git a/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs b/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs index cf118531a0..cc4cce77a2 100644 --- a/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs @@ -3,7 +3,7 @@ using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform.MacOS { @@ -24,23 +24,23 @@ protected override string GetReadableKey(InputKey key) } } - protected override bool TryGetNameFromKeycode(SDL.SDL_Keycode keycode, out string name) + protected override bool TryGetNameFromKeycode(SDL_Keycode keycode, out string name) { switch (keycode) { - case SDL.SDL_Keycode.SDLK_LGUI: + case SDL_Keycode.SDLK_LGUI: name = "LCmd"; return true; - case SDL.SDL_Keycode.SDLK_RGUI: + case SDL_Keycode.SDLK_RGUI: name = "RCmd"; return true; - case SDL.SDL_Keycode.SDLK_LALT: + case SDL_Keycode.SDLK_LALT: name = "LOpt"; return true; - case SDL.SDL_Keycode.SDLK_RALT: + case SDL_Keycode.SDLK_RALT: name = "ROpt"; return true; diff --git a/osu.Framework/Platform/SDL2/SDL2Clipboard.cs b/osu.Framework/Platform/SDL2/SDL2Clipboard.cs index c49cd048fb..f75a4091b5 100644 --- a/osu.Framework/Platform/SDL2/SDL2Clipboard.cs +++ b/osu.Framework/Platform/SDL2/SDL2Clipboard.cs @@ -1,8 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using SDL2; using SixLabors.ImageSharp; +using static SDL2.SDL; namespace osu.Framework.Platform.SDL2 { @@ -11,9 +11,9 @@ public class SDL2Clipboard : Clipboard // SDL cannot differentiate between string.Empty and no text (eg. empty clipboard or an image) // doesn't matter as text editors don't really allow copying empty strings. // assume that empty text means no text. - public override string? GetText() => SDL.SDL_HasClipboardText() == SDL.SDL_bool.SDL_TRUE ? SDL.SDL_GetClipboardText() : null; + public override string? GetText() => SDL_HasClipboardText() == SDL_bool.SDL_TRUE ? SDL_GetClipboardText() : null; - public override void SetText(string text) => SDL.SDL_SetClipboardText(text); + public override void SetText(string text) => SDL_SetClipboardText(text); public override Image? GetImage() { diff --git a/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs b/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs index b364c4031f..fbf06b7cb3 100644 --- a/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs +++ b/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs @@ -5,7 +5,7 @@ using System; using System.Linq; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform.SDL2 { @@ -19,16 +19,16 @@ internal class SDL2ControllerBindings public readonly IntPtr ControllerHandle; /// - /// Bindings returned from , indexed by . + /// Bindings returned from , indexed by . /// Empty if the joystick does not have a corresponding ControllerHandle. /// - public SDL.SDL_GameControllerButtonBind[] ButtonBindings; + public SDL_GameControllerButtonBind[] ButtonBindings; /// - /// Bindings returned from , indexed by . + /// Bindings returned from , indexed by . /// Empty if the joystick does not have a corresponding ControllerHandle. /// - public SDL.SDL_GameControllerButtonBind[] AxisBindings; + public SDL_GameControllerButtonBind[] AxisBindings; public SDL2ControllerBindings(IntPtr joystickHandle, IntPtr controllerHandle) { @@ -42,23 +42,23 @@ public void PopulateBindings() { if (ControllerHandle == IntPtr.Zero) { - ButtonBindings = Array.Empty(); - AxisBindings = Array.Empty(); + ButtonBindings = Array.Empty(); + AxisBindings = Array.Empty(); return; } - ButtonBindings = Enumerable.Range(0, (int)SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_MAX) - .Select(i => SDL.SDL_GameControllerGetBindForButton(ControllerHandle, (SDL.SDL_GameControllerButton)i)).ToArray(); + ButtonBindings = Enumerable.Range(0, (int)SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_MAX) + .Select(i => SDL_GameControllerGetBindForButton(ControllerHandle, (SDL_GameControllerButton)i)).ToArray(); - AxisBindings = Enumerable.Range(0, (int)SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_MAX) - .Select(i => SDL.SDL_GameControllerGetBindForAxis(ControllerHandle, (SDL.SDL_GameControllerAxis)i)).ToArray(); + AxisBindings = Enumerable.Range(0, (int)SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_MAX) + .Select(i => SDL_GameControllerGetBindForAxis(ControllerHandle, (SDL_GameControllerAxis)i)).ToArray(); } public bool IsJoystickButtonBound(byte buttonIndex) { for (int i = 0; i < ButtonBindings.Length; i++) { - if (ButtonBindings[i].bindType != SDL.SDL_GameControllerBindType.SDL_CONTROLLER_BINDTYPE_NONE && ButtonBindings[i].value.button == buttonIndex) + if (ButtonBindings[i].bindType != SDL_GameControllerBindType.SDL_CONTROLLER_BINDTYPE_NONE && ButtonBindings[i].value.button == buttonIndex) return true; } @@ -69,7 +69,7 @@ public bool IsJoystickAxisBound(byte axisIndex) { for (int i = 0; i < AxisBindings.Length; i++) { - if (AxisBindings[i].bindType != SDL.SDL_GameControllerBindType.SDL_CONTROLLER_BINDTYPE_NONE && AxisBindings[i].value.axis == axisIndex) + if (AxisBindings[i].bindType != SDL_GameControllerBindType.SDL_CONTROLLER_BINDTYPE_NONE && AxisBindings[i].value.axis == axisIndex) return true; } diff --git a/osu.Framework/Platform/SDL2/SDL2Extensions.cs b/osu.Framework/Platform/SDL2/SDL2Extensions.cs index 0f154a20ea..edfd63b6f8 100644 --- a/osu.Framework/Platform/SDL2/SDL2Extensions.cs +++ b/osu.Framework/Platform/SDL2/SDL2Extensions.cs @@ -11,458 +11,458 @@ using osu.Framework.Input; using osu.Framework.Input.Bindings; using osuTK.Input; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform.SDL2 { public static class SDL2Extensions { - public static Key ToKey(this SDL.SDL_Keysym sdlKeysym) + public static Key ToKey(this SDL_Keysym sdlKeysym) { // Apple devices don't have the notion of NumLock (they have a Clear key instead). // treat them as if they always have NumLock on (the numpad always performs its primary actions). - bool numLockOn = sdlKeysym.mod.HasFlagFast(SDL.SDL_Keymod.KMOD_NUM) || RuntimeInfo.IsApple; + bool numLockOn = sdlKeysym.mod.HasFlagFast(SDL_Keymod.KMOD_NUM) || RuntimeInfo.IsApple; switch (sdlKeysym.scancode) { default: - case SDL.SDL_Scancode.SDL_SCANCODE_UNKNOWN: + case SDL_Scancode.SDL_SCANCODE_UNKNOWN: return Key.Unknown; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_COMMA: + case SDL_Scancode.SDL_SCANCODE_KP_COMMA: return Key.Comma; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_TAB: + case SDL_Scancode.SDL_SCANCODE_KP_TAB: return Key.Tab; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_BACKSPACE: + case SDL_Scancode.SDL_SCANCODE_KP_BACKSPACE: return Key.BackSpace; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_A: + case SDL_Scancode.SDL_SCANCODE_KP_A: return Key.A; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_B: + case SDL_Scancode.SDL_SCANCODE_KP_B: return Key.B; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_C: + case SDL_Scancode.SDL_SCANCODE_KP_C: return Key.C; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_D: + case SDL_Scancode.SDL_SCANCODE_KP_D: return Key.D; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_E: + case SDL_Scancode.SDL_SCANCODE_KP_E: return Key.E; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_F: + case SDL_Scancode.SDL_SCANCODE_KP_F: return Key.F; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_SPACE: + case SDL_Scancode.SDL_SCANCODE_KP_SPACE: return Key.Space; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_CLEAR: + case SDL_Scancode.SDL_SCANCODE_KP_CLEAR: return Key.Clear; - case SDL.SDL_Scancode.SDL_SCANCODE_RETURN: + case SDL_Scancode.SDL_SCANCODE_RETURN: return Key.Enter; - case SDL.SDL_Scancode.SDL_SCANCODE_ESCAPE: + case SDL_Scancode.SDL_SCANCODE_ESCAPE: return Key.Escape; - case SDL.SDL_Scancode.SDL_SCANCODE_BACKSPACE: + case SDL_Scancode.SDL_SCANCODE_BACKSPACE: return Key.BackSpace; - case SDL.SDL_Scancode.SDL_SCANCODE_TAB: + case SDL_Scancode.SDL_SCANCODE_TAB: return Key.Tab; - case SDL.SDL_Scancode.SDL_SCANCODE_SPACE: + case SDL_Scancode.SDL_SCANCODE_SPACE: return Key.Space; - case SDL.SDL_Scancode.SDL_SCANCODE_APOSTROPHE: + case SDL_Scancode.SDL_SCANCODE_APOSTROPHE: return Key.Quote; - case SDL.SDL_Scancode.SDL_SCANCODE_COMMA: + case SDL_Scancode.SDL_SCANCODE_COMMA: return Key.Comma; - case SDL.SDL_Scancode.SDL_SCANCODE_MINUS: + case SDL_Scancode.SDL_SCANCODE_MINUS: return Key.Minus; - case SDL.SDL_Scancode.SDL_SCANCODE_PERIOD: + case SDL_Scancode.SDL_SCANCODE_PERIOD: return Key.Period; - case SDL.SDL_Scancode.SDL_SCANCODE_SLASH: + case SDL_Scancode.SDL_SCANCODE_SLASH: return Key.Slash; - case SDL.SDL_Scancode.SDL_SCANCODE_0: + case SDL_Scancode.SDL_SCANCODE_0: return Key.Number0; - case SDL.SDL_Scancode.SDL_SCANCODE_1: + case SDL_Scancode.SDL_SCANCODE_1: return Key.Number1; - case SDL.SDL_Scancode.SDL_SCANCODE_2: + case SDL_Scancode.SDL_SCANCODE_2: return Key.Number2; - case SDL.SDL_Scancode.SDL_SCANCODE_3: + case SDL_Scancode.SDL_SCANCODE_3: return Key.Number3; - case SDL.SDL_Scancode.SDL_SCANCODE_4: + case SDL_Scancode.SDL_SCANCODE_4: return Key.Number4; - case SDL.SDL_Scancode.SDL_SCANCODE_5: + case SDL_Scancode.SDL_SCANCODE_5: return Key.Number5; - case SDL.SDL_Scancode.SDL_SCANCODE_6: + case SDL_Scancode.SDL_SCANCODE_6: return Key.Number6; - case SDL.SDL_Scancode.SDL_SCANCODE_7: + case SDL_Scancode.SDL_SCANCODE_7: return Key.Number7; - case SDL.SDL_Scancode.SDL_SCANCODE_8: + case SDL_Scancode.SDL_SCANCODE_8: return Key.Number8; - case SDL.SDL_Scancode.SDL_SCANCODE_9: + case SDL_Scancode.SDL_SCANCODE_9: return Key.Number9; - case SDL.SDL_Scancode.SDL_SCANCODE_SEMICOLON: + case SDL_Scancode.SDL_SCANCODE_SEMICOLON: return Key.Semicolon; - case SDL.SDL_Scancode.SDL_SCANCODE_EQUALS: + case SDL_Scancode.SDL_SCANCODE_EQUALS: return Key.Plus; - case SDL.SDL_Scancode.SDL_SCANCODE_LEFTBRACKET: + case SDL_Scancode.SDL_SCANCODE_LEFTBRACKET: return Key.BracketLeft; - case SDL.SDL_Scancode.SDL_SCANCODE_BACKSLASH: + case SDL_Scancode.SDL_SCANCODE_BACKSLASH: return Key.BackSlash; - case SDL.SDL_Scancode.SDL_SCANCODE_RIGHTBRACKET: + case SDL_Scancode.SDL_SCANCODE_RIGHTBRACKET: return Key.BracketRight; - case SDL.SDL_Scancode.SDL_SCANCODE_GRAVE: + case SDL_Scancode.SDL_SCANCODE_GRAVE: return Key.Tilde; - case SDL.SDL_Scancode.SDL_SCANCODE_A: + case SDL_Scancode.SDL_SCANCODE_A: return Key.A; - case SDL.SDL_Scancode.SDL_SCANCODE_B: + case SDL_Scancode.SDL_SCANCODE_B: return Key.B; - case SDL.SDL_Scancode.SDL_SCANCODE_C: + case SDL_Scancode.SDL_SCANCODE_C: return Key.C; - case SDL.SDL_Scancode.SDL_SCANCODE_D: + case SDL_Scancode.SDL_SCANCODE_D: return Key.D; - case SDL.SDL_Scancode.SDL_SCANCODE_E: + case SDL_Scancode.SDL_SCANCODE_E: return Key.E; - case SDL.SDL_Scancode.SDL_SCANCODE_F: + case SDL_Scancode.SDL_SCANCODE_F: return Key.F; - case SDL.SDL_Scancode.SDL_SCANCODE_G: + case SDL_Scancode.SDL_SCANCODE_G: return Key.G; - case SDL.SDL_Scancode.SDL_SCANCODE_H: + case SDL_Scancode.SDL_SCANCODE_H: return Key.H; - case SDL.SDL_Scancode.SDL_SCANCODE_I: + case SDL_Scancode.SDL_SCANCODE_I: return Key.I; - case SDL.SDL_Scancode.SDL_SCANCODE_J: + case SDL_Scancode.SDL_SCANCODE_J: return Key.J; - case SDL.SDL_Scancode.SDL_SCANCODE_K: + case SDL_Scancode.SDL_SCANCODE_K: return Key.K; - case SDL.SDL_Scancode.SDL_SCANCODE_L: + case SDL_Scancode.SDL_SCANCODE_L: return Key.L; - case SDL.SDL_Scancode.SDL_SCANCODE_M: + case SDL_Scancode.SDL_SCANCODE_M: return Key.M; - case SDL.SDL_Scancode.SDL_SCANCODE_N: + case SDL_Scancode.SDL_SCANCODE_N: return Key.N; - case SDL.SDL_Scancode.SDL_SCANCODE_O: + case SDL_Scancode.SDL_SCANCODE_O: return Key.O; - case SDL.SDL_Scancode.SDL_SCANCODE_P: + case SDL_Scancode.SDL_SCANCODE_P: return Key.P; - case SDL.SDL_Scancode.SDL_SCANCODE_Q: + case SDL_Scancode.SDL_SCANCODE_Q: return Key.Q; - case SDL.SDL_Scancode.SDL_SCANCODE_R: + case SDL_Scancode.SDL_SCANCODE_R: return Key.R; - case SDL.SDL_Scancode.SDL_SCANCODE_S: + case SDL_Scancode.SDL_SCANCODE_S: return Key.S; - case SDL.SDL_Scancode.SDL_SCANCODE_T: + case SDL_Scancode.SDL_SCANCODE_T: return Key.T; - case SDL.SDL_Scancode.SDL_SCANCODE_U: + case SDL_Scancode.SDL_SCANCODE_U: return Key.U; - case SDL.SDL_Scancode.SDL_SCANCODE_V: + case SDL_Scancode.SDL_SCANCODE_V: return Key.V; - case SDL.SDL_Scancode.SDL_SCANCODE_W: + case SDL_Scancode.SDL_SCANCODE_W: return Key.W; - case SDL.SDL_Scancode.SDL_SCANCODE_X: + case SDL_Scancode.SDL_SCANCODE_X: return Key.X; - case SDL.SDL_Scancode.SDL_SCANCODE_Y: + case SDL_Scancode.SDL_SCANCODE_Y: return Key.Y; - case SDL.SDL_Scancode.SDL_SCANCODE_Z: + case SDL_Scancode.SDL_SCANCODE_Z: return Key.Z; - case SDL.SDL_Scancode.SDL_SCANCODE_CAPSLOCK: + case SDL_Scancode.SDL_SCANCODE_CAPSLOCK: return Key.CapsLock; - case SDL.SDL_Scancode.SDL_SCANCODE_F1: + case SDL_Scancode.SDL_SCANCODE_F1: return Key.F1; - case SDL.SDL_Scancode.SDL_SCANCODE_F2: + case SDL_Scancode.SDL_SCANCODE_F2: return Key.F2; - case SDL.SDL_Scancode.SDL_SCANCODE_F3: + case SDL_Scancode.SDL_SCANCODE_F3: return Key.F3; - case SDL.SDL_Scancode.SDL_SCANCODE_F4: + case SDL_Scancode.SDL_SCANCODE_F4: return Key.F4; - case SDL.SDL_Scancode.SDL_SCANCODE_F5: + case SDL_Scancode.SDL_SCANCODE_F5: return Key.F5; - case SDL.SDL_Scancode.SDL_SCANCODE_F6: + case SDL_Scancode.SDL_SCANCODE_F6: return Key.F6; - case SDL.SDL_Scancode.SDL_SCANCODE_F7: + case SDL_Scancode.SDL_SCANCODE_F7: return Key.F7; - case SDL.SDL_Scancode.SDL_SCANCODE_F8: + case SDL_Scancode.SDL_SCANCODE_F8: return Key.F8; - case SDL.SDL_Scancode.SDL_SCANCODE_F9: + case SDL_Scancode.SDL_SCANCODE_F9: return Key.F9; - case SDL.SDL_Scancode.SDL_SCANCODE_F10: + case SDL_Scancode.SDL_SCANCODE_F10: return Key.F10; - case SDL.SDL_Scancode.SDL_SCANCODE_F11: + case SDL_Scancode.SDL_SCANCODE_F11: return Key.F11; - case SDL.SDL_Scancode.SDL_SCANCODE_F12: + case SDL_Scancode.SDL_SCANCODE_F12: return Key.F12; - case SDL.SDL_Scancode.SDL_SCANCODE_PRINTSCREEN: + case SDL_Scancode.SDL_SCANCODE_PRINTSCREEN: return Key.PrintScreen; - case SDL.SDL_Scancode.SDL_SCANCODE_SCROLLLOCK: + case SDL_Scancode.SDL_SCANCODE_SCROLLLOCK: return Key.ScrollLock; - case SDL.SDL_Scancode.SDL_SCANCODE_PAUSE: + case SDL_Scancode.SDL_SCANCODE_PAUSE: return Key.Pause; - case SDL.SDL_Scancode.SDL_SCANCODE_INSERT: + case SDL_Scancode.SDL_SCANCODE_INSERT: return Key.Insert; - case SDL.SDL_Scancode.SDL_SCANCODE_HOME: + case SDL_Scancode.SDL_SCANCODE_HOME: return Key.Home; - case SDL.SDL_Scancode.SDL_SCANCODE_PAGEUP: + case SDL_Scancode.SDL_SCANCODE_PAGEUP: return Key.PageUp; - case SDL.SDL_Scancode.SDL_SCANCODE_DELETE: + case SDL_Scancode.SDL_SCANCODE_DELETE: return Key.Delete; - case SDL.SDL_Scancode.SDL_SCANCODE_END: + case SDL_Scancode.SDL_SCANCODE_END: return Key.End; - case SDL.SDL_Scancode.SDL_SCANCODE_PAGEDOWN: + case SDL_Scancode.SDL_SCANCODE_PAGEDOWN: return Key.PageDown; - case SDL.SDL_Scancode.SDL_SCANCODE_RIGHT: + case SDL_Scancode.SDL_SCANCODE_RIGHT: return Key.Right; - case SDL.SDL_Scancode.SDL_SCANCODE_LEFT: + case SDL_Scancode.SDL_SCANCODE_LEFT: return Key.Left; - case SDL.SDL_Scancode.SDL_SCANCODE_DOWN: + case SDL_Scancode.SDL_SCANCODE_DOWN: return Key.Down; - case SDL.SDL_Scancode.SDL_SCANCODE_UP: + case SDL_Scancode.SDL_SCANCODE_UP: return Key.Up; - case SDL.SDL_Scancode.SDL_SCANCODE_NUMLOCKCLEAR: + case SDL_Scancode.SDL_SCANCODE_NUMLOCKCLEAR: return Key.NumLock; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_DIVIDE: + case SDL_Scancode.SDL_SCANCODE_KP_DIVIDE: return Key.KeypadDivide; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_MULTIPLY: + case SDL_Scancode.SDL_SCANCODE_KP_MULTIPLY: return Key.KeypadMultiply; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_MINUS: + case SDL_Scancode.SDL_SCANCODE_KP_MINUS: return Key.KeypadMinus; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_PLUS: + case SDL_Scancode.SDL_SCANCODE_KP_PLUS: return Key.KeypadPlus; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_ENTER: + case SDL_Scancode.SDL_SCANCODE_KP_ENTER: return Key.KeypadEnter; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_1: + case SDL_Scancode.SDL_SCANCODE_KP_1: return numLockOn ? Key.Keypad1 : Key.End; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_2: + case SDL_Scancode.SDL_SCANCODE_KP_2: return numLockOn ? Key.Keypad2 : Key.Down; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_3: + case SDL_Scancode.SDL_SCANCODE_KP_3: return numLockOn ? Key.Keypad3 : Key.PageDown; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_4: + case SDL_Scancode.SDL_SCANCODE_KP_4: return numLockOn ? Key.Keypad4 : Key.Left; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_5: + case SDL_Scancode.SDL_SCANCODE_KP_5: return numLockOn ? Key.Keypad5 : Key.Clear; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_6: + case SDL_Scancode.SDL_SCANCODE_KP_6: return numLockOn ? Key.Keypad6 : Key.Right; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_7: + case SDL_Scancode.SDL_SCANCODE_KP_7: return numLockOn ? Key.Keypad7 : Key.Home; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_8: + case SDL_Scancode.SDL_SCANCODE_KP_8: return numLockOn ? Key.Keypad8 : Key.Up; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_9: + case SDL_Scancode.SDL_SCANCODE_KP_9: return numLockOn ? Key.Keypad9 : Key.PageUp; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_0: + case SDL_Scancode.SDL_SCANCODE_KP_0: return numLockOn ? Key.Keypad0 : Key.Insert; - case SDL.SDL_Scancode.SDL_SCANCODE_KP_PERIOD: + case SDL_Scancode.SDL_SCANCODE_KP_PERIOD: return numLockOn ? Key.KeypadPeriod : Key.Delete; - case SDL.SDL_Scancode.SDL_SCANCODE_NONUSBACKSLASH: + case SDL_Scancode.SDL_SCANCODE_NONUSBACKSLASH: return Key.NonUSBackSlash; - case SDL.SDL_Scancode.SDL_SCANCODE_F13: + case SDL_Scancode.SDL_SCANCODE_F13: return Key.F13; - case SDL.SDL_Scancode.SDL_SCANCODE_F14: + case SDL_Scancode.SDL_SCANCODE_F14: return Key.F14; - case SDL.SDL_Scancode.SDL_SCANCODE_F15: + case SDL_Scancode.SDL_SCANCODE_F15: return Key.F15; - case SDL.SDL_Scancode.SDL_SCANCODE_F16: + case SDL_Scancode.SDL_SCANCODE_F16: return Key.F16; - case SDL.SDL_Scancode.SDL_SCANCODE_F17: + case SDL_Scancode.SDL_SCANCODE_F17: return Key.F17; - case SDL.SDL_Scancode.SDL_SCANCODE_F18: + case SDL_Scancode.SDL_SCANCODE_F18: return Key.F18; - case SDL.SDL_Scancode.SDL_SCANCODE_F19: + case SDL_Scancode.SDL_SCANCODE_F19: return Key.F19; - case SDL.SDL_Scancode.SDL_SCANCODE_F20: + case SDL_Scancode.SDL_SCANCODE_F20: return Key.F20; - case SDL.SDL_Scancode.SDL_SCANCODE_F21: + case SDL_Scancode.SDL_SCANCODE_F21: return Key.F21; - case SDL.SDL_Scancode.SDL_SCANCODE_F22: + case SDL_Scancode.SDL_SCANCODE_F22: return Key.F22; - case SDL.SDL_Scancode.SDL_SCANCODE_F23: + case SDL_Scancode.SDL_SCANCODE_F23: return Key.F23; - case SDL.SDL_Scancode.SDL_SCANCODE_F24: + case SDL_Scancode.SDL_SCANCODE_F24: return Key.F24; - case SDL.SDL_Scancode.SDL_SCANCODE_MENU: - case SDL.SDL_Scancode.SDL_SCANCODE_APPLICATION: + case SDL_Scancode.SDL_SCANCODE_MENU: + case SDL_Scancode.SDL_SCANCODE_APPLICATION: return Key.Menu; - case SDL.SDL_Scancode.SDL_SCANCODE_STOP: + case SDL_Scancode.SDL_SCANCODE_STOP: return Key.Stop; - case SDL.SDL_Scancode.SDL_SCANCODE_MUTE: + case SDL_Scancode.SDL_SCANCODE_MUTE: return Key.Mute; - case SDL.SDL_Scancode.SDL_SCANCODE_VOLUMEUP: + case SDL_Scancode.SDL_SCANCODE_VOLUMEUP: return Key.VolumeUp; - case SDL.SDL_Scancode.SDL_SCANCODE_VOLUMEDOWN: + case SDL_Scancode.SDL_SCANCODE_VOLUMEDOWN: return Key.VolumeDown; - case SDL.SDL_Scancode.SDL_SCANCODE_CLEAR: + case SDL_Scancode.SDL_SCANCODE_CLEAR: return Key.Clear; - case SDL.SDL_Scancode.SDL_SCANCODE_DECIMALSEPARATOR: + case SDL_Scancode.SDL_SCANCODE_DECIMALSEPARATOR: return Key.KeypadDecimal; - case SDL.SDL_Scancode.SDL_SCANCODE_LCTRL: + case SDL_Scancode.SDL_SCANCODE_LCTRL: return Key.ControlLeft; - case SDL.SDL_Scancode.SDL_SCANCODE_LSHIFT: + case SDL_Scancode.SDL_SCANCODE_LSHIFT: return Key.ShiftLeft; - case SDL.SDL_Scancode.SDL_SCANCODE_LALT: + case SDL_Scancode.SDL_SCANCODE_LALT: return Key.AltLeft; - case SDL.SDL_Scancode.SDL_SCANCODE_LGUI: + case SDL_Scancode.SDL_SCANCODE_LGUI: return Key.WinLeft; - case SDL.SDL_Scancode.SDL_SCANCODE_RCTRL: + case SDL_Scancode.SDL_SCANCODE_RCTRL: return Key.ControlRight; - case SDL.SDL_Scancode.SDL_SCANCODE_RSHIFT: + case SDL_Scancode.SDL_SCANCODE_RSHIFT: return Key.ShiftRight; - case SDL.SDL_Scancode.SDL_SCANCODE_RALT: + case SDL_Scancode.SDL_SCANCODE_RALT: return Key.AltRight; - case SDL.SDL_Scancode.SDL_SCANCODE_RGUI: + case SDL_Scancode.SDL_SCANCODE_RGUI: return Key.WinRight; - case SDL.SDL_Scancode.SDL_SCANCODE_AUDIONEXT: + case SDL_Scancode.SDL_SCANCODE_AUDIONEXT: return Key.TrackNext; - case SDL.SDL_Scancode.SDL_SCANCODE_AUDIOPREV: + case SDL_Scancode.SDL_SCANCODE_AUDIOPREV: return Key.TrackPrevious; - case SDL.SDL_Scancode.SDL_SCANCODE_AUDIOSTOP: + case SDL_Scancode.SDL_SCANCODE_AUDIOSTOP: return Key.Stop; - case SDL.SDL_Scancode.SDL_SCANCODE_AUDIOPLAY: + case SDL_Scancode.SDL_SCANCODE_AUDIOPLAY: return Key.PlayPause; - case SDL.SDL_Scancode.SDL_SCANCODE_AUDIOMUTE: + case SDL_Scancode.SDL_SCANCODE_AUDIOMUTE: return Key.Mute; - case SDL.SDL_Scancode.SDL_SCANCODE_SLEEP: + case SDL_Scancode.SDL_SCANCODE_SLEEP: return Key.Sleep; } } /// - /// Returns the corresponding for a given . + /// Returns the corresponding for a given . /// /// /// Should be a keyboard key. /// /// - /// The corresponding if the is valid. - /// otherwise. + /// The corresponding if the is valid. + /// otherwise. /// - public static SDL.SDL_Scancode ToScancode(this InputKey inputKey) + public static SDL_Scancode ToScancode(this InputKey inputKey) { switch (inputKey) { @@ -483,404 +483,404 @@ public static SDL.SDL_Scancode ToScancode(this InputKey inputKey) case InputKey.F34: case InputKey.F35: case InputKey.Clear: - return SDL.SDL_Scancode.SDL_SCANCODE_UNKNOWN; + return SDL_Scancode.SDL_SCANCODE_UNKNOWN; case InputKey.Menu: - return SDL.SDL_Scancode.SDL_SCANCODE_MENU; + return SDL_Scancode.SDL_SCANCODE_MENU; case InputKey.F1: - return SDL.SDL_Scancode.SDL_SCANCODE_F1; + return SDL_Scancode.SDL_SCANCODE_F1; case InputKey.F2: - return SDL.SDL_Scancode.SDL_SCANCODE_F2; + return SDL_Scancode.SDL_SCANCODE_F2; case InputKey.F3: - return SDL.SDL_Scancode.SDL_SCANCODE_F3; + return SDL_Scancode.SDL_SCANCODE_F3; case InputKey.F4: - return SDL.SDL_Scancode.SDL_SCANCODE_F4; + return SDL_Scancode.SDL_SCANCODE_F4; case InputKey.F5: - return SDL.SDL_Scancode.SDL_SCANCODE_F5; + return SDL_Scancode.SDL_SCANCODE_F5; case InputKey.F6: - return SDL.SDL_Scancode.SDL_SCANCODE_F6; + return SDL_Scancode.SDL_SCANCODE_F6; case InputKey.F7: - return SDL.SDL_Scancode.SDL_SCANCODE_F7; + return SDL_Scancode.SDL_SCANCODE_F7; case InputKey.F8: - return SDL.SDL_Scancode.SDL_SCANCODE_F8; + return SDL_Scancode.SDL_SCANCODE_F8; case InputKey.F9: - return SDL.SDL_Scancode.SDL_SCANCODE_F9; + return SDL_Scancode.SDL_SCANCODE_F9; case InputKey.F10: - return SDL.SDL_Scancode.SDL_SCANCODE_F10; + return SDL_Scancode.SDL_SCANCODE_F10; case InputKey.F11: - return SDL.SDL_Scancode.SDL_SCANCODE_F11; + return SDL_Scancode.SDL_SCANCODE_F11; case InputKey.F12: - return SDL.SDL_Scancode.SDL_SCANCODE_F12; + return SDL_Scancode.SDL_SCANCODE_F12; case InputKey.F13: - return SDL.SDL_Scancode.SDL_SCANCODE_F13; + return SDL_Scancode.SDL_SCANCODE_F13; case InputKey.F14: - return SDL.SDL_Scancode.SDL_SCANCODE_F14; + return SDL_Scancode.SDL_SCANCODE_F14; case InputKey.F15: - return SDL.SDL_Scancode.SDL_SCANCODE_F15; + return SDL_Scancode.SDL_SCANCODE_F15; case InputKey.F16: - return SDL.SDL_Scancode.SDL_SCANCODE_F16; + return SDL_Scancode.SDL_SCANCODE_F16; case InputKey.F17: - return SDL.SDL_Scancode.SDL_SCANCODE_F17; + return SDL_Scancode.SDL_SCANCODE_F17; case InputKey.F18: - return SDL.SDL_Scancode.SDL_SCANCODE_F18; + return SDL_Scancode.SDL_SCANCODE_F18; case InputKey.F19: - return SDL.SDL_Scancode.SDL_SCANCODE_F19; + return SDL_Scancode.SDL_SCANCODE_F19; case InputKey.F20: - return SDL.SDL_Scancode.SDL_SCANCODE_F20; + return SDL_Scancode.SDL_SCANCODE_F20; case InputKey.F21: - return SDL.SDL_Scancode.SDL_SCANCODE_F21; + return SDL_Scancode.SDL_SCANCODE_F21; case InputKey.F22: - return SDL.SDL_Scancode.SDL_SCANCODE_F22; + return SDL_Scancode.SDL_SCANCODE_F22; case InputKey.F23: - return SDL.SDL_Scancode.SDL_SCANCODE_F23; + return SDL_Scancode.SDL_SCANCODE_F23; case InputKey.F24: - return SDL.SDL_Scancode.SDL_SCANCODE_F24; + return SDL_Scancode.SDL_SCANCODE_F24; case InputKey.Up: - return SDL.SDL_Scancode.SDL_SCANCODE_UP; + return SDL_Scancode.SDL_SCANCODE_UP; case InputKey.Down: - return SDL.SDL_Scancode.SDL_SCANCODE_DOWN; + return SDL_Scancode.SDL_SCANCODE_DOWN; case InputKey.Left: - return SDL.SDL_Scancode.SDL_SCANCODE_LEFT; + return SDL_Scancode.SDL_SCANCODE_LEFT; case InputKey.Right: - return SDL.SDL_Scancode.SDL_SCANCODE_RIGHT; + return SDL_Scancode.SDL_SCANCODE_RIGHT; case InputKey.Enter: - return SDL.SDL_Scancode.SDL_SCANCODE_RETURN; + return SDL_Scancode.SDL_SCANCODE_RETURN; case InputKey.Escape: - return SDL.SDL_Scancode.SDL_SCANCODE_ESCAPE; + return SDL_Scancode.SDL_SCANCODE_ESCAPE; case InputKey.Space: - return SDL.SDL_Scancode.SDL_SCANCODE_SPACE; + return SDL_Scancode.SDL_SCANCODE_SPACE; case InputKey.Tab: - return SDL.SDL_Scancode.SDL_SCANCODE_TAB; + return SDL_Scancode.SDL_SCANCODE_TAB; case InputKey.BackSpace: - return SDL.SDL_Scancode.SDL_SCANCODE_BACKSPACE; + return SDL_Scancode.SDL_SCANCODE_BACKSPACE; case InputKey.Insert: - return SDL.SDL_Scancode.SDL_SCANCODE_INSERT; + return SDL_Scancode.SDL_SCANCODE_INSERT; case InputKey.Delete: - return SDL.SDL_Scancode.SDL_SCANCODE_DELETE; + return SDL_Scancode.SDL_SCANCODE_DELETE; case InputKey.PageUp: - return SDL.SDL_Scancode.SDL_SCANCODE_PAGEUP; + return SDL_Scancode.SDL_SCANCODE_PAGEUP; case InputKey.PageDown: - return SDL.SDL_Scancode.SDL_SCANCODE_PAGEDOWN; + return SDL_Scancode.SDL_SCANCODE_PAGEDOWN; case InputKey.Home: - return SDL.SDL_Scancode.SDL_SCANCODE_HOME; + return SDL_Scancode.SDL_SCANCODE_HOME; case InputKey.End: - return SDL.SDL_Scancode.SDL_SCANCODE_END; + return SDL_Scancode.SDL_SCANCODE_END; case InputKey.CapsLock: - return SDL.SDL_Scancode.SDL_SCANCODE_CAPSLOCK; + return SDL_Scancode.SDL_SCANCODE_CAPSLOCK; case InputKey.ScrollLock: - return SDL.SDL_Scancode.SDL_SCANCODE_SCROLLLOCK; + return SDL_Scancode.SDL_SCANCODE_SCROLLLOCK; case InputKey.PrintScreen: - return SDL.SDL_Scancode.SDL_SCANCODE_PRINTSCREEN; + return SDL_Scancode.SDL_SCANCODE_PRINTSCREEN; case InputKey.Pause: - return SDL.SDL_Scancode.SDL_SCANCODE_PAUSE; + return SDL_Scancode.SDL_SCANCODE_PAUSE; case InputKey.NumLock: - return SDL.SDL_Scancode.SDL_SCANCODE_NUMLOCKCLEAR; + return SDL_Scancode.SDL_SCANCODE_NUMLOCKCLEAR; case InputKey.Sleep: - return SDL.SDL_Scancode.SDL_SCANCODE_SLEEP; + return SDL_Scancode.SDL_SCANCODE_SLEEP; case InputKey.Keypad0: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_0; + return SDL_Scancode.SDL_SCANCODE_KP_0; case InputKey.Keypad1: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_1; + return SDL_Scancode.SDL_SCANCODE_KP_1; case InputKey.Keypad2: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_2; + return SDL_Scancode.SDL_SCANCODE_KP_2; case InputKey.Keypad3: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_3; + return SDL_Scancode.SDL_SCANCODE_KP_3; case InputKey.Keypad4: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_4; + return SDL_Scancode.SDL_SCANCODE_KP_4; case InputKey.Keypad5: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_5; + return SDL_Scancode.SDL_SCANCODE_KP_5; case InputKey.Keypad6: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_6; + return SDL_Scancode.SDL_SCANCODE_KP_6; case InputKey.Keypad7: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_7; + return SDL_Scancode.SDL_SCANCODE_KP_7; case InputKey.Keypad8: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_8; + return SDL_Scancode.SDL_SCANCODE_KP_8; case InputKey.Keypad9: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_9; + return SDL_Scancode.SDL_SCANCODE_KP_9; case InputKey.KeypadDivide: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_DIVIDE; + return SDL_Scancode.SDL_SCANCODE_KP_DIVIDE; case InputKey.KeypadMultiply: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_MULTIPLY; + return SDL_Scancode.SDL_SCANCODE_KP_MULTIPLY; case InputKey.KeypadMinus: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_MINUS; + return SDL_Scancode.SDL_SCANCODE_KP_MINUS; case InputKey.KeypadPlus: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_PLUS; + return SDL_Scancode.SDL_SCANCODE_KP_PLUS; case InputKey.KeypadPeriod: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_PERIOD; + return SDL_Scancode.SDL_SCANCODE_KP_PERIOD; case InputKey.KeypadEnter: - return SDL.SDL_Scancode.SDL_SCANCODE_KP_ENTER; + return SDL_Scancode.SDL_SCANCODE_KP_ENTER; case InputKey.A: - return SDL.SDL_Scancode.SDL_SCANCODE_A; + return SDL_Scancode.SDL_SCANCODE_A; case InputKey.B: - return SDL.SDL_Scancode.SDL_SCANCODE_B; + return SDL_Scancode.SDL_SCANCODE_B; case InputKey.C: - return SDL.SDL_Scancode.SDL_SCANCODE_C; + return SDL_Scancode.SDL_SCANCODE_C; case InputKey.D: - return SDL.SDL_Scancode.SDL_SCANCODE_D; + return SDL_Scancode.SDL_SCANCODE_D; case InputKey.E: - return SDL.SDL_Scancode.SDL_SCANCODE_E; + return SDL_Scancode.SDL_SCANCODE_E; case InputKey.F: - return SDL.SDL_Scancode.SDL_SCANCODE_F; + return SDL_Scancode.SDL_SCANCODE_F; case InputKey.G: - return SDL.SDL_Scancode.SDL_SCANCODE_G; + return SDL_Scancode.SDL_SCANCODE_G; case InputKey.H: - return SDL.SDL_Scancode.SDL_SCANCODE_H; + return SDL_Scancode.SDL_SCANCODE_H; case InputKey.I: - return SDL.SDL_Scancode.SDL_SCANCODE_I; + return SDL_Scancode.SDL_SCANCODE_I; case InputKey.J: - return SDL.SDL_Scancode.SDL_SCANCODE_J; + return SDL_Scancode.SDL_SCANCODE_J; case InputKey.K: - return SDL.SDL_Scancode.SDL_SCANCODE_K; + return SDL_Scancode.SDL_SCANCODE_K; case InputKey.L: - return SDL.SDL_Scancode.SDL_SCANCODE_L; + return SDL_Scancode.SDL_SCANCODE_L; case InputKey.M: - return SDL.SDL_Scancode.SDL_SCANCODE_M; + return SDL_Scancode.SDL_SCANCODE_M; case InputKey.N: - return SDL.SDL_Scancode.SDL_SCANCODE_N; + return SDL_Scancode.SDL_SCANCODE_N; case InputKey.O: - return SDL.SDL_Scancode.SDL_SCANCODE_O; + return SDL_Scancode.SDL_SCANCODE_O; case InputKey.P: - return SDL.SDL_Scancode.SDL_SCANCODE_P; + return SDL_Scancode.SDL_SCANCODE_P; case InputKey.Q: - return SDL.SDL_Scancode.SDL_SCANCODE_Q; + return SDL_Scancode.SDL_SCANCODE_Q; case InputKey.R: - return SDL.SDL_Scancode.SDL_SCANCODE_R; + return SDL_Scancode.SDL_SCANCODE_R; case InputKey.S: - return SDL.SDL_Scancode.SDL_SCANCODE_S; + return SDL_Scancode.SDL_SCANCODE_S; case InputKey.T: - return SDL.SDL_Scancode.SDL_SCANCODE_T; + return SDL_Scancode.SDL_SCANCODE_T; case InputKey.U: - return SDL.SDL_Scancode.SDL_SCANCODE_U; + return SDL_Scancode.SDL_SCANCODE_U; case InputKey.V: - return SDL.SDL_Scancode.SDL_SCANCODE_V; + return SDL_Scancode.SDL_SCANCODE_V; case InputKey.W: - return SDL.SDL_Scancode.SDL_SCANCODE_W; + return SDL_Scancode.SDL_SCANCODE_W; case InputKey.X: - return SDL.SDL_Scancode.SDL_SCANCODE_X; + return SDL_Scancode.SDL_SCANCODE_X; case InputKey.Y: - return SDL.SDL_Scancode.SDL_SCANCODE_Y; + return SDL_Scancode.SDL_SCANCODE_Y; case InputKey.Z: - return SDL.SDL_Scancode.SDL_SCANCODE_Z; + return SDL_Scancode.SDL_SCANCODE_Z; case InputKey.Number0: - return SDL.SDL_Scancode.SDL_SCANCODE_0; + return SDL_Scancode.SDL_SCANCODE_0; case InputKey.Number1: - return SDL.SDL_Scancode.SDL_SCANCODE_1; + return SDL_Scancode.SDL_SCANCODE_1; case InputKey.Number2: - return SDL.SDL_Scancode.SDL_SCANCODE_2; + return SDL_Scancode.SDL_SCANCODE_2; case InputKey.Number3: - return SDL.SDL_Scancode.SDL_SCANCODE_3; + return SDL_Scancode.SDL_SCANCODE_3; case InputKey.Number4: - return SDL.SDL_Scancode.SDL_SCANCODE_4; + return SDL_Scancode.SDL_SCANCODE_4; case InputKey.Number5: - return SDL.SDL_Scancode.SDL_SCANCODE_5; + return SDL_Scancode.SDL_SCANCODE_5; case InputKey.Number6: - return SDL.SDL_Scancode.SDL_SCANCODE_6; + return SDL_Scancode.SDL_SCANCODE_6; case InputKey.Number7: - return SDL.SDL_Scancode.SDL_SCANCODE_7; + return SDL_Scancode.SDL_SCANCODE_7; case InputKey.Number8: - return SDL.SDL_Scancode.SDL_SCANCODE_8; + return SDL_Scancode.SDL_SCANCODE_8; case InputKey.Number9: - return SDL.SDL_Scancode.SDL_SCANCODE_9; + return SDL_Scancode.SDL_SCANCODE_9; case InputKey.Grave: - return SDL.SDL_Scancode.SDL_SCANCODE_GRAVE; + return SDL_Scancode.SDL_SCANCODE_GRAVE; case InputKey.Minus: - return SDL.SDL_Scancode.SDL_SCANCODE_MINUS; + return SDL_Scancode.SDL_SCANCODE_MINUS; case InputKey.Plus: - return SDL.SDL_Scancode.SDL_SCANCODE_EQUALS; + return SDL_Scancode.SDL_SCANCODE_EQUALS; case InputKey.BracketLeft: - return SDL.SDL_Scancode.SDL_SCANCODE_LEFTBRACKET; + return SDL_Scancode.SDL_SCANCODE_LEFTBRACKET; case InputKey.BracketRight: - return SDL.SDL_Scancode.SDL_SCANCODE_RIGHTBRACKET; + return SDL_Scancode.SDL_SCANCODE_RIGHTBRACKET; case InputKey.Semicolon: - return SDL.SDL_Scancode.SDL_SCANCODE_SEMICOLON; + return SDL_Scancode.SDL_SCANCODE_SEMICOLON; case InputKey.Quote: - return SDL.SDL_Scancode.SDL_SCANCODE_APOSTROPHE; + return SDL_Scancode.SDL_SCANCODE_APOSTROPHE; case InputKey.Comma: - return SDL.SDL_Scancode.SDL_SCANCODE_COMMA; + return SDL_Scancode.SDL_SCANCODE_COMMA; case InputKey.Period: - return SDL.SDL_Scancode.SDL_SCANCODE_PERIOD; + return SDL_Scancode.SDL_SCANCODE_PERIOD; case InputKey.Slash: - return SDL.SDL_Scancode.SDL_SCANCODE_SLASH; + return SDL_Scancode.SDL_SCANCODE_SLASH; case InputKey.BackSlash: - return SDL.SDL_Scancode.SDL_SCANCODE_BACKSLASH; + return SDL_Scancode.SDL_SCANCODE_BACKSLASH; case InputKey.NonUSBackSlash: - return SDL.SDL_Scancode.SDL_SCANCODE_NONUSBACKSLASH; + return SDL_Scancode.SDL_SCANCODE_NONUSBACKSLASH; case InputKey.Mute: - return SDL.SDL_Scancode.SDL_SCANCODE_AUDIOMUTE; + return SDL_Scancode.SDL_SCANCODE_AUDIOMUTE; case InputKey.PlayPause: - return SDL.SDL_Scancode.SDL_SCANCODE_AUDIOPLAY; + return SDL_Scancode.SDL_SCANCODE_AUDIOPLAY; case InputKey.Stop: - return SDL.SDL_Scancode.SDL_SCANCODE_AUDIOSTOP; + return SDL_Scancode.SDL_SCANCODE_AUDIOSTOP; case InputKey.VolumeUp: - return SDL.SDL_Scancode.SDL_SCANCODE_VOLUMEUP; + return SDL_Scancode.SDL_SCANCODE_VOLUMEUP; case InputKey.VolumeDown: - return SDL.SDL_Scancode.SDL_SCANCODE_VOLUMEDOWN; + return SDL_Scancode.SDL_SCANCODE_VOLUMEDOWN; case InputKey.TrackPrevious: - return SDL.SDL_Scancode.SDL_SCANCODE_AUDIOPREV; + return SDL_Scancode.SDL_SCANCODE_AUDIOPREV; case InputKey.TrackNext: - return SDL.SDL_Scancode.SDL_SCANCODE_AUDIONEXT; + return SDL_Scancode.SDL_SCANCODE_AUDIONEXT; case InputKey.LShift: - return SDL.SDL_Scancode.SDL_SCANCODE_LSHIFT; + return SDL_Scancode.SDL_SCANCODE_LSHIFT; case InputKey.RShift: - return SDL.SDL_Scancode.SDL_SCANCODE_RSHIFT; + return SDL_Scancode.SDL_SCANCODE_RSHIFT; case InputKey.LControl: - return SDL.SDL_Scancode.SDL_SCANCODE_LCTRL; + return SDL_Scancode.SDL_SCANCODE_LCTRL; case InputKey.RControl: - return SDL.SDL_Scancode.SDL_SCANCODE_RCTRL; + return SDL_Scancode.SDL_SCANCODE_RCTRL; case InputKey.LAlt: - return SDL.SDL_Scancode.SDL_SCANCODE_LALT; + return SDL_Scancode.SDL_SCANCODE_LALT; case InputKey.RAlt: - return SDL.SDL_Scancode.SDL_SCANCODE_RALT; + return SDL_Scancode.SDL_SCANCODE_RALT; case InputKey.LSuper: - return SDL.SDL_Scancode.SDL_SCANCODE_LGUI; + return SDL_Scancode.SDL_SCANCODE_LGUI; case InputKey.RSuper: - return SDL.SDL_Scancode.SDL_SCANCODE_RGUI; + return SDL_Scancode.SDL_SCANCODE_RGUI; } } - public static WindowState ToWindowState(this SDL.SDL_WindowFlags windowFlags) + public static WindowState ToWindowState(this SDL_WindowFlags windowFlags) { - if (windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) || - windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_BORDERLESS)) + if (windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) || + windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_BORDERLESS)) return WindowState.FullscreenBorderless; - if (windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_MINIMIZED)) + if (windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_MINIMIZED)) return WindowState.Minimised; - if (windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN)) + if (windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN)) return WindowState.Fullscreen; - if (windowFlags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED)) + if (windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_MAXIMIZED)) return WindowState.Maximised; return WindowState.Normal; } - public static SDL.SDL_WindowFlags ToFlags(this WindowState state) + public static SDL_WindowFlags ToFlags(this WindowState state) { switch (state) { @@ -888,124 +888,124 @@ public static SDL.SDL_WindowFlags ToFlags(this WindowState state) return 0; case WindowState.Fullscreen: - return SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; + return SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; case WindowState.Maximised: - return SDL.SDL_WindowFlags.SDL_WINDOW_MAXIMIZED; + return SDL_WindowFlags.SDL_WINDOW_MAXIMIZED; case WindowState.Minimised: - return SDL.SDL_WindowFlags.SDL_WINDOW_MINIMIZED; + return SDL_WindowFlags.SDL_WINDOW_MINIMIZED; case WindowState.FullscreenBorderless: - return SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP; + return SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP; } return 0; } - public static SDL.SDL_WindowFlags ToFlags(this GraphicsSurfaceType surfaceType) + public static SDL_WindowFlags ToFlags(this GraphicsSurfaceType surfaceType) { switch (surfaceType) { case GraphicsSurfaceType.OpenGL: - return SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL; + return SDL_WindowFlags.SDL_WINDOW_OPENGL; case GraphicsSurfaceType.Vulkan when !RuntimeInfo.IsApple: - return SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN; + return SDL_WindowFlags.SDL_WINDOW_VULKAN; case GraphicsSurfaceType.Metal: case GraphicsSurfaceType.Vulkan when RuntimeInfo.IsApple: - return SDL.SDL_WindowFlags.SDL_WINDOW_METAL; + return SDL_WindowFlags.SDL_WINDOW_METAL; } return 0; } - public static JoystickAxisSource ToJoystickAxisSource(this SDL.SDL_GameControllerAxis axis) + public static JoystickAxisSource ToJoystickAxisSource(this SDL_GameControllerAxis axis) { switch (axis) { default: - case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_INVALID: + case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_INVALID: return 0; - case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX: + case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX: return JoystickAxisSource.GamePadLeftStickX; - case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY: + case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY: return JoystickAxisSource.GamePadLeftStickY; - case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT: + case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT: return JoystickAxisSource.GamePadLeftTrigger; - case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX: + case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX: return JoystickAxisSource.GamePadRightStickX; - case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY: + case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY: return JoystickAxisSource.GamePadRightStickY; - case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT: + case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT: return JoystickAxisSource.GamePadRightTrigger; } } - public static JoystickButton ToJoystickButton(this SDL.SDL_GameControllerButton button) + public static JoystickButton ToJoystickButton(this SDL_GameControllerButton button) { switch (button) { default: - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_INVALID: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_INVALID: return 0; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A: return JoystickButton.GamePadA; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B: return JoystickButton.GamePadB; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X: return JoystickButton.GamePadX; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y: return JoystickButton.GamePadY; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK: return JoystickButton.GamePadBack; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE: return JoystickButton.GamePadGuide; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START: return JoystickButton.GamePadStart; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK: return JoystickButton.GamePadLeftStick; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK: return JoystickButton.GamePadRightStick; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER: return JoystickButton.GamePadLeftShoulder; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: return JoystickButton.GamePadRightShoulder; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP: return JoystickButton.GamePadDPadUp; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN: return JoystickButton.GamePadDPadDown; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT: return JoystickButton.GamePadDPadLeft; - case SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT: return JoystickButton.GamePadDPadRight; } } - public static SDL.SDL_Rect ToSDLRect(this RectangleI rectangle) => - new SDL.SDL_Rect + public static SDL_Rect ToSDLRect(this RectangleI rectangle) => + new SDL_Rect { x = rectangle.X, y = rectangle.Y, @@ -1034,41 +1034,41 @@ public static unsafe bool TryGetStringFromBytePointer(byte* bytePointer, out str return true; } - public static DisplayMode ToDisplayMode(this SDL.SDL_DisplayMode mode, int displayIndex) + public static DisplayMode ToDisplayMode(this SDL_DisplayMode mode, int displayIndex) { - SDL.SDL_PixelFormatEnumToMasks(mode.format, out int bpp, out _, out _, out _, out _); - return new DisplayMode(SDL.SDL_GetPixelFormatName(mode.format), new Size(mode.w, mode.h), bpp, mode.refresh_rate, displayIndex); + SDL_PixelFormatEnumToMasks(mode.format, out int bpp, out _, out _, out _, out _); + return new DisplayMode(SDL_GetPixelFormatName(mode.format), new Size(mode.w, mode.h), bpp, mode.refresh_rate, displayIndex); } - public static string ReadableName(this SDL.SDL_LogCategory category) + public static string ReadableName(this SDL_LogCategory category) { switch (category) { - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_APPLICATION: + case SDL_LogCategory.SDL_LOG_CATEGORY_APPLICATION: return "application"; - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_ERROR: + case SDL_LogCategory.SDL_LOG_CATEGORY_ERROR: return "error"; - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_ASSERT: + case SDL_LogCategory.SDL_LOG_CATEGORY_ASSERT: return "assert"; - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_SYSTEM: + case SDL_LogCategory.SDL_LOG_CATEGORY_SYSTEM: return "system"; - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_AUDIO: + case SDL_LogCategory.SDL_LOG_CATEGORY_AUDIO: return "audio"; - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_VIDEO: + case SDL_LogCategory.SDL_LOG_CATEGORY_VIDEO: return "video"; - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_RENDER: + case SDL_LogCategory.SDL_LOG_CATEGORY_RENDER: return "render"; - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_INPUT: + case SDL_LogCategory.SDL_LOG_CATEGORY_INPUT: return "input"; - case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_TEST: + case SDL_LogCategory.SDL_LOG_CATEGORY_TEST: return "test"; default: @@ -1076,26 +1076,26 @@ public static string ReadableName(this SDL.SDL_LogCategory category) } } - public static string ReadableName(this SDL.SDL_LogPriority priority) + public static string ReadableName(this SDL_LogPriority priority) { switch (priority) { - case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_VERBOSE: + case SDL_LogPriority.SDL_LOG_PRIORITY_VERBOSE: return "verbose"; - case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG: + case SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG: return "debug"; - case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_INFO: + case SDL_LogPriority.SDL_LOG_PRIORITY_INFO: return "info"; - case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_WARN: + case SDL_LogPriority.SDL_LOG_PRIORITY_WARN: return "warn"; - case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_ERROR: + case SDL_LogPriority.SDL_LOG_PRIORITY_ERROR: return "error"; - case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_CRITICAL: + case SDL_LogPriority.SDL_LOG_PRIORITY_CRITICAL: return "critical"; default: @@ -1104,30 +1104,30 @@ public static string ReadableName(this SDL.SDL_LogPriority priority) } /// - /// Gets the readable string for this . + /// Gets the readable string for this . /// /// /// string in the format of 1920x1080@60. /// - public static string ReadableString(this SDL.SDL_DisplayMode mode) => $"{mode.w}x{mode.h}@{mode.refresh_rate}"; + public static string ReadableString(this SDL_DisplayMode mode) => $"{mode.w}x{mode.h}@{mode.refresh_rate}"; /// /// Gets the SDL error, and then clears it. /// public static string GetAndClearError() { - string error = SDL.SDL_GetError(); - SDL.SDL_ClearError(); + string error = SDL_GetError(); + SDL_ClearError(); return error; } private static bool tryGetTouchDeviceIndex(long touchId, out int index) { - int n = SDL.SDL_GetNumTouchDevices(); + int n = SDL_GetNumTouchDevices(); for (int i = 0; i < n; i++) { - long currentTouchId = SDL.SDL_GetTouchDevice(i); + long currentTouchId = SDL_GetTouchDevice(i); if (touchId == currentTouchId) { @@ -1141,16 +1141,16 @@ private static bool tryGetTouchDeviceIndex(long touchId, out int index) } /// - /// Gets the of the touch device for this . + /// Gets the of the touch device for this . /// /// /// On Windows, this will return "touch" for touchscreen events or "pen" for pen/tablet events. /// - public static bool TryGetTouchName(this SDL.SDL_TouchFingerEvent e, out string name) + public static bool TryGetTouchName(this SDL_TouchFingerEvent e, out string name) { if (tryGetTouchDeviceIndex(e.touchId, out int index)) { - name = SDL.SDL_GetTouchName(index); + name = SDL_GetTouchName(index); return name != null; } diff --git a/osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs b/osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs index c5bc15842f..c0f5e0b7d9 100644 --- a/osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs +++ b/osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; using osuTK.Graphics; using osuTK.Graphics.ES30; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform.SDL2 { @@ -32,12 +32,12 @@ public SDL2GraphicsSurface(SDL2Window window, GraphicsSurfaceType surfaceType) switch (surfaceType) { case GraphicsSurfaceType.OpenGL: - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8); - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8); - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8); - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ACCUM_ALPHA_SIZE, 0); - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 16); - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ACCUM_ALPHA_SIZE, 0); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DEPTH_SIZE, 16); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_STENCIL_SIZE, 8); break; case GraphicsSurfaceType.Vulkan: @@ -58,7 +58,7 @@ public void Initialise() public Size GetDrawableSize() { - SDL.SDL_GetWindowSizeInPixels(window.SDLWindowHandle, out int width, out int height); + SDL_GetWindowSizeInPixels(window.SDLWindowHandle, out int width, out int height); return new Size(width, height); } @@ -68,27 +68,27 @@ private void initialiseOpenGL() { if (RuntimeInfo.IsMobile) { - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_ES); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_ES); // Minimum OpenGL version for ES profile: - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 0); } else { - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE); // Minimum OpenGL version for core profile: - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 2); } - context = SDL.SDL_GL_CreateContext(window.SDLWindowHandle); + context = SDL_GL_CreateContext(window.SDLWindowHandle); if (context == IntPtr.Zero) - throw new InvalidOperationException($"Failed to create an SDL2 GL context ({SDL.SDL_GetError()})"); + throw new InvalidOperationException($"Failed to create an SDL2 GL context ({SDL_GetError()})"); - SDL.SDL_GL_MakeCurrent(window.SDLWindowHandle, context); + SDL_GL_MakeCurrent(window.SDLWindowHandle, context); loadBindings(); } @@ -133,16 +133,16 @@ private unsafe void loadEntryPoints(GraphicsBindingsBase bindings) private IntPtr getProcAddress(string symbol) { - const int error_category = (int)SDL.SDL_LogCategory.SDL_LOG_CATEGORY_ERROR; - SDL.SDL_LogPriority oldPriority = SDL.SDL_LogGetPriority(error_category); + const int error_category = (int)SDL_LogCategory.SDL_LOG_CATEGORY_ERROR; + SDL_LogPriority oldPriority = SDL_LogGetPriority(error_category); // Prevent logging calls to SDL_GL_GetProcAddress() that fail on systems which don't have the requested symbol (typically macOS). - SDL.SDL_LogSetPriority(error_category, SDL.SDL_LogPriority.SDL_LOG_PRIORITY_INFO); + SDL_LogSetPriority(error_category, SDL_LogPriority.SDL_LOG_PRIORITY_INFO); - IntPtr ret = SDL.SDL_GL_GetProcAddress(symbol); + IntPtr ret = SDL_GL_GetProcAddress(symbol); // Reset the logging behaviour. - SDL.SDL_LogSetPriority(error_category, oldPriority); + SDL_LogSetPriority(error_category, oldPriority); return ret; } @@ -158,7 +158,7 @@ private IntPtr getProcAddress(string symbol) switch (wmInfo.subsystem) { - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_UIKIT: + case SDL_SYSWM_TYPE.SDL_SYSWM_UIKIT: return (int)wmInfo.info.uikit.framebuffer; } @@ -177,33 +177,33 @@ bool IOpenGLGraphicsSurface.VerticalSync if (verticalSync != null) return verticalSync.Value; - return (verticalSync = SDL.SDL_GL_GetSwapInterval() != 0).Value; + return (verticalSync = SDL_GL_GetSwapInterval() != 0).Value; } set { if (RuntimeInfo.IsDesktop) { - SDL.SDL_GL_SetSwapInterval(value ? 1 : 0); + SDL_GL_SetSwapInterval(value ? 1 : 0); verticalSync = value; } } } IntPtr IOpenGLGraphicsSurface.WindowContext => context; - IntPtr IOpenGLGraphicsSurface.CurrentContext => SDL.SDL_GL_GetCurrentContext(); + IntPtr IOpenGLGraphicsSurface.CurrentContext => SDL_GL_GetCurrentContext(); - void IOpenGLGraphicsSurface.SwapBuffers() => SDL.SDL_GL_SwapWindow(window.SDLWindowHandle); - void IOpenGLGraphicsSurface.CreateContext() => SDL.SDL_GL_CreateContext(window.SDLWindowHandle); - void IOpenGLGraphicsSurface.DeleteContext(IntPtr context) => SDL.SDL_GL_DeleteContext(context); - void IOpenGLGraphicsSurface.MakeCurrent(IntPtr context) => SDL.SDL_GL_MakeCurrent(window.SDLWindowHandle, context); - void IOpenGLGraphicsSurface.ClearCurrent() => SDL.SDL_GL_MakeCurrent(window.SDLWindowHandle, IntPtr.Zero); + void IOpenGLGraphicsSurface.SwapBuffers() => SDL_GL_SwapWindow(window.SDLWindowHandle); + void IOpenGLGraphicsSurface.CreateContext() => SDL_GL_CreateContext(window.SDLWindowHandle); + void IOpenGLGraphicsSurface.DeleteContext(IntPtr context) => SDL_GL_DeleteContext(context); + void IOpenGLGraphicsSurface.MakeCurrent(IntPtr context) => SDL_GL_MakeCurrent(window.SDLWindowHandle, context); + void IOpenGLGraphicsSurface.ClearCurrent() => SDL_GL_MakeCurrent(window.SDLWindowHandle, IntPtr.Zero); IntPtr IOpenGLGraphicsSurface.GetProcAddress(string symbol) => getProcAddress(symbol); #endregion #region Metal-specific implementation - IntPtr IMetalGraphicsSurface.CreateMetalView() => SDL.SDL_Metal_CreateView(window.SDLWindowHandle); + IntPtr IMetalGraphicsSurface.CreateMetalView() => SDL_Metal_CreateView(window.SDLWindowHandle); #endregion diff --git a/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs b/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs index 538dbf9b29..14c042d74e 100644 --- a/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs @@ -4,7 +4,7 @@ using System.Globalization; using osu.Framework.Input; using osu.Framework.Input.Bindings; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform.SDL2 { @@ -12,10 +12,10 @@ public class SDL2ReadableKeyCombinationProvider : ReadableKeyCombinationProvider { protected override string GetReadableKey(InputKey key) { - var keycode = SDL.SDL_GetKeyFromScancode(key.ToScancode()); + var keycode = SDL_GetKeyFromScancode(key.ToScancode()); // early return if unknown. probably because key isn't a keyboard key, or doesn't map to an `SDL_Scancode`. - if (keycode == SDL.SDL_Keycode.SDLK_UNKNOWN) + if (keycode == SDL_Keycode.SDLK_UNKNOWN) return base.GetReadableKey(key); string name; @@ -24,7 +24,7 @@ protected override string GetReadableKey(InputKey key) if (TryGetNameFromKeycode(keycode, out name)) return name; - name = SDL.SDL_GetKeyName(keycode); + name = SDL_GetKeyName(keycode); // fall back if SDL couldn't find a name. if (string.IsNullOrEmpty(name)) @@ -32,7 +32,7 @@ protected override string GetReadableKey(InputKey key) // true if SDL_GetKeyName() returned a proper key/scancode name. // see https://github.com/libsdl-org/SDL/blob/release-2.0.16/src/events/SDL_keyboard.c#L1012 - if (((int)keycode & SDL.SDLK_SCANCODE_MASK) != 0) + if (((int)keycode & SDLK_SCANCODE_MASK) != 0) return name; // SDL_GetKeyName() returned a unicode character that would be produced if that key was pressed. @@ -49,175 +49,175 @@ protected override string GetReadableKey(InputKey key) /// /// Should be overriden per-platform to provide platform-specific names for applicable keys. /// - protected virtual bool TryGetNameFromKeycode(SDL.SDL_Keycode keycode, out string name) + protected virtual bool TryGetNameFromKeycode(SDL_Keycode keycode, out string name) { switch (keycode) { - case SDL.SDL_Keycode.SDLK_RETURN: + case SDL_Keycode.SDLK_RETURN: name = "Enter"; return true; - case SDL.SDL_Keycode.SDLK_ESCAPE: + case SDL_Keycode.SDLK_ESCAPE: name = "Esc"; return true; - case SDL.SDL_Keycode.SDLK_BACKSPACE: + case SDL_Keycode.SDLK_BACKSPACE: name = "Backsp"; return true; - case SDL.SDL_Keycode.SDLK_TAB: + case SDL_Keycode.SDLK_TAB: name = "Tab"; return true; - case SDL.SDL_Keycode.SDLK_SPACE: + case SDL_Keycode.SDLK_SPACE: name = "Space"; return true; - case SDL.SDL_Keycode.SDLK_PLUS: + case SDL_Keycode.SDLK_PLUS: name = "Plus"; return true; - case SDL.SDL_Keycode.SDLK_MINUS: + case SDL_Keycode.SDLK_MINUS: name = "Minus"; return true; - case SDL.SDL_Keycode.SDLK_DELETE: + case SDL_Keycode.SDLK_DELETE: name = "Del"; return true; - case SDL.SDL_Keycode.SDLK_CAPSLOCK: + case SDL_Keycode.SDLK_CAPSLOCK: name = "Caps"; return true; - case SDL.SDL_Keycode.SDLK_INSERT: + case SDL_Keycode.SDLK_INSERT: name = "Ins"; return true; - case SDL.SDL_Keycode.SDLK_PAGEUP: + case SDL_Keycode.SDLK_PAGEUP: name = "PgUp"; return true; - case SDL.SDL_Keycode.SDLK_PAGEDOWN: + case SDL_Keycode.SDLK_PAGEDOWN: name = "PgDn"; return true; - case SDL.SDL_Keycode.SDLK_NUMLOCKCLEAR: + case SDL_Keycode.SDLK_NUMLOCKCLEAR: name = "NumLock"; return true; - case SDL.SDL_Keycode.SDLK_KP_DIVIDE: + case SDL_Keycode.SDLK_KP_DIVIDE: name = "NumpadDivide"; return true; - case SDL.SDL_Keycode.SDLK_KP_MULTIPLY: + case SDL_Keycode.SDLK_KP_MULTIPLY: name = "NumpadMultiply"; return true; - case SDL.SDL_Keycode.SDLK_KP_MINUS: + case SDL_Keycode.SDLK_KP_MINUS: name = "NumpadMinus"; return true; - case SDL.SDL_Keycode.SDLK_KP_PLUS: + case SDL_Keycode.SDLK_KP_PLUS: name = "NumpadPlus"; return true; - case SDL.SDL_Keycode.SDLK_KP_ENTER: + case SDL_Keycode.SDLK_KP_ENTER: name = "NumpadEnter"; return true; - case SDL.SDL_Keycode.SDLK_KP_PERIOD: + case SDL_Keycode.SDLK_KP_PERIOD: name = "NumpadDecimal"; return true; - case SDL.SDL_Keycode.SDLK_KP_0: + case SDL_Keycode.SDLK_KP_0: name = "Numpad0"; return true; - case SDL.SDL_Keycode.SDLK_KP_1: + case SDL_Keycode.SDLK_KP_1: name = "Numpad1"; return true; - case SDL.SDL_Keycode.SDLK_KP_2: + case SDL_Keycode.SDLK_KP_2: name = "Numpad2"; return true; - case SDL.SDL_Keycode.SDLK_KP_3: + case SDL_Keycode.SDLK_KP_3: name = "Numpad3"; return true; - case SDL.SDL_Keycode.SDLK_KP_4: + case SDL_Keycode.SDLK_KP_4: name = "Numpad4"; return true; - case SDL.SDL_Keycode.SDLK_KP_5: + case SDL_Keycode.SDLK_KP_5: name = "Numpad5"; return true; - case SDL.SDL_Keycode.SDLK_KP_6: + case SDL_Keycode.SDLK_KP_6: name = "Numpad6"; return true; - case SDL.SDL_Keycode.SDLK_KP_7: + case SDL_Keycode.SDLK_KP_7: name = "Numpad7"; return true; - case SDL.SDL_Keycode.SDLK_KP_8: + case SDL_Keycode.SDLK_KP_8: name = "Numpad8"; return true; - case SDL.SDL_Keycode.SDLK_KP_9: + case SDL_Keycode.SDLK_KP_9: name = "Numpad9"; return true; - case SDL.SDL_Keycode.SDLK_LCTRL: + case SDL_Keycode.SDLK_LCTRL: name = "LCtrl"; return true; - case SDL.SDL_Keycode.SDLK_LSHIFT: + case SDL_Keycode.SDLK_LSHIFT: name = "LShift"; return true; - case SDL.SDL_Keycode.SDLK_LALT: + case SDL_Keycode.SDLK_LALT: name = "LAlt"; return true; - case SDL.SDL_Keycode.SDLK_RCTRL: + case SDL_Keycode.SDLK_RCTRL: name = "RCtrl"; return true; - case SDL.SDL_Keycode.SDLK_RSHIFT: + case SDL_Keycode.SDLK_RSHIFT: name = "RShift"; return true; - case SDL.SDL_Keycode.SDLK_RALT: + case SDL_Keycode.SDLK_RALT: name = "RAlt"; return true; - case SDL.SDL_Keycode.SDLK_VOLUMEUP: + case SDL_Keycode.SDLK_VOLUMEUP: name = "Vol. Up"; return true; - case SDL.SDL_Keycode.SDLK_VOLUMEDOWN: + case SDL_Keycode.SDLK_VOLUMEDOWN: name = "Vol. Down"; return true; - case SDL.SDL_Keycode.SDLK_AUDIONEXT: + case SDL_Keycode.SDLK_AUDIONEXT: name = "Media Next"; return true; - case SDL.SDL_Keycode.SDLK_AUDIOPREV: + case SDL_Keycode.SDLK_AUDIOPREV: name = "Media Previous"; return true; - case SDL.SDL_Keycode.SDLK_AUDIOSTOP: + case SDL_Keycode.SDLK_AUDIOSTOP: name = "Media Stop"; return true; - case SDL.SDL_Keycode.SDLK_AUDIOPLAY: + case SDL_Keycode.SDLK_AUDIOPLAY: name = "Media Play"; return true; - case SDL.SDL_Keycode.SDLK_AUDIOMUTE: + case SDL_Keycode.SDLK_AUDIOMUTE: name = "Mute"; return true; diff --git a/osu.Framework/Platform/SDL2/SDL2Structs.cs b/osu.Framework/Platform/SDL2/SDL2Structs.cs index 32c7ffaf9d..0108edaf45 100644 --- a/osu.Framework/Platform/SDL2/SDL2Structs.cs +++ b/osu.Framework/Platform/SDL2/SDL2Structs.cs @@ -3,7 +3,7 @@ using System; using System.Runtime.InteropServices; -using SDL2; +using static SDL2.SDL; // ReSharper disable MemberCanBePrivate.Global // (Some members not currently used) @@ -37,13 +37,13 @@ internal struct INTERNAL_SysWMmsgUnion } /// - /// Member msg of . + /// Member msg of . /// [StructLayout(LayoutKind.Sequential)] public struct SDL_SysWMmsg { - public SDL.SDL_version version; - public SDL.SDL_SYSWM_TYPE subsystem; + public SDL_version version; + public SDL_SYSWM_TYPE subsystem; public INTERNAL_SysWMmsgUnion msg; } } diff --git a/osu.Framework/Platform/SDL2DesktopWindow.cs b/osu.Framework/Platform/SDL2DesktopWindow.cs index 56807f19fb..f596eb144d 100644 --- a/osu.Framework/Platform/SDL2DesktopWindow.cs +++ b/osu.Framework/Platform/SDL2DesktopWindow.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform { @@ -17,9 +17,9 @@ protected override void UpdateWindowStateAndSize(WindowState state, Display disp // this reset is required even on changing from one fullscreen resolution to another. // if it is not included, the GL context will not get the correct size. // this is mentioned by multiple sources as an SDL issue, which seems to resolve by similar means (see https://discourse.libsdl.org/t/sdl-setwindowsize-does-not-work-in-fullscreen/20711/4). - SDL.SDL_SetWindowBordered(SDLWindowHandle, SDL.SDL_bool.SDL_TRUE); - SDL.SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL.SDL_bool.SDL_FALSE); - SDL.SDL_RestoreWindow(SDLWindowHandle); + SDL_SetWindowBordered(SDLWindowHandle, SDL_bool.SDL_TRUE); + SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL_bool.SDL_FALSE); + SDL_RestoreWindow(SDLWindowHandle); base.UpdateWindowStateAndSize(state, display, displayMode); } diff --git a/osu.Framework/Platform/SDL2Window.cs b/osu.Framework/Platform/SDL2Window.cs index 028431b631..d870809d2f 100644 --- a/osu.Framework/Platform/SDL2Window.cs +++ b/osu.Framework/Platform/SDL2Window.cs @@ -13,11 +13,11 @@ using osu.Framework.Logging; using osu.Framework.Platform.SDL2; using osu.Framework.Threading; -using SDL2; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using Image = SixLabors.ImageSharp.Image; using Point = System.Drawing.Point; +using static SDL2.SDL; namespace osu.Framework.Platform { @@ -69,7 +69,7 @@ public string Title set { title = value; - ScheduleCommand(() => SDL.SDL_SetWindowTitle(SDLWindowHandle, title)); + ScheduleCommand(() => SDL_SetWindowTitle(SDLWindowHandle, title)); } } @@ -83,7 +83,7 @@ internal bool IsWayland if (SDLWindowHandle == IntPtr.Zero) return false; - return GetWindowSystemInformation().subsystem == SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WAYLAND; + return GetWindowSystemInformation().subsystem == SDL_SYSWM_TYPE.SDL_SYSWM_WAYLAND; } } @@ -103,25 +103,25 @@ public IntPtr WindowHandle // https://wiki.libsdl.org/SDL_SysWMinfo switch (wmInfo.subsystem) { - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WINDOWS: + case SDL_SYSWM_TYPE.SDL_SYSWM_WINDOWS: return wmInfo.info.win.window; - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_X11: + case SDL_SYSWM_TYPE.SDL_SYSWM_X11: return wmInfo.info.x11.window; - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_DIRECTFB: + case SDL_SYSWM_TYPE.SDL_SYSWM_DIRECTFB: return wmInfo.info.dfb.window; - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_COCOA: + case SDL_SYSWM_TYPE.SDL_SYSWM_COCOA: return wmInfo.info.cocoa.window; - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_UIKIT: + case SDL_SYSWM_TYPE.SDL_SYSWM_UIKIT: return wmInfo.info.uikit.window; - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WAYLAND: + case SDL_SYSWM_TYPE.SDL_SYSWM_WAYLAND: return wmInfo.info.wl.surface; - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_ANDROID: + case SDL_SYSWM_TYPE.SDL_SYSWM_ANDROID: return wmInfo.info.android.window; default: @@ -141,10 +141,10 @@ public IntPtr DisplayHandle switch (wmInfo.subsystem) { - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_X11: + case SDL_SYSWM_TYPE.SDL_SYSWM_X11: return wmInfo.info.x11.display; - case SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WAYLAND: + case SDL_SYSWM_TYPE.SDL_SYSWM_WAYLAND: return wmInfo.info.wl.display; default: @@ -153,29 +153,29 @@ public IntPtr DisplayHandle } } - internal SDL.SDL_SysWMinfo GetWindowSystemInformation() + internal SDL_SysWMinfo GetWindowSystemInformation() { if (SDLWindowHandle == IntPtr.Zero) return default; - var wmInfo = new SDL.SDL_SysWMinfo(); - SDL.SDL_GetVersion(out wmInfo.version); - SDL.SDL_GetWindowWMInfo(SDLWindowHandle, ref wmInfo); + var wmInfo = new SDL_SysWMinfo(); + SDL_GetVersion(out wmInfo.version); + SDL_GetWindowWMInfo(SDLWindowHandle, ref wmInfo); return wmInfo; } - public bool CapsLockPressed => SDL.SDL_GetModState().HasFlagFast(SDL.SDL_Keymod.KMOD_CAPS); + public bool CapsLockPressed => SDL_GetModState().HasFlagFast(SDL_Keymod.KMOD_CAPS); // references must be kept to avoid GC, see https://stackoverflow.com/a/6193914 [UsedImplicitly] - private SDL.SDL_LogOutputFunction logOutputDelegate; + private SDL_LogOutputFunction logOutputDelegate; [UsedImplicitly] - private SDL.SDL_EventFilter? eventFilterDelegate; + private SDL_EventFilter? eventFilterDelegate; [UsedImplicitly] - private SDL.SDL_EventFilter? eventWatchDelegate; + private SDL_EventFilter? eventWatchDelegate; /// /// Represents a handle to this instance, used for unmanaged callbacks. @@ -186,13 +186,13 @@ protected SDL2Window(GraphicsSurfaceType surfaceType) { ObjectHandle = new ObjectHandle(this, GCHandleType.Normal); - if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_GAMECONTROLLER) < 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) { - throw new InvalidOperationException($"Failed to initialise SDL: {SDL.SDL_GetError()}"); + throw new InvalidOperationException($"Failed to initialise SDL: {SDL_GetError()}"); } - SDL.SDL_LogSetPriority((int)SDL.SDL_LogCategory.SDL_LOG_CATEGORY_ERROR, SDL.SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG); - SDL.SDL_LogSetOutputFunction(logOutputDelegate = logOutput, IntPtr.Zero); + SDL_LogSetPriority((int)SDL_LogCategory.SDL_LOG_CATEGORY_ERROR, SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG); + SDL_LogSetOutputFunction(logOutputDelegate = logOutput, IntPtr.Zero); graphicsSurface = new SDL2GraphicsSurface(this, surfaceType); @@ -205,10 +205,10 @@ protected SDL2Window(GraphicsSurfaceType surfaceType) populateJoysticks(); } - [MonoPInvokeCallback(typeof(SDL.SDL_LogOutputFunction))] - private static void logOutput(IntPtr _, int categoryInt, SDL.SDL_LogPriority priority, IntPtr messagePtr) + [MonoPInvokeCallback(typeof(SDL_LogOutputFunction))] + private static void logOutput(IntPtr _, int categoryInt, SDL_LogPriority priority, IntPtr messagePtr) { - var category = (SDL.SDL_LogCategory)categoryInt; + var category = (SDL_LogCategory)categoryInt; string? message = Marshal.PtrToStringUTF8(messagePtr); Logger.Log($@"SDL {category.ReadableName()} log [{priority.ReadableName()}]: {message}"); @@ -222,28 +222,28 @@ public void SetupWindow(FrameworkConfigManager config) public virtual void Create() { - SDL.SDL_WindowFlags flags = SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE | - SDL.SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | - SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN; // shown after first swap to avoid white flash on startup (windows) + SDL_WindowFlags flags = SDL_WindowFlags.SDL_WINDOW_RESIZABLE | + SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | + SDL_WindowFlags.SDL_WINDOW_HIDDEN; // shown after first swap to avoid white flash on startup (windows) flags |= WindowState.ToFlags(); flags |= graphicsSurface.Type.ToFlags(); - SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1"); - SDL.SDL_SetHint(SDL.SDL_HINT_IME_SHOW_UI, "1"); - SDL.SDL_SetHint(SDL.SDL_HINT_MOUSE_RELATIVE_MODE_CENTER, "0"); - SDL.SDL_SetHint(SDL.SDL_HINT_TOUCH_MOUSE_EVENTS, "0"); // disable touch events generating synthetic mouse events on desktop platforms - SDL.SDL_SetHint(SDL.SDL_HINT_MOUSE_TOUCH_EVENTS, "0"); // disable mouse events generating synthetic touch events on mobile platforms + SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1"); + SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1"); + SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_CENTER, "0"); + SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0"); // disable touch events generating synthetic mouse events on desktop platforms + SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0"); // disable mouse events generating synthetic touch events on mobile platforms // we want text input to only be active when SDL2DesktopWindowTextInput is active. // SDL activates it by default on some platforms: https://github.com/libsdl-org/SDL/blob/release-2.0.16/src/video/SDL_video.c#L573-L582 // so we deactivate it on startup. - SDL.SDL_StopTextInput(); + SDL_StopTextInput(); - SDLWindowHandle = SDL.SDL_CreateWindow(title, Position.X, Position.Y, Size.Width, Size.Height, flags); + SDLWindowHandle = SDL_CreateWindow(title, Position.X, Position.Y, Size.Width, Size.Height, flags); if (SDLWindowHandle == IntPtr.Zero) - throw new InvalidOperationException($"Failed to create SDL window. SDL Error: {SDL.SDL_GetError()}"); + throw new InvalidOperationException($"Failed to create SDL window. SDL Error: {SDL_GetError()}"); graphicsSurface.Initialise(); @@ -256,8 +256,8 @@ public virtual void Create() /// public void Run() { - SDL.SDL_SetEventFilter(eventFilterDelegate = eventFilter, ObjectHandle.Handle); - SDL.SDL_AddEventWatch(eventWatchDelegate = eventWatch, ObjectHandle.Handle); + SDL_SetEventFilter(eventFilterDelegate = eventFilter, ObjectHandle.Handle); + SDL_AddEventWatch(eventWatchDelegate = eventWatch, ObjectHandle.Handle); RunMainLoop(); } @@ -279,7 +279,7 @@ protected virtual void RunMainLoop() Exited?.Invoke(); Close(); - SDL.SDL_Quit(); + SDL_Quit(); } /// @@ -305,63 +305,63 @@ protected void RunFrame() } /// - /// Handles s fired from the SDL event filter. + /// Handles s fired from the SDL event filter. /// /// /// As per SDL's recommendation, application events should always be handled via the event filter. /// See: https://wiki.libsdl.org/SDL2/SDL_EventType#android_ios_and_winrt_events /// - protected virtual void HandleEventFromFilter(SDL.SDL_Event evt) + protected virtual void HandleEventFromFilter(SDL_Event evt) { switch (evt.type) { - case SDL.SDL_EventType.SDL_APP_TERMINATING: + case SDL_EventType.SDL_APP_TERMINATING: handleQuitEvent(evt.quit); break; - case SDL.SDL_EventType.SDL_APP_DIDENTERBACKGROUND: + case SDL_EventType.SDL_APP_DIDENTERBACKGROUND: Suspended?.Invoke(); break; - case SDL.SDL_EventType.SDL_APP_WILLENTERFOREGROUND: + case SDL_EventType.SDL_APP_WILLENTERFOREGROUND: Resumed?.Invoke(); break; - case SDL.SDL_EventType.SDL_APP_LOWMEMORY: + case SDL_EventType.SDL_APP_LOWMEMORY: LowOnMemory?.Invoke(); break; } } - protected void HandleEventFromWatch(SDL.SDL_Event evt) + protected void HandleEventFromWatch(SDL_Event evt) { switch (evt.type) { - case SDL.SDL_EventType.SDL_WINDOWEVENT: + case SDL_EventType.SDL_WINDOWEVENT: // polling via SDL_PollEvent blocks on resizes (https://stackoverflow.com/a/50858339) - if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED && !updatingWindowStateAndSize) + if (evt.window.windowEvent == SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED && !updatingWindowStateAndSize) fetchWindowSize(); break; } } - [MonoPInvokeCallback(typeof(SDL.SDL_EventFilter))] + [MonoPInvokeCallback(typeof(SDL_EventFilter))] private static int eventFilter(IntPtr userdata, IntPtr eventPtr) { var handle = new ObjectHandle(userdata); if (handle.GetTarget(out SDL2Window window)) - window.HandleEventFromFilter(Marshal.PtrToStructure(eventPtr)); + window.HandleEventFromFilter(Marshal.PtrToStructure(eventPtr)); return 1; } - [MonoPInvokeCallback(typeof(SDL.SDL_EventFilter))] + [MonoPInvokeCallback(typeof(SDL_EventFilter))] private static int eventWatch(IntPtr userdata, IntPtr eventPtr) { var handle = new ObjectHandle(userdata); if (handle.GetTarget(out SDL2Window window)) - window.HandleEventFromWatch(Marshal.PtrToStructure(eventPtr)); + window.HandleEventFromWatch(Marshal.PtrToStructure(eventPtr)); return 1; } @@ -391,7 +391,7 @@ public void Close() { if (SDLWindowHandle != IntPtr.Zero) { - SDL.SDL_DestroyWindow(SDLWindowHandle); + SDL_DestroyWindow(SDLWindowHandle); SDLWindowHandle = IntPtr.Zero; } } @@ -399,22 +399,22 @@ public void Close() public void Raise() => ScheduleCommand(() => { - var flags = (SDL.SDL_WindowFlags)SDL.SDL_GetWindowFlags(SDLWindowHandle); + var flags = (SDL_WindowFlags)SDL_GetWindowFlags(SDLWindowHandle); - if (flags.HasFlagFast(SDL.SDL_WindowFlags.SDL_WINDOW_MINIMIZED)) - SDL.SDL_RestoreWindow(SDLWindowHandle); + if (flags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_MINIMIZED)) + SDL_RestoreWindow(SDLWindowHandle); - SDL.SDL_RaiseWindow(SDLWindowHandle); + SDL_RaiseWindow(SDLWindowHandle); }); public void Hide() => ScheduleCommand(() => { - SDL.SDL_HideWindow(SDLWindowHandle); + SDL_HideWindow(SDLWindowHandle); }); public void Show() => ScheduleCommand(() => { - SDL.SDL_ShowWindow(SDLWindowHandle); + SDL_ShowWindow(SDLWindowHandle); }); public void Flash(bool flashUntilFocused = false) => ScheduleCommand(() => @@ -425,9 +425,9 @@ public void Close() if (!RuntimeInfo.IsDesktop) return; - SDL.SDL_FlashWindow(SDLWindowHandle, flashUntilFocused - ? SDL.SDL_FlashOperation.SDL_FLASH_UNTIL_FOCUSED - : SDL.SDL_FlashOperation.SDL_FLASH_BRIEFLY); + SDL_FlashWindow(SDLWindowHandle, flashUntilFocused + ? SDL_FlashOperation.SDL_FLASH_UNTIL_FOCUSED + : SDL_FlashOperation.SDL_FLASH_BRIEFLY); }); public void CancelFlash() => ScheduleCommand(() => @@ -435,7 +435,7 @@ public void Close() if (!RuntimeInfo.IsDesktop) return; - SDL.SDL_FlashWindow(SDLWindowHandle, SDL.SDL_FlashOperation.SDL_FLASH_CANCEL); + SDL_FlashWindow(SDLWindowHandle, SDL_FlashOperation.SDL_FLASH_CANCEL); }); /// @@ -453,10 +453,10 @@ private unsafe void setSDLIcon(Image image) IntPtr surface; fixed (Rgba32* ptr = pixelSpan) - surface = SDL.SDL_CreateRGBSurfaceFrom(new IntPtr(ptr), imageSize.Width, imageSize.Height, 32, imageSize.Width * 4, 0xff, 0xff00, 0xff0000, 0xff000000); + surface = SDL_CreateRGBSurfaceFrom(new IntPtr(ptr), imageSize.Width, imageSize.Height, 32, imageSize.Width * 4, 0xff, 0xff00, 0xff0000, 0xff000000); - SDL.SDL_SetWindowIcon(SDLWindowHandle, surface); - SDL.SDL_FreeSurface(surface); + SDL_SetWindowIcon(SDLWindowHandle, surface); + SDL_FreeSurface(surface); }); } @@ -471,128 +471,128 @@ private unsafe void setSDLIcon(Image image) protected void ScheduleCommand(Action action) => commandScheduler.Add(action, false); private const int events_per_peep = 64; - private readonly SDL.SDL_Event[] events = new SDL.SDL_Event[events_per_peep]; + private readonly SDL_Event[] events = new SDL_Event[events_per_peep]; /// /// Poll for all pending events. /// private void pollSDLEvents() { - SDL.SDL_PumpEvents(); + SDL_PumpEvents(); int eventsRead; do { - eventsRead = SDL.SDL_PeepEvents(events, events_per_peep, SDL.SDL_eventaction.SDL_GETEVENT, SDL.SDL_EventType.SDL_FIRSTEVENT, SDL.SDL_EventType.SDL_LASTEVENT); + eventsRead = SDL_PeepEvents(events, events_per_peep, SDL_eventaction.SDL_GETEVENT, SDL_EventType.SDL_FIRSTEVENT, SDL_EventType.SDL_LASTEVENT); for (int i = 0; i < eventsRead; i++) HandleEvent(events[i]); } while (eventsRead == events_per_peep); } /// - /// Handles s polled on the main thread. + /// Handles s polled on the main thread. /// - protected virtual void HandleEvent(SDL.SDL_Event e) + protected virtual void HandleEvent(SDL_Event e) { switch (e.type) { - case SDL.SDL_EventType.SDL_QUIT: + case SDL_EventType.SDL_QUIT: handleQuitEvent(e.quit); break; - case SDL.SDL_EventType.SDL_DISPLAYEVENT: + case SDL_EventType.SDL_DISPLAYEVENT: handleDisplayEvent(e.display); break; - case SDL.SDL_EventType.SDL_WINDOWEVENT: + case SDL_EventType.SDL_WINDOWEVENT: handleWindowEvent(e.window); break; - case SDL.SDL_EventType.SDL_KEYDOWN: - case SDL.SDL_EventType.SDL_KEYUP: + case SDL_EventType.SDL_KEYDOWN: + case SDL_EventType.SDL_KEYUP: handleKeyboardEvent(e.key); break; - case SDL.SDL_EventType.SDL_TEXTEDITING: + case SDL_EventType.SDL_TEXTEDITING: HandleTextEditingEvent(e.edit); break; - case SDL.SDL_EventType.SDL_TEXTINPUT: + case SDL_EventType.SDL_TEXTINPUT: HandleTextInputEvent(e.text); break; - case SDL.SDL_EventType.SDL_KEYMAPCHANGED: + case SDL_EventType.SDL_KEYMAPCHANGED: handleKeymapChangedEvent(); break; - case SDL.SDL_EventType.SDL_MOUSEMOTION: + case SDL_EventType.SDL_MOUSEMOTION: handleMouseMotionEvent(e.motion); break; - case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN: - case SDL.SDL_EventType.SDL_MOUSEBUTTONUP: + case SDL_EventType.SDL_MOUSEBUTTONDOWN: + case SDL_EventType.SDL_MOUSEBUTTONUP: handleMouseButtonEvent(e.button); break; - case SDL.SDL_EventType.SDL_MOUSEWHEEL: + case SDL_EventType.SDL_MOUSEWHEEL: handleMouseWheelEvent(e.wheel); break; - case SDL.SDL_EventType.SDL_JOYAXISMOTION: + case SDL_EventType.SDL_JOYAXISMOTION: handleJoyAxisEvent(e.jaxis); break; - case SDL.SDL_EventType.SDL_JOYBALLMOTION: + case SDL_EventType.SDL_JOYBALLMOTION: handleJoyBallEvent(e.jball); break; - case SDL.SDL_EventType.SDL_JOYHATMOTION: + case SDL_EventType.SDL_JOYHATMOTION: handleJoyHatEvent(e.jhat); break; - case SDL.SDL_EventType.SDL_JOYBUTTONDOWN: - case SDL.SDL_EventType.SDL_JOYBUTTONUP: + case SDL_EventType.SDL_JOYBUTTONDOWN: + case SDL_EventType.SDL_JOYBUTTONUP: handleJoyButtonEvent(e.jbutton); break; - case SDL.SDL_EventType.SDL_JOYDEVICEADDED: - case SDL.SDL_EventType.SDL_JOYDEVICEREMOVED: + case SDL_EventType.SDL_JOYDEVICEADDED: + case SDL_EventType.SDL_JOYDEVICEREMOVED: handleJoyDeviceEvent(e.jdevice); break; - case SDL.SDL_EventType.SDL_CONTROLLERAXISMOTION: + case SDL_EventType.SDL_CONTROLLERAXISMOTION: handleControllerAxisEvent(e.caxis); break; - case SDL.SDL_EventType.SDL_CONTROLLERBUTTONDOWN: - case SDL.SDL_EventType.SDL_CONTROLLERBUTTONUP: + case SDL_EventType.SDL_CONTROLLERBUTTONDOWN: + case SDL_EventType.SDL_CONTROLLERBUTTONUP: handleControllerButtonEvent(e.cbutton); break; - case SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED: - case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: - case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED: + case SDL_EventType.SDL_CONTROLLERDEVICEADDED: + case SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: + case SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED: handleControllerDeviceEvent(e.cdevice); break; - case SDL.SDL_EventType.SDL_FINGERDOWN: - case SDL.SDL_EventType.SDL_FINGERUP: - case SDL.SDL_EventType.SDL_FINGERMOTION: + case SDL_EventType.SDL_FINGERDOWN: + case SDL_EventType.SDL_FINGERUP: + case SDL_EventType.SDL_FINGERMOTION: HandleTouchFingerEvent(e.tfinger); break; - case SDL.SDL_EventType.SDL_DROPFILE: - case SDL.SDL_EventType.SDL_DROPTEXT: - case SDL.SDL_EventType.SDL_DROPBEGIN: - case SDL.SDL_EventType.SDL_DROPCOMPLETE: + case SDL_EventType.SDL_DROPFILE: + case SDL_EventType.SDL_DROPTEXT: + case SDL_EventType.SDL_DROPBEGIN: + case SDL_EventType.SDL_DROPCOMPLETE: handleDropEvent(e.drop); break; } } // ReSharper disable once UnusedParameter.Local - private void handleQuitEvent(SDL.SDL_QuitEvent evtQuit) => ExitRequested?.Invoke(); + private void handleQuitEvent(SDL_QuitEvent evtQuit) => ExitRequested?.Invoke(); #endregion @@ -669,7 +669,7 @@ internal virtual void SetIconFromGroup(IconGroup iconGroup) public void Dispose() { Close(); - SDL.SDL_Quit(); + SDL_Quit(); ObjectHandle.Dispose(); } diff --git a/osu.Framework/Platform/SDL2Window_Input.cs b/osu.Framework/Platform/SDL2Window_Input.cs index e09842121d..c28e85e6e5 100644 --- a/osu.Framework/Platform/SDL2Window_Input.cs +++ b/osu.Framework/Platform/SDL2Window_Input.cs @@ -15,7 +15,7 @@ using osu.Framework.Platform.SDL2; using osuTK; using osuTK.Input; -using SDL2; +using static SDL2.SDL; using RectangleF = osu.Framework.Graphics.Primitives.RectangleF; namespace osu.Framework.Platform @@ -49,7 +49,7 @@ public bool RelativeMouseMode throw new InvalidOperationException($"Cannot set {nameof(RelativeMouseMode)} to true when the cursor is not hidden via {nameof(CursorState)}."); relativeMouseMode = value; - ScheduleCommand(() => SDL.SDL_SetRelativeMouseMode(value ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE)); + ScheduleCommand(() => SDL_SetRelativeMouseMode(value ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE)); updateCursorConfinement(); } } @@ -59,15 +59,15 @@ public bool RelativeMouseMode /// Only works with disabled. /// /// - /// If the cursor leaves the window while it's captured, is not sent until the button(s) are released. - /// And if the cursor leaves and enters the window while captured, is not sent either. - /// We disable relative mode when the cursor exits window bounds (not on the event), but we only enable it again on . + /// If the cursor leaves the window while it's captured, is not sent until the button(s) are released. + /// And if the cursor leaves and enters the window while captured, is not sent either. + /// We disable relative mode when the cursor exits window bounds (not on the event), but we only enable it again on . /// The above culminate in staying off when the cursor leaves and enters the window bounds when any buttons are pressed. /// This is an invalid state, as the cursor is inside the window, and is off. /// internal bool MouseAutoCapture { - set => ScheduleCommand(() => SDL.SDL_SetHint(SDL.SDL_HINT_MOUSE_AUTO_CAPTURE, value ? "1" : "0")); + set => ScheduleCommand(() => SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, value ? "1" : "0")); } /// @@ -96,7 +96,7 @@ public CursorState CursorState private readonly Dictionary controllers = new Dictionary(); private void updateCursorVisibility(bool cursorVisible) => - ScheduleCommand(() => SDL.SDL_ShowCursor(cursorVisible ? SDL.SDL_ENABLE : SDL.SDL_DISABLE)); + ScheduleCommand(() => SDL_ShowCursor(cursorVisible ? SDL_ENABLE : SDL_DISABLE)); /// /// Updates OS cursor confinement based on the current , and . @@ -105,18 +105,18 @@ private void updateCursorConfinement() { bool confined = CursorState.HasFlagFast(CursorState.Confined); - ScheduleCommand(() => SDL.SDL_SetWindowGrab(SDLWindowHandle, confined ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE)); + ScheduleCommand(() => SDL_SetWindowGrab(SDLWindowHandle, confined ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE)); // Don't use SDL_SetWindowMouseRect when relative mode is enabled, as relative mode already confines the OS cursor to the window. // This is fine for our use case, as UserInputManager will clamp the mouse position. if (CursorConfineRect != null && confined && !RelativeMouseMode) { var rect = ((RectangleI)(CursorConfineRect / Scale)).ToSDLRect(); - ScheduleCommand(() => SDL.SDL_SetWindowMouseRect(SDLWindowHandle, ref rect)); + ScheduleCommand(() => SDL_SetWindowMouseRect(SDLWindowHandle, ref rect)); } else { - ScheduleCommand(() => SDL.SDL_SetWindowMouseRect(SDLWindowHandle, IntPtr.Zero)); + ScheduleCommand(() => SDL_SetWindowMouseRect(SDLWindowHandle, IntPtr.Zero)); } } @@ -146,7 +146,7 @@ private void enqueueJoystickButtonInput(JoystickButton button, bool isPressed) private void pollMouse() { - SDLButtonMask globalButtons = (SDLButtonMask)SDL.SDL_GetGlobalMouseState(out int x, out int y); + SDLButtonMask globalButtons = (SDLButtonMask)SDL_GetGlobalMouseState(out int x, out int y); if (previousPolledPoint.X != x || previousPolledPoint.Y != y) { @@ -173,9 +173,9 @@ private void pollMouse() } } - public virtual void StartTextInput(bool allowIme) => ScheduleCommand(SDL.SDL_StartTextInput); + public virtual void StartTextInput(bool allowIme) => ScheduleCommand(SDL_StartTextInput); - public void StopTextInput() => ScheduleCommand(SDL.SDL_StopTextInput); + public void StopTextInput() => ScheduleCommand(SDL_StopTextInput); /// /// Resets internal state of the platform-native IME. @@ -183,24 +183,24 @@ private void pollMouse() /// public virtual void ResetIme() => ScheduleCommand(() => { - SDL.SDL_StopTextInput(); - SDL.SDL_StartTextInput(); + SDL_StopTextInput(); + SDL_StartTextInput(); }); public void SetTextInputRect(RectangleF rect) => ScheduleCommand(() => { var sdlRect = ((RectangleI)(rect / Scale)).ToSDLRect(); - SDL.SDL_SetTextInputRect(ref sdlRect); + SDL_SetTextInputRect(ref sdlRect); }); #region SDL Event Handling - private void handleDropEvent(SDL.SDL_DropEvent evtDrop) + private void handleDropEvent(SDL_DropEvent evtDrop) { switch (evtDrop.type) { - case SDL.SDL_EventType.SDL_DROPFILE: - string str = SDL.UTF8_ToManaged(evtDrop.file, true); + case SDL_EventType.SDL_DROPFILE: + string str = UTF8_ToManaged(evtDrop.file, true); if (str != null) DragDrop?.Invoke(str); @@ -235,11 +235,11 @@ private void handleDropEvent(SDL.SDL_DropEvent evtDrop) return null; } - protected virtual void HandleTouchFingerEvent(SDL.SDL_TouchFingerEvent evtTfinger) + protected virtual void HandleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger) { var existingSource = getTouchSource(evtTfinger.fingerId); - if (evtTfinger.type == SDL.SDL_EventType.SDL_FINGERDOWN) + if (evtTfinger.type == SDL_EventType.SDL_FINGERDOWN) { Debug.Assert(existingSource == null); existingSource = assignNextAvailableTouchSource(evtTfinger.fingerId); @@ -255,32 +255,32 @@ protected virtual void HandleTouchFingerEvent(SDL.SDL_TouchFingerEvent evtTfinge switch (evtTfinger.type) { - case SDL.SDL_EventType.SDL_FINGERDOWN: - case SDL.SDL_EventType.SDL_FINGERMOTION: + case SDL_EventType.SDL_FINGERDOWN: + case SDL_EventType.SDL_FINGERMOTION: TouchDown?.Invoke(touch); break; - case SDL.SDL_EventType.SDL_FINGERUP: + case SDL_EventType.SDL_FINGERUP: TouchUp?.Invoke(touch); activeTouches[(int)existingSource] = null; break; } } - private void handleControllerDeviceEvent(SDL.SDL_ControllerDeviceEvent evtCdevice) + private void handleControllerDeviceEvent(SDL_ControllerDeviceEvent evtCdevice) { switch (evtCdevice.type) { - case SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED: + case SDL_EventType.SDL_CONTROLLERDEVICEADDED: addJoystick(evtCdevice.which); break; - case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: - SDL.SDL_GameControllerClose(controllers[evtCdevice.which].ControllerHandle); + case SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: + SDL_GameControllerClose(controllers[evtCdevice.which].ControllerHandle); controllers.Remove(evtCdevice.which); break; - case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED: + case SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED: if (controllers.TryGetValue(evtCdevice.which, out var state)) state.PopulateBindings(); @@ -288,38 +288,38 @@ private void handleControllerDeviceEvent(SDL.SDL_ControllerDeviceEvent evtCdevic } } - private void handleControllerButtonEvent(SDL.SDL_ControllerButtonEvent evtCbutton) + private void handleControllerButtonEvent(SDL_ControllerButtonEvent evtCbutton) { - var button = ((SDL.SDL_GameControllerButton)evtCbutton.button).ToJoystickButton(); + var button = ((SDL_GameControllerButton)evtCbutton.button).ToJoystickButton(); switch (evtCbutton.type) { - case SDL.SDL_EventType.SDL_CONTROLLERBUTTONDOWN: + case SDL_EventType.SDL_CONTROLLERBUTTONDOWN: enqueueJoystickButtonInput(button, true); break; - case SDL.SDL_EventType.SDL_CONTROLLERBUTTONUP: + case SDL_EventType.SDL_CONTROLLERBUTTONUP: enqueueJoystickButtonInput(button, false); break; } } - private void handleControllerAxisEvent(SDL.SDL_ControllerAxisEvent evtCaxis) => - enqueueJoystickAxisInput(((SDL.SDL_GameControllerAxis)evtCaxis.axis).ToJoystickAxisSource(), evtCaxis.axisValue); + private void handleControllerAxisEvent(SDL_ControllerAxisEvent evtCaxis) => + enqueueJoystickAxisInput(((SDL_GameControllerAxis)evtCaxis.axis).ToJoystickAxisSource(), evtCaxis.axisValue); private void addJoystick(int which) { - int instanceID = SDL.SDL_JoystickGetDeviceInstanceID(which); + int instanceID = SDL_JoystickGetDeviceInstanceID(which); // if the joystick is already opened, ignore it if (controllers.ContainsKey(instanceID)) return; - IntPtr joystick = SDL.SDL_JoystickOpen(which); + IntPtr joystick = SDL_JoystickOpen(which); IntPtr controller = IntPtr.Zero; - if (SDL.SDL_IsGameController(which) == SDL.SDL_bool.SDL_TRUE) - controller = SDL.SDL_GameControllerOpen(which); + if (SDL_IsGameController(which) == SDL_bool.SDL_TRUE) + controller = SDL_GameControllerOpen(which); controllers[instanceID] = new SDL2ControllerBindings(joystick, controller); } @@ -329,32 +329,32 @@ private void addJoystick(int which) /// private void populateJoysticks() { - for (int i = 0; i < SDL.SDL_NumJoysticks(); i++) + for (int i = 0; i < SDL_NumJoysticks(); i++) { addJoystick(i); } } - private void handleJoyDeviceEvent(SDL.SDL_JoyDeviceEvent evtJdevice) + private void handleJoyDeviceEvent(SDL_JoyDeviceEvent evtJdevice) { switch (evtJdevice.type) { - case SDL.SDL_EventType.SDL_JOYDEVICEADDED: + case SDL_EventType.SDL_JOYDEVICEADDED: addJoystick(evtJdevice.which); break; - case SDL.SDL_EventType.SDL_JOYDEVICEREMOVED: + case SDL_EventType.SDL_JOYDEVICEREMOVED: // if the joystick is already closed, ignore it if (!controllers.ContainsKey(evtJdevice.which)) break; - SDL.SDL_JoystickClose(controllers[evtJdevice.which].JoystickHandle); + SDL_JoystickClose(controllers[evtJdevice.which].JoystickHandle); controllers.Remove(evtJdevice.which); break; } } - private void handleJoyButtonEvent(SDL.SDL_JoyButtonEvent evtJbutton) + private void handleJoyButtonEvent(SDL_JoyButtonEvent evtJbutton) { // if this button exists in the controller bindings, skip it if (controllers.TryGetValue(evtJbutton.which, out var state) && state.IsJoystickButtonBound(evtJbutton.button)) @@ -364,27 +364,27 @@ private void handleJoyButtonEvent(SDL.SDL_JoyButtonEvent evtJbutton) switch (evtJbutton.type) { - case SDL.SDL_EventType.SDL_JOYBUTTONDOWN: + case SDL_EventType.SDL_JOYBUTTONDOWN: enqueueJoystickButtonInput(button, true); break; - case SDL.SDL_EventType.SDL_JOYBUTTONUP: + case SDL_EventType.SDL_JOYBUTTONUP: enqueueJoystickButtonInput(button, false); break; } } // ReSharper disable once UnusedParameter.Local - private void handleJoyHatEvent(SDL.SDL_JoyHatEvent evtJhat) + private void handleJoyHatEvent(SDL_JoyHatEvent evtJhat) { } // ReSharper disable once UnusedParameter.Local - private void handleJoyBallEvent(SDL.SDL_JoyBallEvent evtJball) + private void handleJoyBallEvent(SDL_JoyBallEvent evtJball) { } - private void handleJoyAxisEvent(SDL.SDL_JoyAxisEvent evtJaxis) + private void handleJoyAxisEvent(SDL_JoyAxisEvent evtJaxis) { // if this axis exists in the controller bindings, skip it if (controllers.TryGetValue(evtJaxis.which, out var state) && state.IsJoystickAxisBound(evtJaxis.axis)) @@ -396,7 +396,7 @@ private void handleJoyAxisEvent(SDL.SDL_JoyAxisEvent evtJaxis) private uint lastPreciseScroll; private const uint precise_scroll_debounce = 100; - private void handleMouseWheelEvent(SDL.SDL_MouseWheelEvent evtWheel) + private void handleMouseWheelEvent(SDL_MouseWheelEvent evtWheel) { bool isPrecise(float f) => f % 1 != 0; @@ -409,35 +409,35 @@ private void handleMouseWheelEvent(SDL.SDL_MouseWheelEvent evtWheel) TriggerMouseWheel(new Vector2(-evtWheel.preciseX, evtWheel.preciseY), precise); } - private void handleMouseButtonEvent(SDL.SDL_MouseButtonEvent evtButton) + private void handleMouseButtonEvent(SDL_MouseButtonEvent evtButton) { MouseButton button = mouseButtonFromEvent(evtButton.button); - SDLButtonMask mask = (SDLButtonMask)SDL.SDL_BUTTON(evtButton.button); + SDLButtonMask mask = (SDLButtonMask)SDL_BUTTON(evtButton.button); Debug.Assert(Enum.IsDefined(mask)); switch (evtButton.type) { - case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN: + case SDL_EventType.SDL_MOUSEBUTTONDOWN: pressedButtons |= mask; MouseDown?.Invoke(button); break; - case SDL.SDL_EventType.SDL_MOUSEBUTTONUP: + case SDL_EventType.SDL_MOUSEBUTTONUP: pressedButtons &= ~mask; MouseUp?.Invoke(button); break; } } - private void handleMouseMotionEvent(SDL.SDL_MouseMotionEvent evtMotion) + private void handleMouseMotionEvent(SDL_MouseMotionEvent evtMotion) { - if (SDL.SDL_GetRelativeMouseMode() == SDL.SDL_bool.SDL_FALSE) + if (SDL_GetRelativeMouseMode() == SDL_bool.SDL_FALSE) MouseMove?.Invoke(new Vector2(evtMotion.x * Scale, evtMotion.y * Scale)); else MouseMoveRelative?.Invoke(new Vector2(evtMotion.xrel * Scale, evtMotion.yrel * Scale)); } - protected virtual unsafe void HandleTextInputEvent(SDL.SDL_TextInputEvent evtText) + protected virtual unsafe void HandleTextInputEvent(SDL_TextInputEvent evtText) { if (!SDL2Extensions.TryGetStringFromBytePointer(evtText.text, out string text)) return; @@ -445,7 +445,7 @@ protected virtual unsafe void HandleTextInputEvent(SDL.SDL_TextInputEvent evtTex TriggerTextInput(text); } - protected virtual unsafe void HandleTextEditingEvent(SDL.SDL_TextEditingEvent evtEdit) + protected virtual unsafe void HandleTextEditingEvent(SDL_TextEditingEvent evtEdit) { if (!SDL2Extensions.TryGetStringFromBytePointer(evtEdit.text, out string text)) return; @@ -453,7 +453,7 @@ protected virtual unsafe void HandleTextEditingEvent(SDL.SDL_TextEditingEvent ev TriggerTextEditing(text, evtEdit.start, evtEdit.length); } - private void handleKeyboardEvent(SDL.SDL_KeyboardEvent evtKey) + private void handleKeyboardEvent(SDL_KeyboardEvent evtKey) { Key key = evtKey.keysym.ToKey(); @@ -465,11 +465,11 @@ private void handleKeyboardEvent(SDL.SDL_KeyboardEvent evtKey) switch (evtKey.type) { - case SDL.SDL_EventType.SDL_KEYDOWN: + case SDL_EventType.SDL_KEYDOWN: KeyDown?.Invoke(key); break; - case SDL.SDL_EventType.SDL_KEYUP: + case SDL_EventType.SDL_KEYUP: KeyUp?.Invoke(key); break; } @@ -482,44 +482,44 @@ private MouseButton mouseButtonFromEvent(byte button) switch ((uint)button) { default: - case SDL.SDL_BUTTON_LEFT: + case SDL_BUTTON_LEFT: return MouseButton.Left; - case SDL.SDL_BUTTON_RIGHT: + case SDL_BUTTON_RIGHT: return MouseButton.Right; - case SDL.SDL_BUTTON_MIDDLE: + case SDL_BUTTON_MIDDLE: return MouseButton.Middle; - case SDL.SDL_BUTTON_X1: + case SDL_BUTTON_X1: return MouseButton.Button1; - case SDL.SDL_BUTTON_X2: + case SDL_BUTTON_X2: return MouseButton.Button2; } } /// - /// Button mask as returned from and . + /// Button mask as returned from and . /// [Flags] private enum SDLButtonMask { None = 0, - /// + /// Left = 1 << 0, - /// + /// Middle = 1 << 1, - /// + /// Right = 1 << 2, - /// + /// X1 = 1 << 3, - /// + /// X2 = 1 << 4 } @@ -530,7 +530,7 @@ private enum SDLButtonMask /// /// A position inside the window. public void UpdateMousePosition(Vector2 mousePosition) => ScheduleCommand(() => - SDL.SDL_WarpMouseInWindow(SDLWindowHandle, (int)(mousePosition.X / Scale), (int)(mousePosition.Y / Scale))); + SDL_WarpMouseInWindow(SDLWindowHandle, (int)(mousePosition.X / Scale), (int)(mousePosition.Y / Scale))); private void updateConfineMode() { diff --git a/osu.Framework/Platform/SDL2Window_Windowing.cs b/osu.Framework/Platform/SDL2Window_Windowing.cs index 4652f8823b..c6b4a23cdf 100644 --- a/osu.Framework/Platform/SDL2Window_Windowing.cs +++ b/osu.Framework/Platform/SDL2Window_Windowing.cs @@ -13,7 +13,7 @@ using osu.Framework.Logging; using osu.Framework.Platform.SDL2; using osuTK; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform { @@ -24,7 +24,7 @@ private void setupWindowing(FrameworkConfigManager config) config.BindWith(FrameworkSetting.MinimiseOnFocusLossInFullscreen, minimiseOnFocusLoss); minimiseOnFocusLoss.BindValueChanged(e => { - ScheduleCommand(() => SDL.SDL_SetHint(SDL.SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, e.NewValue ? "1" : "0")); + ScheduleCommand(() => SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, e.NewValue ? "1" : "0")); }, true); fetchDisplays(); @@ -69,7 +69,7 @@ private void setupWindowing(FrameworkConfigManager config) if (min.Width > sizeWindowed.MaxValue.Width || min.Height > sizeWindowed.MaxValue.Height) throw new InvalidOperationException($"Expected a size less than max window size ({sizeWindowed.MaxValue}), got {min}"); - ScheduleCommand(() => SDL.SDL_SetWindowMinimumSize(SDLWindowHandle, min.Width, min.Height)); + ScheduleCommand(() => SDL_SetWindowMinimumSize(SDLWindowHandle, min.Width, min.Height)); }; sizeWindowed.MaxValueChanged += max => @@ -80,7 +80,7 @@ private void setupWindowing(FrameworkConfigManager config) if (max.Width < sizeWindowed.MinValue.Width || max.Height < sizeWindowed.MinValue.Height) throw new InvalidOperationException($"Expected a size greater than min window size ({sizeWindowed.MinValue}), got {max}"); - ScheduleCommand(() => SDL.SDL_SetWindowMaximumSize(SDLWindowHandle, max.Width, max.Height)); + ScheduleCommand(() => SDL_SetWindowMaximumSize(SDLWindowHandle, max.Width, max.Height)); }; config.BindWith(FrameworkSetting.SizeFullscreen, sizeFullscreen); @@ -161,7 +161,7 @@ public Point Position set { position = value; - ScheduleCommand(() => SDL.SDL_SetWindowPosition(SDLWindowHandle, value.X, value.Y)); + ScheduleCommand(() => SDL_SetWindowPosition(SDLWindowHandle, value.X, value.Y)); } } @@ -179,7 +179,7 @@ public bool Resizable return; resizable = value; - ScheduleCommand(() => SDL.SDL_SetWindowResizable(SDLWindowHandle, value ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE)); + ScheduleCommand(() => SDL_SetWindowResizable(SDLWindowHandle, value ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE)); } } @@ -241,9 +241,9 @@ public bool Visible ScheduleCommand(() => { if (value) - SDL.SDL_ShowWindow(SDLWindowHandle); + SDL_ShowWindow(SDLWindowHandle); else - SDL.SDL_HideWindow(SDLWindowHandle); + SDL_HideWindow(SDLWindowHandle); }); } } @@ -290,7 +290,7 @@ public WindowState WindowState public event Action>? DisplaysChanged; // ReSharper disable once UnusedParameter.Local - private void handleDisplayEvent(SDL.SDL_DisplayEvent evtDisplay) => fetchDisplays(); + private void handleDisplayEvent(SDL_DisplayEvent evtDisplay) => fetchDisplays(); /// /// Updates with the latest display information reported by SDL. @@ -326,10 +326,10 @@ private void assertDisplaysMatchSDL() private static ImmutableArray getSDLDisplays() { - int numDisplays = SDL.SDL_GetNumVideoDisplays(); + int numDisplays = SDL_GetNumVideoDisplays(); if (numDisplays <= 0) - throw new InvalidOperationException($"Failed to get number of SDL displays. Return code: {numDisplays}. SDL Error: {SDL.SDL_GetError()}"); + throw new InvalidOperationException($"Failed to get number of SDL displays. Return code: {numDisplays}. SDL Error: {SDL_GetError()}"); var builder = ImmutableArray.CreateBuilder(numDisplays); @@ -348,9 +348,9 @@ private static bool tryGetDisplayFromSDL(int displayIndex, [NotNullWhen(true)] o { ArgumentOutOfRangeException.ThrowIfNegative(displayIndex); - if (SDL.SDL_GetDisplayBounds(displayIndex, out var rect) < 0) + if (SDL_GetDisplayBounds(displayIndex, out var rect) < 0) { - Logger.Log($"Failed to get display bounds for display at index ({displayIndex}). SDL Error: {SDL.SDL_GetError()}"); + Logger.Log($"Failed to get display bounds for display at index ({displayIndex}). SDL Error: {SDL_GetError()}"); display = null; return false; } @@ -359,11 +359,11 @@ private static bool tryGetDisplayFromSDL(int displayIndex, [NotNullWhen(true)] o if (RuntimeInfo.IsDesktop) { - int numModes = SDL.SDL_GetNumDisplayModes(displayIndex); + int numModes = SDL_GetNumDisplayModes(displayIndex); if (numModes < 0) { - Logger.Log($"Failed to get display modes for display at index ({displayIndex}) ({rect.w}x{rect.h}). SDL Error: {SDL.SDL_GetError()} ({numModes})"); + Logger.Log($"Failed to get display modes for display at index ({displayIndex}) ({rect.w}x{rect.h}). SDL Error: {SDL_GetError()} ({numModes})"); display = null; return false; } @@ -374,13 +374,13 @@ private static bool tryGetDisplayFromSDL(int displayIndex, [NotNullWhen(true)] o displayModes = Enumerable.Range(0, numModes) .Select(modeIndex => { - SDL.SDL_GetDisplayMode(displayIndex, modeIndex, out var mode); + SDL_GetDisplayMode(displayIndex, modeIndex, out var mode); return mode.ToDisplayMode(displayIndex); }) .ToArray(); } - display = new Display(displayIndex, SDL.SDL_GetDisplayName(displayIndex), new Rectangle(rect.x, rect.y, rect.w, rect.h), displayModes); + display = new Display(displayIndex, SDL_GetDisplayName(displayIndex), new Rectangle(rect.x, rect.y, rect.w, rect.h), displayModes); return true; } @@ -405,7 +405,7 @@ private Rectangle windowDisplayBounds { get { - SDL.SDL_GetDisplayBounds(displayIndex, out var rect); + SDL_GetDisplayBounds(displayIndex, out var rect); return new Rectangle(rect.x, rect.y, rect.w, rect.h); } } @@ -443,7 +443,7 @@ private Rectangle windowDisplayBounds /// Whether the window size has been changed after updating. private void fetchWindowSize() { - SDL.SDL_GetWindowSize(SDLWindowHandle, out int w, out int h); + SDL_GetWindowSize(SDLWindowHandle, out int w, out int h); int drawableW = graphicsSurface.GetDrawableSize().Width; @@ -460,15 +460,15 @@ private void fetchWindowSize() #region SDL Event Handling - private void handleWindowEvent(SDL.SDL_WindowEvent evtWindow) + private void handleWindowEvent(SDL_WindowEvent evtWindow) { updateAndFetchWindowSpecifics(); switch (evtWindow.windowEvent) { - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED: + case SDL_WindowEventID.SDL_WINDOWEVENT_MOVED: // explicitly requery as there are occasions where what SDL has provided us with is not up-to-date. - SDL.SDL_GetWindowPosition(SDLWindowHandle, out int x, out int y); + SDL_GetWindowPosition(SDLWindowHandle, out int x, out int y); var newPosition = new Point(x, y); if (!newPosition.Equals(Position)) @@ -482,31 +482,31 @@ private void handleWindowEvent(SDL.SDL_WindowEvent evtWindow) break; - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: + case SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: fetchWindowSize(); break; - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER: + case SDL_WindowEventID.SDL_WINDOWEVENT_ENTER: cursorInWindow.Value = true; MouseEntered?.Invoke(); break; - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE: + case SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE: cursorInWindow.Value = false; MouseLeft?.Invoke(); break; - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED: - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: + case SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED: + case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: Focused = true; break; - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED: - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: + case SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED: + case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: Focused = false; break; - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE: + case SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE: break; } @@ -515,12 +515,12 @@ private void handleWindowEvent(SDL.SDL_WindowEvent evtWindow) // eg. this covers scenarios when changing resolution outside of the game, and then tabbing in. switch (evtWindow.windowEvent) { - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED: - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED: - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN: - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN: + case SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED: + case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: + case SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED: + case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: + case SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN: + case SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN: fetchDisplays(); break; } @@ -572,7 +572,7 @@ private void updateAndFetchWindowSpecifics() } else { - windowState = ((SDL.SDL_WindowFlags)SDL.SDL_GetWindowFlags(SDLWindowHandle)).ToWindowState(); + windowState = ((SDL_WindowFlags)SDL_GetWindowFlags(SDLWindowHandle)).ToWindowState(); } if (windowState != stateBefore) @@ -583,7 +583,7 @@ private void updateAndFetchWindowSpecifics() windowMaximised = maximized; } - int newDisplayIndex = SDL.SDL_GetWindowDisplayIndex(SDLWindowHandle); + int newDisplayIndex = SDL_GetWindowDisplayIndex(SDLWindowHandle); if (displayIndex != newDisplayIndex) { @@ -606,9 +606,9 @@ protected virtual void UpdateWindowStateAndSize(WindowState state, Display displ case WindowState.Normal: Size = sizeWindowed.Value; - SDL.SDL_RestoreWindow(SDLWindowHandle); - SDL.SDL_SetWindowSize(SDLWindowHandle, Size.Width, Size.Height); - SDL.SDL_SetWindowResizable(SDLWindowHandle, Resizable ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE); + SDL_RestoreWindow(SDLWindowHandle); + SDL_SetWindowSize(SDLWindowHandle, Size.Width, Size.Height); + SDL_SetWindowResizable(SDLWindowHandle, Resizable ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE); readWindowPositionFromConfig(state, display); break; @@ -620,8 +620,8 @@ protected virtual void UpdateWindowStateAndSize(WindowState state, Display displ ensureWindowOnDisplay(display); - SDL.SDL_SetWindowDisplayMode(SDLWindowHandle, ref closestMode); - SDL.SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN); + SDL_SetWindowDisplayMode(SDLWindowHandle, ref closestMode); + SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL_WindowFlags.SDL_WINDOW_FULLSCREEN); break; case WindowState.FullscreenBorderless: @@ -629,16 +629,16 @@ protected virtual void UpdateWindowStateAndSize(WindowState state, Display displ break; case WindowState.Maximised: - SDL.SDL_RestoreWindow(SDLWindowHandle); + SDL_RestoreWindow(SDLWindowHandle); ensureWindowOnDisplay(display); - SDL.SDL_MaximizeWindow(SDLWindowHandle); + SDL_MaximizeWindow(SDLWindowHandle); break; case WindowState.Minimised: ensureWindowOnDisplay(display); - SDL.SDL_MinimizeWindow(SDLWindowHandle); + SDL_MinimizeWindow(SDLWindowHandle); break; } } @@ -648,18 +648,18 @@ private static bool tryFetchDisplayMode(IntPtr windowHandle, WindowState windowS // TODO: displayIndex should be valid here at all times. // on startup, the displayIndex will be invalid (-1) due to it being set later in the startup sequence. // related to order of operations in `updateWindowSpecifics()`. - int localIndex = SDL.SDL_GetWindowDisplayIndex(windowHandle); + int localIndex = SDL_GetWindowDisplayIndex(windowHandle); if (localIndex != display.Index) Logger.Log($"Stored display index ({display.Index}) doesn't match current index ({localIndex})"); bool success; - SDL.SDL_DisplayMode mode; + SDL_DisplayMode mode; if (windowState == WindowState.Fullscreen) - success = SDL.SDL_GetWindowDisplayMode(windowHandle, out mode) >= 0; + success = SDL_GetWindowDisplayMode(windowHandle, out mode) >= 0; else - success = SDL.SDL_GetCurrentDisplayMode(localIndex, out mode) >= 0; + success = SDL_GetCurrentDisplayMode(localIndex, out mode) >= 0; string type = windowState == WindowState.Fullscreen ? "fullscreen" : "desktop"; @@ -671,7 +671,7 @@ private static bool tryFetchDisplayMode(IntPtr windowHandle, WindowState windowS } else { - Logger.Log($"Failed to get {type} display mode. Display index: {localIndex}. SDL error: {SDL.SDL_GetError()}"); + Logger.Log($"Failed to get {type} display mode. Display index: {localIndex}. SDL error: {SDL_GetError()}"); displayMode = default; return false; } @@ -705,7 +705,7 @@ private void readWindowPositionFromConfig(WindowState state, Display display) /// The to center the window on. private void ensureWindowOnDisplay(Display display) { - if (display.Index == SDL.SDL_GetWindowDisplayIndex(SDLWindowHandle)) + if (display.Index == SDL_GetWindowDisplayIndex(SDLWindowHandle)) return; moveWindowTo(display, new Vector2(0.5f)); @@ -780,7 +780,7 @@ protected virtual Size SetBorderless(Display display) ensureWindowOnDisplay(display); // this is a generally sane method of handling borderless, and works well on macOS and linux. - SDL.SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP); + SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP); return display.Bounds.Size; } @@ -814,17 +814,17 @@ public void CycleMode() #region Helper functions - private static SDL.SDL_DisplayMode getClosestDisplayMode(IntPtr windowHandle, Size size, Display display, DisplayMode requestedMode) + private static SDL_DisplayMode getClosestDisplayMode(IntPtr windowHandle, Size size, Display display, DisplayMode requestedMode) { - SDL.SDL_ClearError(); // clear any stale error. + SDL_ClearError(); // clear any stale error. // default size means to use the display's native size. if (size.Width == 9999 && size.Height == 9999) size = display.Bounds.Size; - var targetMode = new SDL.SDL_DisplayMode { w = size.Width, h = size.Height, refresh_rate = requestedMode.RefreshRate }; + var targetMode = new SDL_DisplayMode { w = size.Width, h = size.Height, refresh_rate = requestedMode.RefreshRate }; - if (SDL.SDL_GetClosestDisplayMode(display.Index, ref targetMode, out var mode) != IntPtr.Zero) + if (SDL_GetClosestDisplayMode(display.Index, ref targetMode, out var mode) != IntPtr.Zero) return mode; else Logger.Log($"Unable to get preferred display mode (try #1/2). Target display: {display.Index}, mode: {targetMode.ReadableString()}. SDL error: {SDL2Extensions.GetAndClearError()}"); @@ -834,31 +834,31 @@ private static SDL.SDL_DisplayMode getClosestDisplayMode(IntPtr windowHandle, Si targetMode.h = display.Bounds.Height; targetMode.refresh_rate = 0; - if (SDL.SDL_GetClosestDisplayMode(display.Index, ref targetMode, out mode) != IntPtr.Zero) + if (SDL_GetClosestDisplayMode(display.Index, ref targetMode, out mode) != IntPtr.Zero) return mode; else Logger.Log($"Unable to get preferred display mode (try #2/2). Target display: {display.Index}, mode: {targetMode.ReadableString()}. SDL error: {SDL2Extensions.GetAndClearError()}"); // try the display's native display mode. - if (SDL.SDL_GetDesktopDisplayMode(display.Index, out mode) == 0) + if (SDL_GetDesktopDisplayMode(display.Index, out mode) == 0) return mode; else Logger.Log($"Failed to get desktop display mode (try #1/3). Target display: {display.Index}. SDL error: {SDL2Extensions.GetAndClearError()}", level: LogLevel.Error); // try the primary display mode. - if (SDL.SDL_GetDisplayMode(display.Index, 0, out mode) == 0) + if (SDL_GetDisplayMode(display.Index, 0, out mode) == 0) return mode; else Logger.Log($"Failed to get desktop display mode (try #2/3). Target display: {display.Index}. SDL error: {SDL2Extensions.GetAndClearError()}", level: LogLevel.Error); // try the primary display's primary display mode. - if (SDL.SDL_GetDisplayMode(0, 0, out mode) == 0) + if (SDL_GetDisplayMode(0, 0, out mode) == 0) return mode; else Logger.Log($"Failed to get desktop display mode (try #3/3). Target display: primary. SDL error: {SDL2Extensions.GetAndClearError()}", level: LogLevel.Error); // finally return the current mode if everything else fails. - if (SDL.SDL_GetWindowDisplayMode(windowHandle, out mode) >= 0) + if (SDL_GetWindowDisplayMode(windowHandle, out mode) >= 0) return mode; else Logger.Log($"Failed to get window display mode. SDL error: {SDL2Extensions.GetAndClearError()}", level: LogLevel.Error); diff --git a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs index ae8070e11e..8610dc4886 100644 --- a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs +++ b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs @@ -10,7 +10,7 @@ using osu.Framework.Platform.Windows.Native; using osu.Framework.Statistics; using osuTK; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform.Windows { @@ -28,7 +28,7 @@ internal unsafe class WindowsMouseHandler : MouseHandler private const int raw_input_coordinate_space = 65535; - private SDL.SDL_WindowsMessageHook callback = null!; + private SDL_WindowsMessageHook callback = null!; private WindowsWindow window = null!; public override bool IsActive => Enabled.Value; @@ -44,7 +44,7 @@ public override bool Initialize(GameHost host) Enabled.BindValueChanged(enabled => { - host.InputThread.Scheduler.Add(() => SDL.SDL_SetWindowsMessageHook(enabled.NewValue ? callback : null, IntPtr.Zero)); + host.InputThread.Scheduler.Add(() => SDL_SetWindowsMessageHook(enabled.NewValue ? callback : null, IntPtr.Zero)); }, true); return base.Initialize(host); diff --git a/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs b/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs index a97a06e4d9..daad7fda20 100644 --- a/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs @@ -3,7 +3,7 @@ using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; -using SDL2; +using static SDL2.SDL; namespace osu.Framework.Platform.Windows { @@ -21,15 +21,15 @@ protected override string GetReadableKey(InputKey key) } } - protected override bool TryGetNameFromKeycode(SDL.SDL_Keycode keycode, out string name) + protected override bool TryGetNameFromKeycode(SDL_Keycode keycode, out string name) { switch (keycode) { - case SDL.SDL_Keycode.SDLK_LGUI: + case SDL_Keycode.SDLK_LGUI: name = "LWin"; return true; - case SDL.SDL_Keycode.SDLK_RGUI: + case SDL_Keycode.SDLK_RGUI: name = "RWin"; return true; diff --git a/osu.Framework/Platform/Windows/WindowsWindow.cs b/osu.Framework/Platform/Windows/WindowsWindow.cs index 72041de6d2..c854e95296 100644 --- a/osu.Framework/Platform/Windows/WindowsWindow.cs +++ b/osu.Framework/Platform/Windows/WindowsWindow.cs @@ -10,7 +10,7 @@ using osu.Framework.Platform.Windows.Native; using osuTK; using osuTK.Input; -using SDL2; +using static SDL2.SDL; using Icon = osu.Framework.Platform.Windows.Native.Icon; namespace osu.Framework.Platform.Windows @@ -87,12 +87,12 @@ public override void Create() Native.Input.SetWindowFeedbackSetting(WindowHandle, feedbackType, false); // enable window message events to use with `OnSDLEvent` below. - SDL.SDL_EventState(SDL.SDL_EventType.SDL_SYSWMEVENT, SDL.SDL_ENABLE); + SDL_EventState(SDL_EventType.SDL_SYSWMEVENT, SDL_ENABLE); } - protected override void HandleEventFromFilter(SDL.SDL_Event e) + protected override void HandleEventFromFilter(SDL_Event e) { - if (e.type == SDL.SDL_EventType.SDL_SYSWMEVENT) + if (e.type == SDL_EventType.SDL_SYSWMEVENT) { var wmMsg = Marshal.PtrToStructure(e.syswm.msg); var m = wmMsg.msg.win; @@ -134,7 +134,7 @@ private void warpCursorFromFocusLoss() && RelativeMouseMode) { var pt = PointToScreen(new Point((int)LastMousePosition.Value.X, (int)LastMousePosition.Value.Y)); - SDL.SDL_WarpMouseGlobal(pt.X, pt.Y); // this directly calls the SetCursorPos win32 API + SDL_WarpMouseGlobal(pt.X, pt.Y); // this directly calls the SetCursorPos win32 API } } @@ -148,7 +148,7 @@ public override void StartTextInput(bool allowIme) public override void ResetIme() => ScheduleCommand(() => Imm.CancelComposition(WindowHandle)); - protected override unsafe void HandleTextInputEvent(SDL.SDL_TextInputEvent evtText) + protected override unsafe void HandleTextInputEvent(SDL_TextInputEvent evtText) { if (!SDL2Extensions.TryGetStringFromBytePointer(evtText.text, out string sdlResult)) return; @@ -169,7 +169,7 @@ protected override unsafe void HandleTextInputEvent(SDL.SDL_TextInputEvent evtTe base.HandleTextInputEvent(evtText); } - protected override void HandleTextEditingEvent(SDL.SDL_TextEditingEvent evtEdit) + protected override void HandleTextEditingEvent(SDL_TextEditingEvent evtEdit) { // handled by custom logic below } @@ -224,7 +224,7 @@ private void handleImeMessage(IntPtr hWnd, uint uMsg, long lParam) #endregion - protected override void HandleTouchFingerEvent(SDL.SDL_TouchFingerEvent evtTfinger) + protected override void HandleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger) { if (evtTfinger.TryGetTouchName(out string name) && name == "pen") { @@ -236,11 +236,11 @@ protected override void HandleTouchFingerEvent(SDL.SDL_TouchFingerEvent evtTfing switch (evtTfinger.type) { - case SDL.SDL_EventType.SDL_FINGERDOWN: + case SDL_EventType.SDL_FINGERDOWN: TriggerMouseDown(MouseButton.Left); break; - case SDL.SDL_EventType.SDL_FINGERUP: + case SDL_EventType.SDL_FINGERUP: TriggerMouseUp(MouseButton.Left); break; } @@ -272,7 +272,7 @@ protected set protected override Size SetBorderless(Display display) { - SDL.SDL_SetWindowBordered(SDLWindowHandle, SDL.SDL_bool.SDL_FALSE); + SDL_SetWindowBordered(SDLWindowHandle, SDL_bool.SDL_FALSE); var newSize = display.Bounds.Size; @@ -281,7 +281,7 @@ protected override Size SetBorderless(Display display) // we also trick the game into thinking the window has normal size: see Size setter override newSize += new Size(windows_borderless_width_hack, 0); - SDL.SDL_SetWindowSize(SDLWindowHandle, newSize.Width, newSize.Height); + SDL_SetWindowSize(SDLWindowHandle, newSize.Width, newSize.Height); Position = display.Bounds.Location; return newSize; From dc7ce4efca4f9308bcb8952db5363537f14f52df Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 7 Apr 2024 12:29:39 +0200 Subject: [PATCH 02/45] Run SDL `build-scripits/rename_symbols.py` This renames SDL2 symbols to SDL3 names. --- .../Platform/SDL2/SDL2ControllerBindings.cs | 16 ++-- osu.Framework/Platform/SDL2/SDL2Extensions.cs | 54 ++++++------ osu.Framework/Platform/SDL2/SDL2Structs.cs | 2 +- osu.Framework/Platform/SDL2Window.cs | 82 +++++++++---------- osu.Framework/Platform/SDL2Window_Input.cs | 62 +++++++------- .../Platform/SDL2Window_Windowing.cs | 46 +++++------ .../Platform/Windows/WindowsWindow.cs | 4 +- 7 files changed, 133 insertions(+), 133 deletions(-) diff --git a/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs b/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs index fbf06b7cb3..1bae4139a5 100644 --- a/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs +++ b/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs @@ -19,13 +19,13 @@ internal class SDL2ControllerBindings public readonly IntPtr ControllerHandle; /// - /// Bindings returned from , indexed by . + /// Bindings returned from , indexed by . /// Empty if the joystick does not have a corresponding ControllerHandle. /// public SDL_GameControllerButtonBind[] ButtonBindings; /// - /// Bindings returned from , indexed by . + /// Bindings returned from , indexed by . /// Empty if the joystick does not have a corresponding ControllerHandle. /// public SDL_GameControllerButtonBind[] AxisBindings; @@ -47,18 +47,18 @@ public void PopulateBindings() return; } - ButtonBindings = Enumerable.Range(0, (int)SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_MAX) - .Select(i => SDL_GameControllerGetBindForButton(ControllerHandle, (SDL_GameControllerButton)i)).ToArray(); + ButtonBindings = Enumerable.Range(0, (int)SDL_GamepadButton.SDL_GAMEPAD_BUTTON_MAX) + .Select(i => SDL_GameControllerGetBindForButton(ControllerHandle, (SDL_GamepadButton)i)).ToArray(); - AxisBindings = Enumerable.Range(0, (int)SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_MAX) - .Select(i => SDL_GameControllerGetBindForAxis(ControllerHandle, (SDL_GameControllerAxis)i)).ToArray(); + AxisBindings = Enumerable.Range(0, (int)SDL_GamepadAxis.SDL_GAMEPAD_AXIS_MAX) + .Select(i => SDL_GameControllerGetBindForAxis(ControllerHandle, (SDL_GamepadAxis)i)).ToArray(); } public bool IsJoystickButtonBound(byte buttonIndex) { for (int i = 0; i < ButtonBindings.Length; i++) { - if (ButtonBindings[i].bindType != SDL_GameControllerBindType.SDL_CONTROLLER_BINDTYPE_NONE && ButtonBindings[i].value.button == buttonIndex) + if (ButtonBindings[i].bindType != SDL_GamepadBindingType.SDL_GAMEPAD_BINDTYPE_NONE && ButtonBindings[i].value.button == buttonIndex) return true; } @@ -69,7 +69,7 @@ public bool IsJoystickAxisBound(byte axisIndex) { for (int i = 0; i < AxisBindings.Length; i++) { - if (AxisBindings[i].bindType != SDL_GameControllerBindType.SDL_CONTROLLER_BINDTYPE_NONE && AxisBindings[i].value.axis == axisIndex) + if (AxisBindings[i].bindType != SDL_GamepadBindingType.SDL_GAMEPAD_BINDTYPE_NONE && AxisBindings[i].value.axis == axisIndex) return true; } diff --git a/osu.Framework/Platform/SDL2/SDL2Extensions.cs b/osu.Framework/Platform/SDL2/SDL2Extensions.cs index edfd63b6f8..c4f54ff85a 100644 --- a/osu.Framework/Platform/SDL2/SDL2Extensions.cs +++ b/osu.Framework/Platform/SDL2/SDL2Extensions.cs @@ -21,7 +21,7 @@ public static Key ToKey(this SDL_Keysym sdlKeysym) { // Apple devices don't have the notion of NumLock (they have a Clear key instead). // treat them as if they always have NumLock on (the numpad always performs its primary actions). - bool numLockOn = sdlKeysym.mod.HasFlagFast(SDL_Keymod.KMOD_NUM) || RuntimeInfo.IsApple; + bool numLockOn = sdlKeysym.mod.HasFlagFast(SDL_Keymod.SDL_KMOD_NUM) || RuntimeInfo.IsApple; switch (sdlKeysym.scancode) { @@ -921,85 +921,85 @@ public static SDL_WindowFlags ToFlags(this GraphicsSurfaceType surfaceType) return 0; } - public static JoystickAxisSource ToJoystickAxisSource(this SDL_GameControllerAxis axis) + public static JoystickAxisSource ToJoystickAxisSource(this SDL_GamepadAxis axis) { switch (axis) { default: - case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_INVALID: + case SDL_GamepadAxis.SDL_GAMEPAD_AXIS_INVALID: return 0; - case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX: + case SDL_GamepadAxis.SDL_GAMEPAD_AXIS_LEFTX: return JoystickAxisSource.GamePadLeftStickX; - case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY: + case SDL_GamepadAxis.SDL_GAMEPAD_AXIS_LEFTY: return JoystickAxisSource.GamePadLeftStickY; - case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT: + case SDL_GamepadAxis.SDL_GAMEPAD_AXIS_LEFT_TRIGGER: return JoystickAxisSource.GamePadLeftTrigger; - case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX: + case SDL_GamepadAxis.SDL_GAMEPAD_AXIS_RIGHTX: return JoystickAxisSource.GamePadRightStickX; - case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY: + case SDL_GamepadAxis.SDL_GAMEPAD_AXIS_RIGHTY: return JoystickAxisSource.GamePadRightStickY; - case SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT: + case SDL_GamepadAxis.SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: return JoystickAxisSource.GamePadRightTrigger; } } - public static JoystickButton ToJoystickButton(this SDL_GameControllerButton button) + public static JoystickButton ToJoystickButton(this SDL_GamepadButton button) { switch (button) { default: - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_INVALID: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_INVALID: return 0; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_SOUTH: return JoystickButton.GamePadA; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_EAST: return JoystickButton.GamePadB; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_WEST: return JoystickButton.GamePadX; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_NORTH: return JoystickButton.GamePadY; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_BACK: return JoystickButton.GamePadBack; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_GUIDE: return JoystickButton.GamePadGuide; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_START: return JoystickButton.GamePadStart; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_LEFT_STICK: return JoystickButton.GamePadLeftStick; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_RIGHT_STICK: return JoystickButton.GamePadRightStick; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_LEFT_SHOULDER: return JoystickButton.GamePadLeftShoulder; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER: return JoystickButton.GamePadRightShoulder; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_DPAD_UP: return JoystickButton.GamePadDPadUp; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_DPAD_DOWN: return JoystickButton.GamePadDPadDown; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_DPAD_LEFT: return JoystickButton.GamePadDPadLeft; - case SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + case SDL_GamepadButton.SDL_GAMEPAD_BUTTON_DPAD_RIGHT: return JoystickButton.GamePadDPadRight; } } @@ -1036,7 +1036,7 @@ public static unsafe bool TryGetStringFromBytePointer(byte* bytePointer, out str public static DisplayMode ToDisplayMode(this SDL_DisplayMode mode, int displayIndex) { - SDL_PixelFormatEnumToMasks(mode.format, out int bpp, out _, out _, out _, out _); + SDL_GetMasksForPixelFormatEnum(mode.format, out int bpp, out _, out _, out _, out _); return new DisplayMode(SDL_GetPixelFormatName(mode.format), new Size(mode.w, mode.h), bpp, mode.refresh_rate, displayIndex); } diff --git a/osu.Framework/Platform/SDL2/SDL2Structs.cs b/osu.Framework/Platform/SDL2/SDL2Structs.cs index 0108edaf45..ccf2494b17 100644 --- a/osu.Framework/Platform/SDL2/SDL2Structs.cs +++ b/osu.Framework/Platform/SDL2/SDL2Structs.cs @@ -42,7 +42,7 @@ internal struct INTERNAL_SysWMmsgUnion [StructLayout(LayoutKind.Sequential)] public struct SDL_SysWMmsg { - public SDL_version version; + public SDL_Version version; public SDL_SYSWM_TYPE subsystem; public INTERNAL_SysWMmsgUnion msg; } diff --git a/osu.Framework/Platform/SDL2Window.cs b/osu.Framework/Platform/SDL2Window.cs index d870809d2f..1b12ef3c89 100644 --- a/osu.Framework/Platform/SDL2Window.cs +++ b/osu.Framework/Platform/SDL2Window.cs @@ -164,7 +164,7 @@ internal SDL_SysWMinfo GetWindowSystemInformation() return wmInfo; } - public bool CapsLockPressed => SDL_GetModState().HasFlagFast(SDL_Keymod.KMOD_CAPS); + public bool CapsLockPressed => SDL_GetModState().HasFlagFast(SDL_Keymod.SDL_KMOD_CAPS); // references must be kept to avoid GC, see https://stackoverflow.com/a/6193914 @@ -186,13 +186,13 @@ protected SDL2Window(GraphicsSurfaceType surfaceType) { ObjectHandle = new ObjectHandle(this, GCHandleType.Normal); - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD) < 0) { throw new InvalidOperationException($"Failed to initialise SDL: {SDL_GetError()}"); } SDL_LogSetPriority((int)SDL_LogCategory.SDL_LOG_CATEGORY_ERROR, SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG); - SDL_LogSetOutputFunction(logOutputDelegate = logOutput, IntPtr.Zero); + SDL_SetLogOutputFunction(logOutputDelegate = logOutput, IntPtr.Zero); graphicsSurface = new SDL2GraphicsSurface(this, surfaceType); @@ -223,7 +223,7 @@ public void SetupWindow(FrameworkConfigManager config) public virtual void Create() { SDL_WindowFlags flags = SDL_WindowFlags.SDL_WINDOW_RESIZABLE | - SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | + SDL_WindowFlags.SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WindowFlags.SDL_WINDOW_HIDDEN; // shown after first swap to avoid white flash on startup (windows) flags |= WindowState.ToFlags(); @@ -315,19 +315,19 @@ protected virtual void HandleEventFromFilter(SDL_Event evt) { switch (evt.type) { - case SDL_EventType.SDL_APP_TERMINATING: + case SDL_EventType.SDL_EVENT_TERMINATING: handleQuitEvent(evt.quit); break; - case SDL_EventType.SDL_APP_DIDENTERBACKGROUND: + case SDL_EventType.SDL_EVENT_DID_ENTER_BACKGROUND: Suspended?.Invoke(); break; - case SDL_EventType.SDL_APP_WILLENTERFOREGROUND: + case SDL_EventType.SDL_EVENT_WILL_ENTER_FOREGROUND: Resumed?.Invoke(); break; - case SDL_EventType.SDL_APP_LOWMEMORY: + case SDL_EventType.SDL_EVENT_LOW_MEMORY: LowOnMemory?.Invoke(); break; } @@ -339,7 +339,7 @@ protected void HandleEventFromWatch(SDL_Event evt) { case SDL_EventType.SDL_WINDOWEVENT: // polling via SDL_PollEvent blocks on resizes (https://stackoverflow.com/a/50858339) - if (evt.window.windowEvent == SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED && !updatingWindowStateAndSize) + if (evt.window.windowEvent == SDL_WindowEventID.SDL_EVENT_WINDOW_RESIZED && !updatingWindowStateAndSize) fetchWindowSize(); break; @@ -456,7 +456,7 @@ private unsafe void setSDLIcon(Image image) surface = SDL_CreateRGBSurfaceFrom(new IntPtr(ptr), imageSize.Width, imageSize.Height, 32, imageSize.Width * 4, 0xff, 0xff00, 0xff0000, 0xff000000); SDL_SetWindowIcon(SDLWindowHandle, surface); - SDL_FreeSurface(surface); + SDL_DestroySurface(surface); }); } @@ -484,7 +484,7 @@ private void pollSDLEvents() do { - eventsRead = SDL_PeepEvents(events, events_per_peep, SDL_eventaction.SDL_GETEVENT, SDL_EventType.SDL_FIRSTEVENT, SDL_EventType.SDL_LASTEVENT); + eventsRead = SDL_PeepEvents(events, events_per_peep, SDL_eventaction.SDL_GETEVENT, SDL_EventType.SDL_EVENT_FIRST, SDL_EventType.SDL_EVENT_LAST); for (int i = 0; i < eventsRead; i++) HandleEvent(events[i]); } while (eventsRead == events_per_peep); @@ -497,7 +497,7 @@ protected virtual void HandleEvent(SDL_Event e) { switch (e.type) { - case SDL_EventType.SDL_QUIT: + case SDL_EventType.SDL_EVENT_QUIT: handleQuitEvent(e.quit); break; @@ -509,83 +509,83 @@ protected virtual void HandleEvent(SDL_Event e) handleWindowEvent(e.window); break; - case SDL_EventType.SDL_KEYDOWN: - case SDL_EventType.SDL_KEYUP: + case SDL_EventType.SDL_EVENT_KEY_DOWN: + case SDL_EventType.SDL_EVENT_KEY_UP: handleKeyboardEvent(e.key); break; - case SDL_EventType.SDL_TEXTEDITING: + case SDL_EventType.SDL_EVENT_TEXT_EDITING: HandleTextEditingEvent(e.edit); break; - case SDL_EventType.SDL_TEXTINPUT: + case SDL_EventType.SDL_EVENT_TEXT_INPUT: HandleTextInputEvent(e.text); break; - case SDL_EventType.SDL_KEYMAPCHANGED: + case SDL_EventType.SDL_EVENT_KEYMAP_CHANGED: handleKeymapChangedEvent(); break; - case SDL_EventType.SDL_MOUSEMOTION: + case SDL_EventType.SDL_EVENT_MOUSE_MOTION: handleMouseMotionEvent(e.motion); break; - case SDL_EventType.SDL_MOUSEBUTTONDOWN: - case SDL_EventType.SDL_MOUSEBUTTONUP: + case SDL_EventType.SDL_EVENT_MOUSE_BUTTON_DOWN: + case SDL_EventType.SDL_EVENT_MOUSE_BUTTON_UP: handleMouseButtonEvent(e.button); break; - case SDL_EventType.SDL_MOUSEWHEEL: + case SDL_EventType.SDL_EVENT_MOUSE_WHEEL: handleMouseWheelEvent(e.wheel); break; - case SDL_EventType.SDL_JOYAXISMOTION: + case SDL_EventType.SDL_EVENT_JOYSTICK_AXIS_MOTION: handleJoyAxisEvent(e.jaxis); break; - case SDL_EventType.SDL_JOYBALLMOTION: + case SDL_EventType.SDL_EVENT_JOYSTICK_BALL_MOTION: handleJoyBallEvent(e.jball); break; - case SDL_EventType.SDL_JOYHATMOTION: + case SDL_EventType.SDL_EVENT_JOYSTICK_HAT_MOTION: handleJoyHatEvent(e.jhat); break; - case SDL_EventType.SDL_JOYBUTTONDOWN: - case SDL_EventType.SDL_JOYBUTTONUP: + case SDL_EventType.SDL_EVENT_JOYSTICK_BUTTON_DOWN: + case SDL_EventType.SDL_EVENT_JOYSTICK_BUTTON_UP: handleJoyButtonEvent(e.jbutton); break; - case SDL_EventType.SDL_JOYDEVICEADDED: - case SDL_EventType.SDL_JOYDEVICEREMOVED: + case SDL_EventType.SDL_EVENT_JOYSTICK_ADDED: + case SDL_EventType.SDL_EVENT_JOYSTICK_REMOVED: handleJoyDeviceEvent(e.jdevice); break; - case SDL_EventType.SDL_CONTROLLERAXISMOTION: + case SDL_EventType.SDL_EVENT_GAMEPAD_AXIS_MOTION: handleControllerAxisEvent(e.caxis); break; - case SDL_EventType.SDL_CONTROLLERBUTTONDOWN: - case SDL_EventType.SDL_CONTROLLERBUTTONUP: + case SDL_EventType.SDL_EVENT_GAMEPAD_BUTTON_DOWN: + case SDL_EventType.SDL_EVENT_GAMEPAD_BUTTON_UP: handleControllerButtonEvent(e.cbutton); break; - case SDL_EventType.SDL_CONTROLLERDEVICEADDED: - case SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: - case SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED: + case SDL_EventType.SDL_EVENT_GAMEPAD_ADDED: + case SDL_EventType.SDL_EVENT_GAMEPAD_REMOVED: + case SDL_EventType.SDL_EVENT_GAMEPAD_REMAPPED: handleControllerDeviceEvent(e.cdevice); break; - case SDL_EventType.SDL_FINGERDOWN: - case SDL_EventType.SDL_FINGERUP: - case SDL_EventType.SDL_FINGERMOTION: + case SDL_EventType.SDL_EVENT_FINGER_DOWN: + case SDL_EventType.SDL_EVENT_FINGER_UP: + case SDL_EventType.SDL_EVENT_FINGER_MOTION: HandleTouchFingerEvent(e.tfinger); break; - case SDL_EventType.SDL_DROPFILE: - case SDL_EventType.SDL_DROPTEXT: - case SDL_EventType.SDL_DROPBEGIN: - case SDL_EventType.SDL_DROPCOMPLETE: + case SDL_EventType.SDL_EVENT_DROP_FILE: + case SDL_EventType.SDL_EVENT_DROP_TEXT: + case SDL_EventType.SDL_EVENT_DROP_BEGIN: + case SDL_EventType.SDL_EVENT_DROP_COMPLETE: handleDropEvent(e.drop); break; } diff --git a/osu.Framework/Platform/SDL2Window_Input.cs b/osu.Framework/Platform/SDL2Window_Input.cs index c28e85e6e5..bdd071c5c8 100644 --- a/osu.Framework/Platform/SDL2Window_Input.cs +++ b/osu.Framework/Platform/SDL2Window_Input.cs @@ -59,9 +59,9 @@ public bool RelativeMouseMode /// Only works with disabled. /// /// - /// If the cursor leaves the window while it's captured, is not sent until the button(s) are released. - /// And if the cursor leaves and enters the window while captured, is not sent either. - /// We disable relative mode when the cursor exits window bounds (not on the event), but we only enable it again on . + /// If the cursor leaves the window while it's captured, is not sent until the button(s) are released. + /// And if the cursor leaves and enters the window while captured, is not sent either. + /// We disable relative mode when the cursor exits window bounds (not on the event), but we only enable it again on . /// The above culminate in staying off when the cursor leaves and enters the window bounds when any buttons are pressed. /// This is an invalid state, as the cursor is inside the window, and is off. /// @@ -199,7 +199,7 @@ private void handleDropEvent(SDL_DropEvent evtDrop) { switch (evtDrop.type) { - case SDL_EventType.SDL_DROPFILE: + case SDL_EventType.SDL_EVENT_DROP_FILE: string str = UTF8_ToManaged(evtDrop.file, true); if (str != null) DragDrop?.Invoke(str); @@ -239,7 +239,7 @@ protected virtual void HandleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger) { var existingSource = getTouchSource(evtTfinger.fingerId); - if (evtTfinger.type == SDL_EventType.SDL_FINGERDOWN) + if (evtTfinger.type == SDL_EventType.SDL_EVENT_FINGER_DOWN) { Debug.Assert(existingSource == null); existingSource = assignNextAvailableTouchSource(evtTfinger.fingerId); @@ -255,32 +255,32 @@ protected virtual void HandleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger) switch (evtTfinger.type) { - case SDL_EventType.SDL_FINGERDOWN: - case SDL_EventType.SDL_FINGERMOTION: + case SDL_EventType.SDL_EVENT_FINGER_DOWN: + case SDL_EventType.SDL_EVENT_FINGER_MOTION: TouchDown?.Invoke(touch); break; - case SDL_EventType.SDL_FINGERUP: + case SDL_EventType.SDL_EVENT_FINGER_UP: TouchUp?.Invoke(touch); activeTouches[(int)existingSource] = null; break; } } - private void handleControllerDeviceEvent(SDL_ControllerDeviceEvent evtCdevice) + private void handleControllerDeviceEvent(SDL_GamepadDeviceEvent evtCdevice) { switch (evtCdevice.type) { - case SDL_EventType.SDL_CONTROLLERDEVICEADDED: + case SDL_EventType.SDL_EVENT_GAMEPAD_ADDED: addJoystick(evtCdevice.which); break; - case SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: - SDL_GameControllerClose(controllers[evtCdevice.which].ControllerHandle); + case SDL_EventType.SDL_EVENT_GAMEPAD_REMOVED: + SDL_CloseGamepad(controllers[evtCdevice.which].ControllerHandle); controllers.Remove(evtCdevice.which); break; - case SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED: + case SDL_EventType.SDL_EVENT_GAMEPAD_REMAPPED: if (controllers.TryGetValue(evtCdevice.which, out var state)) state.PopulateBindings(); @@ -288,24 +288,24 @@ private void handleControllerDeviceEvent(SDL_ControllerDeviceEvent evtCdevice) } } - private void handleControllerButtonEvent(SDL_ControllerButtonEvent evtCbutton) + private void handleControllerButtonEvent(SDL_GamepadButtonEvent evtCbutton) { - var button = ((SDL_GameControllerButton)evtCbutton.button).ToJoystickButton(); + var button = ((SDL_GamepadButton)evtCbutton.button).ToJoystickButton(); switch (evtCbutton.type) { - case SDL_EventType.SDL_CONTROLLERBUTTONDOWN: + case SDL_EventType.SDL_EVENT_GAMEPAD_BUTTON_DOWN: enqueueJoystickButtonInput(button, true); break; - case SDL_EventType.SDL_CONTROLLERBUTTONUP: + case SDL_EventType.SDL_EVENT_GAMEPAD_BUTTON_UP: enqueueJoystickButtonInput(button, false); break; } } - private void handleControllerAxisEvent(SDL_ControllerAxisEvent evtCaxis) => - enqueueJoystickAxisInput(((SDL_GameControllerAxis)evtCaxis.axis).ToJoystickAxisSource(), evtCaxis.axisValue); + private void handleControllerAxisEvent(SDL_GamepadAxisEvent evtCaxis) => + enqueueJoystickAxisInput(((SDL_GamepadAxis)evtCaxis.axis).ToJoystickAxisSource(), evtCaxis.axisValue); private void addJoystick(int which) { @@ -315,11 +315,11 @@ private void addJoystick(int which) if (controllers.ContainsKey(instanceID)) return; - IntPtr joystick = SDL_JoystickOpen(which); + IntPtr joystick = SDL_OpenJoystick(which); IntPtr controller = IntPtr.Zero; - if (SDL_IsGameController(which) == SDL_bool.SDL_TRUE) - controller = SDL_GameControllerOpen(which); + if (SDL_IsGamepad(which) == SDL_bool.SDL_TRUE) + controller = SDL_OpenGamepad(which); controllers[instanceID] = new SDL2ControllerBindings(joystick, controller); } @@ -339,16 +339,16 @@ private void handleJoyDeviceEvent(SDL_JoyDeviceEvent evtJdevice) { switch (evtJdevice.type) { - case SDL_EventType.SDL_JOYDEVICEADDED: + case SDL_EventType.SDL_EVENT_JOYSTICK_ADDED: addJoystick(evtJdevice.which); break; - case SDL_EventType.SDL_JOYDEVICEREMOVED: + case SDL_EventType.SDL_EVENT_JOYSTICK_REMOVED: // if the joystick is already closed, ignore it if (!controllers.ContainsKey(evtJdevice.which)) break; - SDL_JoystickClose(controllers[evtJdevice.which].JoystickHandle); + SDL_CloseJoystick(controllers[evtJdevice.which].JoystickHandle); controllers.Remove(evtJdevice.which); break; } @@ -364,11 +364,11 @@ private void handleJoyButtonEvent(SDL_JoyButtonEvent evtJbutton) switch (evtJbutton.type) { - case SDL_EventType.SDL_JOYBUTTONDOWN: + case SDL_EventType.SDL_EVENT_JOYSTICK_BUTTON_DOWN: enqueueJoystickButtonInput(button, true); break; - case SDL_EventType.SDL_JOYBUTTONUP: + case SDL_EventType.SDL_EVENT_JOYSTICK_BUTTON_UP: enqueueJoystickButtonInput(button, false); break; } @@ -417,12 +417,12 @@ private void handleMouseButtonEvent(SDL_MouseButtonEvent evtButton) switch (evtButton.type) { - case SDL_EventType.SDL_MOUSEBUTTONDOWN: + case SDL_EventType.SDL_EVENT_MOUSE_BUTTON_DOWN: pressedButtons |= mask; MouseDown?.Invoke(button); break; - case SDL_EventType.SDL_MOUSEBUTTONUP: + case SDL_EventType.SDL_EVENT_MOUSE_BUTTON_UP: pressedButtons &= ~mask; MouseUp?.Invoke(button); break; @@ -465,11 +465,11 @@ private void handleKeyboardEvent(SDL_KeyboardEvent evtKey) switch (evtKey.type) { - case SDL_EventType.SDL_KEYDOWN: + case SDL_EventType.SDL_EVENT_KEY_DOWN: KeyDown?.Invoke(key); break; - case SDL_EventType.SDL_KEYUP: + case SDL_EventType.SDL_EVENT_KEY_UP: KeyUp?.Invoke(key); break; } diff --git a/osu.Framework/Platform/SDL2Window_Windowing.cs b/osu.Framework/Platform/SDL2Window_Windowing.cs index c6b4a23cdf..c80e9a4ec4 100644 --- a/osu.Framework/Platform/SDL2Window_Windowing.cs +++ b/osu.Framework/Platform/SDL2Window_Windowing.cs @@ -466,7 +466,7 @@ private void handleWindowEvent(SDL_WindowEvent evtWindow) switch (evtWindow.windowEvent) { - case SDL_WindowEventID.SDL_WINDOWEVENT_MOVED: + case SDL_WindowEventID.SDL_EVENT_WINDOW_MOVED: // explicitly requery as there are occasions where what SDL has provided us with is not up-to-date. SDL_GetWindowPosition(SDLWindowHandle, out int x, out int y); var newPosition = new Point(x, y); @@ -482,31 +482,31 @@ private void handleWindowEvent(SDL_WindowEvent evtWindow) break; - case SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: + case SDL_WindowEventID.SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: fetchWindowSize(); break; - case SDL_WindowEventID.SDL_WINDOWEVENT_ENTER: + case SDL_WindowEventID.SDL_EVENT_WINDOW_MOUSE_ENTER: cursorInWindow.Value = true; MouseEntered?.Invoke(); break; - case SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE: + case SDL_WindowEventID.SDL_EVENT_WINDOW_MOUSE_LEAVE: cursorInWindow.Value = false; MouseLeft?.Invoke(); break; - case SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED: - case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: + case SDL_WindowEventID.SDL_EVENT_WINDOW_RESTORED: + case SDL_WindowEventID.SDL_EVENT_WINDOW_FOCUS_GAINED: Focused = true; break; - case SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED: - case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: + case SDL_WindowEventID.SDL_EVENT_WINDOW_MINIMIZED: + case SDL_WindowEventID.SDL_EVENT_WINDOW_FOCUS_LOST: Focused = false; break; - case SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE: + case SDL_WindowEventID.SDL_EVENT_WINDOW_CLOSE_REQUESTED: break; } @@ -515,12 +515,12 @@ private void handleWindowEvent(SDL_WindowEvent evtWindow) // eg. this covers scenarios when changing resolution outside of the game, and then tabbing in. switch (evtWindow.windowEvent) { - case SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED: - case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: - case SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED: - case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: - case SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN: - case SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN: + case SDL_WindowEventID.SDL_EVENT_WINDOW_RESTORED: + case SDL_WindowEventID.SDL_EVENT_WINDOW_FOCUS_GAINED: + case SDL_WindowEventID.SDL_EVENT_WINDOW_MINIMIZED: + case SDL_WindowEventID.SDL_EVENT_WINDOW_FOCUS_LOST: + case SDL_WindowEventID.SDL_EVENT_WINDOW_SHOWN: + case SDL_WindowEventID.SDL_EVENT_WINDOW_HIDDEN: fetchDisplays(); break; } @@ -583,7 +583,7 @@ private void updateAndFetchWindowSpecifics() windowMaximised = maximized; } - int newDisplayIndex = SDL_GetWindowDisplayIndex(SDLWindowHandle); + int newDisplayIndex = SDL_GetDisplayForWindow(SDLWindowHandle); if (displayIndex != newDisplayIndex) { @@ -620,7 +620,7 @@ protected virtual void UpdateWindowStateAndSize(WindowState state, Display displ ensureWindowOnDisplay(display); - SDL_SetWindowDisplayMode(SDLWindowHandle, ref closestMode); + SDL_SetWindowFullscreenMode(SDLWindowHandle, ref closestMode); SDL_SetWindowFullscreen(SDLWindowHandle, (uint)SDL_WindowFlags.SDL_WINDOW_FULLSCREEN); break; @@ -648,7 +648,7 @@ private static bool tryFetchDisplayMode(IntPtr windowHandle, WindowState windowS // TODO: displayIndex should be valid here at all times. // on startup, the displayIndex will be invalid (-1) due to it being set later in the startup sequence. // related to order of operations in `updateWindowSpecifics()`. - int localIndex = SDL_GetWindowDisplayIndex(windowHandle); + int localIndex = SDL_GetDisplayForWindow(windowHandle); if (localIndex != display.Index) Logger.Log($"Stored display index ({display.Index}) doesn't match current index ({localIndex})"); @@ -657,7 +657,7 @@ private static bool tryFetchDisplayMode(IntPtr windowHandle, WindowState windowS SDL_DisplayMode mode; if (windowState == WindowState.Fullscreen) - success = SDL_GetWindowDisplayMode(windowHandle, out mode) >= 0; + success = SDL_GetWindowFullscreenMode(windowHandle, out mode) >= 0; else success = SDL_GetCurrentDisplayMode(localIndex, out mode) >= 0; @@ -705,7 +705,7 @@ private void readWindowPositionFromConfig(WindowState state, Display display) /// The to center the window on. private void ensureWindowOnDisplay(Display display) { - if (display.Index == SDL_GetWindowDisplayIndex(SDLWindowHandle)) + if (display.Index == SDL_GetDisplayForWindow(SDLWindowHandle)) return; moveWindowTo(display, new Vector2(0.5f)); @@ -824,7 +824,7 @@ private static SDL_DisplayMode getClosestDisplayMode(IntPtr windowHandle, Size s var targetMode = new SDL_DisplayMode { w = size.Width, h = size.Height, refresh_rate = requestedMode.RefreshRate }; - if (SDL_GetClosestDisplayMode(display.Index, ref targetMode, out var mode) != IntPtr.Zero) + if (SDL_GetClosestFullscreenDisplayMode(display.Index, ref targetMode, out var mode) != IntPtr.Zero) return mode; else Logger.Log($"Unable to get preferred display mode (try #1/2). Target display: {display.Index}, mode: {targetMode.ReadableString()}. SDL error: {SDL2Extensions.GetAndClearError()}"); @@ -834,7 +834,7 @@ private static SDL_DisplayMode getClosestDisplayMode(IntPtr windowHandle, Size s targetMode.h = display.Bounds.Height; targetMode.refresh_rate = 0; - if (SDL_GetClosestDisplayMode(display.Index, ref targetMode, out mode) != IntPtr.Zero) + if (SDL_GetClosestFullscreenDisplayMode(display.Index, ref targetMode, out mode) != IntPtr.Zero) return mode; else Logger.Log($"Unable to get preferred display mode (try #2/2). Target display: {display.Index}, mode: {targetMode.ReadableString()}. SDL error: {SDL2Extensions.GetAndClearError()}"); @@ -858,7 +858,7 @@ private static SDL_DisplayMode getClosestDisplayMode(IntPtr windowHandle, Size s Logger.Log($"Failed to get desktop display mode (try #3/3). Target display: primary. SDL error: {SDL2Extensions.GetAndClearError()}", level: LogLevel.Error); // finally return the current mode if everything else fails. - if (SDL_GetWindowDisplayMode(windowHandle, out mode) >= 0) + if (SDL_GetWindowFullscreenMode(windowHandle, out mode) >= 0) return mode; else Logger.Log($"Failed to get window display mode. SDL error: {SDL2Extensions.GetAndClearError()}", level: LogLevel.Error); diff --git a/osu.Framework/Platform/Windows/WindowsWindow.cs b/osu.Framework/Platform/Windows/WindowsWindow.cs index c854e95296..11a10e5a31 100644 --- a/osu.Framework/Platform/Windows/WindowsWindow.cs +++ b/osu.Framework/Platform/Windows/WindowsWindow.cs @@ -236,11 +236,11 @@ protected override void HandleTouchFingerEvent(SDL_TouchFingerEvent evtTfinger) switch (evtTfinger.type) { - case SDL_EventType.SDL_FINGERDOWN: + case SDL_EventType.SDL_EVENT_FINGER_DOWN: TriggerMouseDown(MouseButton.Left); break; - case SDL_EventType.SDL_FINGERUP: + case SDL_EventType.SDL_EVENT_FINGER_UP: TriggerMouseUp(MouseButton.Left); break; } From e936173aa48727876ad9e98081e212c15b7b2716 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 7 Apr 2024 12:34:11 +0200 Subject: [PATCH 03/45] Switch to ppy.SDL3-CS and update `using`s --- osu.Framework.iOS/GameApplication.cs | 2 +- osu.Framework.iOS/IOSWindow.cs | 3 ++- osu.Framework/Platform/Linux/LinuxGameHost.cs | 2 +- .../Platform/Linux/LinuxReadableKeyCombinationProvider.cs | 3 ++- .../Platform/MacOS/MacOSReadableKeyCombinationProvider.cs | 3 ++- osu.Framework/Platform/SDL2/SDL2Clipboard.cs | 3 ++- osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs | 3 ++- osu.Framework/Platform/SDL2/SDL2Extensions.cs | 3 ++- osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs | 3 ++- .../Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs | 3 ++- osu.Framework/Platform/SDL2/SDL2Structs.cs | 3 ++- osu.Framework/Platform/SDL2DesktopWindow.cs | 3 ++- osu.Framework/Platform/SDL2Window.cs | 3 ++- osu.Framework/Platform/SDL2Window_Input.cs | 3 ++- osu.Framework/Platform/SDL2Window_Windowing.cs | 3 ++- osu.Framework/Platform/Windows/WindowsMouseHandler.cs | 2 +- .../Platform/Windows/WindowsReadableKeyCombinationProvider.cs | 3 ++- osu.Framework/Platform/Windows/WindowsWindow.cs | 3 ++- osu.Framework/osu.Framework.csproj | 4 ++-- 19 files changed, 35 insertions(+), 20 deletions(-) diff --git a/osu.Framework.iOS/GameApplication.cs b/osu.Framework.iOS/GameApplication.cs index b0f9a15333..75afa7d70d 100644 --- a/osu.Framework.iOS/GameApplication.cs +++ b/osu.Framework.iOS/GameApplication.cs @@ -9,7 +9,7 @@ using ManagedBass.Fx; using ManagedBass.Mix; using ObjCRuntime; -using static SDL2.SDL; +using static SDL.SDL3; namespace osu.Framework.iOS { diff --git a/osu.Framework.iOS/IOSWindow.cs b/osu.Framework.iOS/IOSWindow.cs index 40a4801a1b..8d76690b76 100644 --- a/osu.Framework.iOS/IOSWindow.cs +++ b/osu.Framework.iOS/IOSWindow.cs @@ -8,8 +8,9 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Platform; +using SDL; using UIKit; -using static SDL2.SDL; +using static SDL.SDL3; namespace osu.Framework.iOS { diff --git a/osu.Framework/Platform/Linux/LinuxGameHost.cs b/osu.Framework/Platform/Linux/LinuxGameHost.cs index 835ee56814..85290ecdf2 100644 --- a/osu.Framework/Platform/Linux/LinuxGameHost.cs +++ b/osu.Framework/Platform/Linux/LinuxGameHost.cs @@ -6,7 +6,7 @@ using osu.Framework.Input; using osu.Framework.Input.Handlers; using osu.Framework.Input.Handlers.Mouse; -using static SDL2.SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.Linux { diff --git a/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs b/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs index d83dc9554b..40a613f531 100644 --- a/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs @@ -3,7 +3,8 @@ using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.Linux { diff --git a/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs b/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs index cc4cce77a2..d240c53770 100644 --- a/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs @@ -3,7 +3,8 @@ using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.MacOS { diff --git a/osu.Framework/Platform/SDL2/SDL2Clipboard.cs b/osu.Framework/Platform/SDL2/SDL2Clipboard.cs index f75a4091b5..49e895d5ce 100644 --- a/osu.Framework/Platform/SDL2/SDL2Clipboard.cs +++ b/osu.Framework/Platform/SDL2/SDL2Clipboard.cs @@ -1,8 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using SDL; using SixLabors.ImageSharp; -using static SDL2.SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.SDL2 { diff --git a/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs b/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs index 1bae4139a5..ab01e2b9e4 100644 --- a/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs +++ b/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs @@ -5,7 +5,8 @@ using System; using System.Linq; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.SDL2 { diff --git a/osu.Framework/Platform/SDL2/SDL2Extensions.cs b/osu.Framework/Platform/SDL2/SDL2Extensions.cs index c4f54ff85a..5ca6d2a4ac 100644 --- a/osu.Framework/Platform/SDL2/SDL2Extensions.cs +++ b/osu.Framework/Platform/SDL2/SDL2Extensions.cs @@ -11,7 +11,8 @@ using osu.Framework.Input; using osu.Framework.Input.Bindings; using osuTK.Input; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.SDL2 { diff --git a/osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs b/osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs index c0f5e0b7d9..7c276ed59a 100644 --- a/osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs +++ b/osu.Framework/Platform/SDL2/SDL2GraphicsSurface.cs @@ -9,7 +9,8 @@ using System.Runtime.InteropServices; using osuTK.Graphics; using osuTK.Graphics.ES30; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.SDL2 { diff --git a/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs b/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs index 14c042d74e..0523645d79 100644 --- a/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs @@ -4,7 +4,8 @@ using System.Globalization; using osu.Framework.Input; using osu.Framework.Input.Bindings; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.SDL2 { diff --git a/osu.Framework/Platform/SDL2/SDL2Structs.cs b/osu.Framework/Platform/SDL2/SDL2Structs.cs index ccf2494b17..49dbed3c44 100644 --- a/osu.Framework/Platform/SDL2/SDL2Structs.cs +++ b/osu.Framework/Platform/SDL2/SDL2Structs.cs @@ -3,7 +3,8 @@ using System; using System.Runtime.InteropServices; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; // ReSharper disable MemberCanBePrivate.Global // (Some members not currently used) diff --git a/osu.Framework/Platform/SDL2DesktopWindow.cs b/osu.Framework/Platform/SDL2DesktopWindow.cs index f596eb144d..c9c1fdeb3d 100644 --- a/osu.Framework/Platform/SDL2DesktopWindow.cs +++ b/osu.Framework/Platform/SDL2DesktopWindow.cs @@ -1,7 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform { diff --git a/osu.Framework/Platform/SDL2Window.cs b/osu.Framework/Platform/SDL2Window.cs index 1b12ef3c89..4c2c0e14c6 100644 --- a/osu.Framework/Platform/SDL2Window.cs +++ b/osu.Framework/Platform/SDL2Window.cs @@ -13,11 +13,12 @@ using osu.Framework.Logging; using osu.Framework.Platform.SDL2; using osu.Framework.Threading; +using SDL; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using Image = SixLabors.ImageSharp.Image; using Point = System.Drawing.Point; -using static SDL2.SDL; +using static SDL.SDL3; namespace osu.Framework.Platform { diff --git a/osu.Framework/Platform/SDL2Window_Input.cs b/osu.Framework/Platform/SDL2Window_Input.cs index bdd071c5c8..b9c9943bd8 100644 --- a/osu.Framework/Platform/SDL2Window_Input.cs +++ b/osu.Framework/Platform/SDL2Window_Input.cs @@ -15,7 +15,8 @@ using osu.Framework.Platform.SDL2; using osuTK; using osuTK.Input; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; using RectangleF = osu.Framework.Graphics.Primitives.RectangleF; namespace osu.Framework.Platform diff --git a/osu.Framework/Platform/SDL2Window_Windowing.cs b/osu.Framework/Platform/SDL2Window_Windowing.cs index c80e9a4ec4..81016c1d55 100644 --- a/osu.Framework/Platform/SDL2Window_Windowing.cs +++ b/osu.Framework/Platform/SDL2Window_Windowing.cs @@ -13,7 +13,8 @@ using osu.Framework.Logging; using osu.Framework.Platform.SDL2; using osuTK; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform { diff --git a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs index 8610dc4886..6dc97d5334 100644 --- a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs +++ b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs @@ -10,7 +10,7 @@ using osu.Framework.Platform.Windows.Native; using osu.Framework.Statistics; using osuTK; -using static SDL2.SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.Windows { diff --git a/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs b/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs index daad7fda20..9b5211e9de 100644 --- a/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs @@ -3,7 +3,8 @@ using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; namespace osu.Framework.Platform.Windows { diff --git a/osu.Framework/Platform/Windows/WindowsWindow.cs b/osu.Framework/Platform/Windows/WindowsWindow.cs index 11a10e5a31..7e2a1fc5dc 100644 --- a/osu.Framework/Platform/Windows/WindowsWindow.cs +++ b/osu.Framework/Platform/Windows/WindowsWindow.cs @@ -10,7 +10,8 @@ using osu.Framework.Platform.Windows.Native; using osuTK; using osuTK.Input; -using static SDL2.SDL; +using SDL; +using static SDL.SDL3; using Icon = osu.Framework.Platform.Windows.Native.Icon; namespace osu.Framework.Platform.Windows diff --git a/osu.Framework/osu.Framework.csproj b/osu.Framework/osu.Framework.csproj index 732b4a8d27..ad33a6496d 100644 --- a/osu.Framework/osu.Framework.csproj +++ b/osu.Framework/osu.Framework.csproj @@ -36,10 +36,10 @@ - + - +