Updated touch API

* Normalized touch coordinates as floats in the 0...1 range
* Removed unused touchpad concepts from the API
* Added API functions to get active touch devices and current finger state
This commit is contained in:
Sam Lantinga 2013-03-03 01:01:33 -08:00
parent 71ea3033fa
commit bb0752e573
15 changed files with 356 additions and 917 deletions

View file

@ -105,8 +105,6 @@ typedef enum
SDL_FINGERDOWN = 0x700,
SDL_FINGERUP,
SDL_FINGERMOTION,
SDL_TOUCHBUTTONDOWN,
SDL_TOUCHBUTTONUP,
/* Gesture events */
SDL_DOLLARGESTURE = 0x800,
@ -367,43 +365,22 @@ typedef struct SDL_ControllerDeviceEvent
/**
* \brief Touch finger motion/finger event structure (event.tfinger.*)
* \brief Touch finger event structure (event.tfinger.*)
*/
typedef struct SDL_TouchFingerEvent
{
Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */
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;
/**
* \brief Touch finger motion/finger event structure (event.tbutton.*)
*/
typedef struct SDL_TouchButtonEvent
{
Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */
SDL_TouchID touchId; /**< The touch device index */
Uint8 state; /**< The current button state */
Uint8 button; /**< The button changing state */
Uint8 padding1;
Uint8 padding2;
} SDL_TouchButtonEvent;
/**
* \brief Multiple Finger Gesture Event (event.mgesture.*)
*/
@ -411,31 +388,27 @@ typedef struct SDL_MultiGestureEvent
{
Uint32 type; /**< ::SDL_MULTIGESTURE */
Uint32 timestamp;
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 dDist;
float x; /* currently 0...1. Change to screen coords? */
float x;
float y;
Uint16 numFingers;
Uint16 padding;
} SDL_MultiGestureEvent;
/* (event.dgesture.*) */
typedef struct SDL_DollarGestureEvent
{
Uint32 type; /**< ::SDL_DOLLARGESTURE */
Uint32 timestamp;
Uint32 windowID; /**< The window with mouse focus, if any */
SDL_TouchID touchId; /**< The touch device index */
SDL_TouchID touchId; /**< The touch device id */
SDL_GestureID gestureId;
Uint32 numFingers;
float error;
/*
//TODO: Enable to give location?
float x; //currently 0...1. Change to screen coords?
float y;
*/
float x; /**< Normalized center of gesture */
float y; /**< Normalized center of gesture */
} SDL_DollarGestureEvent;
@ -518,9 +491,8 @@ typedef union SDL_Event
SDL_UserEvent user; /**< Custom event data */
SDL_SysWMEvent syswm; /**< System dependent window event data */
SDL_TouchFingerEvent tfinger; /**< 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 */
SDL_MultiGestureEvent mgesture; /**< Gesture event data */
SDL_DollarGestureEvent dgesture; /**< Gesture event data */
SDL_DropEvent drop; /**< Drag and drop event data */
/* This is necessary for ABI compatibility between Visual C++ and GCC

View file

@ -46,46 +46,11 @@ typedef Sint64 SDL_FingerID;
typedef 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;
float x;
float y;
float pressure;
} SDL_Finger;
typedef struct SDL_Touch
{
/* Free the touch when it's time */
void (*FreeTouch) (struct 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_x; /* for future use */
float tilt_y; /* 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;
} SDL_Touch;
/* Used as the device ID for mouse events simulated with touch input */
#define SDL_TOUCH_MOUSEID ((Uint32)-1)
@ -93,14 +58,24 @@ typedef struct SDL_Touch
/* Function prototypes */
/**
* \brief Get the touch object with 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();
/**
* \brief Get the finger object of the given touch, with the given id.
* \brief Get the touch ID with the given index, or 0 if the index is invalid.
*/
extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id);
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, with the given index.
*/
extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus