From 5a5fbc0c770078552cad4c3f886e0fb2a36314f2 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 28 Jul 2022 16:06:50 -0700 Subject: [PATCH] handle OS window size changes --- src/Game.cs | 12 ++++++++++++ src/Window.cs | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Game.cs b/src/Game.cs index 173b8297..9cdb67a6 100644 --- a/src/Game.cs +++ b/src/Game.cs @@ -213,10 +213,22 @@ namespace MoonWorks case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: HandleControllerRemoved(_event); break; + + case SDL.SDL_EventType.SDL_WINDOWEVENT: + HandleWindowEvent(_event); + break; } } } + private void HandleWindowEvent(SDL.SDL_Event evt) + { + if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED) + { + Window.SizeChanged((uint) evt.window.data1, (uint) evt.window.data2); + } + } + private void HandleTextInput(SDL.SDL_Event evt) { // Based on the SDL2# LPUtf8StrMarshaler diff --git a/src/Window.cs b/src/Window.cs index c5176e5f..b81cb029 100644 --- a/src/Window.cs +++ b/src/Window.cs @@ -1,4 +1,4 @@ -using System; +using System; using SDL2; namespace MoonWorks @@ -81,6 +81,12 @@ namespace MoonWorks Height = height; } + internal void SizeChanged(uint width, uint height) + { + Width = width; + Height = height; + } + protected virtual void Dispose(bool disposing) { if (!IsDisposed)