+ private fun poll_event: nullable SDLInputEvent import SDLKeyEvent, SDLMouseButtonEvent, SDLMouseMotionEvent, SDLQuitEvent, NativeString.to_s, SDLMouseButtonEvent.as(nullable SDLInputEvent), SDLMouseMotionEvent.as(nullable SDLInputEvent), SDLKeyEvent.as(nullable SDLInputEvent), SDLQuitEvent.as(nullable SDLInputEvent) `{
+ SDL_Event event;
+
+ SDL_PumpEvents();
+
+ if (SDL_PollEvent(&event))
+ {
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ case SDL_KEYUP:
+ #ifdef DEBUG
+ printf("The \"%s\" key was pressed!\n",
+ SDL_GetKeyName(event.key.keysym.sym));
+ #endif
+
+ return SDLKeyEvent_as_nullable_SDLInputEvent(
+ new_SDLKeyEvent(NativeString_to_s(
+ SDL_GetKeyName(event.key.keysym.sym)),
+ event.type==SDL_KEYDOWN));
+
+ case SDL_MOUSEMOTION:
+ #ifdef DEBUG
+ printf("Mouse moved by %d,%d to (%d,%d)\n",
+ event.motion.xrel, event.motion.yrel,
+ event.motion.x, event.motion.y);
+ #endif
+
+ return SDLMouseMotionEvent_as_nullable_SDLInputEvent(
+ new_SDLMouseMotionEvent(event.motion.x, event.motion.y,
+ event.motion.xrel, event.motion.yrel, SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)));
+
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ #ifdef DEBUG
+ printf("Mouse button \"%d\" pressed at (%d,%d)\n",
+ event.button.button, event.button.x, event.button.y);
+ #endif
+ return SDLMouseButtonEvent_as_nullable_SDLInputEvent(
+ new_SDLMouseButtonEvent(event.button.x, event.button.y,
+ event.button.button, event.type == SDL_MOUSEBUTTONDOWN));
+
+ case SDL_QUIT:
+ #ifdef DEBUG
+ printf("Quit event\n");
+ #endif
+ return SDLQuitEvent_as_nullable_SDLInputEvent(new_SDLQuitEvent());
+ }
+ }
+
+ return null_SDLInputEvent();
+ `}
+
+ # Set the position of the cursor to x,y
+ fun warp_mouse(x,y: Int) `{ SDL_WarpMouse(x, y); `}
+
+ # Show or hide the cursor
+ fun show_cursor=(val: Bool) `{ SDL_ShowCursor(val? SDL_ENABLE: SDL_DISABLE); `}
+
+ # Is the cursor visible?
+ fun show_cursor: Bool `{ return SDL_ShowCursor(SDL_QUERY); `}
+
+ # Grab or release the input
+ fun grab_input=(val: Bool) `{ SDL_WM_GrabInput(val? SDL_GRAB_ON: SDL_GRAB_OFF); `}
+
+ # Is the input grabbed?
+ fun grab_input: Bool `{ return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON; `}
+
+ # Are instances of `SDLMouseMotionEvent` ignored?
+ fun ignore_mouse_motion_events: Bool `{
+ return SDL_EventState(SDL_MOUSEMOTION, SDL_QUERY);
+ `}
+
+ # Do not raise instances of `SDLMouseMotionEvent` if `val`
+ fun ignore_mouse_motion_events=(val: Bool) `{
+ SDL_EventState(SDL_MOUSEMOTION, val? SDL_IGNORE: SDL_ENABLE);
+ `}
+
+ # Does `self` has the mouse focus?
+ fun mouse_focus: Bool `{ return SDL_GetAppState() & SDL_APPMOUSEFOCUS; `}
+
+ # Does `self` has the input focus?
+ fun input_focus: Bool `{ return SDL_GetAppState() & SDL_APPINPUTFOCUS; `}