From 248be33550961ffa88130f8815616cf61701ff1e Mon Sep 17 00:00:00 2001 From: Michael Bishop Date: Fri, 18 Oct 2013 11:04:08 -0400 Subject: Added preliminary support for the SDL2 touch api. Missing items: 1. Timestamps 2. TouchID (the Device ID) As inline with the SDL spec, we will pass a touch ID of `SDL_TOUCH_MOUSEID` for touch events that are simulated by the mouse so games can rely solely on touch events if they like. Includes the SDL2 Copyright notice on the headers that contain SDL2 content. Includes a fix to SDL_PeepEvents. --- system/include/SDL/COPYING | 5 +++ system/include/SDL/SDL_events.h | 70 +++++++++++++++++++------------ system/include/SDL/SDL_touch.h | 92 ++++++++++++++--------------------------- 3 files changed, 78 insertions(+), 89 deletions(-) (limited to 'system') diff --git a/system/include/SDL/COPYING b/system/include/SDL/COPYING index 15639581..71cc7e42 100644 --- a/system/include/SDL/COPYING +++ b/system/include/SDL/COPYING @@ -17,3 +17,8 @@ freely, subject to the following restrictions: 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. + +--- + + Portions of these headers taken from SDL2 (where noted) + Copyright (C) 1997-2013 Sam Lantinga diff --git a/system/include/SDL/SDL_events.h b/system/include/SDL/SDL_events.h index 8be00ceb..183ea4b2 100644 --- a/system/include/SDL/SDL_events.h +++ b/system/include/SDL/SDL_events.h @@ -2,6 +2,9 @@ Simple DirectMedia Layer Copyright (C) 1997-2011 Sam Lantinga + Portions of these headers taken from SDL2 (where noted) + Copyright (C) 1997-2013 Sam Lantinga + This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. @@ -182,33 +185,43 @@ typedef struct SDL_TextInputEvent /** * \brief Mouse motion event structure (event.motion.*) */ +/*================================= IMPORTANT ================================ + The version of SDL_MouseMotionEvent that comes in these (emscripten) + headers is taken from the finalized version of SDL2 + ============================================================================*/ + typedef struct SDL_MouseMotionEvent { Uint32 type; /**< ::SDL_MOUSEMOTION */ + Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ - Uint8 state; /**< The current button state */ - Uint8 padding1; - Uint8 padding2; - Uint8 padding3; - int x; /**< X coordinate, relative to window */ - int y; /**< Y coordinate, relative to window */ - int xrel; /**< The relative motion in the X direction */ - int yrel; /**< The relative motion in the Y direction */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ + Uint32 state; /**< The current button state */ + Sint32 x; /**< X coordinate, relative to window */ + Sint32 y; /**< Y coordinate, relative to window */ + Sint32 xrel; /**< The relative motion in the X direction */ + Sint32 yrel; /**< The relative motion in the Y direction */ } SDL_MouseMotionEvent; /** * \brief Mouse button event structure (event.button.*) */ +/*================================= IMPORTANT ================================ + The version of SDL_MouseButtonEvent that comes in these (emscripten) + headers is taken from the finalized version of SDL2 + ============================================================================*/ typedef struct SDL_MouseButtonEvent { Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */ + Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ Uint8 button; /**< The mouse button index */ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */ Uint8 padding1; Uint8 padding2; - int x; /**< X coordinate, relative to window */ - int y; /**< Y coordinate, relative to window */ + Sint32 x; /**< X coordinate, relative to window */ + Sint32 y; /**< Y coordinate, relative to window */ } SDL_MouseButtonEvent; /** @@ -217,9 +230,11 @@ typedef struct SDL_MouseButtonEvent typedef struct SDL_MouseWheelEvent { Uint32 type; /**< ::SDL_MOUSEWHEEL */ + Uint32 timestamp; Uint32 windowID; /**< The window with mouse focus, if any */ - int x; /**< The amount scrolled horizontally */ - int y; /**< The amount scrolled vertically */ + Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ + Sint32 x; /**< The amount scrolled horizontally */ + Sint32 y; /**< The amount scrolled vertically */ } SDL_MouseWheelEvent; /** @@ -281,24 +296,25 @@ typedef struct SDL_JoyButtonEvent /** - * \brief Touch finger motion/finger event structure (event.tmotion.*) + * \brief Touch finger motion/finger event structure (event.tfinger.*) */ + +/*================================= IMPORTANT ================================ + The version of SDL_TouchFingerEvent that comes in these (emscripten) + headers is taken from the finalized version of SDL2 + ============================================================================*/ + typedef struct SDL_TouchFingerEvent { - Uint32 type; /**< ::SDL_FINGERMOTION OR - SDL_FINGERDOWN OR SDL_FINGERUP*/ - Uint32 windowID; /**< The window with mouse focus, if any */ - SDL_TouchID touchId; /**< The touch device id */ + Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */ + Uint32 timestamp; + SDL_TouchID touchId; /**< The touch device id */ SDL_FingerID fingerId; - Uint8 state; /**< The current button state */ - Uint8 padding1; - Uint8 padding2; - Uint8 padding3; - Uint16 x; - Uint16 y; - Sint16 dx; - Sint16 dy; - Uint16 pressure; + float x; /**< Normalized in the range 0...1 */ + float y; /**< Normalized in the range 0...1 */ + float dx; /**< Normalized in the range 0...1 */ + float dy; /**< Normalized in the range 0...1 */ + float pressure; /**< Normalized in the range 0...1 */ } SDL_TouchFingerEvent; @@ -434,7 +450,7 @@ typedef union SDL_Event SDL_QuitEvent quit; /**< Quit request event data */ SDL_UserEvent user; /**< Custom event data */ SDL_SysWMEvent syswm; /**< System dependent window event data */ - SDL_TouchFingerEvent tfinger; /**< Touch finger event data */ + SDL_TouchFingerEvent tfinger; /**< SDL2 Touch finger event data */ SDL_TouchButtonEvent tbutton; /**< Touch button event data */ SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */ SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */ diff --git a/system/include/SDL/SDL_touch.h b/system/include/SDL/SDL_touch.h index 587efcbf..fe238f10 100644 --- a/system/include/SDL/SDL_touch.h +++ b/system/include/SDL/SDL_touch.h @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer - Copyright (C) 1997-2011 Sam Lantinga + Copyright (C) 1997-2013 Sam Lantinga This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -19,9 +19,15 @@ 3. This notice may not be removed or altered from any source distribution. */ +/* + ================================= IMPORTANT ================================ + This header taken from SDL2 + ============================================================================ +*/ + /** * \file SDL_touch.h - * + * * Include file for SDL touch event handling. */ @@ -35,90 +41,52 @@ #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus -/* *INDENT-OFF* */ extern "C" { -/* *INDENT-ON* */ #endif - typedef Sint64 SDL_TouchID; typedef Sint64 SDL_FingerID; +typedef struct SDL_Finger +{ + SDL_FingerID id; + float x; + float y; + float pressure; +} SDL_Finger; -struct SDL_Finger { - SDL_FingerID id; - Uint16 x; - Uint16 y; - Uint16 pressure; - Uint16 xdelta; - Uint16 ydelta; - Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */ - SDL_bool down; -}; - -typedef struct SDL_Touch SDL_Touch; -typedef struct SDL_Finger SDL_Finger; - - -struct SDL_Touch { - - /* Free the touch when it's time */ - void (*FreeTouch) (SDL_Touch * touch); - - /* data common for tablets */ - float pressure_max, pressure_min; - float x_max,x_min; - float y_max,y_min; - Uint16 xres,yres,pressureres; - float native_xres,native_yres,native_pressureres; - float tilt; /* for future use */ - float rotation; /* for future use */ - - /* Data common to all touch */ - SDL_TouchID id; - SDL_Window *focus; - - char *name; - Uint8 buttonstate; - SDL_bool relative_mode; - SDL_bool flush_motion; - - int num_fingers; - int max_fingers; - SDL_Finger** fingers; - - void *driverdata; -}; - +/* Used as the device ID for mouse events simulated with touch input */ +#define SDL_TOUCH_MOUSEID ((Uint32)-1) /* Function prototypes */ /** - * \brief Get the touch object at the given id. - * - * + * \brief Get the number of registered touch devices. */ - extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id); +extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices(void); +/** + * \brief Get the touch ID with the given index, or 0 if the index is invalid. + */ +extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index); +/** + * \brief Get the number of active fingers for a given touch device. + */ +extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID); /** - * \brief Get the finger object of the given touch, at the given id. - * - * + * \brief Get the finger object of the given touch, with the given index. */ - extern - DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id); +extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index); /* Ends C function definitions when using C++ */ #ifdef __cplusplus -/* *INDENT-OFF* */ } -/* *INDENT-ON* */ #endif #include "close_code.h" -#endif /* _SDL_mouse_h */ +#endif /* _SDL_touch_h */ /* vi: set ts=4 sw=4 expandtab: */ -- cgit v1.2.3-18-g5258