22#include " util/fastMath.h"
33#include " app.h"
44
5+ #include < SDL3/SDL_events.h>
6+
7+ bool resizingEventWatcher (void * data, SDL_Event* event) {
8+ if (event->type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
9+ SDL_Window* win = SDL_GetWindowFromID (event->window .windowID );
10+ if (((SdlWindow*)data)->getHandle () == win) {
11+ if (((SdlWindow*)data)->doRecieveEvent ) {
12+ ((SdlWindow*)data)->doRecieveEvent (*event);
13+ }
14+ }
15+ }
16+ return 0 ;
17+ }
18+
519SdlWindow::SdlWindow (const std::string& name, unsigned int width, unsigned int height) {
620 logInfo (" Creating SDL window..." );
721
@@ -11,6 +25,8 @@ SdlWindow::SdlWindow(const std::string& name, unsigned int width, unsigned int h
1125 throwFatalError (" SDL could not create window! SDL_Error: " + std::string (SDL_GetError ()));
1226 }
1327
28+ SDL_AddEventWatch (resizingEventWatcher, this );
29+
1430 int winW, winH, drawW, drawH;
1531 SDL_GetWindowSize (handle, &winW, &winH);
1632 SDL_GetWindowSizeInPixels (handle, &drawW, &drawH);
@@ -33,19 +49,19 @@ SdlWindow::~SdlWindow() {
3349}
3450
3551bool SdlWindow::recieveEvent (SDL_Event& event) {
36- if (doRecieveEvent) {
37- return doRecieveEvent (event);
38- }
39- if (isThisMyEvent (event)) {
40- if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
41- App::get ().deregisterWindow (this );
42- }
43- return true ;
52+ if (doRecieveEvent) {
53+ return doRecieveEvent (event);
54+ }
55+ if (isThisMyEvent (event)) {
56+ if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
57+ App::get ().deregisterWindow (this );
4458 }
45-
46- return false ;
59+ return true ;
4760 }
4861
62+ return false ;
63+ }
64+
4965bool SdlWindow::isThisMyEvent (const SDL_Event& event) {
5066 if (event.type == 2050 ) return true ; // the fuck is this? - jack quay jamison
5167 return SDL_GetWindowFromEvent (&event) == handle;
0 commit comments