An instance of this class should be used to call poll_event
and to_event
.
sdl2 :: SDLEventBuffer :: defaultinit
sdl2 :: SDLEventBuffer :: malloc
Allocate memory for a newSDLEventBuffer
sdl2 :: SDLEventBuffer :: to_event
Get a reference to the data atself
as a precise SDLEvent
sdl2 :: SDLEventBuffer :: to_keydown
Get a reference to data atself
as a SDLKeyboardDownEvent
sdl2 :: SDLEventBuffer :: to_keyup
Get a reference to data atself
as a SDLKeyboardUpEvent
sdl2 :: SDLEventBuffer :: to_mouse_motion
Get a reference to data atself
as a SDLMouseMotionEvent
sdl2 :: SDLEventBuffer :: to_mouse_wheel
Get a reference to data atself
as a SDLMouseWheelEvent
sdl2 :: SDLEventBuffer :: to_quit
Get a reference to data atself
as a SDLQuitEvent
sdl2 :: SDLEventBuffer :: to_window
Get a reference to data atself
as a SDLWindowEvent
sdl2 $ SDLEventBuffer :: SELF
Type of this instance, automatically specialized in every classcore :: Pointer :: address_is_null
Is the address behind this Object at NULL?core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
sdl2 :: SDLEventBuffer :: defaultinit
core :: Pointer :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
sdl2 :: SDLEventBuffer :: malloc
Allocate memory for a newSDLEventBuffer
core :: Object :: output_class_name
Display class name on stdout (debug only).sdl2 :: SDLEventBuffer :: to_event
Get a reference to the data atself
as a precise SDLEvent
sdl2 :: SDLEventBuffer :: to_keydown
Get a reference to data atself
as a SDLKeyboardDownEvent
sdl2 :: SDLEventBuffer :: to_keyup
Get a reference to data atself
as a SDLKeyboardUpEvent
sdl2 :: SDLEventBuffer :: to_mouse_motion
Get a reference to data atself
as a SDLMouseMotionEvent
sdl2 :: SDLEventBuffer :: to_mouse_wheel
Get a reference to data atself
as a SDLMouseWheelEvent
sdl2 :: SDLEventBuffer :: to_quit
Get a reference to data atself
as a SDLQuitEvent
sdl2 :: SDLEventBuffer :: to_window
Get a reference to data atself
as a SDLWindowEvent
# Temporary buffer for an SDL 2 event exposing the pseudo-class hierarchy metadata
#
# An instance of this class should be used to call `poll_event` and `to_event`.
extern class SDLEventBuffer `{SDL_Event *`}
# Allocate memory for a new `SDLEventBuffer`
new malloc `{ return malloc(sizeof(SDL_Event)); `}
# Poll and event into `self`
#
# Returns `true` if an event was available.
fun poll_event: Bool `{ return SDL_PollEvent(self); `}
# Get a reference to the data at `self` as a precise `SDLEvent`
#
# Returns `null` if the event is unknown.
#
# Note: The returned `SDLEvent` is just a different Nit instance pointing to the same data.
# A call to `poll_event` will invalidate any instances returned previously by `to_event`.
fun to_event: SDLEvent
do
if is_quit then return to_quit
if is_mouse_motion then return to_mouse_motion
if is_mouse_button_down then return to_mouse_button_down
if is_mouse_button_up then return to_mouse_button_up
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
private fun to_event_direct: SDLEvent `{ return self; `}
# Is this a quit event?
fun is_quit: Bool `{ return self->type == SDL_QUIT; `}
# Get a reference to data at `self` as a `SDLQuitEvent`
#
# Require: `is_quit`
fun to_quit: SDLQuitEvent `{ return self; `}
# Is this a mouse motion event?
fun is_mouse_motion: Bool `{ return self->type == SDL_MOUSEMOTION; `}
# Get a reference to data at `self` as a `SDLMouseMotionEvent`
#
# Require: `is_mouse_motion`
fun to_mouse_motion: SDLMouseMotionEvent `{ return self; `}
# Is this a mouse button down event?
fun is_mouse_button_down: Bool `{ return self->type == SDL_MOUSEBUTTONDOWN; `}
# Get a reference to data at `self` as a `SDLMouseButtonDownEvent`
#
# Require: `is_mouse_button_down`
fun to_mouse_button_down: SDLMouseButtonDownEvent `{ return self; `}
# Is this a mouse button up event?
fun is_mouse_button_up: Bool `{ return self->type == SDL_MOUSEBUTTONUP; `}
# Get a reference to data at `self` as a `SDLMouseButtonUpEvent`
#
# Require: `is_mouse_button_up`
fun to_mouse_button_up: SDLMouseButtonUpEvent `{ return self; `}
# Is this a mouse wheel event?
fun is_mouse_wheel: Bool `{ return self->type == SDL_MOUSEWHEEL; `}
# Get a reference to data at `self` as a `SDLMouseWheelEvent`
#
# Require: `is_mouse_wheel`
fun to_mouse_wheel: SDLMouseWheelEvent `{ return self; `}
# Is this a key presse event?
fun is_keydown: Bool `{ return self->type == SDL_KEYDOWN; `}
# Get a reference to data at `self` as a `SDLKeyboardDownEvent`
#
# Require: `is_keydown`
fun to_keydown: SDLKeyboardDownEvent `{ return self; `}
# Is this a key release event?
fun is_keyup: Bool `{ return self->type == SDL_KEYUP; `}
# Get a reference to data at `self` as a `SDLKeyboardUpEvent`
#
# 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
# SDL_WindowEvent window
# SDL_TextEditingEvent edit
# SDL_TextInputEvent text
# SDL_JoyAxisEvent jaxis
# SDL_JoyBallEvent jball
# SDL_JoyHatEvent jhat;
# SDL_JoyButtonEvent jbutton
# SDL_JoyDeviceEvent jdevice
# SDL_ControllerAxisEvent caxis
# SDL_ControllerButtonEvent cbutton
# SDL_ControllerDeviceEvent cdevice
# SDL_UserEvent user
# SDL_SysWMEvent syswm
# SDL_TouchFingerEvent tfinger
# SDL_MultiGestureEvent mgesture
# SDL_DollarGestureEvent dgesture
# SDL_DropEvent drop
end
lib/sdl2/events.nit:26,1--143,3