Add SDL2Swift wrappers for OpenGL, keyboard, mouse, and misc APIs#14
Merged
Conversation
Wraps SDL_GL_CreateContext/MakeCurrent/DeleteContext/SwapWindow and the attribute get/set + swap interval APIs, which had no coverage before.
Wraps SDL_GetKeyboardState/SDL_GetScancodeName and adds ~50 named Scancode constants for keybinding use cases.
Wraps SDL_GetMouseState/GetRelativeMouseState, SDL2's global relative-mouse-mode setting, and per-window mouse grab.
Adds SDL_GameControllerName/HasRumble/Rumble/SetPlayerIndex, axis/button string lookups, and the mapping-file/isGameController helpers.
Adds SDL_SetWindowFullscreen and SDL_GetWindowPosition. SDL2 has no SDL_SyncWindow equivalent.
Needed as the return type for the new display bounds accessors.
Adds SDL_GetDisplayBounds/GetDisplayUsableBounds/GetWindowDisplayIndex and SDL_GetCurrentVideoDriver.
Wraps SDL_GetTicks64/SDL_Delay, alongside SDL's existing reconstructed nanosecond tick counter. SDL2 has no SDL_GetCurrentTime/DateTime API.
SDL's logging functions are C-variadic and unavailable in Swift, so this routes through SDL_LogMessageV via withVaList with a fixed "%s" format.
Wraps SDL_ShowSimpleMessageBox.
Wraps SDL_NumJoysticks/SDL_JoystickGetDeviceInstanceID/SDL_JoystickNameForIndex, distinct from the higher-level Gamepad API. SDL2 enumerates joysticks by device index rather than returning an array of instance IDs like SDL3.
Adds SDL_MOUSEWHEEL, SDL_TEXTINPUT, and the SDL_WINDOWEVENT_CLOSE sub-event cases, previously falling through to .unknown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion to #13 — adds the same surface area to
SDL2Swift, adapted to SDL2's APIs (int/SDL_boolreturn codes instead ofbool, device-index-based joystick enumeration, global relative-mouse-mode, noSDL_SyncWindow/SDL_GetCurrentTime/Properties API equivalents).OpenGL.swift: GL context management (SDL_GL_CreateContext/MakeCurrent/DeleteContext/SwapWindow/attributes/swap interval), previously uncovered.Keyboard.swift/Mouse.swift: polled input state (SDL_GetKeyboardState,SDL_GetMouseState, relative mouse mode, window mouse grab).Time.swift,Log.swift,MessageBox.swift,Rect.swift,Joystick.swift.Gamepad.swift(name, rumble, player index, mapping files),Window.swift(fullscreen, position),VideoDisplay.swift(bounds, usable bounds, per-window display index, current video driver), andEvent.swift(mouse wheel, text input, window close requested).Not ported (no SDL2 equivalent):
Properties.swift(SDL2 exposesSDL_GameControllerHasRumbledirectly, no general properties API),SDLWindow.sync()(noSDL_SyncWindowin SDL2),SDL.currentTime/SDLDateTime(noSDL_GetCurrentTime/SDL_time.hin SDL2).Test plan
swift build(whole package) succeedsswift test --filter SDL2Testspasses