Commit 3a7d58dd authored by Sam Lantinga's avatar Sam Lantinga

Fixed bug 1336 - Added a timestamp on all SDL events

Gueniffey 2011-11-23 04:11:31 PST

The attached simple patch adds a timestamp to all SDL events. It is useful to
dismiss old events and add UI responsiveness (my application does some
extensive tasks that creates a delay in the event queue handling. With this
patch, I can deal only with the most recent events.
parent a76f024e
...@@ -132,6 +132,7 @@ typedef enum ...@@ -132,6 +132,7 @@ typedef enum
typedef struct SDL_WindowEvent typedef struct SDL_WindowEvent
{ {
Uint32 type; /**< ::SDL_WINDOWEVENT */ Uint32 type; /**< ::SDL_WINDOWEVENT */
Uint32 timestamp;
Uint32 windowID; /**< The associated window */ Uint32 windowID; /**< The associated window */
Uint8 event; /**< ::SDL_WindowEventID */ Uint8 event; /**< ::SDL_WindowEventID */
Uint8 padding1; Uint8 padding1;
...@@ -147,6 +148,7 @@ typedef struct SDL_WindowEvent ...@@ -147,6 +148,7 @@ typedef struct SDL_WindowEvent
typedef struct SDL_KeyboardEvent typedef struct SDL_KeyboardEvent
{ {
Uint32 type; /**< ::SDL_KEYDOWN or ::SDL_KEYUP */ Uint32 type; /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
Uint32 timestamp;
Uint32 windowID; /**< The window with keyboard focus, if any */ Uint32 windowID; /**< The window with keyboard focus, if any */
Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
Uint8 repeat; /**< Non-zero if this is a key repeat */ Uint8 repeat; /**< Non-zero if this is a key repeat */
...@@ -162,6 +164,7 @@ typedef struct SDL_KeyboardEvent ...@@ -162,6 +164,7 @@ typedef struct SDL_KeyboardEvent
typedef struct SDL_TextEditingEvent typedef struct SDL_TextEditingEvent
{ {
Uint32 type; /**< ::SDL_TEXTEDITING */ Uint32 type; /**< ::SDL_TEXTEDITING */
Uint32 timestamp;
Uint32 windowID; /**< The window with keyboard focus, if any */ Uint32 windowID; /**< The window with keyboard focus, if any */
char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */ char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */
int start; /**< The start cursor of selected editing text */ int start; /**< The start cursor of selected editing text */
...@@ -176,6 +179,7 @@ typedef struct SDL_TextEditingEvent ...@@ -176,6 +179,7 @@ typedef struct SDL_TextEditingEvent
typedef struct SDL_TextInputEvent typedef struct SDL_TextInputEvent
{ {
Uint32 type; /**< ::SDL_TEXTINPUT */ Uint32 type; /**< ::SDL_TEXTINPUT */
Uint32 timestamp;
Uint32 windowID; /**< The window with keyboard focus, if any */ Uint32 windowID; /**< The window with keyboard focus, if any */
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */
} SDL_TextInputEvent; } SDL_TextInputEvent;
...@@ -186,6 +190,7 @@ typedef struct SDL_TextInputEvent ...@@ -186,6 +190,7 @@ typedef struct SDL_TextInputEvent
typedef struct SDL_MouseMotionEvent typedef struct SDL_MouseMotionEvent
{ {
Uint32 type; /**< ::SDL_MOUSEMOTION */ Uint32 type; /**< ::SDL_MOUSEMOTION */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
Uint8 state; /**< The current button state */ Uint8 state; /**< The current button state */
Uint8 padding1; Uint8 padding1;
...@@ -203,6 +208,7 @@ typedef struct SDL_MouseMotionEvent ...@@ -203,6 +208,7 @@ typedef struct SDL_MouseMotionEvent
typedef struct SDL_MouseButtonEvent typedef struct SDL_MouseButtonEvent
{ {
Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */ Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
Uint8 button; /**< The mouse button index */ Uint8 button; /**< The mouse button index */
Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
...@@ -218,6 +224,7 @@ typedef struct SDL_MouseButtonEvent ...@@ -218,6 +224,7 @@ typedef struct SDL_MouseButtonEvent
typedef struct SDL_MouseWheelEvent typedef struct SDL_MouseWheelEvent
{ {
Uint32 type; /**< ::SDL_MOUSEWHEEL */ Uint32 type; /**< ::SDL_MOUSEWHEEL */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
int x; /**< The amount scrolled horizontally */ int x; /**< The amount scrolled horizontally */
int y; /**< The amount scrolled vertically */ int y; /**< The amount scrolled vertically */
...@@ -229,6 +236,7 @@ typedef struct SDL_MouseWheelEvent ...@@ -229,6 +236,7 @@ typedef struct SDL_MouseWheelEvent
typedef struct SDL_JoyAxisEvent typedef struct SDL_JoyAxisEvent
{ {
Uint32 type; /**< ::SDL_JOYAXISMOTION */ Uint32 type; /**< ::SDL_JOYAXISMOTION */
Uint32 timestamp;
Uint8 which; /**< The joystick device index */ Uint8 which; /**< The joystick device index */
Uint8 axis; /**< The joystick axis index */ Uint8 axis; /**< The joystick axis index */
Uint8 padding1; Uint8 padding1;
...@@ -242,6 +250,7 @@ typedef struct SDL_JoyAxisEvent ...@@ -242,6 +250,7 @@ typedef struct SDL_JoyAxisEvent
typedef struct SDL_JoyBallEvent typedef struct SDL_JoyBallEvent
{ {
Uint32 type; /**< ::SDL_JOYBALLMOTION */ Uint32 type; /**< ::SDL_JOYBALLMOTION */
Uint32 timestamp;
Uint8 which; /**< The joystick device index */ Uint8 which; /**< The joystick device index */
Uint8 ball; /**< The joystick trackball index */ Uint8 ball; /**< The joystick trackball index */
Uint8 padding1; Uint8 padding1;
...@@ -256,6 +265,7 @@ typedef struct SDL_JoyBallEvent ...@@ -256,6 +265,7 @@ typedef struct SDL_JoyBallEvent
typedef struct SDL_JoyHatEvent typedef struct SDL_JoyHatEvent
{ {
Uint32 type; /**< ::SDL_JOYHATMOTION */ Uint32 type; /**< ::SDL_JOYHATMOTION */
Uint32 timestamp;
Uint8 which; /**< The joystick device index */ Uint8 which; /**< The joystick device index */
Uint8 hat; /**< The joystick hat index */ Uint8 hat; /**< The joystick hat index */
Uint8 value; /**< The hat position value. Uint8 value; /**< The hat position value.
...@@ -274,6 +284,7 @@ typedef struct SDL_JoyHatEvent ...@@ -274,6 +284,7 @@ typedef struct SDL_JoyHatEvent
typedef struct SDL_JoyButtonEvent typedef struct SDL_JoyButtonEvent
{ {
Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */ Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
Uint32 timestamp;
Uint8 which; /**< The joystick device index */ Uint8 which; /**< The joystick device index */
Uint8 button; /**< The joystick button index */ Uint8 button; /**< The joystick button index */
Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
...@@ -288,6 +299,7 @@ typedef struct SDL_TouchFingerEvent ...@@ -288,6 +299,7 @@ typedef struct SDL_TouchFingerEvent
{ {
Uint32 type; /**< ::SDL_FINGERMOTION OR Uint32 type; /**< ::SDL_FINGERMOTION OR
SDL_FINGERDOWN OR SDL_FINGERUP*/ SDL_FINGERDOWN OR SDL_FINGERUP*/
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
SDL_TouchID touchId; /**< The touch device id */ SDL_TouchID touchId; /**< The touch device id */
SDL_FingerID fingerId; SDL_FingerID fingerId;
...@@ -309,6 +321,7 @@ typedef struct SDL_TouchFingerEvent ...@@ -309,6 +321,7 @@ typedef struct SDL_TouchFingerEvent
typedef struct SDL_TouchButtonEvent typedef struct SDL_TouchButtonEvent
{ {
Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */ Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
SDL_TouchID touchId; /**< The touch device index */ SDL_TouchID touchId; /**< The touch device index */
Uint8 state; /**< The current button state */ Uint8 state; /**< The current button state */
...@@ -324,6 +337,7 @@ typedef struct SDL_TouchButtonEvent ...@@ -324,6 +337,7 @@ typedef struct SDL_TouchButtonEvent
typedef struct SDL_MultiGestureEvent typedef struct SDL_MultiGestureEvent
{ {
Uint32 type; /**< ::SDL_MULTIGESTURE */ Uint32 type; /**< ::SDL_MULTIGESTURE */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
SDL_TouchID touchId; /**< The touch device index */ SDL_TouchID touchId; /**< The touch device index */
float dTheta; float dTheta;
...@@ -338,6 +352,7 @@ typedef struct SDL_MultiGestureEvent ...@@ -338,6 +352,7 @@ typedef struct SDL_MultiGestureEvent
typedef struct SDL_DollarGestureEvent typedef struct SDL_DollarGestureEvent
{ {
Uint32 type; /**< ::SDL_DOLLARGESTURE */ Uint32 type; /**< ::SDL_DOLLARGESTURE */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
SDL_TouchID touchId; /**< The touch device index */ SDL_TouchID touchId; /**< The touch device index */
SDL_GestureID gestureId; SDL_GestureID gestureId;
...@@ -359,6 +374,7 @@ typedef struct SDL_DollarGestureEvent ...@@ -359,6 +374,7 @@ typedef struct SDL_DollarGestureEvent
typedef struct SDL_DropEvent typedef struct SDL_DropEvent
{ {
Uint32 type; /**< ::SDL_DROPFILE */ Uint32 type; /**< ::SDL_DROPFILE */
Uint32 timestamp;
char *file; /**< The file name, which should be freed with SDL_free() */ char *file; /**< The file name, which should be freed with SDL_free() */
} SDL_DropEvent; } SDL_DropEvent;
...@@ -369,6 +385,7 @@ typedef struct SDL_DropEvent ...@@ -369,6 +385,7 @@ typedef struct SDL_DropEvent
typedef struct SDL_QuitEvent typedef struct SDL_QuitEvent
{ {
Uint32 type; /**< ::SDL_QUIT */ Uint32 type; /**< ::SDL_QUIT */
Uint32 timestamp;
} SDL_QuitEvent; } SDL_QuitEvent;
...@@ -378,6 +395,7 @@ typedef struct SDL_QuitEvent ...@@ -378,6 +395,7 @@ typedef struct SDL_QuitEvent
typedef struct SDL_UserEvent typedef struct SDL_UserEvent
{ {
Uint32 type; /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */ Uint32 type; /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */
Uint32 timestamp;
Uint32 windowID; /**< The associated window if any */ Uint32 windowID; /**< The associated window if any */
int code; /**< User defined event code */ int code; /**< User defined event code */
void *data1; /**< User defined data pointer */ void *data1; /**< User defined data pointer */
...@@ -397,6 +415,7 @@ typedef struct SDL_SysWMmsg SDL_SysWMmsg; ...@@ -397,6 +415,7 @@ typedef struct SDL_SysWMmsg SDL_SysWMmsg;
typedef struct SDL_SysWMEvent typedef struct SDL_SysWMEvent
{ {
Uint32 type; /**< ::SDL_SYSWMEVENT */ Uint32 type; /**< ::SDL_SYSWMEVENT */
Uint32 timestamp;
SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */ SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */
} SDL_SysWMEvent; } SDL_SysWMEvent;
...@@ -413,6 +432,7 @@ typedef struct SDL_SysWMEvent ...@@ -413,6 +432,7 @@ typedef struct SDL_SysWMEvent
typedef struct SDL_ActiveEvent typedef struct SDL_ActiveEvent
{ {
Uint32 type; Uint32 type;
Uint32 timestamp;
Uint8 gain; Uint8 gain;
Uint8 state; Uint8 state;
} SDL_ActiveEvent; } SDL_ActiveEvent;
...@@ -420,6 +440,7 @@ typedef struct SDL_ActiveEvent ...@@ -420,6 +440,7 @@ typedef struct SDL_ActiveEvent
typedef struct SDL_ResizeEvent typedef struct SDL_ResizeEvent
{ {
Uint32 type; Uint32 type;
Uint32 timestamp;
int w; int w;
int h; int h;
} SDL_ResizeEvent; } SDL_ResizeEvent;
......
...@@ -358,7 +358,7 @@ int ...@@ -358,7 +358,7 @@ int
SDL_PushEvent(SDL_Event * event) SDL_PushEvent(SDL_Event * event)
{ {
SDL_EventWatcher *curr; SDL_EventWatcher *curr;
event->window.timestamp = SDL_GetTicks();
if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) { if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) {
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment