Path: blob/main/system/include/SDL/SDL_events.h
6169 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2011 Sam Lantinga <[email protected]>34Portions of these headers taken from SDL2 (where noted)5Copyright (C) 1997-2013 Sam Lantinga <[email protected]>67This software is provided 'as-is', without any express or implied8warranty. In no event will the authors be held liable for any damages9arising from the use of this software.1011Permission is granted to anyone to use this software for any purpose,12including commercial applications, and to alter it and redistribute it13freely, subject to the following restrictions:14151. The origin of this software must not be misrepresented; you must not16claim that you wrote the original software. If you use this software17in a product, an acknowledgment in the product documentation would be18appreciated but is not required.192. Altered source versions must be plainly marked as such, and must not be20misrepresented as being the original software.213. This notice may not be removed or altered from any source distribution.22*/2324/**25* \file SDL_events.h26*27* Include file for SDL event handling.28*/2930#ifndef _SDL_events_h31#define _SDL_events_h3233#include "SDL_stdinc.h"34#include "SDL_error.h"35#include "SDL_video.h"36#include "SDL_keyboard.h"37#include "SDL_mouse.h"38#include "SDL_joystick.h"39#include "SDL_quit.h"40#include "SDL_gesture.h"41#include "SDL_touch.h"4243#include "begin_code.h"44/* Set up for C function definitions, even when using C++ */45#ifdef __cplusplus46/* *INDENT-OFF* */47extern "C" {48/* *INDENT-ON* */49#endif5051/* General keyboard/mouse state definitions */52#define SDL_RELEASED 053#define SDL_PRESSED 15455/**56* \brief The types of events that can be delivered.57*/58typedef enum59{60SDL_NOEVENT = 0,61SDL_FIRSTEVENT = 0, /**< Unused (do not remove) */6263/* Application events */64SDL_QUIT = 0x100, /**< User-requested quit */6566/* Window events */67SDL_WINDOWEVENT = 0x200, /**< Window state change */68SDL_SYSWMEVENT, /**< System specific event */6970/* Keyboard events */71SDL_KEYDOWN = 0x300, /**< Key pressed */72SDL_KEYUP, /**< Key released */73SDL_TEXTEDITING, /**< Keyboard text editing (composition) */74SDL_TEXTINPUT, /**< Keyboard text input */7576/* Mouse events */77SDL_MOUSEMOTION = 0x400, /**< Mouse moved */78SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */79SDL_MOUSEBUTTONUP, /**< Mouse button released */80SDL_MOUSEWHEEL, /**< Mouse wheel motion */8182/* Tablet or multiple mice input device events */83SDL_INPUTMOTION = 0x500, /**< Input moved */84SDL_INPUTBUTTONDOWN, /**< Input button pressed */85SDL_INPUTBUTTONUP, /**< Input button released */86SDL_INPUTWHEEL, /**< Input wheel motion */87SDL_INPUTPROXIMITYIN, /**< Input pen entered proximity */88SDL_INPUTPROXIMITYOUT, /**< Input pen left proximity */8990/* Joystick events */91SDL_JOYAXISMOTION = 0x600, /**< Joystick axis motion */92SDL_JOYBALLMOTION, /**< Joystick trackball motion */93SDL_JOYHATMOTION, /**< Joystick hat position change */94SDL_JOYBUTTONDOWN, /**< Joystick button pressed */95SDL_JOYBUTTONUP, /**< Joystick button released */9697/* Touch events */98SDL_FINGERDOWN = 0x700,99SDL_FINGERUP,100SDL_FINGERMOTION,101SDL_TOUCHBUTTONDOWN,102SDL_TOUCHBUTTONUP,103104/* Gesture events */105SDL_DOLLARGESTURE = 0x800,106SDL_DOLLARRECORD,107SDL_MULTIGESTURE,108109/* Clipboard events */110111SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */112113/* Obsolete events */114SDL_EVENT_COMPAT1 = 0x7000, /**< SDL 1.2 events for compatibility */115SDL_EVENT_COMPAT2,116SDL_EVENT_COMPAT3,117118119/** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,120* and should be allocated with SDL_RegisterEvents()121*/122SDL_USEREVENT = 0x8000,123124/**125* This last event is only for bounding internal arrays126*/127SDL_LASTEVENT = 0xFFFF128} SDL_EventType;129130/**131* \brief Window state change event data (event.window.*)132*/133typedef struct SDL_WindowEvent134{135Uint32 type; /**< ::SDL_WINDOWEVENT */136Uint32 windowID; /**< The associated window */137Uint8 event; /**< ::SDL_WindowEventID */138Uint8 padding1;139Uint8 padding2;140Uint8 padding3;141int data1; /**< event dependent data */142int data2; /**< event dependent data */143} SDL_WindowEvent;144145/**146* \brief Keyboard button event structure (event.key.*)147*/148typedef struct SDL_KeyboardEvent149{150Uint32 type; /**< ::SDL_KEYDOWN or ::SDL_KEYUP */151Uint32 windowID; /**< The window with keyboard focus, if any */152Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */153Uint8 repeat; /**< Non-zero if this is a key repeat */154Uint8 padding2;155Uint8 padding3;156SDL_Keysym keysym; /**< The key that was pressed or released */157} SDL_KeyboardEvent;158159#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)160/**161* \brief Keyboard text editing event structure (event.edit.*)162*/163typedef struct SDL_TextEditingEvent164{165Uint32 type; /**< ::SDL_TEXTEDITING */166Uint32 windowID; /**< The window with keyboard focus, if any */167char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */168int start; /**< The start cursor of selected editing text */169int length; /**< The length of selected editing text */170} SDL_TextEditingEvent;171172173#define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)174/**175* \brief Keyboard text input event structure (event.text.*)176*/177typedef struct SDL_TextInputEvent178{179Uint32 type; /**< ::SDL_TEXTINPUT */180Uint32 windowID; /**< The window with keyboard focus, if any */181char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */182} SDL_TextInputEvent;183184/**185* \brief Mouse motion event structure (event.motion.*)186*/187/*================================= IMPORTANT ================================188The version of SDL_MouseMotionEvent that comes in these (emscripten)189headers is taken from the finalized version of SDL2190============================================================================*/191192typedef struct SDL_MouseMotionEvent193{194Uint32 type; /**< ::SDL_MOUSEMOTION */195Uint32 timestamp;196Uint32 windowID; /**< The window with mouse focus, if any */197Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */198Uint32 state; /**< The current button state */199Sint32 x; /**< X coordinate, relative to window */200Sint32 y; /**< Y coordinate, relative to window */201Sint32 xrel; /**< The relative motion in the X direction */202Sint32 yrel; /**< The relative motion in the Y direction */203} SDL_MouseMotionEvent;204205/**206* \brief Mouse button event structure (event.button.*)207*/208/*================================= IMPORTANT ================================209The version of SDL_MouseButtonEvent that comes in these (emscripten)210headers is taken from the finalized version of SDL2211============================================================================*/212typedef struct SDL_MouseButtonEvent213{214Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */215Uint32 timestamp;216Uint32 windowID; /**< The window with mouse focus, if any */217Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */218Uint8 button; /**< The mouse button index */219Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */220Uint8 padding1;221Uint8 padding2;222Sint32 x; /**< X coordinate, relative to window */223Sint32 y; /**< Y coordinate, relative to window */224} SDL_MouseButtonEvent;225226/**227* \brief Mouse wheel event structure (event.wheel.*)228*/229typedef struct SDL_MouseWheelEvent230{231Uint32 type; /**< ::SDL_MOUSEWHEEL */232Uint32 timestamp;233Uint32 windowID; /**< The window with mouse focus, if any */234Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */235Sint32 x; /**< The amount scrolled horizontally */236Sint32 y; /**< The amount scrolled vertically */237} SDL_MouseWheelEvent;238239/**240* \brief Joystick axis motion event structure (event.jaxis.*)241*/242typedef struct SDL_JoyAxisEvent243{244Uint32 type; /**< ::SDL_JOYAXISMOTION */245Uint8 which; /**< The joystick device index */246Uint8 axis; /**< The joystick axis index */247Uint8 padding1;248Uint8 padding2;249int value; /**< The axis value (range: -32768 to 32767) */250} SDL_JoyAxisEvent;251252/**253* \brief Joystick trackball motion event structure (event.jball.*)254*/255typedef struct SDL_JoyBallEvent256{257Uint32 type; /**< ::SDL_JOYBALLMOTION */258Uint8 which; /**< The joystick device index */259Uint8 ball; /**< The joystick trackball index */260Uint8 padding1;261Uint8 padding2;262int xrel; /**< The relative motion in the X direction */263int yrel; /**< The relative motion in the Y direction */264} SDL_JoyBallEvent;265266/**267* \brief Joystick hat position change event structure (event.jhat.*)268*/269typedef struct SDL_JoyHatEvent270{271Uint32 type; /**< ::SDL_JOYHATMOTION */272Uint8 which; /**< The joystick device index */273Uint8 hat; /**< The joystick hat index */274Uint8 value; /**< The hat position value.275* \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP276* \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT277* \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN278*279* Note that zero means the POV is centered.280*/281Uint8 padding1;282} SDL_JoyHatEvent;283284/**285* \brief Joystick button event structure (event.jbutton.*)286*/287typedef struct SDL_JoyButtonEvent288{289Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */290Uint8 which; /**< The joystick device index */291Uint8 button; /**< The joystick button index */292Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */293Uint8 padding1;294} SDL_JoyButtonEvent;295296297/**298* \brief Touch finger motion/finger event structure (event.tfinger.*)299*/300301/*================================= IMPORTANT ================================302The version of SDL_TouchFingerEvent that comes in these (emscripten)303headers is taken from the finalized version of SDL2304============================================================================*/305306typedef struct SDL_TouchFingerEvent307{308Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */309Uint32 timestamp;310SDL_TouchID touchId; /**< The touch device id */311SDL_FingerID fingerId;312float x; /**< Normalized in the range 0...1 */313float y; /**< Normalized in the range 0...1 */314float dx; /**< Normalized in the range 0...1 */315float dy; /**< Normalized in the range 0...1 */316float pressure; /**< Normalized in the range 0...1 */317} SDL_TouchFingerEvent;318319320/**321* \brief Touch finger motion/finger event structure (event.tmotion.*)322*/323typedef struct SDL_TouchButtonEvent324{325Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */326Uint32 windowID; /**< The window with mouse focus, if any */327SDL_TouchID touchId; /**< The touch device index */328Uint8 state; /**< The current button state */329Uint8 button; /**< The button changing state */330Uint8 padding1;331Uint8 padding2;332} SDL_TouchButtonEvent;333334335/**336* \brief Multiple Finger Gesture Event (event.mgesture.*)337*/338typedef struct SDL_MultiGestureEvent339{340Uint32 type; /**< ::SDL_MULTIGESTURE */341Uint32 windowID; /**< The window with mouse focus, if any */342SDL_TouchID touchId; /**< The touch device index */343float dTheta;344float dDist;345float x; //currently 0...1. Change to screen coords?346float y;347Uint16 numFingers;348Uint16 padding;349} SDL_MultiGestureEvent;350351/* (event.dgesture.*) */352typedef struct SDL_DollarGestureEvent353{354Uint32 type; /**< ::SDL_DOLLARGESTURE */355Uint32 windowID; /**< The window with mouse focus, if any */356SDL_TouchID touchId; /**< The touch device index */357SDL_GestureID gestureId;358Uint32 numFingers;359float error;360/*361//TODO: Enable to give location?362float x; //currently 0...1. Change to screen coords?363float y;364*/365} SDL_DollarGestureEvent;366367368/**369* \brief The "quit requested" event370*/371typedef struct SDL_QuitEvent372{373Uint32 type; /**< ::SDL_QUIT */374} SDL_QuitEvent;375376377/**378* \brief A user-defined event type (event.user.*)379*/380typedef struct SDL_UserEvent381{382Uint32 type; /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */383Uint32 windowID; /**< The associated window if any */384int code; /**< User defined event code */385void *data1; /**< User defined data pointer */386void *data2; /**< User defined data pointer */387} SDL_UserEvent;388389390struct SDL_SysWMmsg;391typedef struct SDL_SysWMmsg SDL_SysWMmsg;392393/**394* \brief A video driver dependent system event (event.syswm.*)395*396* \note If you want to use this event, you should include SDL_syswm.h.397*/398typedef struct SDL_SysWMEvent399{400Uint32 type; /**< ::SDL_SYSWMEVENT */401SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */402} SDL_SysWMEvent;403404#ifndef SDL_NO_COMPAT405/**406* \addtogroup Compatibility407*/408/*@{*/409410/**411* \name Typedefs for backwards compatibility412*/413/*@{*/414typedef struct SDL_ActiveEvent415{416Uint32 type;417Uint8 gain;418Uint8 state;419} SDL_ActiveEvent;420421typedef struct SDL_ResizeEvent422{423Uint32 type;424int w;425int h;426} SDL_ResizeEvent;427/*@}*/428429/*@}*//*Compatibility*/430#endif431432/**433* \brief General event structure434*/435typedef union SDL_Event436{437Uint32 type; /**< Event type, shared with all events */438SDL_WindowEvent window; /**< Window event data */439SDL_KeyboardEvent key; /**< Keyboard event data */440SDL_TextEditingEvent edit; /**< Text editing event data */441SDL_TextInputEvent text; /**< Text input event data */442SDL_MouseMotionEvent motion; /**< Mouse motion event data */443SDL_MouseButtonEvent button; /**< Mouse button event data */444SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */445SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */446SDL_JoyBallEvent jball; /**< Joystick ball event data */447SDL_JoyHatEvent jhat; /**< Joystick hat event data */448SDL_JoyButtonEvent jbutton; /**< Joystick button event data */449SDL_QuitEvent quit; /**< Quit request event data */450SDL_UserEvent user; /**< Custom event data */451SDL_SysWMEvent syswm; /**< System dependent window event data */452SDL_TouchFingerEvent tfinger; /**< SDL2 Touch finger event data */453SDL_TouchButtonEvent tbutton; /**< Touch button event data */454SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */455SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */456457/** Temporarily here for backwards compatibility */458/*@{*/459#ifndef SDL_NO_COMPAT460SDL_ActiveEvent active;461SDL_ResizeEvent resize;462#endif463/*@}*/464} SDL_Event;465466467/* Function prototypes */468469/**470* Pumps the event loop, gathering events from the input devices.471*472* This function updates the event queue and internal input device state.473*474* This should only be run in the thread that sets the video mode.475*/476extern DECLSPEC void SDLCALL SDL_PumpEvents(void);477478/*@{*/479typedef enum480{481SDL_ADDEVENT,482SDL_PEEKEVENT,483SDL_GETEVENT484} SDL_eventaction;485486/**487* Checks the event queue for messages and optionally returns them.488*489* If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to490* the back of the event queue.491*492* If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front493* of the event queue, within the specified minimum and maximum type,494* will be returned and will not be removed from the queue.495*496* If \c action is ::SDL_GETEVENT, up to \c numevents events at the front497* of the event queue, within the specified minimum and maximum type,498* will be returned and will be removed from the queue.499*500* \return The number of events actually stored, or -1 if there was an error.501*502* This function is thread-safe.503*/504extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,505SDL_eventaction action,506Uint32 minType, Uint32 maxType);507/*@}*/508509/**510* Checks to see if certain event types are in the event queue.511*/512extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);513extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);514515/**516* This function clears events from the event queue517*/518extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);519extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);520521/**522* \brief Polls for currently pending events.523*524* \return 1 if there are any pending events, or 0 if there are none available.525*526* \param event If not NULL, the next event is removed from the queue and527* stored in that area.528*/529extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);530531/**532* \brief Waits indefinitely for the next available event.533*534* \return 1, or 0 if there was an error while waiting for events.535*536* \param event If not NULL, the next event is removed from the queue and537* stored in that area.538*/539extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);540541/**542* \brief Waits until the specified timeout (in milliseconds) for the next543* available event.544*545* \return 1, or 0 if there was an error while waiting for events.546*547* \param event If not NULL, the next event is removed from the queue and548* stored in that area.549*/550extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,551int timeout);552553/**554* \brief Add an event to the event queue.555*556* \return 1 on success, 0 if the event was filtered, or -1 if the event queue557* was full or there was some other error.558*/559extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);560561typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);562563/**564* Sets up a filter to process all events before they change internal state and565* are posted to the internal event queue.566*567* The filter is protypted as:568* \code569* int SDL_EventFilter(void *userdata, SDL_Event * event);570* \endcode571*572* If the filter returns 1, then the event will be added to the internal queue.573* If it returns 0, then the event will be dropped from the queue, but the574* internal state will still be updated. This allows selective filtering of575* dynamically arriving events.576*577* \warning Be very careful of what you do in the event filter function, as578* it may run in a different thread!579*580* There is one caveat when dealing with the ::SDL_QUITEVENT event type. The581* event filter is only called when the window manager desires to close the582* application window. If the event filter returns 1, then the window will583* be closed, otherwise the window will remain open if possible.584*585* If the quit event is generated by an interrupt signal, it will bypass the586* internal queue and be delivered to the application at the next event poll.587*/588extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,589void *userdata);590591/**592* Return the current event filter - can be used to "chain" filters.593* If there is no event filter set, this function returns SDL_FALSE.594*/595extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,596void **userdata);597598/**599* Add a function which is called when an event is added to the queue.600*/601extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,602void *userdata);603604/**605* Remove an event watch function added with SDL_AddEventWatch()606*/607extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,608void *userdata);609610/**611* Run the filter function on the current event queue, removing any612* events for which the filter returns 0.613*/614extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,615void *userdata);616617/**618* An Emscripten-specific extension to SDL: Some browser APIs require that they are called from within an event handler function.619* Allow recording a callback that will be called for each received event. This is used in place of SDL_PollEvent.620* Your application will be called whenever there are events available.621*/622extern DECLSPEC void SDLCALL emscripten_SDL_SetEventHandler(SDL_EventFilter handler,623void *userdata);624625/*@{*/626#define SDL_QUERY -1627#define SDL_IGNORE 0628#define SDL_DISABLE 0629#define SDL_ENABLE 1630631/**632* This function allows you to set the state of processing certain events.633* - If \c state is set to ::SDL_IGNORE, that event will be automatically634* dropped from the event queue and will not event be filtered.635* - If \c state is set to ::SDL_ENABLE, that event will be processed636* normally.637* - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the638* current processing state of the specified event.639*/640extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);641/*@}*/642#define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)643644/**645* This function allocates a set of user-defined events, and returns646* the beginning event number for that set of events.647*648* If there aren't enough user-defined events left, this function649* returns (Uint32)-1650*/651extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);652653/* Ends C function definitions when using C++ */654#ifdef __cplusplus655/* *INDENT-OFF* */656}657/* *INDENT-ON* */658#endif659#include "close_code.h"660661#endif /* _SDL_events_h */662663/* vi: set ts=4 sw=4 expandtab: */664665666