module lib.sdl2.events

Code Map

module lib.sdl2.events;


enum SDL_RELEASED;
enum SDL_PRESSED;
enum SDL_FIRSTEVENT;
enum SDL_QUIT;
enum SDL_APP_TERMINATING;
enum SDL_APP_LOWMEMORY;
enum SDL_APP_WILLENTERBACKGROUND;
enum SDL_APP_DIDENTERBACKGROUND;
enum SDL_APP_WILLENTERFOREGROUND;
enum SDL_APP_DIDENTERFOREGROUND;
enum SDL_WINDOWEVENT;
enum SDL_SYSWMEVENT;
enum SDL_KEYDOWN;
enum SDL_KEYUP;
enum SDL_TEXTEDITING;
enum SDL_TEXTINPUT;
enum SDL_MOUSEMOTION;
enum SDL_MOUSEBUTTONDOWN;
enum SDL_MOUSEBUTTONUP;
enum SDL_MOUSEWHEEL;
enum SDL_JOYAXISMOTION;
enum SDL_JOYBALLMOTION;
enum SDL_JOYHATMOTION;
enum SDL_JOYBUTTONDOWN;
enum SDL_JOYBUTTONUP;
enum SDL_JOYDEVICEADDED;
enum SDL_JOYDEVICEREMOVED;
enum SDL_CONTROLLERAXISMOTION;
enum SDL_CONTROLLERBUTTONDOWN;
enum SDL_CONTROLLERBUTTONUP;
enum SDL_CONTROLLERDEVICEADDED;
enum SDL_CONTROLLERDEVICEREMOVED;
enum SDL_CONTROLLERDEVICEREMAPPED;
enum SDL_FINGERDOWN;
enum SDL_FINGERUP;
enum SDL_FINGERMOTION;
enum SDL_DOLLARGESTURE;
enum SDL_DOLLARRECORD;
enum SDL_MULTIGESTURE;
enum SDL_CLIPBOARDUPDATE;
enum SDL_DROPFILE;
enum SDL_DROPTEXT;
enum SDL_DROPBEGIN;
enum SDL_DROPCOMPLETE;
enum SDL_USEREVENT;
enum SDL_LASTEVENT;
enum SDL_TEXTEDITINGEVENT_TEXT_SIZE;
enum SDL_TEXTINPUTEVENT_TEXT_SIZE;
enum SDL_ADDEVENT;
enum SDL_PEEKEVENT;
enum SDL_GETEVENT;
enum SDL_QUERY;
enum SDL_IGNORE;
enum SDL_DISABLE;
enum SDL_ENABLE;

//! \brief The types of events that can be delivered.
alias SDL_EventType = u32;
alias SDL_eventaction = i32;
alias SDL_EventFilter = fn (void*, SDL_Event*) (i32);

//! \brief Fields shared by every event
struct SDL_CommonEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
}

//! \brief Window state change event data (event.window.*)
struct SDL_WindowEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	windowID: Uint32;
	event: Uint8;
	padding1: Uint8;
	padding2: Uint8;
	padding3: Uint8;
	data1: Sint32;
	data2: Sint32;
}

//! \brief Keyboard button event structure (event.key.*)
struct SDL_KeyboardEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	windowID: Uint32;
	state: Uint8;
	repeat: Uint8;
	padding2: Uint8;
	padding3: Uint8;
	keysym: SDL_Keysym;
}

//! \brief Keyboard text editing event structure (event.edit.*)
struct SDL_TextEditingEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	windowID: Uint32;
	text: char[32];
	start: Sint32;
	length: Sint32;
}

//! \brief Keyboard text input event structure (event.text.*)
struct SDL_TextInputEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	windowID: Uint32;
	text: char[32];
}

//! \brief Mouse motion event structure (event.motion.*)
struct SDL_MouseMotionEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	windowID: Uint32;
	which: Uint32;
	state: Uint32;
	x: Sint32;
	y: Sint32;
	xrel: Sint32;
	yrel: Sint32;
}

//! \brief Mouse button event structure (event.button.*)
struct SDL_MouseButtonEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	windowID: Uint32;
	which: Uint32;
	button: Uint8;
	state: Uint8;
	padding1: Uint8;
	padding2: Uint8;
	x: Sint32;
	y: Sint32;
}

//! \brief Mouse wheel event structure (event.wheel.*)
struct SDL_MouseWheelEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	windowID: Uint32;
	which: Uint32;
	x: Sint32;
	y: Sint32;
}

