Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple SDL_tray test #190

Merged
merged 4 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion External/SDL
Submodule SDL updated 177 files
2 changes: 2 additions & 0 deletions SDL3-CS.Tests/TestPositionalInputVisualisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// See the LICENCE file in the repository root for full licence text.

using System.Drawing;
using NUnit.Framework;
using static SDL.SDL3;

namespace SDL.Tests
{
[Explicit("Uses an interactive window.")]
public unsafe class TestPositionalInputVisualisation : MainCallbacksTest
{
private SDL_Window* window;
Expand Down
36 changes: 36 additions & 0 deletions SDL3-CS.Tests/TestTray.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using NUnit.Framework;
using static SDL.SDL3;

namespace SDL.Tests
{
[Explicit("Uses an interactive tray icon.")]
public unsafe class TestTray : TrayTest
{
private volatile bool running;

[Test]
public void TestBasic()
{
var checkbox = SDL_InsertTrayEntryAt(RootMenu, -1, "Check box?", SDL_TrayEntryFlags.SDL_TRAYENTRY_CHECKBOX);
Assert.That(checkbox != null, SDL_GetError);
SetCallback(checkbox, () => Console.WriteLine("Checkbox was toggled."));

var separator = SDL_InsertTrayEntryAt(RootMenu, -1, (byte*)null, 0);
Assert.That(separator != null, SDL_GetError);

var exit = SDL_InsertTrayEntryAt(RootMenu, -1, "Exit tray", SDL_TrayEntryFlags.SDL_TRAYENTRY_BUTTON);
Assert.That(exit != null, SDL_GetError);
SetCallback(exit, () => running = false);

running = true;

while (running)
{
SDL_PumpEvents();
}
}
}
}
52 changes: 52 additions & 0 deletions SDL3-CS.Tests/TrayTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using NUnit.Framework;

namespace SDL.Tests
{
[TestFixture]
public abstract unsafe class TrayTest
{
private SDL_Tray* tray;
protected SDL_TrayMenu* RootMenu { get; private set; }

[SetUp]
public void SetUp()
{
Assert.That(SDL3.SDL_Init(SDL_InitFlags.SDL_INIT_VIDEO), SDL3.SDL_GetError);
tray = SDL3.SDL_CreateTray(null, "Test tray");
Assert.That(tray != null, SDL3.SDL_GetError);
RootMenu = SDL3.SDL_CreateTrayMenu(tray);
Assert.That(RootMenu != null, SDL3.SDL_GetError);
}

protected static void SetCallback(SDL_TrayEntry* entry, Action callback)
{
var objectHandle = new ObjectHandle<Action>(callback, GCHandleType.Normal);
SDL3.SDL_SetTrayEntryCallback(entry, &nativeOnSelect, objectHandle.Handle); // this is leaking object handles, fine for tests
}

[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
private static void nativeOnSelect(IntPtr userdata, SDL_TrayEntry* entry)
{
var objectHandle = new ObjectHandle<Action>(userdata, true);

if (objectHandle.GetTarget(out var action))
action();
else
Assert.Fail("Accessing disposed object handle.");
}

[TearDown]
public void TearDown()
{
if (tray != null)
SDL3.SDL_DestroyTray(tray);

SDL3.SDL_Quit();
}
}
}
4 changes: 2 additions & 2 deletions SDL3-CS/SDL3/ClangSharp/SDL_audio.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public static unsafe partial class SDL3

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("bool")]
public static extern SDLBool SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream** streams, int num_streams);
public static extern SDLBool SDL_BindAudioStreams(SDL_AudioDeviceID devid, [NativeTypeName("SDL_AudioStream *const *")] SDL_AudioStream** streams, int num_streams);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("bool")]
public static extern SDLBool SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream* stream);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_UnbindAudioStreams(SDL_AudioStream** streams, int num_streams);
public static extern void SDL_UnbindAudioStreams([NativeTypeName("SDL_AudioStream *const *")] SDL_AudioStream** streams, int num_streams);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_UnbindAudioStream(SDL_AudioStream* stream);
Expand Down
10 changes: 5 additions & 5 deletions SDL3-CS/SDL3/ClangSharp/SDL_gamepad.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ public partial struct SDL_GamepadBinding
{
public SDL_GamepadBindingType input_type;

[NativeTypeName("__AnonymousRecord_SDL_gamepad_L247_C5")]
[NativeTypeName("__AnonymousRecord_SDL_gamepad_L259_C5")]
public _input_e__Union input;

public SDL_GamepadBindingType output_type;

[NativeTypeName("__AnonymousRecord_SDL_gamepad_L267_C5")]
[NativeTypeName("__AnonymousRecord_SDL_gamepad_L279_C5")]
public _output_e__Union output;

[StructLayout(LayoutKind.Explicit)]
Expand All @@ -132,11 +132,11 @@ public partial struct _input_e__Union
public int button;

[FieldOffset(0)]
[NativeTypeName("__AnonymousRecord_SDL_gamepad_L251_C9")]
[NativeTypeName("__AnonymousRecord_SDL_gamepad_L263_C9")]
public _axis_e__Struct axis;

[FieldOffset(0)]
[NativeTypeName("__AnonymousRecord_SDL_gamepad_L258_C9")]
[NativeTypeName("__AnonymousRecord_SDL_gamepad_L270_C9")]
public _hat_e__Struct hat;

public partial struct _axis_e__Struct
Expand All @@ -163,7 +163,7 @@ public partial struct _output_e__Union
public SDL_GamepadButton button;

[FieldOffset(0)]
[NativeTypeName("__AnonymousRecord_SDL_gamepad_L271_C9")]
[NativeTypeName("__AnonymousRecord_SDL_gamepad_L283_C9")]
public _axis_e__Struct axis;

public partial struct _axis_e__Struct
Expand Down
38 changes: 19 additions & 19 deletions SDL3-CS/SDL3/ClangSharp/SDL_gpu.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public enum SDL_GPUSwapchainComposition
SDL_GPU_SWAPCHAINCOMPOSITION_SDR,
SDL_GPU_SWAPCHAINCOMPOSITION_SDR_LINEAR,
SDL_GPU_SWAPCHAINCOMPOSITION_HDR_EXTENDED_LINEAR,
SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048,
SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2084,
}

