1.1 --- a/include/SDL_events.h Sat Mar 02 20:44:16 2013 -0800
1.2 +++ b/include/SDL_events.h Sun Mar 03 01:01:33 2013 -0800
1.3 @@ -105,8 +105,6 @@
1.4 SDL_FINGERDOWN = 0x700,
1.5 SDL_FINGERUP,
1.6 SDL_FINGERMOTION,
1.7 - SDL_TOUCHBUTTONDOWN,
1.8 - SDL_TOUCHBUTTONUP,
1.9
1.10 /* Gesture events */
1.11 SDL_DOLLARGESTURE = 0x800,
1.12 @@ -367,75 +365,50 @@
1.13
1.14
1.15 /**
1.16 - * \brief Touch finger motion/finger event structure (event.tfinger.*)
1.17 + * \brief Touch finger event structure (event.tfinger.*)
1.18 */
1.19 typedef struct SDL_TouchFingerEvent
1.20 {
1.21 Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
1.22 Uint32 timestamp;
1.23 - Uint32 windowID; /**< The window with mouse focus, if any */
1.24 SDL_TouchID touchId; /**< The touch device id */
1.25 SDL_FingerID fingerId;
1.26 - Uint8 state; /**< The current button state */
1.27 - Uint8 padding1;
1.28 - Uint8 padding2;
1.29 - Uint8 padding3;
1.30 - Uint16 x;
1.31 - Uint16 y;
1.32 - Sint16 dx;
1.33 - Sint16 dy;
1.34 - Uint16 pressure;
1.35 + float x; /**< Normalized in the range 0...1 */
1.36 + float y; /**< Normalized in the range 0...1 */
1.37 + float dx; /**< Normalized in the range 0...1 */
1.38 + float dy; /**< Normalized in the range 0...1 */
1.39 + float pressure; /**< Normalized in the range 0...1 */
1.40 } SDL_TouchFingerEvent;
1.41
1.42
1.43 /**
1.44 - * \brief Touch finger motion/finger event structure (event.tbutton.*)
1.45 - */
1.46 -typedef struct SDL_TouchButtonEvent
1.47 -{
1.48 - Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
1.49 - Uint32 timestamp;
1.50 - Uint32 windowID; /**< The window with mouse focus, if any */
1.51 - SDL_TouchID touchId; /**< The touch device index */
1.52 - Uint8 state; /**< The current button state */
1.53 - Uint8 button; /**< The button changing state */
1.54 - Uint8 padding1;
1.55 - Uint8 padding2;
1.56 -} SDL_TouchButtonEvent;
1.57 -
1.58 -
1.59 -/**
1.60 * \brief Multiple Finger Gesture Event (event.mgesture.*)
1.61 */
1.62 typedef struct SDL_MultiGestureEvent
1.63 {
1.64 Uint32 type; /**< ::SDL_MULTIGESTURE */
1.65 Uint32 timestamp;
1.66 - Uint32 windowID; /**< The window with mouse focus, if any */
1.67 - SDL_TouchID touchId; /**< The touch device index */
1.68 + SDL_TouchID touchId; /**< The touch device index */
1.69 float dTheta;
1.70 float dDist;
1.71 - float x; /* currently 0...1. Change to screen coords? */
1.72 + float x;
1.73 float y;
1.74 Uint16 numFingers;
1.75 Uint16 padding;
1.76 } SDL_MultiGestureEvent;
1.77
1.78 +
1.79 /* (event.dgesture.*) */
1.80 typedef struct SDL_DollarGestureEvent
1.81 {
1.82 Uint32 type; /**< ::SDL_DOLLARGESTURE */
1.83 Uint32 timestamp;
1.84 - Uint32 windowID; /**< The window with mouse focus, if any */
1.85 - SDL_TouchID touchId; /**< The touch device index */
1.86 + SDL_TouchID touchId; /**< The touch device id */
1.87 SDL_GestureID gestureId;
1.88 Uint32 numFingers;
1.89 float error;
1.90 - /*
1.91 - //TODO: Enable to give location?
1.92 - float x; //currently 0...1. Change to screen coords?
1.93 - float y;
1.94 - */
1.95 + float x; /**< Normalized center of gesture */
1.96 + float y; /**< Normalized center of gesture */
1.97 } SDL_DollarGestureEvent;
1.98
1.99
1.100 @@ -518,9 +491,8 @@
1.101 SDL_UserEvent user; /**< Custom event data */
1.102 SDL_SysWMEvent syswm; /**< System dependent window event data */
1.103 SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
1.104 - SDL_TouchButtonEvent tbutton; /**< Touch button event data */
1.105 - SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */
1.106 - SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */
1.107 + SDL_MultiGestureEvent mgesture; /**< Gesture event data */
1.108 + SDL_DollarGestureEvent dgesture; /**< Gesture event data */
1.109 SDL_DropEvent drop; /**< Drag and drop event data */
1.110
1.111 /* This is necessary for ABI compatibility between Visual C++ and GCC
2.1 --- a/include/SDL_touch.h Sat Mar 02 20:44:16 2013 -0800
2.2 +++ b/include/SDL_touch.h Sun Mar 03 01:01:33 2013 -0800
2.3 @@ -46,46 +46,11 @@
2.4 typedef struct SDL_Finger
2.5 {
2.6 SDL_FingerID id;
2.7 - Uint16 x;
2.8 - Uint16 y;
2.9 - Uint16 pressure;
2.10 - Uint16 xdelta;
2.11 - Uint16 ydelta;
2.12 - Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */
2.13 - SDL_bool down;
2.14 + float x;
2.15 + float y;
2.16 + float pressure;
2.17 } SDL_Finger;
2.18
2.19 -typedef struct SDL_Touch
2.20 -{
2.21 - /* Free the touch when it's time */
2.22 - void (*FreeTouch) (struct SDL_Touch * touch);
2.23 -
2.24 - /* data common for tablets */
2.25 - float pressure_max, pressure_min;
2.26 - float x_max,x_min;
2.27 - float y_max,y_min;
2.28 - Uint16 xres,yres,pressureres;
2.29 - float native_xres,native_yres,native_pressureres;
2.30 - float tilt_x; /* for future use */
2.31 - float tilt_y; /* for future use */
2.32 - float rotation; /* for future use */
2.33 -
2.34 - /* Data common to all touch */
2.35 - SDL_TouchID id;
2.36 - SDL_Window *focus;
2.37 -
2.38 - char *name;
2.39 - Uint8 buttonstate;
2.40 - SDL_bool relative_mode;
2.41 - SDL_bool flush_motion;
2.42 -
2.43 - int num_fingers;
2.44 - int max_fingers;
2.45 - SDL_Finger** fingers;
2.46 -
2.47 - void *driverdata;
2.48 -} SDL_Touch;
2.49 -
2.50 /* Used as the device ID for mouse events simulated with touch input */
2.51 #define SDL_TOUCH_MOUSEID ((Uint32)-1)
2.52
2.53 @@ -93,14 +58,24 @@
2.54 /* Function prototypes */
2.55
2.56 /**
2.57 - * \brief Get the touch object with the given id.
2.58 + * \brief Get the number of registered touch devices.
2.59 */
2.60 -extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id);
2.61 +extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices();
2.62
2.63 /**
2.64 - * \brief Get the finger object of the given touch, with the given id.
2.65 + * \brief Get the touch ID with the given index, or 0 if the index is invalid.
2.66 + */
2.67 +extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index);
2.68 +
2.69 +/**
2.70 + * \brief Get the number of active fingers for a given touch device.
2.71 */
2.72 -extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id);
2.73 +extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID);
2.74 +
2.75 +/**
2.76 + * \brief Get the finger object of the given touch, with the given index.
2.77 + */
2.78 +extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index);
2.79
2.80 /* Ends C function definitions when using C++ */
2.81 #ifdef __cplusplus
3.1 --- a/src/events/SDL_gesture.c Sat Mar 02 20:44:16 2013 -0800
3.2 +++ b/src/events/SDL_gesture.c Sun Mar 03 01:01:33 2013 -0800
3.3 @@ -64,7 +64,6 @@
3.4
3.5 typedef struct {
3.6 SDL_TouchID id;
3.7 - SDL_FloatPoint res;
3.8 SDL_FloatPoint centroid;
3.9 SDL_DollarPath dollarPath;
3.10 Uint16 numDownFingers;
3.11 @@ -410,7 +409,7 @@
3.12 return bestDiff;
3.13 }
3.14
3.15 -int SDL_GestureAddTouch(SDL_Touch* touch)
3.16 +int SDL_GestureAddTouch(SDL_TouchID touchId)
3.17 {
3.18 SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch,
3.19 (SDL_numGestureTouches + 1) *
3.20 @@ -423,12 +422,8 @@
3.21
3.22 SDL_gestureTouch = gestureTouch;
3.23
3.24 - SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres;
3.25 - SDL_gestureTouch[SDL_numGestureTouches].res.y = touch->yres;
3.26 SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
3.27 -
3.28 - SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres;
3.29 - SDL_gestureTouch[SDL_numGestureTouches].id = touch->id;
3.30 + SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
3.31
3.32 SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0;
3.33
3.34 @@ -468,11 +463,8 @@
3.35 SDL_Event event;
3.36 event.dgesture.type = SDL_DOLLARGESTURE;
3.37 event.dgesture.touchId = touch->id;
3.38 - /*
3.39 - //TODO: Add this to give location of gesture?
3.40 event.mgesture.x = touch->centroid.x;
3.41 event.mgesture.y = touch->centroid.y;
3.42 - */
3.43 event.dgesture.gestureId = gestureId;
3.44 event.dgesture.error = error;
3.45 //A finger came up to trigger this event.
3.46 @@ -513,14 +505,8 @@
3.47 //Shouldn't be possible
3.48 if (inTouch == NULL) return;
3.49
3.50 - //printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x,
3.51 - // (int)event->tfinger.y,
3.52 - // (int)inTouch->res.x,(int)inTouch->res.y);
3.53 -
3.54 -
3.55 - x = ((float)event->tfinger.x)/(float)inTouch->res.x;
3.56 - y = ((float)event->tfinger.y)/(float)inTouch->res.y;
3.57 -
3.58 + x = event->tfinger.x;
3.59 + y = event->tfinger.y;
3.60
3.61 //Finger Up
3.62 if (event->type == SDL_FINGERUP) {
3.63 @@ -569,9 +555,8 @@
3.64 }
3.65 }
3.66 else if (event->type == SDL_FINGERMOTION) {
3.67 - float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x;
3.68 - float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y;
3.69 - //printf("dx,dy: (%f,%f)\n",dx,dy);
3.70 + float dx = event->tfinger.dx;
3.71 + float dy = event->tfinger.dy;
3.72 #ifdef ENABLE_DOLLAR
3.73 SDL_DollarPath* path = &inTouch->dollarPath;
3.74 if (path->numPoints < MAXPATHSIZE) {
4.1 --- a/src/events/SDL_gesture_c.h Sat Mar 02 20:44:16 2013 -0800
4.2 +++ b/src/events/SDL_gesture_c.h Sun Mar 03 01:01:33 2013 -0800
4.3 @@ -23,12 +23,12 @@
4.4 #ifndef _SDL_gesture_c_h
4.5 #define _SDL_gesture_c_h
4.6
4.7 +extern int SDL_GestureAddTouch(SDL_TouchID touchId);
4.8 +
4.9 extern void SDL_GestureProcessEvent(SDL_Event* event);
4.10
4.11 extern int SDL_RecordGesture(SDL_TouchID touchId);
4.12
4.13 -extern int SDL_GestureAddTouch(SDL_Touch* touch);
4.14 -
4.15 #endif /* _SDL_gesture_c_h */
4.16
4.17 /* vi: set ts=4 sw=4 expandtab: */
5.1 --- a/src/events/SDL_touch.c Sat Mar 02 20:44:16 2013 -0800
5.2 +++ b/src/events/SDL_touch.c Sun Mar 03 01:01:33 2013 -0800
5.3 @@ -22,72 +22,46 @@
5.4
5.5 /* General touch handling code for SDL */
5.6
5.7 +#include "SDL_assert.h"
5.8 #include "SDL_events.h"
5.9 #include "SDL_events_c.h"
5.10 -#include "../video/SDL_sysvideo.h"
5.11 -
5.12 -#include <stdio.h>
5.13
5.14
5.15 static int SDL_num_touch = 0;
5.16 -static SDL_Touch **SDL_touchPads = NULL;
5.17 +static SDL_Touch **SDL_touchDevices = NULL;
5.18
5.19
5.20 /* Public functions */
5.21 int
5.22 SDL_TouchInit(void)
5.23 {
5.24 - return (0);
5.25 + return (0);
5.26 +}
5.27 +
5.28 +int
5.29 +SDL_GetNumTouchDevices()
5.30 +{
5.31 + return SDL_num_touch;
5.32 }
5.33
5.34 -SDL_Touch *
5.35 -SDL_GetTouch(SDL_TouchID id)
5.36 -{
5.37 - int index = SDL_GetTouchIndexId(id);
5.38 - if (index < 0 || index >= SDL_num_touch) {
5.39 - return NULL;
5.40 - }
5.41 - return SDL_touchPads[index];
5.42 -}
5.43 -
5.44 -SDL_Touch *
5.45 -SDL_GetTouchIndex(int index)
5.46 +SDL_TouchID
5.47 +SDL_GetTouchDevice(int index)
5.48 {
5.49 if (index < 0 || index >= SDL_num_touch) {
5.50 - return NULL;
5.51 + SDL_SetError("Unknown touch device");
5.52 + return 0;
5.53 }
5.54 - return SDL_touchPads[index];
5.55 + return SDL_touchDevices[index]->id;
5.56 }
5.57
5.58 static int
5.59 -SDL_GetFingerIndexId(SDL_Touch* touch,SDL_FingerID fingerid)
5.60 -{
5.61 - int i;
5.62 - for(i = 0;i < touch->num_fingers;i++)
5.63 - if(touch->fingers[i]->id == fingerid)
5.64 - return i;
5.65 - return -1;
5.66 -}
5.67 -
5.68 -
5.69 -SDL_Finger *
5.70 -SDL_GetFinger(SDL_Touch* touch,SDL_FingerID id)
5.71 -{
5.72 - int index = SDL_GetFingerIndexId(touch,id);
5.73 - if(index < 0 || index >= touch->num_fingers)
5.74 - return NULL;
5.75 - return touch->fingers[index];
5.76 -}
5.77 -
5.78 -
5.79 -int
5.80 -SDL_GetTouchIndexId(SDL_TouchID id)
5.81 +SDL_GetTouchIndex(SDL_TouchID id)
5.82 {
5.83 int index;
5.84 SDL_Touch *touch;
5.85
5.86 for (index = 0; index < SDL_num_touch; ++index) {
5.87 - touch = SDL_touchPads[index];
5.88 + touch = SDL_touchDevices[index];
5.89 if (touch->id == id) {
5.90 return index;
5.91 }
5.92 @@ -95,78 +69,284 @@
5.93 return -1;
5.94 }
5.95
5.96 -int
5.97 -SDL_AddTouch(const SDL_Touch * touch, char *name)
5.98 +SDL_Touch *
5.99 +SDL_GetTouch(SDL_TouchID id)
5.100 {
5.101 - SDL_Touch **touchPads;
5.102 + int index = SDL_GetTouchIndex(id);
5.103 + if (index < 0 || index >= SDL_num_touch) {
5.104 + SDL_SetError("Unknown touch device");
5.105 + return NULL;
5.106 + }
5.107 + return SDL_touchDevices[index];
5.108 +}
5.109 +
5.110 +static int
5.111 +SDL_GetFingerIndex(const SDL_Touch * touch, SDL_FingerID fingerid)
5.112 +{
5.113 int index;
5.114 - size_t length;
5.115 + for (index = 0; index < touch->num_fingers; ++index) {
5.116 + if (touch->fingers[index]->id == fingerid) {
5.117 + return index;
5.118 + }
5.119 + }
5.120 + return -1;
5.121 +}
5.122 +
5.123 +SDL_Finger *
5.124 +SDL_GetFinger(const SDL_Touch * touch, SDL_FingerID id)
5.125 +{
5.126 + int index = SDL_GetFingerIndex(touch, id);
5.127 + if (index < 0 || index >= touch->num_fingers) {
5.128 + return NULL;
5.129 + }
5.130 + return touch->fingers[index];
5.131 +}
5.132
5.133 - if (SDL_GetTouchIndexId(touch->id) != -1) {
5.134 - SDL_SetError("Touch ID already in use");
5.135 +int
5.136 +SDL_GetNumTouchFingers(SDL_TouchID touchID)
5.137 +{
5.138 + SDL_Touch *touch = SDL_GetTouch(touchID);
5.139 + if (touch) {
5.140 + return touch->num_fingers;
5.141 + }
5.142 + return 0;
5.143 +}
5.144 +
5.145 +SDL_Finger *
5.146 +SDL_GetTouchFinger(SDL_TouchID touchID, int index)
5.147 +{
5.148 + SDL_Touch *touch = SDL_GetTouch(touchID);
5.149 + if (!touch) {
5.150 + return NULL;
5.151 + }
5.152 + if (index < 0 || index >= touch->num_fingers) {
5.153 + SDL_SetError("Unknown touch finger");
5.154 + return NULL;
5.155 + }
5.156 + return touch->fingers[index];
5.157 +}
5.158 +
5.159 +int
5.160 +SDL_AddTouch(SDL_TouchID touchID, const char *name)
5.161 +{
5.162 + SDL_Touch **touchDevices;
5.163 + int index;
5.164 +
5.165 + index = SDL_GetTouchIndex(touchID);
5.166 + if (index >= 0) {
5.167 + return index;
5.168 }
5.169
5.170 /* Add the touch to the list of touch */
5.171 - touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads,
5.172 - (SDL_num_touch + 1) * sizeof(*touch));
5.173 - if (!touchPads) {
5.174 + touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
5.175 + (SDL_num_touch + 1) * sizeof(*touchDevices));
5.176 + if (!touchDevices) {
5.177 + SDL_OutOfMemory();
5.178 + return -1;
5.179 + }
5.180 +
5.181 + SDL_touchDevices = touchDevices;
5.182 + index = SDL_num_touch++;
5.183 +
5.184 + SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index]));
5.185 + if (!SDL_touchDevices[index]) {
5.186 SDL_OutOfMemory();
5.187 return -1;
5.188 }
5.189
5.190 - SDL_touchPads = touchPads;
5.191 - index = SDL_num_touch++;
5.192 + /* we're setting the touch properties */
5.193 + SDL_touchDevices[index]->id = touchID;
5.194 + SDL_touchDevices[index]->num_fingers = 0;
5.195 + SDL_touchDevices[index]->max_fingers = 0;
5.196 + SDL_touchDevices[index]->fingers = NULL;
5.197 +
5.198 + /* Record this touch device for gestures */
5.199 + /* We could do this on the fly in the gesture code if we wanted */
5.200 + SDL_GestureAddTouch(touchID);
5.201 +
5.202 + return index;
5.203 +}
5.204 +
5.205 +static int
5.206 +SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure)
5.207 +{
5.208 + SDL_Finger *finger;
5.209 +
5.210 + if (touch->num_fingers == touch->max_fingers) {
5.211 + SDL_Finger **new_fingers;
5.212 + new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers));
5.213 + if (!new_fingers) {
5.214 + SDL_OutOfMemory();
5.215 + return -1;
5.216 + }
5.217 + touch->fingers = new_fingers;
5.218 + touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger));
5.219 + if (!touch->fingers[touch->max_fingers]) {
5.220 + SDL_OutOfMemory();
5.221 + return -1;
5.222 + }
5.223 + touch->max_fingers++;
5.224 + }
5.225
5.226 - SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index]));
5.227 - if (!SDL_touchPads[index]) {
5.228 - SDL_OutOfMemory();
5.229 + finger = touch->fingers[touch->num_fingers++];
5.230 + finger->id = fingerid;
5.231 + finger->x = x;
5.232 + finger->y = y;
5.233 + finger->pressure = pressure;
5.234 + return 0;
5.235 +}
5.236 +
5.237 +static int
5.238 +SDL_DelFinger(SDL_Touch* touch, SDL_FingerID fingerid)
5.239 +{
5.240 + SDL_Finger *temp;
5.241 +
5.242 + int index = SDL_GetFingerIndex(touch, fingerid);
5.243 + if (index < 0) {
5.244 + return -1;
5.245 + }
5.246 +
5.247 + touch->num_fingers--;
5.248 + temp = touch->fingers[index];
5.249 + touch->fingers[index] = touch->fingers[touch->num_fingers];
5.250 + touch->fingers[touch->num_fingers] = temp;
5.251 + return 0;
5.252 +}
5.253 +
5.254 +int
5.255 +SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
5.256 + SDL_bool down, float x, float y, float pressure)
5.257 +{
5.258 + int posted;
5.259 + SDL_Finger *finger;
5.260 +
5.261 + SDL_Touch* touch = SDL_GetTouch(id);
5.262 + if (!touch) {
5.263 return -1;
5.264 }
5.265 - SDL_memcpy(SDL_touchPads[index], touch, sizeof(*touch));
5.266 +
5.267 + finger = SDL_GetFinger(touch, fingerid);
5.268 + if (down) {
5.269 + if (finger) {
5.270 + /* This finger is already down */
5.271 + return 0;
5.272 + }
5.273 +
5.274 + if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
5.275 + return 0;
5.276 + }
5.277
5.278 - /* we're setting the touch properties */
5.279 - length = SDL_strlen(name);
5.280 - SDL_touchPads[index]->focus = 0;
5.281 - SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
5.282 - SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);
5.283 + posted = 0;
5.284 + if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
5.285 + SDL_Event event;
5.286 + event.tfinger.type = SDL_FINGERDOWN;
5.287 + event.tfinger.touchId = id;
5.288 + event.tfinger.fingerId = fingerid;
5.289 + event.tfinger.x = x;
5.290 + event.tfinger.y = y;
5.291 + event.tfinger.dx = 0;
5.292 + event.tfinger.dy = 0;
5.293 + event.tfinger.pressure = pressure;
5.294 + posted = (SDL_PushEvent(&event) > 0);
5.295 + }
5.296 + } else {
5.297 + if (!finger) {
5.298 + /* This finger is already up */
5.299 + return 0;
5.300 + }
5.301 +
5.302 + posted = 0;
5.303 + if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
5.304 + SDL_Event event;
5.305 + event.tfinger.type = SDL_FINGERUP;
5.306 + event.tfinger.touchId = id;
5.307 + event.tfinger.fingerId = fingerid;
5.308 + /* I don't trust the coordinates passed on fingerUp */
5.309 + event.tfinger.x = finger->x;
5.310 + event.tfinger.y = finger->y;
5.311 + event.tfinger.dx = 0;
5.312 + event.tfinger.dy = 0;
5.313 + event.tfinger.pressure = pressure;
5.314 + posted = (SDL_PushEvent(&event) > 0);
5.315 + }
5.316 +
5.317 + SDL_DelFinger(touch, fingerid);
5.318 + }
5.319 + return posted;
5.320 +}
5.321
5.322 - SDL_touchPads[index]->num_fingers = 0;
5.323 - SDL_touchPads[index]->max_fingers = 1;
5.324 - SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
5.325 - SDL_touchPads[index]->fingers[0] = NULL;
5.326 - SDL_touchPads[index]->buttonstate = 0;
5.327 - SDL_touchPads[index]->relative_mode = SDL_FALSE;
5.328 - SDL_touchPads[index]->flush_motion = SDL_FALSE;
5.329 -
5.330 - SDL_touchPads[index]->xres = (1<<(16-1));
5.331 - SDL_touchPads[index]->yres = (1<<(16-1));
5.332 - SDL_touchPads[index]->pressureres = (1<<(16-1));
5.333 - //Do I want this here? Probably
5.334 - SDL_GestureAddTouch(SDL_touchPads[index]);
5.335 +int
5.336 +SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
5.337 + float x, float y, float pressure)
5.338 +{
5.339 + SDL_Touch *touch;
5.340 + SDL_Finger *finger;
5.341 + int posted;
5.342 + float xrel, yrel, prel;
5.343 +
5.344 + touch = SDL_GetTouch(id);
5.345 + if (!touch) {
5.346 + return -1;
5.347 + }
5.348 +
5.349 + finger = SDL_GetFinger(touch,fingerid);
5.350 + if (!finger) {
5.351 + return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);
5.352 + }
5.353 +
5.354 + xrel = x - finger->x;
5.355 + yrel = y - finger->y;
5.356 + prel = pressure - finger->pressure;
5.357
5.358 - return index;
5.359 + /* Drop events that don't change state */
5.360 + if (!xrel && !yrel && !prel) {
5.361 +#if 0
5.362 + printf("Touch event didn't change state - dropped!\n");
5.363 +#endif
5.364 + return 0;
5.365 + }
5.366 +
5.367 + /* Update internal touch coordinates */
5.368 + finger->x = x;
5.369 + finger->y = y;
5.370 + finger->pressure = pressure;
5.371 +
5.372 + /* Post the event, if desired */
5.373 + posted = 0;
5.374 + if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
5.375 + SDL_Event event;
5.376 + event.tfinger.type = SDL_FINGERMOTION;
5.377 + event.tfinger.touchId = id;
5.378 + event.tfinger.fingerId = fingerid;
5.379 + event.tfinger.x = x;
5.380 + event.tfinger.y = y;
5.381 + event.tfinger.dx = xrel;
5.382 + event.tfinger.dy = yrel;
5.383 + event.tfinger.pressure = pressure;
5.384 + posted = (SDL_PushEvent(&event) > 0);
5.385 + }
5.386 + return posted;
5.387 }
5.388
5.389 void
5.390 SDL_DelTouch(SDL_TouchID id)
5.391 {
5.392 - int index = SDL_GetTouchIndexId(id);
5.393 + int i;
5.394 + int index = SDL_GetTouchIndex(id);
5.395 SDL_Touch *touch = SDL_GetTouch(id);
5.396
5.397 if (!touch) {
5.398 return;
5.399 }
5.400
5.401 -
5.402 - SDL_free(touch->name);
5.403 -
5.404 - if (touch->FreeTouch) {
5.405 - touch->FreeTouch(touch);
5.406 + for (i = 0; i < touch->max_fingers; ++i) {
5.407 + SDL_free(touch->fingers[i]);
5.408 }
5.409 + SDL_free(touch->fingers);
5.410 SDL_free(touch);
5.411
5.412 SDL_num_touch--;
5.413 - SDL_touchPads[index] = SDL_touchPads[SDL_num_touch];
5.414 + SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch];
5.415 }
5.416
5.417 void
5.418 @@ -174,400 +354,15 @@
5.419 {
5.420 int i;
5.421
5.422 - for (i = SDL_num_touch-1; i > 0 ; --i) {
5.423 - SDL_DelTouch(i);
5.424 - }
5.425 - SDL_num_touch = 0;
5.426 -
5.427 - if (SDL_touchPads) {
5.428 - SDL_free(SDL_touchPads);
5.429 - SDL_touchPads = NULL;
5.430 + for (i = SDL_num_touch; i--; ) {
5.431 + SDL_DelTouch(SDL_touchDevices[i]->id);
5.432 }
5.433 -}
5.434 -
5.435 -int
5.436 -SDL_GetNumTouch(void)
5.437 -{
5.438 - return SDL_num_touch;
5.439 -}
5.440 -
5.441 -SDL_Window *
5.442 -SDL_GetTouchFocusWindow(SDL_TouchID id)
5.443 -{
5.444 - SDL_Touch *touch = SDL_GetTouch(id);
5.445 -
5.446 - if (!touch) {
5.447 - return 0;
5.448 - }
5.449 - return touch->focus;
5.450 -}
5.451 -
5.452 -void
5.453 -SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window)
5.454 -{
5.455 - int index = SDL_GetTouchIndexId(id);
5.456 - SDL_Touch *touch = SDL_GetTouch(id);
5.457 - int i;
5.458 - SDL_bool focus;
5.459 + SDL_assert(SDL_num_touch == 0);
5.460
5.461 - if (!touch || (touch->focus == window)) {
5.462 - return;
5.463 - }
5.464 -
5.465 - /* See if the current window has lost focus */
5.466 - if (touch->focus) {
5.467 - focus = SDL_FALSE;
5.468 - for (i = 0; i < SDL_num_touch; ++i) {
5.469 - SDL_Touch *check;
5.470 - if (i != index) {
5.471 - check = SDL_touchPads[i];
5.472 - if (check && check->focus == touch->focus) {
5.473 - focus = SDL_TRUE;
5.474 - break;
5.475 - }
5.476 - }
5.477 - }
5.478 - if (!focus) {
5.479 - SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
5.480 - }
5.481 - }
5.482 -
5.483 - touch->focus = window;
5.484 -
5.485 - if (touch->focus) {
5.486 - focus = SDL_FALSE;
5.487 - for (i = 0; i < SDL_num_touch; ++i) {
5.488 - SDL_Touch *check;
5.489 - if (i != index) {
5.490 - check = SDL_touchPads[i];
5.491 - if (check && check->focus == touch->focus) {
5.492 - focus = SDL_TRUE;
5.493 - break;
5.494 - }
5.495 - }
5.496 - }
5.497 - if (!focus) {
5.498 - SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
5.499 - }
5.500 + if (SDL_touchDevices) {
5.501 + SDL_free(SDL_touchDevices);
5.502 + SDL_touchDevices = NULL;
5.503 }
5.504 }
5.505
5.506 -int
5.507 -SDL_AddFinger(SDL_Touch* touch,SDL_Finger *finger)
5.508 -{
5.509 - int index;
5.510 - SDL_Finger **fingers;
5.511 - //printf("Adding Finger...\n");
5.512 - if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
5.513 - SDL_SetError("Finger ID already in use");
5.514 - }
5.515 -
5.516 - /* Add the touch to the list of touch */
5.517 - if(touch->num_fingers >= touch->max_fingers){
5.518 - //printf("Making room for it!\n");
5.519 - fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
5.520 - (touch->num_fingers + 1) * sizeof(SDL_Finger *));
5.521 - if (!fingers) {
5.522 - SDL_OutOfMemory();
5.523 - return -1;
5.524 - } else {
5.525 - touch->max_fingers = touch->num_fingers+1;
5.526 - touch->fingers = fingers;
5.527 - }
5.528 - }
5.529 -
5.530 - index = touch->num_fingers;
5.531 - //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);
5.532 -
5.533 - touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
5.534 - if (!touch->fingers[index]) {
5.535 - SDL_OutOfMemory();
5.536 - return -1;
5.537 - }
5.538 - *(touch->fingers[index]) = *finger;
5.539 - touch->num_fingers++;
5.540 -
5.541 - return index;
5.542 -}
5.543 -
5.544 -int
5.545 -SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid)
5.546 -{
5.547 - int index = SDL_GetFingerIndexId(touch,fingerid);
5.548 - SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
5.549 -
5.550 - if (!finger) {
5.551 - return -1;
5.552 - }
5.553 -
5.554 -
5.555 - SDL_free(finger);
5.556 - touch->num_fingers--;
5.557 - touch->fingers[index] = touch->fingers[touch->num_fingers];
5.558 - return 0;
5.559 -}
5.560 -
5.561 -
5.562 -int
5.563 -SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
5.564 - float xin, float yin, float pressurein)
5.565 -{
5.566 - int posted;
5.567 - Uint16 x;
5.568 - Uint16 y;
5.569 - Uint16 pressure;
5.570 - SDL_Finger *finger;
5.571 -
5.572 - SDL_Touch* touch = SDL_GetTouch(id);
5.573 -
5.574 - if(!touch) {
5.575 - return SDL_TouchNotFoundError(id);
5.576 - }
5.577 -
5.578 -
5.579 - //scale to Integer coordinates
5.580 - x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
5.581 - y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
5.582 - pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
5.583 -
5.584 - finger = SDL_GetFinger(touch,fingerid);
5.585 - if(down) {
5.586 - if(finger == NULL) {
5.587 - SDL_Finger nf;
5.588 - nf.id = fingerid;
5.589 - nf.x = x;
5.590 - nf.y = y;
5.591 - nf.pressure = pressure;
5.592 - nf.xdelta = 0;
5.593 - nf.ydelta = 0;
5.594 - nf.last_x = x;
5.595 - nf.last_y = y;
5.596 - nf.last_pressure = pressure;
5.597 - nf.down = SDL_FALSE;
5.598 - if(SDL_AddFinger(touch,&nf) < 0) return 0;
5.599 - finger = SDL_GetFinger(touch,fingerid);
5.600 - }
5.601 - else if(finger->down) return 0;
5.602 - if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input
5.603 - posted = 0;
5.604 - if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
5.605 - SDL_Event event;
5.606 - event.tfinger.type = SDL_FINGERDOWN;
5.607 - event.tfinger.touchId = id;
5.608 - event.tfinger.x = x;
5.609 - event.tfinger.y = y;
5.610 - event.tfinger.dx = 0;
5.611 - event.tfinger.dy = 0;
5.612 - event.tfinger.pressure = pressure;
5.613 - event.tfinger.state = touch->buttonstate;
5.614 - event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
5.615 - event.tfinger.fingerId = fingerid;
5.616 - posted = (SDL_PushEvent(&event) > 0);
5.617 - }
5.618 - if(posted) finger->down = SDL_TRUE;
5.619 - return posted;
5.620 - }
5.621 - else {
5.622 - if(finger == NULL) {
5.623 - SDL_SetError("Finger not found.");
5.624 - return 0;
5.625 - }
5.626 - posted = 0;
5.627 - if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
5.628 - SDL_Event event;
5.629 - event.tfinger.type = SDL_FINGERUP;
5.630 - event.tfinger.touchId = id;
5.631 - event.tfinger.state = touch->buttonstate;
5.632 - event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
5.633 - event.tfinger.fingerId = fingerid;
5.634 - //I don't trust the coordinates passed on fingerUp
5.635 - event.tfinger.x = finger->x;
5.636 - event.tfinger.y = finger->y;
5.637 - event.tfinger.dx = 0;
5.638 - event.tfinger.dy = 0;
5.639 - event.tfinger.pressure = pressure;
5.640 -
5.641 - if(SDL_DelFinger(touch,fingerid) < 0) return 0;
5.642 - posted = (SDL_PushEvent(&event) > 0);
5.643 - }
5.644 - return posted;
5.645 - }
5.646 -}
5.647 -
5.648 -int
5.649 -SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative,
5.650 - float xin, float yin, float pressurein)
5.651 -{
5.652 - SDL_Touch *touch;
5.653 - SDL_Finger *finger;
5.654 - int posted;
5.655 - Sint16 xrel, yrel;
5.656 - Uint16 x;
5.657 - Uint16 y;
5.658 - Uint16 pressure;
5.659 -
5.660 - touch = SDL_GetTouch(id);
5.661 - if (!touch) {
5.662 - return SDL_TouchNotFoundError(id);
5.663 - }
5.664 -
5.665 - //scale to Integer coordinates
5.666 - x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
5.667 - y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
5.668 - pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
5.669 - if(touch->flush_motion) {
5.670 - return 0;
5.671 - }
5.672 -
5.673 - finger = SDL_GetFinger(touch,fingerid);
5.674 - if(finger == NULL || !finger->down) {
5.675 - return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein);
5.676 - } else {
5.677 - /* the relative motion is calculated regarding the last position */
5.678 - if (relative) {
5.679 - xrel = x;
5.680 - yrel = y;
5.681 - x = (finger->last_x + x);
5.682 - y = (finger->last_y + y);
5.683 - } else {
5.684 - if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/
5.685 - if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/
5.686 - if(pressurein < touch->pressure_min) pressure = finger->last_pressure;
5.687 - xrel = x - finger->last_x;
5.688 - yrel = y - finger->last_y;
5.689 - //printf("xrel,yrel (%i,%i)\n",(int)xrel,(int)yrel);
5.690 - }
5.691 -
5.692 - /* Drop events that don't change state */
5.693 - if (!xrel && !yrel) {
5.694 -#if 0
5.695 - printf("Touch event didn't change state - dropped!\n");
5.696 -#endif
5.697 - return 0;
5.698 - }
5.699 -
5.700 - /* Update internal touch coordinates */
5.701 -
5.702 - finger->x = x;
5.703 - finger->y = y;
5.704 -
5.705 - /*Should scale to window? Normalize? Maintain Aspect?*/
5.706 - //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
5.707 -
5.708 - /* make sure that the pointers find themselves inside the windows */
5.709 - /* only check if touch->xmax is set ! */
5.710 - /*
5.711 - if (x_max && touch->x > x_max) {
5.712 - touch->x = x_max;
5.713 - } else if (touch->x < 0) {
5.714 - touch->x = 0;
5.715 - }
5.716 -
5.717 - if (y_max && touch->y > y_max) {
5.718 - touch->y = y_max;
5.719 - } else if (touch->y < 0) {
5.720 - touch->y = 0;
5.721 - }
5.722 - */
5.723 - finger->xdelta = xrel;
5.724 - finger->ydelta = yrel;
5.725 - finger->pressure = pressure;
5.726 -
5.727 -
5.728 -
5.729 - /* Post the event, if desired */
5.730 - posted = 0;
5.731 - if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
5.732 - SDL_Event event;
5.733 - event.tfinger.type = SDL_FINGERMOTION;
5.734 - event.tfinger.touchId = id;
5.735 - event.tfinger.fingerId = fingerid;
5.736 - event.tfinger.x = x;
5.737 - event.tfinger.y = y;
5.738 - event.tfinger.dx = xrel;
5.739 - event.tfinger.dy = yrel;
5.740 -
5.741 - event.tfinger.pressure = pressure;
5.742 - event.tfinger.state = touch->buttonstate;
5.743 - event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
5.744 - posted = (SDL_PushEvent(&event) > 0);
5.745 - }
5.746 - finger->last_x = finger->x;
5.747 - finger->last_y = finger->y;
5.748 - finger->last_pressure = finger->pressure;
5.749 - return posted;
5.750 - }
5.751 -}
5.752 -
5.753 -int
5.754 -SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button)
5.755 -{
5.756 - SDL_Touch *touch;
5.757 - int posted;
5.758 - Uint32 type;
5.759 -
5.760 -
5.761 - touch = SDL_GetTouch(id);
5.762 - if (!touch) {
5.763 - return SDL_TouchNotFoundError(id);
5.764 - }
5.765 -
5.766 - /* Figure out which event to perform */
5.767 - switch (state) {
5.768 - case SDL_PRESSED:
5.769 - if (touch->buttonstate & SDL_BUTTON(button)) {
5.770 - /* Ignore this event, no state change */
5.771 - return 0;
5.772 - }
5.773 - type = SDL_TOUCHBUTTONDOWN;
5.774 - touch->buttonstate |= SDL_BUTTON(button);
5.775 - break;
5.776 - case SDL_RELEASED:
5.777 - if (!(touch->buttonstate & SDL_BUTTON(button))) {
5.778 - /* Ignore this event, no state change */
5.779 - return 0;
5.780 - }
5.781 - type = SDL_TOUCHBUTTONUP;
5.782 - touch->buttonstate &= ~SDL_BUTTON(button);
5.783 - break;
5.784 - default:
5.785 - /* Invalid state -- bail */
5.786 - return 0;
5.787 - }
5.788 -
5.789 - /* Post the event, if desired */
5.790 - posted = 0;
5.791 - if (SDL_GetEventState(type) == SDL_ENABLE) {
5.792 - SDL_Event event;
5.793 - event.type = type;
5.794 - event.tbutton.touchId = touch->id;
5.795 - event.tbutton.state = state;
5.796 - event.tbutton.button = button;
5.797 - event.tbutton.windowID = touch->focus ? touch->focus->id : 0;
5.798 - posted = (SDL_PushEvent(&event) > 0);
5.799 - }
5.800 - return posted;
5.801 -}
5.802 -
5.803 -char *
5.804 -SDL_GetTouchName(SDL_TouchID id)
5.805 -{
5.806 - SDL_Touch *touch = SDL_GetTouch(id);
5.807 - if (!touch) {
5.808 - return NULL;
5.809 - }
5.810 - return touch->name;
5.811 -}
5.812 -
5.813 -int SDL_TouchNotFoundError(SDL_TouchID id) {
5.814 - //int i;
5.815 - SDL_SetError("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id);
5.816 -#if 0
5.817 - printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch);
5.818 - for(i=0;i < SDL_num_touch;i++) {
5.819 - printf("ERROR: %li\n",SDL_touchPads[i]->id);
5.820 - }
5.821 -#endif
5.822 - return 0;
5.823 -}
5.824 /* vi: set ts=4 sw=4 expandtab: */
6.1 --- a/src/events/SDL_touch_c.h Sat Mar 02 20:44:16 2013 -0800
6.2 +++ b/src/events/SDL_touch_c.h Sun Mar 03 01:01:33 2013 -0800
6.3 @@ -24,55 +24,38 @@
6.4 #ifndef _SDL_touch_c_h
6.5 #define _SDL_touch_c_h
6.6
6.7 +typedef struct SDL_Touch
6.8 +{
6.9 + SDL_TouchID id;
6.10 + int num_fingers;
6.11 + int max_fingers;
6.12 + SDL_Finger** fingers;
6.13 +} SDL_Touch;
6.14
6.15
6.16 /* Initialize the touch subsystem */
6.17 extern int SDL_TouchInit(void);
6.18
6.19 -/*Get the touch at an index */
6.20 -extern SDL_Touch *SDL_GetTouchIndex(int index);
6.21 -
6.22 -/* Get the touch with id = id */
6.23 +/* Add a touch, returning the index of the touch, or -1 if there was an error. */
6.24 +extern int SDL_AddTouch(SDL_TouchID id, const char *name);
6.25 +
6.26 +/* Get the touch with a given id */
6.27 extern SDL_Touch *SDL_GetTouch(SDL_TouchID id);
6.28
6.29 -/*Get the finger at an index */
6.30 -extern SDL_Finger *SDL_GetFingerIndex(SDL_Touch *touch, int index);
6.31 -
6.32 -/* Get the finger with id = id */
6.33 -extern SDL_Finger *SDL_GetFinger(SDL_Touch *touch,SDL_FingerID id);
6.34 -
6.35 -
6.36 -/* Add a touch, possibly reattaching at a particular index (or -1),
6.37 - returning the index of the touch, or -1 if there was an error. */
6.38 -extern int SDL_AddTouch(const SDL_Touch * touch, char *name);
6.39 -
6.40 -
6.41 -/* Remove a touch at an index, clearing the slot for later */
6.42 -extern void SDL_DelTouch(SDL_TouchID id);
6.43 -
6.44 -/* Set the touch focus window */
6.45 -extern void SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window);
6.46 +/* Send a touch down/up event for a touch */
6.47 +extern int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
6.48 + SDL_bool down, float x, float y, float pressure);
6.49
6.50 /* Send a touch motion event for a touch */
6.51 extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
6.52 - int relative, float x, float y, float z);
6.53 + float x, float y, float pressure);
6.54
6.55 -/* Send a touch down/up event for a touch */
6.56 -extern int SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid,
6.57 - SDL_bool down, float x, float y, float pressure);
6.58 -
6.59 -/* Send a touch button event for a touch */
6.60 -extern int SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button);
6.61 +/* Remove a touch */
6.62 +extern void SDL_DelTouch(SDL_TouchID id);
6.63
6.64 /* Shutdown the touch subsystem */
6.65 extern void SDL_TouchQuit(void);
6.66
6.67 -/* Get the index of a touch device */
6.68 -extern int SDL_GetTouchIndexId(SDL_TouchID id);
6.69 -
6.70 -/* Print a debug message for a nonexistent touch */
6.71 -extern int SDL_TouchNotFoundError(SDL_TouchID id);
6.72 -
6.73 #endif /* _SDL_touch_c_h */
6.74
6.75 /* vi: set ts=4 sw=4 expandtab: */
7.1 --- a/src/video/android/SDL_androidtouch.c Sat Mar 02 20:44:16 2013 -0800
7.2 +++ b/src/video/android/SDL_androidtouch.c Sun Mar 03 01:01:33 2013 -0800
7.3 @@ -64,19 +64,7 @@
7.4
7.5 touchDeviceId = (SDL_TouchID)touch_device_id_in;
7.6 if (!SDL_GetTouch(touchDeviceId)) {
7.7 - SDL_Touch touch;
7.8 - memset( &touch, 0, sizeof(touch) );
7.9 - touch.id = touchDeviceId;
7.10 - touch.x_min = 0.0f;
7.11 - touch.x_max = 1.0f;
7.12 - touch.native_xres = touch.x_max - touch.x_min;
7.13 - touch.y_min = 0.0f;
7.14 - touch.y_max = 1.0f;
7.15 - touch.native_yres = touch.y_max - touch.y_min;
7.16 - touch.pressure_min = 0.0f;
7.17 - touch.pressure_max = 1.0f;
7.18 - touch.native_pressureres = touch.pressure_max - touch.pressure_min;
7.19 - if (SDL_AddTouch(&touch, "") < 0) {
7.20 + if (SDL_AddTouch(touchDeviceId, "") < 0) {
7.21 SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
7.22 }
7.23 }
7.24 @@ -96,7 +84,7 @@
7.25
7.26 leftFingerDown = fingerId;
7.27 }
7.28 - SDL_SendFingerDown(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
7.29 + SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
7.30 break;
7.31 case ACTION_MOVE:
7.32 if (!leftFingerDown) {
7.33 @@ -105,7 +93,7 @@
7.34 /* send moved event */
7.35 SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
7.36 }
7.37 - SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
7.38 + SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
7.39 break;
7.40 case ACTION_UP:
7.41 case ACTION_POINTER_1_UP:
7.42 @@ -114,7 +102,7 @@
7.43 SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
7.44 leftFingerDown = 0;
7.45 }
7.46 - SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
7.47 + SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
7.48 break;
7.49 default:
7.50 break;
8.1 --- a/src/video/cocoa/SDL_cocoawindow.m Sat Mar 02 20:44:16 2013 -0800
8.2 +++ b/src/video/cocoa/SDL_cocoawindow.m Sun Mar 03 01:01:33 2013 -0800
8.3 @@ -408,27 +408,14 @@
8.4 enumerator = [touches objectEnumerator];
8.5 touch = (NSTouch*)[enumerator nextObject];
8.6 while (touch) {
8.7 - const SDL_TouchID touchId = (SDL_TouchID) ((size_t) [touch device]);
8.8 + const SDL_TouchID touchId = (SDL_TouchID)[touch device];
8.9 if (!SDL_GetTouch(touchId)) {
8.10 - SDL_Touch touch;
8.11 -
8.12 - touch.id = touchId;
8.13 - touch.x_min = 0;
8.14 - touch.x_max = 1;
8.15 - touch.native_xres = touch.x_max - touch.x_min;
8.16 - touch.y_min = 0;
8.17 - touch.y_max = 1;
8.18 - touch.native_yres = touch.y_max - touch.y_min;
8.19 - touch.pressure_min = 0;
8.20 - touch.pressure_max = 1;
8.21 - touch.native_pressureres = touch.pressure_max - touch.pressure_min;
8.22 -
8.23 - if (SDL_AddTouch(&touch, "") < 0) {
8.24 + if (SDL_AddTouch(touchId, "") < 0) {
8.25 return;
8.26 }
8.27 }
8.28
8.29 - const SDL_FingerID fingerId = (SDL_FingerID) ((size_t) [touch identity]);
8.30 + const SDL_FingerID fingerId = (SDL_FingerID)[touch identity];
8.31 float x = [touch normalizedPosition].x;
8.32 float y = [touch normalizedPosition].y;
8.33 /* Make the origin the upper left instead of the lower left */
8.34 @@ -436,17 +423,17 @@
8.35
8.36 switch (type) {
8.37 case COCOA_TOUCH_DOWN:
8.38 - SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);
8.39 + SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
8.40 break;
8.41 case COCOA_TOUCH_UP:
8.42 case COCOA_TOUCH_CANCELLED:
8.43 - SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1);
8.44 + SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
8.45 break;
8.46 case COCOA_TOUCH_MOVE:
8.47 - SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1);
8.48 + SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
8.49 break;
8.50 }
8.51 -
8.52 +
8.53 touch = (NSTouch*)[enumerator nextObject];
8.54 }
8.55 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 */
9.1 --- a/src/video/uikit/SDL_uikitview.m Sat Mar 02 20:44:16 2013 -0800
9.2 +++ b/src/video/uikit/SDL_uikitview.m Sun Mar 03 01:01:33 2013 -0800
9.3 @@ -52,23 +52,8 @@
9.4
9.5 self.multipleTouchEnabled = YES;
9.6
9.7 - SDL_Touch touch;
9.8 - touch.id = 0; //TODO: Should be -1?
9.9 -
9.10 - //touch.driverdata = SDL_malloc(sizeof(EventTouchData));
9.11 - //EventTouchData* data = (EventTouchData*)(touch.driverdata);
9.12 -
9.13 - touch.x_min = 0;
9.14 - touch.x_max = 1;
9.15 - touch.native_xres = touch.x_max - touch.x_min;
9.16 - touch.y_min = 0;
9.17 - touch.y_max = 1;
9.18 - touch.native_yres = touch.y_max - touch.y_min;
9.19 - touch.pressure_min = 0;
9.20 - touch.pressure_max = 1;
9.21 - touch.native_pressureres = touch.pressure_max - touch.pressure_min;
9.22 -
9.23 - touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
9.24 + touchId = 1;
9.25 + SDL_AddTouch(touchId, "");
9.26
9.27 return self;
9.28
9.29 @@ -117,17 +102,15 @@
9.30 // FIXME: TODO: Using touch as the fingerId is potentially dangerous
9.31 // It is also much more efficient than storing the UITouch pointer
9.32 // and comparing it to the incoming event.
9.33 - SDL_SendFingerDown(touchId, (SDL_FingerID)touch,
9.34 - SDL_TRUE, locationInView.x, locationInView.y,
9.35 - 1);
9.36 + SDL_SendTouch(touchId, (SDL_FingerID)touch,
9.37 + SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
9.38 #else
9.39 int i;
9.40 for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
9.41 if (finger[i] == NULL) {
9.42 finger[i] = touch;
9.43 - SDL_SendFingerDown(touchId, i,
9.44 - SDL_TRUE, locationInView.x, locationInView.y,
9.45 - 1);
9.46 + SDL_SendTouch(touchId, i,
9.47 + SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
9.48 break;
9.49 }
9.50 }
9.51 @@ -150,16 +133,14 @@
9.52
9.53 CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
9.54 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
9.55 - SDL_SendFingerDown(touchId, (long)touch,
9.56 - SDL_FALSE, locationInView.x, locationInView.y,
9.57 - 1);
9.58 + SDL_SendTouch(touchId, (long)touch,
9.59 + SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
9.60 #else
9.61 int i;
9.62 for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
9.63 if (finger[i] == touch) {
9.64 - SDL_SendFingerDown(touchId, i,
9.65 - SDL_FALSE, locationInView.x, locationInView.y,
9.66 - 1);
9.67 + SDL_SendTouch(touchId, i,
9.68 + SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
9.69 finger[i] = NULL;
9.70 break;
9.71 }
9.72 @@ -195,15 +176,13 @@
9.73 CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
9.74 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
9.75 SDL_SendTouchMotion(touchId, (long)touch,
9.76 - SDL_FALSE, locationInView.x, locationInView.y,
9.77 - 1);
9.78 + locationInView.x, locationInView.y, 1.0f);
9.79 #else
9.80 int i;
9.81 for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
9.82 if (finger[i] == touch) {
9.83 SDL_SendTouchMotion(touchId, i,
9.84 - SDL_FALSE, locationInView.x, locationInView.y,
9.85 - 1);
9.86 + locationInView.x, locationInView.y, 1.0f);
9.87 break;
9.88 }
9.89 }
10.1 --- a/src/video/windows/SDL_windowsevents.c Sat Mar 02 20:44:16 2013 -0800
10.2 +++ b/src/video/windows/SDL_windowsevents.c Sun Mar 03 01:01:33 2013 -0800
10.3 @@ -691,23 +691,9 @@
10.4 for (i = 0; i < num_inputs; ++i) {
10.5 PTOUCHINPUT input = &inputs[i];
10.6
10.7 - const SDL_TouchID touchId = (SDL_TouchID)
10.8 - ((size_t)input->hSource);
10.9 + const SDL_TouchID touchId = (SDL_TouchID)input->hSource;
10.10 if (!SDL_GetTouch(touchId)) {
10.11 - SDL_Touch touch;
10.12 -
10.13 - touch.id = touchId;
10.14 - touch.x_min = 0;
10.15 - touch.x_max = 1;
10.16 - touch.native_xres = touch.x_max - touch.x_min;
10.17 - touch.y_min = 0;
10.18 - touch.y_max = 1;
10.19 - touch.native_yres = touch.y_max - touch.y_min;
10.20 - touch.pressure_min = 0;
10.21 - touch.pressure_max = 1;
10.22 - touch.native_pressureres = touch.pressure_max - touch.pressure_min;
10.23 -
10.24 - if (SDL_AddTouch(&touch, "") < 0) {
10.25 + if (SDL_AddTouch(touchId, "") < 0) {
10.26 continue;
10.27 }
10.28 }
10.29 @@ -717,13 +703,13 @@
10.30 y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
10.31
10.32 if (input->dwFlags & TOUCHEVENTF_DOWN) {
10.33 - SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1);
10.34 + SDL_SendTouch(touchId, input->dwID, SDL_TRUE, x, y, 1.0f);
10.35 }
10.36 if (input->dwFlags & TOUCHEVENTF_MOVE) {
10.37 - SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1);
10.38 + SDL_SendTouchMotion(touchId, input->dwID, x, y, 1.0f);
10.39 }
10.40 if (input->dwFlags & TOUCHEVENTF_UP) {
10.41 - SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1);
10.42 + SDL_SendTouch(touchId, input->dwID, SDL_FALSE, x, y, 1.0f);
10.43 }
10.44 }
10.45 }
11.1 --- a/src/video/x11/SDL_x11events.c Sat Mar 02 20:44:16 2013 -0800
11.2 +++ b/src/video/x11/SDL_x11events.c Sun Mar 03 01:01:33 2013 -0800
11.3 @@ -41,12 +41,6 @@
11.4
11.5 #include <stdio.h>
11.6
11.7 -#ifdef SDL_INPUT_LINUXEV
11.8 -/* Touch Input/event* includes */
11.9 -#include <linux/input.h>
11.10 -#include <fcntl.h>
11.11 -#endif
11.12 -
11.13 /*#define DEBUG_XEVENTS*/
11.14
11.15 /* Check to see if this is a repeated key.
11.16 @@ -703,90 +697,6 @@
11.17
11.18 /* FIXME: Only need to do this when there are pending focus changes */
11.19 X11_HandleFocusChanges(_this);
11.20 -
11.21 - /*Dont process evtouch events if XInput2 multitouch is supported*/
11.22 - if(X11_Xinput2IsMultitouchSupported()) {
11.23 - return;
11.24 - }
11.25 -
11.26 -#ifdef SDL_INPUT_LINUXEV
11.27 - /* Process Touch events*/
11.28 - int i = 0,rd;
11.29 - struct input_event ev[64];
11.30 - int size = sizeof (struct input_event);
11.31 -
11.32 -/* !!! FIXME: clean the tabstops out of here. */
11.33 - for(i = 0;i < SDL_GetNumTouch();++i) {
11.34 - SDL_Touch* touch = SDL_GetTouchIndex(i);
11.35 - if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
11.36 - EventTouchData* data;
11.37 - data = (EventTouchData*)(touch->driverdata);
11.38 - if(data == NULL) {
11.39 - printf("No driver data\n");
11.40 - continue;
11.41 - }
11.42 - if(data->eventStream <= 0)
11.43 - printf("Error: Couldn't open stream\n");
11.44 - rd = read(data->eventStream, ev, size * 64);
11.45 - if(rd >= size) {
11.46 - for (i = 0; i < rd / sizeof(struct input_event); i++) {
11.47 - switch (ev[i].type) {
11.48 - case EV_ABS:
11.49 - switch (ev[i].code) {
11.50 - case ABS_X:
11.51 - data->x = ev[i].value;
11.52 - break;
11.53 - case ABS_Y:
11.54 - data->y = ev[i].value;
11.55 - break;
11.56 - case ABS_PRESSURE:
11.57 - data->pressure = ev[i].value;
11.58 - if(data->pressure < 0) data->pressure = 0;
11.59 - break;
11.60 - case ABS_MISC:
11.61 - if(ev[i].value == 0)
11.62 - data->up = SDL_TRUE;
11.63 - break;
11.64 - }
11.65 - break;
11.66 - case EV_MSC:
11.67 - if(ev[i].code == MSC_SERIAL)
11.68 - data->finger = ev[i].value;
11.69 - break;
11.70 - case EV_KEY:
11.71 - if(ev[i].code == BTN_TOUCH)
11.72 - if(ev[i].value == 0)
11.73 - data->up = SDL_TRUE;
11.74 - break;
11.75 - case EV_SYN:
11.76 - if(!data->down) {
11.77 - data->down = SDL_TRUE;
11.78 - SDL_SendFingerDown(touch->id,data->finger,
11.79 - data->down, data->x, data->y,
11.80 - data->pressure);
11.81 - }
11.82 - else if(!data->up)
11.83 - SDL_SendTouchMotion(touch->id,data->finger,
11.84 - SDL_FALSE, data->x,data->y,
11.85 - data->pressure);
11.86 - else
11.87 - {
11.88 - data->down = SDL_FALSE;
11.89 - SDL_SendFingerDown(touch->id,data->finger,
11.90 - data->down, data->x,data->y,
11.91 - data->pressure);
11.92 - data->x = -1;
11.93 - data->y = -1;
11.94 - data->pressure = -1;
11.95 - data->finger = 0;
11.96 - data->up = SDL_FALSE;
11.97 - }
11.98 - break;
11.99 - }
11.100 - }
11.101 - }
11.102 - }
11.103 -#endif
11.104 }
11.105
11.106
12.1 --- a/src/video/x11/SDL_x11touch.c Sat Mar 02 20:44:16 2013 -0800
12.2 +++ b/src/video/x11/SDL_x11touch.c Sun Mar 03 01:01:33 2013 -0800
12.3 @@ -28,97 +28,12 @@
12.4 #include "../../events/SDL_touch_c.h"
12.5
12.6
12.7 -#ifdef SDL_INPUT_LINUXEV
12.8 -#include <linux/input.h>
12.9 -#include <fcntl.h>
12.10 -#endif
12.11 -
12.12 void
12.13 X11_InitTouch(_THIS)
12.14 {
12.15 - /*Initilized Xinput2 multitouch
12.16 - * and return in order to not initialize
12.17 - * evtouch also*/
12.18 - if(X11_Xinput2IsMultitouchSupported()) {
12.19 + if (X11_Xinput2IsMultitouchSupported()) {
12.20 X11_InitXinput2Multitouch(_this);
12.21 - return;
12.22 }
12.23 -#ifdef SDL_INPUT_LINUXEV
12.24 - FILE *fd;
12.25 - fd = fopen("/proc/bus/input/devices","r");
12.26 - if (!fd) return;
12.27 -
12.28 - int i = 0;
12.29 - int tsfd;
12.30 - char line[256];
12.31 - char tstr[256];
12.32 - int vendor = -1,product = -1,event = -1;
12.33 - while(!feof(fd)) {
12.34 - if(fgets(line,256,fd) <=0) continue;
12.35 - if(line[0] == '\n') {
12.36 - if(vendor == 1386 || vendor==1) {
12.37 - sprintf(tstr,"/dev/input/event%i",event);
12.38 -
12.39 - tsfd = open( tstr, O_RDONLY | O_NONBLOCK );
12.40 - if ( tsfd == -1 )
12.41 - continue; /* Maybe not enough permissions ? */
12.42 -
12.43 - SDL_Touch touch;
12.44 - touch.pressure_max = 0;
12.45 - touch.pressure_min = 0;
12.46 - touch.id = event;
12.47 -
12.48 - touch.driverdata = SDL_malloc(sizeof(EventTouchData));
12.49 - EventTouchData* data = (EventTouchData*)(touch.driverdata);
12.50 -
12.51 - data->x = -1;
12.52 - data->y = -1;
12.53 - data->pressure = -1;
12.54 - data->finger = 0;
12.55 - data->up = SDL_FALSE;
12.56 - data->down = SDL_FALSE;
12.57 -
12.58 - data->eventStream = tsfd;
12.59 - ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
12.60 -
12.61 - int abs[5];
12.62 - ioctl(data->eventStream,EVIOCGABS(0),abs);
12.63 - touch.x_min = abs[1];
12.64 - touch.x_max = abs[2];
12.65 - touch.native_xres = touch.x_max - touch.x_min;
12.66 - ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);
12.67 - touch.y_min = abs[1];
12.68 - touch.y_max = abs[2];
12.69 - touch.native_yres = touch.y_max - touch.y_min;
12.70 - ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);
12.71 - touch.pressure_min = abs[1];
12.72 - touch.pressure_max = abs[2];
12.73 - touch.native_pressureres = touch.pressure_max - touch.pressure_min;
12.74 -
12.75 - SDL_AddTouch(&touch, tstr);
12.76 - }
12.77 - vendor = -1;
12.78 - product = -1;
12.79 - event = -1;
12.80 - }
12.81 - else if(line[0] == 'I') {
12.82 - i = 1;
12.83 - while(line[i]) {
12.84 - sscanf(&line[i],"Vendor=%x",&vendor);
12.85 - sscanf(&line[i],"Product=%x",&product);
12.86 - i++;
12.87 - }
12.88 - }
12.89 - else if(line[0] == 'H') {
12.90 - i = 1;
12.91 - while(line[i]) {
12.92 - sscanf(&line[i],"event%d",&event);
12.93 - i++;
12.94 - }
12.95 - }
12.96 - }
12.97 - fclose(fd);
12.98 -#endif
12.99 }
12.100
12.101 void
13.1 --- a/src/video/x11/SDL_x11touch.h Sat Mar 02 20:44:16 2013 -0800
13.2 +++ b/src/video/x11/SDL_x11touch.h Sun Mar 03 01:01:33 2013 -0800
13.3 @@ -23,16 +23,6 @@
13.4 #ifndef _SDL_x11touch_h
13.5 #define _SDL_x11touch_h
13.6
13.7 -#ifdef SDL_INPUT_LINUXEV
13.8 -typedef struct EventTouchData
13.9 -{
13.10 - int x,y,pressure,finger; /* Temporary Variables until sync */
13.11 - int eventStream;
13.12 - SDL_bool up;
13.13 - SDL_bool down;
13.14 -} EventTouchData;
13.15 -#endif
13.16 -
13.17 extern void X11_InitTouch(_THIS);
13.18 extern void X11_QuitTouch(_THIS);
13.19
14.1 --- a/src/video/x11/SDL_x11xinput2.c Sat Mar 02 20:44:16 2013 -0800
14.2 +++ b/src/video/x11/SDL_x11xinput2.c Sun Mar 03 01:01:33 2013 -0800
14.3 @@ -121,8 +121,6 @@
14.4 #endif
14.5 }
14.6
14.7 -
14.8 -
14.9 int
14.10 X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
14.11 {
14.12 @@ -149,25 +147,22 @@
14.13 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
14.14 case XI_TouchBegin: {
14.15 const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
14.16 - SDL_SendFingerDown(xev->sourceid,xev->detail,
14.17 - SDL_TRUE, (int)xev->event_x, (int)xev->event_y,
14.18 - 1.0);
14.19 + SDL_SendTouch(xev->sourceid,xev->detail,
14.20 + SDL_TRUE, xev->event_x, xev->event_y, 1.0);
14.21 return 1;
14.22 }
14.23 break;
14.24 case XI_TouchEnd: {
14.25 const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
14.26 - SDL_SendFingerDown(xev->sourceid,xev->detail,
14.27 - SDL_FALSE, (int)xev->event_x, (int)xev->event_y,
14.28 - 1.0);
14.29 + SDL_SendTouch(xev->sourceid,xev->detail,
14.30 + SDL_FALSE, xev->event_x, xev->event_y, 1.0);
14.31 return 1;
14.32 }
14.33 break;
14.34 case XI_TouchUpdate: {
14.35 const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
14.36 SDL_SendTouchMotion(xev->sourceid,xev->detail,
14.37 - SDL_FALSE, (int)xev->event_x, (int)xev->event_y,
14.38 - 1.0);
14.39 + xev->event_x, xev->event_y, 1.0);
14.40 return 1;
14.41 }
14.42 break;
14.43 @@ -198,22 +193,8 @@
14.44 continue;
14.45
14.46 touchId = t->sourceid;
14.47 - /*Add the touch*/
14.48 if (!SDL_GetTouch(touchId)) {
14.49 - SDL_Touch touch;
14.50 -
14.51 - touch.id = touchId;
14.52 - touch.x_min = 0;
14.53 - touch.x_max = 1;
14.54 - touch.native_xres = touch.x_max - touch.x_min;
14.55 - touch.y_min = 0;
14.56 - touch.y_max = 1;
14.57 - touch.native_yres = touch.y_max - touch.y_min;
14.58 - touch.pressure_min = 0;
14.59 - touch.pressure_max = 1;
14.60 - touch.native_pressureres = touch.pressure_max - touch.pressure_min;
14.61 -
14.62 - SDL_AddTouch(&touch,dev->name);
14.63 + SDL_AddTouch(touchId, dev->name);
14.64 }
14.65 }
14.66 }
15.1 --- a/test/testgesture.c Sat Mar 02 20:44:16 2013 -0800
15.2 +++ b/test/testgesture.c Sun Mar 03 01:01:33 2013 -0800
15.3 @@ -167,11 +167,8 @@
15.4 if(event->type == SDL_FINGERMOTION ||
15.5 event->type == SDL_FINGERDOWN ||
15.6 event->type == SDL_FINGERUP) {
15.7 - SDL_Touch* inTouch = SDL_GetTouch(event->tfinger.touchId);
15.8 - if(inTouch == NULL) continue;
15.9 -
15.10 - x = ((float)event->tfinger.x)/inTouch->xres;
15.11 - y = ((float)event->tfinger.y)/inTouch->yres;
15.12 + x = event->tfinger.x;
15.13 + y = event->tfinger.y;
15.14
15.15 //draw the touch:
15.16 c = colors[event->tfinger.fingerId%7];
15.17 @@ -269,10 +266,6 @@
15.18 SDL_Log("Finger: %i,x: %i, y: %i",event.tfinger.fingerId,
15.19 event.tfinger.x,event.tfinger.y);
15.20 #endif
15.21 - {
15.22 - SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
15.23 - SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
15.24 - }
15.25 break;
15.26 case SDL_FINGERDOWN:
15.27 #if VERBOSE