From: Alexis Laferrière Date: Mon, 10 Apr 2017 14:55:18 +0000 (-0400) Subject: sdl2: intro window events X-Git-Url: http://nitlanguage.org sdl2: intro window events Signed-off-by: Alexis Laferrière --- diff --git a/lib/sdl2/events.nit b/lib/sdl2/events.nit index 6506dfd..2ca18aa 100644 --- a/lib/sdl2/events.nit +++ b/lib/sdl2/events.nit @@ -50,6 +50,7 @@ extern class SDLEventBuffer `{SDL_Event *`} if is_mouse_wheel then return to_mouse_wheel if is_keydown then return to_keydown if is_keyup then return to_keyup + if is_window then return to_window return to_event_direct end @@ -111,6 +112,14 @@ extern class SDLEventBuffer `{SDL_Event *`} # Require: `is_keyup` fun to_keyup: SDLKeyboardUpEvent `{ return self; `} + # Is this a window event? + fun is_window: Bool `{ return self->type == SDL_WINDOWEVENT; `} + + # Get a reference to data at `self` as a `SDLWindowEvent` + # + # Require: `is_window` + fun to_window: SDLWindowEvent `{ return self; `} + # TODO other SDL events: # # SDL_CommonEvent common @@ -277,3 +286,23 @@ extern class SDLKeysym `{ SDL_Keysym * `} fun mod: Int `{ return self->mod; `} # TODO related masks end + +# Window event +extern class SDLWindowEvent + super SDLEvent + + # Window identifier + fun id: Int `{ return self->window.windowID; `} + + # Is `self` a resized event? + fun is_resized: Bool `{ return self->window.event == SDL_WINDOWEVENT_RESIZED; `} + + # Is `self` a size changed event? + fun is_size_changed: Bool `{ return self->window.event == SDL_WINDOWEVENT_SIZE_CHANGED; `} + + # `data1` field, depends on the event kind + fun data1: Int `{ return self->window.data1; `} + + # `data2` field, depends on the event kind + fun data2: Int `{ return self->window.data2; `} +end