Reputation: 1918
I'm using the SDL2 C# wrapper through FNA and I need to be able to detect when the window resizes, min/maximizes, etc. From what I've found it seems I should use the SDL_EventFilter
delegate and SDL_WindowEventID
enum. I've tried attaching such an event using SDL_AddEventWatch
and SDL_SetEventFilter
methods, but I'm not getting any events related to window management.
How do I use the SDL window events in the C# wrapper correctly?
Upvotes: 3
Views: 1022
Reputation: 23506
In your event polling loop add a case for SDL_WINDOWEVENT
:
SDL_Event event;
while (SDL_PollEvent(out sdlEvent) == 1) {
switch(sdlEvent.type) {
case SDL_EventType.SDL_WINDOWEVENT:
HandleWindowEvent(sdlEvent.window);
break;
// other events here ...
}
Thread.Sleep(1);
}
And then you could have a method handling those events:
HandleWindowEvents(SDL_WindowEvent wEvent) {
switch(wEvent.windowEvent) {
case SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED:
Console.WriteLine($"Window resized: {wEvent.data1}x{wEvent.data2}");
break;
// more window events here ...
}
}
All window events are outlined in the Wiki.
Upvotes: 2