public partial struct SDL_GPUViewport
Expand Down Expand Up @@ -1468,24 +1468,6 @@ public static unsafe partial class SDL3
[NativeTypeName("#define SDL_GPU_COLORCOMPONENT_A (1u << 3)")]
public const uint SDL_GPU_COLORCOMPONENT_A = (1U << 3);

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_R_FLOAT \"SDL.gpu.createtexture.d3d12.clear.r\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_R_FLOAT => "SDL.gpu.createtexture.d3d12.clear.r"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_G_FLOAT \"SDL.gpu.createtexture.d3d12.clear.g\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_G_FLOAT => "SDL.gpu.createtexture.d3d12.clear.g"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_B_FLOAT \"SDL.gpu.createtexture.d3d12.clear.b\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_B_FLOAT => "SDL.gpu.createtexture.d3d12.clear.b"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT \"SDL.gpu.createtexture.d3d12.clear.a\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT => "SDL.gpu.createtexture.d3d12.clear.a"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT \"SDL.gpu.createtexture.d3d12.clear.depth\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT => "SDL.gpu.createtexture.d3d12.clear.depth"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 \"SDL.gpu.createtexture.d3d12.clear.stencil\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 => "SDL.gpu.createtexture.d3d12.clear.stencil"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN \"SDL.gpu.device.create.debugmode\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN => "SDL.gpu.device.create.debugmode"u8;

Expand Down Expand Up @@ -1515,5 +1497,23 @@ public static unsafe partial class SDL3

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING \"SDL.gpu.device.create.d3d12.semantic\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING => "SDL.gpu.device.create.d3d12.semantic"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_R_FLOAT \"SDL.gpu.createtexture.d3d12.clear.r\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_R_FLOAT => "SDL.gpu.createtexture.d3d12.clear.r"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_G_FLOAT \"SDL.gpu.createtexture.d3d12.clear.g\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_G_FLOAT => "SDL.gpu.createtexture.d3d12.clear.g"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_B_FLOAT \"SDL.gpu.createtexture.d3d12.clear.b\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_B_FLOAT => "SDL.gpu.createtexture.d3d12.clear.b"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT \"SDL.gpu.createtexture.d3d12.clear.a\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT => "SDL.gpu.createtexture.d3d12.clear.a"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT \"SDL.gpu.createtexture.d3d12.clear.depth\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT => "SDL.gpu.createtexture.d3d12.clear.depth"u8;

[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 \"SDL.gpu.createtexture.d3d12.clear.stencil\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 => "SDL.gpu.createtexture.d3d12.clear.stencil"u8;
}
}
6 changes: 0 additions & 6 deletions SDL3-CS/SDL3/ClangSharp/SDL_hints.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,6 @@ public static unsafe partial class SDL3
[NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_MODE_CENTER \"SDL_MOUSE_RELATIVE_MODE_CENTER\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_RELATIVE_MODE_CENTER => "SDL_MOUSE_RELATIVE_MODE_CENTER"u8;

[NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_MODE_WARP \"SDL_MOUSE_RELATIVE_MODE_WARP\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_RELATIVE_MODE_WARP => "SDL_MOUSE_RELATIVE_MODE_WARP"u8;

[NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE \"SDL_MOUSE_RELATIVE_SPEED_SCALE\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE => "SDL_MOUSE_RELATIVE_SPEED_SCALE"u8;

Expand All @@ -499,9 +496,6 @@ public static unsafe partial class SDL3
[NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_CURSOR_VISIBLE \"SDL_MOUSE_RELATIVE_CURSOR_VISIBLE\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_RELATIVE_CURSOR_VISIBLE => "SDL_MOUSE_RELATIVE_CURSOR_VISIBLE"u8;

[NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_CLIP_INTERVAL \"SDL_MOUSE_RELATIVE_CLIP_INTERVAL\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_RELATIVE_CLIP_INTERVAL => "SDL_MOUSE_RELATIVE_CLIP_INTERVAL"u8;

[NativeTypeName("#define SDL_HINT_MOUSE_TOUCH_EVENTS \"SDL_MOUSE_TOUCH_EVENTS\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_TOUCH_EVENTS => "SDL_MOUSE_TOUCH_EVENTS"u8;

Expand Down
37 changes: 0 additions & 37 deletions SDL3-CS/SDL3/ClangSharp/SDL_main.GDK.g.cs
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
/*
<auto-generated/>
C# bindings for Simple DirectMedia Layer.
Original copyright notice of input files:

Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <[email protected]>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace SDL
{
public static partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern void SDL_GDKSuspendComplete();
}
}
3 changes: 3 additions & 0 deletions SDL3-CS/SDL3/ClangSharp/SDL_main.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ public static unsafe partial class SDL3

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_EnterAppMainCallbacks(int argc, [NativeTypeName("char *[]")] byte** argv, [NativeTypeName("SDL_AppInit_func")] delegate* unmanaged[Cdecl]<IntPtr*, int, byte**, SDL_AppResult> appinit, [NativeTypeName("SDL_AppIterate_func")] delegate* unmanaged[Cdecl]<IntPtr, SDL_AppResult> appiter, [NativeTypeName("SDL_AppEvent_func")] delegate* unmanaged[Cdecl]<IntPtr, SDL_Event*, SDL_AppResult> appevent, [NativeTypeName("SDL_AppQuit_func")] delegate* unmanaged[Cdecl]<IntPtr, SDL_AppResult, void> appquit);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_GDKSuspendComplete();
}
}
7 changes: 7 additions & 0 deletions SDL3-CS/SDL3/ClangSharp/SDL_render.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ public static unsafe partial class SDL3
[return: NativeTypeName("bool")]
public static extern SDLBool SDL_RenderDebugText(SDL_Renderer* renderer, float x, float y, [NativeTypeName("const char *")] byte* str);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("bool")]
public static extern SDLBool SDL_RenderDebugTextFormat(SDL_Renderer* renderer, float x, float y, [NativeTypeName("const char *")] byte* fmt, __arglist);

[NativeTypeName("#define SDL_SOFTWARE_RENDERER \"software\"")]
public static ReadOnlySpan<byte> SDL_SOFTWARE_RENDERER => "software"u8;

Expand Down Expand Up @@ -510,6 +514,9 @@ public static unsafe partial class SDL3
[NativeTypeName("#define SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER \"SDL.renderer.vulkan.swapchain_image_count\"")]
public static ReadOnlySpan<byte> SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER => "SDL.renderer.vulkan.swapchain_image_count"u8;

[NativeTypeName("#define SDL_PROP_RENDERER_GPU_DEVICE_POINTER \"SDL.renderer.gpu.device\"")]
public static ReadOnlySpan<byte> SDL_PROP_RENDERER_GPU_DEVICE_POINTER => "SDL.renderer.gpu.device"u8;

[NativeTypeName("#define SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER \"SDL.texture.create.colorspace\"")]
public static ReadOnlySpan<byte> SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER => "SDL.texture.create.colorspace"u8;

Expand Down
2 changes: 1 addition & 1 deletion SDL3-CS/SDL3/ClangSharp/SDL_stdinc.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public static unsafe partial class SDL3

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_strtok_r", ExactSpelling = true)]
[return: NativeTypeName("char *")]
public static extern byte* Unsafe_SDL_strtok_r([NativeTypeName("char *")] byte* s1, [NativeTypeName("const char *")] byte* s2, [NativeTypeName("char **")] byte** saveptr);
public static extern byte* Unsafe_SDL_strtok_r([NativeTypeName("char *")] byte* str, [NativeTypeName("const char *")] byte* delim, [NativeTypeName("char **")] byte** saveptr);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("size_t")]
Expand Down
11 changes: 11 additions & 0 deletions SDL3-CS/SDL3/ClangSharp/SDL_thread.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public enum SDL_ThreadPriority
SDL_THREAD_PRIORITY_TIME_CRITICAL,
}

public enum SDL_ThreadState
{
SDL_THREAD_UNKNOWN,
SDL_THREAD_ALIVE,
SDL_THREAD_DETACHED,
SDL_THREAD_COMPLETE,
}

public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
Expand All @@ -65,6 +73,9 @@ public static unsafe partial class SDL3
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_WaitThread(SDL_Thread* thread, int* status);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern SDL_ThreadState SDL_GetThreadState(SDL_Thread* thread);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_DetachThread(SDL_Thread* thread);

Expand Down
Loading