1 module polyplex.core.events; 2 import polyplex.core.input; 3 import derelict.sdl2.sdl; 4 import std.stdio; 5 import sev.event; 6 7 public class GameResizeEventArgs : EventArgs { 8 public void* SDLEvent; 9 } 10 11 public class PPEvents { 12 public static SDL_Event[] Events; 13 14 public static PumpEvents() { 15 // Then poll everything and push it to our own event queue 16 Events.length = 0; 17 SDL_Event ev; 18 while(SDL_PollEvent(&ev)) { 19 Events ~= ev; 20 } 21 } 22 } 23 24 public class GameEventSystem { 25 private bool lastHandled; 26 27 public Event OnWindowSizeChanged = new Event(); 28 public Event OnExitRequested = new Event(); 29 30 this() { 31 } 32 33 /** 34 <BACKEND> Update essential things like handling game exit and resizing. 35 */ 36 public void Update() { 37 38 foreach(SDL_Event ev; PPEvents.Events) { 39 lastHandled = true; 40 if (ev.type == SDL_QUIT) { 41 OnExitRequested(cast(void*)this); 42 } 43 if (ev.type == SDL_WINDOWEVENT) { 44 if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED || ev.window.event == SDL_WINDOWEVENT_RESIZED) { 45 GameResizeEventArgs args = new GameResizeEventArgs(); 46 args.SDLEvent = cast(void*)ev.window.event; 47 OnWindowSizeChanged(cast(void*)this, args); 48 } 49 } 50 51 //Update last handled. 52 lastHandled = false; 53 } 54 } 55 }