From 29c7e9c1266feeaa97daf0b36bf807736775e0d3 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Fri, 6 Jun 2025 18:23:59 +0200 Subject: [PATCH] Add SDL_GetEventDescription helper --- SDL3-CS/SDL3/SDL_events.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/SDL3-CS/SDL3/SDL_events.cs b/SDL3-CS/SDL3/SDL_events.cs index dc7b1ba..359ce30 100644 --- a/SDL3-CS/SDL3/SDL_events.cs +++ b/SDL3-CS/SDL3/SDL_events.cs @@ -1,6 +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 System; +using System.Text; + namespace SDL { public partial struct SDL_CommonEvent @@ -63,5 +66,22 @@ namespace SDL public static void SDL_FlushEvents(SDL_EventType minType, SDL_EventType maxType) => SDL_FlushEvents((uint)minType, (uint)maxType); public static void SDL_SetEventEnabled(SDL_EventType type, bool enabled) => SDL_SetEventEnabled((uint)type, enabled); public static SDLBool SDL_EventEnabled(SDL_EventType type) => SDL_EventEnabled((uint)type); + + public static string SDL_GetEventDescription(SDL_Event @event) + { + const int bufferSize = 256; + Span buf = stackalloc byte[bufferSize]; + + int bytesWritten; + + unsafe + { + fixed (byte* ptr = buf) + bytesWritten = SDL_GetEventDescription(&@event, ptr, bufferSize); + } + + int bytesToRead = bytesWritten > bufferSize ? bufferSize : bytesWritten; + return Encoding.UTF8.GetString(buf[..bytesToRead]); + } } }