//! \brief Joystick axis motion event structure (event.jaxis.*)
struct SDL_JoyAxisEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	which: SDL_JoystickID;
	axis: Uint8;
	padding1: Uint8;
	padding2: Uint8;
	padding3: Uint8;
	value: Sint16;
	padding4: Uint16;
}

//! \brief Joystick trackball motion event structure (event.jball.*)
struct SDL_JoyBallEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	which: SDL_JoystickID;
	ball: Uint8;
	padding1: Uint8;
	padding2: Uint8;
	padding3: Uint8;
	xrel: Sint16;
	yrel: Sint16;
}

//! \brief Joystick hat position change event structure (event.jhat.*)
struct SDL_JoyHatEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	which: SDL_JoystickID;
	hat: Uint8;
	value: Uint8;
	padding1: Uint8;
	padding2: Uint8;
}

//! \brief Joystick button event structure (event.jbutton.*)
struct SDL_JoyButtonEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	which: SDL_JoystickID;
	button: Uint8;
	state: Uint8;
	padding1: Uint8;
	padding2: Uint8;
}

//! \brief Joystick device event structure (event.jdevice.*)
struct SDL_JoyDeviceEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	which: Sint32;
}

//! \brief Game controller axis motion event structure (event.caxis.*)
struct SDL_ControllerAxisEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	which: SDL_JoystickID;
	axis: Uint8;
	padding1: Uint8;
	padding2: Uint8;
	padding3: Uint8;
	value: Sint16;
	padding4: Uint16;
}

//! \brief Game controller button event structure (event.cbutton.*)
struct SDL_ControllerButtonEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	which: SDL_JoystickID;
	button: Uint8;
	state: Uint8;
	padding1: Uint8;
	padding2: Uint8;
}

//! \brief Controller device event structure (event.cdevice.*)
struct SDL_ControllerDeviceEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	which: Sint32;
}

//! \brief Touch finger event structure (event.tfinger.*)
struct SDL_TouchFingerEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	touchId: SDL_TouchID;
	fingerId: SDL_FingerID;
	x: f32;
	y: f32;
	dx: f32;
	dy: f32;
	pressure: f32;
}

//! \brief Multiple Finger Gesture Event (event.mgesture.*)
struct SDL_MultiGestureEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	touchId: SDL_TouchID;
	dTheta: f32;
	dDist: f32;
	x: f32;
	y: f32;
	numFingers: Uint16;
	padding: Uint16;
}

//! \brief Dollar Gesture Event (event.dgesture.*)
struct SDL_DollarGestureEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	touchId: SDL_TouchID;
	gestureId: SDL_GestureID;
	numFingers: Uint32;
	error: f32;
	x: f32;
	y: f32;
}

//! \brief An event used to request a file open by the system (event.drop.
//! *) This event is disabled by default, you can enable it with
//! SDL_EventState() \note If you enable this event, you must free the
//! filename in the event.
struct SDL_DropEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	file: char*;
	windowID: Uint32;
}

//! \brief The "quit requested" event
struct SDL_QuitEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
}

//! \brief OS Specific event
struct SDL_OSEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
}

//! \brief A user-defined event type (event.user.*)
struct SDL_UserEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	windowID: Uint32;
	code: Sint32;
	data1: void*;
	data2: void*;
}

struct SDL_SysWMmsg
{
}

//! \brief A video driver dependent system event (event.syswm.*) This event
//! is disabled by default, you can enable it with SDL_EventState()
struct SDL_SysWMEvent
{
public:
	type: Uint32;
	timestamp: Uint32;
	msg: SDL_SysWMmsg*;
}

//! \brief General event structure
union SDL_Event
{
public:
	type: Uint32;
	common: SDL_CommonEvent;
	window: SDL_WindowEvent;
	key: SDL_KeyboardEvent;
	edit: SDL_TextEditingEvent;
	text: SDL_TextInputEvent;
	motion: SDL_MouseMotionEvent;
	button: SDL_MouseButtonEvent;
	wheel: SDL_MouseWheelEvent;
	jaxis: SDL_JoyAxisEvent;
	jball: SDL_JoyBallEvent;
	jhat: SDL_JoyHatEvent;
	jbutton: SDL_JoyButtonEvent;
	jdevice: SDL_JoyDeviceEvent;
	caxis: SDL_ControllerAxisEvent;
	cbutton: SDL_ControllerButtonEvent;
	cdevice: SDL_ControllerDeviceEvent;
	quit: SDL_QuitEvent;
	user: SDL_UserEvent;
	syswm: SDL_SysWMEvent;
	tfinger: SDL_TouchFingerEvent;
	mgesture: SDL_MultiGestureEvent;
	dgesture: SDL_DollarGestureEvent;
	drop: SDL_DropEvent;
	padding: Uint8[56];
}

//! Pumps the event loop, gathering events from the input devices.
fn SDL_PumpEvents();
//! Checks the event queue for messages and optionally returns them.
fn SDL_PeepEvents(events: SDL_Event*, numevents: i32, action: SDL_eventaction, minType: Uint32, maxType: Uint32) i32;
//! Checks to see if certain event types are in the event queue.
fn SDL_HasEvent(type: Uint32) SDL_bool;
fn SDL_HasEvents(minType: Uint32, maxType: Uint32) SDL_bool;
//! This function clears events from the event queue
fn SDL_FlushEvent(type: Uint32);
fn SDL_FlushEvents(minType: Uint32, maxType: Uint32);
//! \brief Polls for currently pending events.
fn SDL_PollEvent(event: SDL_Event*) i32;
//! \brief Waits indefinitely for the next available event.
fn SDL_WaitEvent(event: SDL_Event*) i32;
//! \brief Waits until the specified timeout (in milliseconds) for the
//! next available event.
fn SDL_WaitEventTimeout(event: SDL_Event*, timeout: i32) i32;
//! \brief Add an event to the event queue.
fn SDL_PushEvent(event: SDL_Event*) i32;
//! Sets up a filter to process all events before they change internal
//! state and are posted to the internal event queue.
fn SDL_SetEventFilter(filter: SDL_EventFilter, userdata: void*);
//! Return the current event filter - can be used to "chain" filters. If
//! there is no event filter set, this function returns SDL_FALSE.
fn SDL_GetEventFilter(filter: SDL_EventFilter*, userdata: void**) SDL_bool;
//! Add a function which is called when an event is added to the queue.
fn SDL_AddEventWatch(filter: SDL_EventFilter, userdata: void*);
//! Remove an event watch function added with SDL_AddEventWatch()
fn SDL_DelEventWatch(filter: SDL_EventFilter, userdata: void*);
//! Run the filter function on the current event queue, removing any events
//! for which the filter returns 0.
fn SDL_FilterEvents(filter: SDL_EventFilter, userdata: void*);
//! This function allows you to set the state of processing certain
//! events.
fn SDL_EventState(type: Uint32, state: i32) Uint8;
fn SDL_GetEventState(type: Uint32) Uint8 { }
//! This function allocates a set of user-defined events, and returns the
//! beginning event number for that set of events.
fn SDL_RegisterEvents(numevents: i32) Uint32;
alias SDL_EventType

\brief The types of events that can be delivered.

struct SDL_CommonEvent

\brief Fields shared by every event

struct SDL_WindowEvent

\brief Window state change event data (event.window.*)

struct SDL_KeyboardEvent

\brief Keyboard button event structure (event.key.*)

struct SDL_TextEditingEvent

\brief Keyboard text editing event structure (event.edit.*)

struct SDL_TextInputEvent

\brief Keyboard text input event structure (event.text.*)

struct SDL_MouseMotionEvent

\brief Mouse motion event structure (event.motion.*)

struct SDL_MouseButtonEvent

\brief Mouse button event structure (event.button.*)

struct SDL_MouseWheelEvent

\brief Mouse wheel event structure (event.wheel.*)

struct SDL_JoyAxisEvent

\brief Joystick axis motion event structure (event.jaxis.*)

struct SDL_JoyBallEvent

\brief Joystick trackball motion event structure (event.jball.*)

struct SDL_JoyHatEvent

\brief Joystick hat position change event structure (event.jhat.*)

struct SDL_JoyButtonEvent

\brief Joystick button event structure (event.jbutton.*)

struct SDL_JoyDeviceEvent

\brief Joystick device event structure (event.jdevice.*)

struct SDL_ControllerAxisEvent

\brief Game controller axis motion event structure (event.caxis.*)

struct SDL_ControllerButtonEvent

\brief Game controller button event structure (event.cbutton.*)

struct SDL_ControllerDeviceEvent

\brief Controller device event structure (event.cdevice.*)

struct SDL_TouchFingerEvent

\brief Touch finger event structure (event.tfinger.*)

struct SDL_MultiGestureEvent

\brief Multiple Finger Gesture Event (event.mgesture.*)

struct SDL_DollarGestureEvent

\brief Dollar Gesture Event (event.dgesture.*)

struct SDL_DropEvent

\brief An event used to request a file open by the system (event.drop.*) This event is disabled by default, you can enable it with SDL_EventState() \note If you enable this event, you must free the filename in the event.

struct SDL_QuitEvent

\brief The "quit requested" event

struct SDL_OSEvent

\brief OS Specific event

struct SDL_UserEvent

\brief A user-defined event type (event.user.*)

struct SDL_SysWMEvent

\brief A video driver dependent system event (event.syswm.*) This event is disabled by default, you can enable it with SDL_EventState()

\note If you want to use this event, you should include SDL_syswm.h.

union SDL_Event

\brief General event structure

fn SDL_PumpEvents()

Pumps the event loop, gathering events from the input devices.

This function updates the event queue and internal input device state.

This should only be run in the thread that sets the video mode.

fn SDL_PeepEvents(events: SDL_Event*, numevents: i32, action: SDL_eventaction, minType: Uint32, maxType: Uint32) i32

Checks the event queue for messages and optionally returns them.

If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to the back of the event queue.

If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front of the event queue, within the specified minimum and maximum type, will be returned and will not be removed from the queue.

If \c action is ::SDL_GETEVENT, up to \c numevents events at the front of the event queue, within the specified minimum and maximum type, will be returned and will be removed from the queue.

\return The number of events actually stored, or -1 if there was an error.

This function is thread-safe.

fn SDL_HasEvent(type: Uint32) SDL_bool

Checks to see if certain event types are in the event queue.

fn SDL_FlushEvent(type: Uint32)

This function clears events from the event queue

fn SDL_PollEvent(event: SDL_Event*) i32

\brief Polls for currently pending events.

\return 1 if there are any pending events, or 0 if there are none available.

\param event If not NULL, the next event is removed from the queue and stored in that area.

fn SDL_WaitEvent(event: SDL_Event*) i32

\brief Waits indefinitely for the next available event.

\return 1, or 0 if there was an error while waiting for events.

\param event If not NULL, the next event is removed from the queue and stored in that area.

fn SDL_WaitEventTimeout(event: SDL_Event*, timeout: i32) i32

\brief Waits until the specified timeout (in milliseconds) for the next available event.

\return 1, or 0 if there was an error while waiting for events.

\param event If not NULL, the next event is removed from the queue and stored in that area. \param timeout The timeout (in milliseconds) to wait for next event.

fn SDL_PushEvent(event: SDL_Event*) i32

\brief Add an event to the event queue.

\return 1 on success, 0 if the event was filtered, or -1 if the event queue was full or there was some other error.

fn SDL_SetEventFilter(filter: SDL_EventFilter, userdata: void*)

Sets up a filter to process all events before they change internal state and are posted to the internal event queue.

The filter is prototyped as: \code int SDL_EventFilter(void *userdata, SDL_Event * event); \endcode

If the filter returns 1, then the event will be added to the internal queue. If it returns 0, then the event will be dropped from the queue, but the internal state will still be updated. This allows selective filtering of dynamically arriving events.

\warning Be very careful of what you do in the event filter function, as it may run in a different thread!

There is one caveat when dealing with the ::SDL_QuitEvent event type. The event filter is only called when the window manager desires to close the application window. If the event filter returns 1, then the window will be closed, otherwise the window will remain open if possible.

If the quit event is generated by an interrupt signal, it will bypass the internal queue and be delivered to the application at the next event poll.

fn SDL_GetEventFilter(filter: SDL_EventFilter*, userdata: void**) SDL_bool

Return the current event filter - can be used to "chain" filters. If there is no event filter set, this function returns SDL_FALSE.

fn SDL_AddEventWatch(filter: SDL_EventFilter, userdata: void*)

Add a function which is called when an event is added to the queue.

fn SDL_DelEventWatch(filter: SDL_EventFilter, userdata: void*)

Remove an event watch function added with SDL_AddEventWatch()

fn SDL_FilterEvents(filter: SDL_EventFilter, userdata: void*)

Run the filter function on the current event queue, removing any events for which the filter returns 0.

fn SDL_EventState(type: Uint32, state: i32) Uint8

This function allows you to set the state of processing certain events.

  • If \c state is set to ::SDL_IGNORE, that event will be automatically dropped from the event queue and will not event be filtered.
  • If \c state is set to ::SDL_ENABLE, that event will be processed normally.
  • If \c state is set to ::SDL_QUERY, SDL_EventState() will return the current processing state of the specified event.
fn SDL_RegisterEvents(numevents: i32) Uint32

This function allocates a set of user-defined events, and returns the beginning event number for that set of events.

If there aren't enough user-defined events left, this function returns (Uint32)-1