Commit 39ee818f authored by jimtla's avatar jimtla

Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer...

Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
parent 598471cf
...@@ -288,15 +288,15 @@ typedef struct SDL_TouchFingerEvent ...@@ -288,15 +288,15 @@ 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 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
long touchId; /**< The touch device id */ SDL_TouchID touchId; /**< The touch device id */
long fingerId; SDL_FingerID fingerId;
Uint8 state; /**< The current button state */ Uint8 state; /**< The current button state */
Uint8 padding1; Uint8 padding1;
Uint8 padding2; Uint8 padding2;
Uint8 padding3; Uint8 padding3;
float x; Uint16 x;
float y; Uint16 y;
int pressure; Uint16 pressure;
} SDL_TouchFingerEvent; } SDL_TouchFingerEvent;
...@@ -307,7 +307,7 @@ typedef struct SDL_TouchButtonEvent ...@@ -307,7 +307,7 @@ typedef struct SDL_TouchButtonEvent
{ {
Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */ Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
long touchId; /**< The touch device index */ SDL_TouchID touchId; /**< The touch device index */
Uint8 state; /**< The current button state */ Uint8 state; /**< The current button state */
Uint8 button; /**< The button changing state */ Uint8 button; /**< The button changing state */
Uint8 padding1; Uint8 padding1;
...@@ -323,7 +323,7 @@ typedef struct SDL_MultiGestureEvent ...@@ -323,7 +323,7 @@ typedef struct SDL_MultiGestureEvent
{ {
Uint32 type; /**< ::SDL_MULTIGESTURE */ Uint32 type; /**< ::SDL_MULTIGESTURE */
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
long touchId; /**< The touch device index */ SDL_TouchID touchId; /**< The touch device index */
float dTheta; float dTheta;
float dDist; float dDist;
float x; //currently 0...1. Change to screen coords? float x; //currently 0...1. Change to screen coords?
...@@ -335,8 +335,8 @@ typedef struct SDL_DollarGestureEvent ...@@ -335,8 +335,8 @@ typedef struct SDL_DollarGestureEvent
{ {
Uint32 type; /**< ::SDL_DOLLARGESTURE */ Uint32 type; /**< ::SDL_DOLLARGESTURE */
Uint32 windowID; /**< The window with mouse focus, if any */ Uint32 windowID; /**< The window with mouse focus, if any */
long touchId; /**< The touch device index */ SDL_TouchID touchId; /**< The touch device index */
unsigned long gestureId; SDL_GestureID gestureId;
float error; float error;
/* /*
//TODO: Enable to give location? //TODO: Enable to give location?
......
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#include "SDL_error.h" #include "SDL_error.h"
#include "SDL_video.h" #include "SDL_video.h"
#include "SDL_touch.h"
#include "begin_code.h" #include "begin_code.h"
/* Set up for C function definitions, even when using C++ */ /* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
...@@ -41,6 +44,7 @@ extern "C" { ...@@ -41,6 +44,7 @@ extern "C" {
/* *INDENT-ON* */ /* *INDENT-ON* */
#endif #endif
typedef Uint64 SDL_GestureID;
/* Function prototypes */ /* Function prototypes */
...@@ -49,7 +53,7 @@ extern "C" { ...@@ -49,7 +53,7 @@ extern "C" {
* *
* *
*/ */
extern DECLSPEC int SDLCALL SDL_RecordGesture(int touchId); extern DECLSPEC int SDLCALL SDL_RecordGesture(SDL_TouchID touchId);
/** /**
...@@ -65,7 +69,7 @@ extern "C" { ...@@ -65,7 +69,7 @@ extern "C" {
* *
*/ */
extern DECLSPEC int extern DECLSPEC int
SDLCALL SDL_SaveDollarTemplate(unsigned long gestureId,SDL_RWops *src); SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_RWops *src);
/** /**
...@@ -73,7 +77,8 @@ extern "C" { ...@@ -73,7 +77,8 @@ extern "C" {
* *
* *
*/ */
extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(int touchId, SDL_RWops *src); extern DECLSPEC
int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src);
......
...@@ -42,15 +42,19 @@ extern "C" { ...@@ -42,15 +42,19 @@ extern "C" {
#endif #endif
typedef Uint64 SDL_TouchID;
typedef Uint64 SDL_FingerID;
struct SDL_Finger { struct SDL_Finger {
long id; SDL_FingerID id;
float x; Uint16 x;
float y; Uint16 y;
float xdelta; Uint16 xdelta;
float ydelta; Uint16 ydelta;
float last_x, last_y,last_pressure; /* the last reported coordinates */ Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */
SDL_bool down; SDL_bool down;
float pressure; Uint16 pressure;
}; };
typedef struct SDL_Touch SDL_Touch; typedef struct SDL_Touch SDL_Touch;
...@@ -66,12 +70,13 @@ struct SDL_Touch { ...@@ -66,12 +70,13 @@ struct SDL_Touch {
float pressure_max, pressure_min; float pressure_max, pressure_min;
float x_max,x_min; float x_max,x_min;
float y_max,y_min; float y_max,y_min;
float xres,yres,pressureres; Uint16 xres,yres,pressureres;
float native_xres,native_yres,native_pressureres;
float tilt; /* for future use */ float tilt; /* for future use */
float rotation; /* for future use */ float rotation; /* for future use */
/* Data common to all touch */ /* Data common to all touch */
long id; SDL_TouchID id;
SDL_Window *focus; SDL_Window *focus;
char *name; char *name;
...@@ -95,7 +100,7 @@ struct SDL_Touch { ...@@ -95,7 +100,7 @@ struct SDL_Touch {
* *
* *
*/ */
extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(long id); extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id);
...@@ -104,7 +109,8 @@ struct SDL_Touch { ...@@ -104,7 +109,8 @@ struct SDL_Touch {
* *
* *
*/ */
extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, long id); extern
DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -46,7 +46,7 @@ typedef struct { ...@@ -46,7 +46,7 @@ typedef struct {
typedef struct { typedef struct {
Point p; Point p;
float pressure; float pressure;
int id; SDL_FingerID id;
} Finger; } Finger;
...@@ -71,7 +71,7 @@ typedef struct { ...@@ -71,7 +71,7 @@ typedef struct {
} DollarTemplate; } DollarTemplate;
typedef struct { typedef struct {
int id; SDL_GestureID id;
Point res; Point res;
Point centroid; Point centroid;
TouchPoint gestureLast[MAXFINGERS]; TouchPoint gestureLast[MAXFINGERS];
...@@ -87,7 +87,7 @@ GestureTouch gestureTouch[MAXTOUCHES]; ...@@ -87,7 +87,7 @@ GestureTouch gestureTouch[MAXTOUCHES];
int numGestureTouches = 0; int numGestureTouches = 0;
SDL_bool recordAll; SDL_bool recordAll;
int SDL_RecordGesture(int touchId) { int SDL_RecordGesture(SDL_TouchID touchId) {
int i; int i;
if(touchId < 0) recordAll = SDL_TRUE; if(touchId < 0) recordAll = SDL_TRUE;
for(i = 0;i < numGestureTouches; i++) { for(i = 0;i < numGestureTouches; i++) {
...@@ -143,7 +143,7 @@ int SDL_SaveAllDollarTemplates(SDL_RWops *src) { ...@@ -143,7 +143,7 @@ int SDL_SaveAllDollarTemplates(SDL_RWops *src) {
return rtrn; return rtrn;
} }
int SDL_SaveDollarTemplate(unsigned long gestureId, SDL_RWops *src) { int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) {
int i,j; int i,j;
for(i = 0; i < numGestureTouches; i++) { for(i = 0; i < numGestureTouches; i++) {
GestureTouch* touch = &gestureTouch[i]; GestureTouch* touch = &gestureTouch[i];
...@@ -185,7 +185,7 @@ static int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) { ...@@ -185,7 +185,7 @@ static int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
return -1; return -1;
} }
int SDL_LoadDollarTemplates(int touchId, SDL_RWops *src) { int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) {
if(src == NULL) return 0; if(src == NULL) return 0;
int i,loaded = 0; int i,loaded = 0;
GestureTouch *touch = NULL; GestureTouch *touch = NULL;
...@@ -394,7 +394,7 @@ int SDL_GestureAddTouch(SDL_Touch* touch) { ...@@ -394,7 +394,7 @@ int SDL_GestureAddTouch(SDL_Touch* touch) {
return 0; return 0;
} }
GestureTouch * SDL_GetGestureTouch(int id) { GestureTouch * SDL_GetGestureTouch(SDL_TouchID id) {
int i; int i;
for(i = 0;i < numGestureTouches; i++) { for(i = 0;i < numGestureTouches; i++) {
//printf("%i ?= %i\n",gestureTouch[i].id,id); //printf("%i ?= %i\n",gestureTouch[i].id,id);
...@@ -414,7 +414,8 @@ int SDL_SendGestureMulti(GestureTouch* touch,float dTheta,float dDist) { ...@@ -414,7 +414,8 @@ int SDL_SendGestureMulti(GestureTouch* touch,float dTheta,float dDist) {
return SDL_PushEvent(&event) > 0; return SDL_PushEvent(&event) > 0;
} }
int SDL_SendGestureDollar(GestureTouch* touch,int gestureId,float error) { int SDL_SendGestureDollar(GestureTouch* touch,
SDL_GestureID gestureId,float error) {
SDL_Event event; SDL_Event event;
event.dgesture.type = SDL_DOLLARGESTURE; event.dgesture.type = SDL_DOLLARGESTURE;
event.dgesture.touchId = touch->id; event.dgesture.touchId = touch->id;
...@@ -429,7 +430,7 @@ int SDL_SendGestureDollar(GestureTouch* touch,int gestureId,float error) { ...@@ -429,7 +430,7 @@ int SDL_SendGestureDollar(GestureTouch* touch,int gestureId,float error) {
} }
int SDL_SendDollarRecord(GestureTouch* touch,int gestureId) { int SDL_SendDollarRecord(GestureTouch* touch,SDL_GestureID gestureId) {
SDL_Event event; SDL_Event event;
event.dgesture.type = SDL_DOLLARRECORD; event.dgesture.type = SDL_DOLLARRECORD;
event.dgesture.touchId = touch->id; event.dgesture.touchId = touch->id;
...@@ -489,7 +490,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -489,7 +490,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
&bestTempl,inTouch); &bestTempl,inTouch);
if(bestTempl >= 0){ if(bestTempl >= 0){
//Send Event //Send Event
int gestureId = inTouch->dollarTemplate[bestTempl].hash; unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
SDL_SendGestureDollar(inTouch,gestureId,error); SDL_SendGestureDollar(inTouch,gestureId,error);
printf("Dollar error: %f\n",error); printf("Dollar error: %f\n",error);
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
extern void SDL_GestureProcessEvent(SDL_Event* event); extern void SDL_GestureProcessEvent(SDL_Event* event);
extern int SDL_RecordGesture(int touchId); extern int SDL_RecordGesture(SDL_TouchID touchId);
extern int SDL_GestureAddTouch(SDL_Touch* touch); extern int SDL_GestureAddTouch(SDL_Touch* touch);
......
...@@ -42,7 +42,7 @@ SDL_TouchInit(void) ...@@ -42,7 +42,7 @@ SDL_TouchInit(void)
} }
SDL_Touch * SDL_Touch *
SDL_GetTouch(long id) SDL_GetTouch(SDL_TouchID id)
{ {
int index = SDL_GetTouchIndexId(id); int index = SDL_GetTouchIndexId(id);
if (index < 0 || index >= SDL_num_touch) { if (index < 0 || index >= SDL_num_touch) {
...@@ -61,7 +61,7 @@ SDL_GetTouchIndex(int index) ...@@ -61,7 +61,7 @@ SDL_GetTouchIndex(int index)
} }
int int
SDL_GetFingerIndexId(SDL_Touch* touch,long fingerid) SDL_GetFingerIndexId(SDL_Touch* touch,SDL_FingerID fingerid)
{ {
int i; int i;
for(i = 0;i < touch->num_fingers;i++) for(i = 0;i < touch->num_fingers;i++)
...@@ -72,7 +72,7 @@ SDL_GetFingerIndexId(SDL_Touch* touch,long fingerid) ...@@ -72,7 +72,7 @@ SDL_GetFingerIndexId(SDL_Touch* touch,long fingerid)
SDL_Finger * SDL_Finger *
SDL_GetFinger(SDL_Touch* touch,long id) SDL_GetFinger(SDL_Touch* touch,SDL_FingerID id)
{ {
int index = SDL_GetFingerIndexId(touch,id); int index = SDL_GetFingerIndexId(touch,id);
if(index < 0 || index >= touch->num_fingers) if(index < 0 || index >= touch->num_fingers)
...@@ -82,7 +82,7 @@ SDL_GetFinger(SDL_Touch* touch,long id) ...@@ -82,7 +82,7 @@ SDL_GetFinger(SDL_Touch* touch,long id)
int int
SDL_GetTouchIndexId(long id) SDL_GetTouchIndexId(SDL_TouchID id)
{ {
int index; int index;
SDL_Touch *touch; SDL_Touch *touch;
...@@ -139,6 +139,8 @@ SDL_AddTouch(const SDL_Touch * touch, char *name) ...@@ -139,6 +139,8 @@ SDL_AddTouch(const SDL_Touch * touch, char *name)
SDL_touchPads[index]->relative_mode = SDL_FALSE; SDL_touchPads[index]->relative_mode = SDL_FALSE;
SDL_touchPads[index]->flush_motion = SDL_FALSE; SDL_touchPads[index]->flush_motion = SDL_FALSE;
SDL_touchPads[index]->xres = (1<<(16-1));
SDL_touchPads[index]->yres = (1<<(16-1));
//Do I want this here? Probably //Do I want this here? Probably
SDL_GestureAddTouch(SDL_touchPads[index]); SDL_GestureAddTouch(SDL_touchPads[index]);
...@@ -146,7 +148,7 @@ SDL_AddTouch(const SDL_Touch * touch, char *name) ...@@ -146,7 +148,7 @@ SDL_AddTouch(const SDL_Touch * touch, char *name)
} }
void void
SDL_DelTouch(long id) SDL_DelTouch(SDL_TouchID id)
{ {
int index = SDL_GetTouchIndexId(id); int index = SDL_GetTouchIndexId(id);
SDL_Touch *touch = SDL_GetTouch(id); SDL_Touch *touch = SDL_GetTouch(id);
...@@ -189,7 +191,7 @@ SDL_GetNumTouch(void) ...@@ -189,7 +191,7 @@ SDL_GetNumTouch(void)
return SDL_num_touch; return SDL_num_touch;
} }
SDL_Window * SDL_Window *
SDL_GetTouchFocusWindow(long id) SDL_GetTouchFocusWindow(SDL_TouchID id)
{ {
SDL_Touch *touch = SDL_GetTouch(id); SDL_Touch *touch = SDL_GetTouch(id);
...@@ -200,7 +202,7 @@ SDL_GetTouchFocusWindow(long id) ...@@ -200,7 +202,7 @@ SDL_GetTouchFocusWindow(long id)
} }
void void
SDL_SetTouchFocus(long id, SDL_Window * window) SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window)
{ {
int index = SDL_GetTouchIndexId(id); int index = SDL_GetTouchIndexId(id);
SDL_Touch *touch = SDL_GetTouch(id); SDL_Touch *touch = SDL_GetTouch(id);
...@@ -250,12 +252,12 @@ SDL_SetTouchFocus(long id, SDL_Window * window) ...@@ -250,12 +252,12 @@ SDL_SetTouchFocus(long id, SDL_Window * window)
} }
int int
SDL_AddFinger(SDL_Touch* touch,SDL_Finger finger) SDL_AddFinger(SDL_Touch* touch,SDL_Finger *finger)
{ {
int index; int index;
SDL_Finger **fingers; SDL_Finger **fingers;
//printf("Adding Finger...\n"); //printf("Adding Finger...\n");
if (SDL_GetFingerIndexId(touch,finger.id) != -1) { if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
SDL_SetError("Finger ID already in use"); SDL_SetError("Finger ID already in use");
} }
...@@ -282,14 +284,14 @@ SDL_AddFinger(SDL_Touch* touch,SDL_Finger finger) ...@@ -282,14 +284,14 @@ SDL_AddFinger(SDL_Touch* touch,SDL_Finger finger)
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
*(touch->fingers[index]) = finger; *(touch->fingers[index]) = *finger;
touch->num_fingers++; touch->num_fingers++;
return index; return index;
} }
int int
SDL_DelFinger(SDL_Touch* touch,long fingerid) SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid)
{ {
int index = SDL_GetFingerIndexId(touch,fingerid); int index = SDL_GetFingerIndexId(touch,fingerid);
SDL_Finger* finger = SDL_GetFinger(touch,fingerid); SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
...@@ -307,7 +309,8 @@ SDL_DelFinger(SDL_Touch* touch,long fingerid) ...@@ -307,7 +309,8 @@ SDL_DelFinger(SDL_Touch* touch,long fingerid)
int int
SDL_SendFingerDown(long id, long fingerid, SDL_bool down, float x, float y, float pressure) SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down,
float xin, float yin, float pressurein)
{ {
int posted; int posted;
SDL_Touch* touch = SDL_GetTouch(id); SDL_Touch* touch = SDL_GetTouch(id);
...@@ -315,11 +318,15 @@ SDL_SendFingerDown(long id, long fingerid, SDL_bool down, float x, float y, floa ...@@ -315,11 +318,15 @@ SDL_SendFingerDown(long id, long fingerid, SDL_bool down, float x, float y, floa
if(!touch) { if(!touch) {
return SDL_TouchNotFoundError(id); return SDL_TouchNotFoundError(id);
} }
//scale to Integer coordinates
Uint16 x = (xin+touch->x_min)*(touch->xres)/(touch->native_xres);
Uint16 y = (yin+touch->y_min)*(touch->yres)/(touch->native_yres);
Uint16 pressure = (yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres);
if(down) { if(down) {
SDL_Finger *finger = SDL_GetFinger(touch,fingerid); SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
SDL_Finger nf;
if(finger == NULL) { if(finger == NULL) {
SDL_Finger nf;
nf.id = fingerid; nf.id = fingerid;
nf.x = x; nf.x = x;
nf.y = y; nf.y = y;
...@@ -330,11 +337,11 @@ SDL_SendFingerDown(long id, long fingerid, SDL_bool down, float x, float y, floa ...@@ -330,11 +337,11 @@ SDL_SendFingerDown(long id, long fingerid, SDL_bool down, float x, float y, floa
nf.last_y = y; nf.last_y = y;
nf.last_pressure = pressure; nf.last_pressure = pressure;
nf.down = SDL_FALSE; nf.down = SDL_FALSE;
SDL_AddFinger(touch,nf); SDL_AddFinger(touch,&nf);
finger = &nf; finger = &nf;
} }
else if(finger->down) return 0; else if(finger->down) return 0;
if(x < 0 || y < 0) return 0; //should defer if only a partial input if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input
posted = 0; posted = 0;
if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
SDL_Event event; SDL_Event event;
...@@ -367,8 +374,8 @@ SDL_SendFingerDown(long id, long fingerid, SDL_bool down, float x, float y, floa ...@@ -367,8 +374,8 @@ SDL_SendFingerDown(long id, long fingerid, SDL_bool down, float x, float y, floa
} }
int int
SDL_SendTouchMotion(long id, long fingerid, int relative, SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative,
float x, float y, float pressure) float xin, float yin, float pressurein)
{ {
int index = SDL_GetTouchIndexId(id); int index = SDL_GetTouchIndexId(id);
SDL_Touch *touch = SDL_GetTouch(id); SDL_Touch *touch = SDL_GetTouch(id);
...@@ -381,6 +388,12 @@ SDL_SendTouchMotion(long id, long fingerid, int relative, ...@@ -381,6 +388,12 @@ SDL_SendTouchMotion(long id, long fingerid, int relative,
if (!touch) { if (!touch) {
return SDL_TouchNotFoundError(id); return SDL_TouchNotFoundError(id);
} }
//scale to Integer coordinates
Uint16 x = (xin+touch->x_min)*(touch->xres)/(touch->native_xres);
Uint16 y = (yin+touch->y_min)*(touch->yres)/(touch->native_yres);
Uint16 pressure = (yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres);
printf("(%f,%f) --> (%i,%i)",xin,yin,x,y);
if(touch->flush_motion) { if(touch->flush_motion) {
return 0; return 0;
} }
...@@ -395,9 +408,9 @@ SDL_SendTouchMotion(long id, long fingerid, int relative, ...@@ -395,9 +408,9 @@ SDL_SendTouchMotion(long id, long fingerid, int relative,
x = (finger->last_x + x); x = (finger->last_x + x);
y = (finger->last_y + y); y = (finger->last_y + y);
} else { } else {
if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/ if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/
if(y < 0) y = finger->last_y; /*The other is marked as -1*/ if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/
if(pressure < 0) pressure = finger->last_pressure; if(pressurein < touch->pressure_min) pressure = finger->last_pressure;
xrel = x - finger->last_x; xrel = x - finger->last_x;
yrel = y - finger->last_y; yrel = y - finger->last_y;
} }
...@@ -448,6 +461,7 @@ SDL_SendTouchMotion(long id, long fingerid, int relative, ...@@ -448,6 +461,7 @@ SDL_SendTouchMotion(long id, long fingerid, int relative,
event.tfinger.fingerId = fingerid; event.tfinger.fingerId = fingerid;
event.tfinger.x = x; event.tfinger.x = x;
event.tfinger.y = y; event.tfinger.y = y;
event.tfinger.pressure = pressure; event.tfinger.pressure = pressure;
event.tfinger.state = touch->buttonstate; event.tfinger.state = touch->buttonstate;
event.tfinger.windowID = touch->focus ? touch->focus->id : 0; event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
...@@ -460,7 +474,7 @@ SDL_SendTouchMotion(long id, long fingerid, int relative, ...@@ -460,7 +474,7 @@ SDL_SendTouchMotion(long id, long fingerid, int relative,
} }
} }
int int
SDL_SendTouchButton(long id, Uint8 state, Uint8 button) SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button)
{ {
SDL_Touch *touch = SDL_GetTouch(id); SDL_Touch *touch = SDL_GetTouch(id);
int posted; int posted;
...@@ -509,7 +523,7 @@ SDL_SendTouchButton(long id, Uint8 state, Uint8 button) ...@@ -509,7 +523,7 @@ SDL_SendTouchButton(long id, Uint8 state, Uint8 button)
} }
char * char *
SDL_GetTouchName(long id) SDL_GetTouchName(SDL_TouchID id)
{ {
SDL_Touch *touch = SDL_GetTouch(id); SDL_Touch *touch = SDL_GetTouch(id);
if (!touch) { if (!touch) {
...@@ -518,7 +532,7 @@ SDL_GetTouchName(long id) ...@@ -518,7 +532,7 @@ SDL_GetTouchName(long id)
return touch->name; return touch->name;
} }
int SDL_TouchNotFoundError(long id) { int SDL_TouchNotFoundError(SDL_TouchID id) {
printf("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id); printf("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id);
printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch); printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch);
int i; int i;
......
...@@ -34,13 +34,13 @@ extern int SDL_TouchInit(void); ...@@ -34,13 +34,13 @@ extern int SDL_TouchInit(void);
extern SDL_Touch *SDL_GetTouchIndex(int index); extern SDL_Touch *SDL_GetTouchIndex(int index);
/* Get the touch with id = id */ /* Get the touch with id = id */
extern SDL_Touch *SDL_GetTouch(long id); extern SDL_Touch *SDL_GetTouch(SDL_TouchID id);
/*Get the finger at an index */ /*Get the finger at an index */
extern SDL_Finger *SDL_GetFingerIndex(SDL_Touch *touch, int index); extern SDL_Finger *SDL_GetFingerIndex(SDL_Touch *touch, int index);
/* Get the finger with id = id */ /* Get the finger with id = id */
extern SDL_Finger *SDL_GetFinger(SDL_Touch *touch,long id); extern SDL_Finger *SDL_GetFinger(SDL_Touch *touch,SDL_FingerID id);
/* Add a touch, possibly reattaching at a particular index (or -1), /* Add a touch, possibly reattaching at a particular index (or -1),
...@@ -49,30 +49,30 @@ extern int SDL_AddTouch(const SDL_Touch * touch, char *name); ...@@ -49,30 +49,30 @@ extern int SDL_AddTouch(const SDL_Touch * touch, char *name);
/* Remove a touch at an index, clearing the slot for later */ /* Remove a touch at an index, clearing the slot for later */
extern void SDL_DelTouch(long id); extern void SDL_DelTouch(SDL_TouchID id);
/* Set the touch focus window */ /* Set the touch focus window */
extern void SDL_SetTouchFocus(long id, SDL_Window * window); extern void SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window);
/* Send a touch motion event for a touch */ /* Send a touch motion event for a touch */
extern int SDL_SendTouchMotion(long id, long fingerid, extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
int relative, float x, float y, float z); int relative, float x, float y, float z);
/* Send a touch down/up event for a touch */ /* Send a touch down/up event for a touch */
extern int SDL_SendFingerDown(long id, long fingerid, SDL_bool down, extern int SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid,
float x, float y, float pressure); SDL_bool down, float x, float y, float pressure);
/* Send a touch button event for a touch */ /* Send a touch button event for a touch */
extern int SDL_SendTouchButton(long id, Uint8 state, Uint8 button); extern int SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button);
/* Shutdown the touch subsystem */ /* Shutdown the touch subsystem */
extern void SDL_TouchQuit(void); extern void SDL_TouchQuit(void);
/* Get the index of a touch device */ /* Get the index of a touch device */
extern int SDL_GetTouchIndexId(long id); extern int SDL_GetTouchIndexId(SDL_TouchID id);
/* Print a debug message for a nonexistent touch */ /* Print a debug message for a nonexistent touch */
extern int SDL_TouchNotFoundError(long id); extern int SDL_TouchNotFoundError(SDL_TouchID id);
#endif /* _SDL_touch_c_h */ #endif /* _SDL_touch_c_h */
......
...@@ -304,13 +304,13 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -304,13 +304,13 @@ static __inline__ void ConvertNSRect(NSRect *r)
touch.id = touchId; touch.id = touchId;
touch.x_min = 0; touch.x_min = 0;
touch.x_max = 1; touch.x_max = 1;
touch.xres = touch.x_max - touch.x_min; touch.native_xres = touch.x_max - touch.x_min;
touch.y_min = 0; touch.y_min = 0;
touch.y_max = 1; touch.y_max = 1;
touch.yres = touch.y_max - touch.y_min; touch.native_yres = touch.y_max - touch.y_min;
touch.pressure_min = 0; touch.pressure_min = 0;
touch.pressure_max = 1; touch.pressure_max = 1;
touch.pressureres = touch.pressure_max - touch.pressure_min; touch.native_pressureres = touch.pressure_max - touch.pressure_min;
if (SDL_AddTouch(&touch, "") < 0) { if (SDL_AddTouch(&touch, "") < 0) {
continue; continue;
......
...@@ -58,13 +58,13 @@ ...@@ -58,13 +58,13 @@
touch.x_min = 0; touch.x_min = 0;
touch.x_max = frame.size.width; touch.x_max = frame.size.width;
touch.xres = touch.x_max - touch.x_min; touch.native_xres = touch.x_max - touch.x_min;
touch.y_min = 0; touch.y_min = 0;
touch.y_max = frame.size.height; touch.y_max = frame.size.height;
touch.yres = touch.y_max - touch.y_min; touch.native_yres = touch.y_max - touch.y_min;
touch.pressure_min = 0; touch.pressure_min = 0;
touch.pressure_max = 1; touch.pressure_max = 1;
touch.pressureres = touch.pressure_max - touch.pressure_min; touch.native_pressureres = touch.pressure_max - touch.pressure_min;
touchId = SDL_AddTouch(&touch, "IPHONE SCREEN"); touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
......
...@@ -56,9 +56,6 @@ X11_InitTouch(_THIS) ...@@ -56,9 +56,6 @@ X11_InitTouch(_THIS)
touch.pressure_max = 0; touch.pressure_max = 0;
touch.pressure_min = 0; touch.pressure_min = 0;
touch.id = event; touch.id = event;
touch.driverdata = SDL_malloc(sizeof(EventTouchData)); touch.driverdata = SDL_malloc(sizeof(EventTouchData));
...@@ -76,19 +73,17 @@ X11_InitTouch(_THIS) ...@@ -76,19 +73,17 @@ X11_InitTouch(_THIS)
ioctl(data->eventStream,EVIOCGABS(0),abs); ioctl(data->eventStream,EVIOCGABS(0),abs);
touch.x_min = abs[1]; touch.x_min = abs[1];
touch.x_max = abs[2]; touch.x_max = abs[2];
touch.xres = touch.x_max - touch.x_min; touch.native_xres = touch.x_max - touch.x_min;
ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs); ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);
touch.y_min = abs[1]; touch.y_min = abs[1];
touch.y_max = abs[2]; touch.y_max = abs[2];
touch.yres = touch.y_max - touch.y_min; touch.native_yres = touch.y_max - touch.y_min;
ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs); ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);
touch.pressure_min = abs[1]; touch.pressure_min = abs[1];
touch.pressure_max = abs[2]; touch.pressure_max = abs[2];
touch.pressureres = touch.pressure_max - touch.pressure_min; touch.native_pressureres = touch.pressure_max - touch.pressure_min;
SDL_AddTouch(&touch, tstr); SDL_AddTouch(&touch, tstr);
} }
vendor = -1; vendor = -1;
product = -1; product = -1;
......
...@@ -335,7 +335,7 @@ int main(int argc, char* argv[]) ...@@ -335,7 +335,7 @@ int main(int argc, char* argv[])
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
mousx = event.motion.x; mousx = event.motion.x;
mousy = event.motion.y; mousy = event.motion.y;
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
bstatus |= (1<<(event.button.button-1)); bstatus |= (1<<(event.button.button-1));
break; break;
...@@ -344,7 +344,7 @@ int main(int argc, char* argv[]) ...@@ -344,7 +344,7 @@ int main(int argc, char* argv[])
break; break;
case SDL_FINGERMOTION: case SDL_FINGERMOTION:
; ;
printf("Finger: %li,x: %f, y: %f\n",event.tfinger.fingerId, printf("Finger: %li,x: %i, y: %i\n",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y); event.tfinger.x,event.tfinger.y);
SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
//SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); //SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
...@@ -353,10 +353,8 @@ int main(int argc, char* argv[]) ...@@ -353,10 +353,8 @@ int main(int argc, char* argv[])
break; break;
if(i == MAXFINGERS) break; if(i == MAXFINGERS) break;
if(inTouch > 0) { if(inTouch > 0) {
finger[i].p.x = ((float)event.tfinger.x)/ finger[i].p.x = ((float)event.tfinger.x)/inTouch->xres;
inTouch->xres; finger[i].p.y = ((float)event.tfinger.y)/inTouch->yres;
finger[i].p.y = ((float)event.tfinger.y)/
inTouch->yres;
finger[i].pressure = finger[i].pressure =
((float)event.tfinger.pressure)/inTouch->pressureres; ((float)event.tfinger.pressure)/inTouch->pressureres;
...@@ -372,7 +370,7 @@ int main(int argc, char* argv[]) ...@@ -372,7 +370,7 @@ int main(int argc, char* argv[])
break; break;
case SDL_FINGERDOWN: case SDL_FINGERDOWN:
printf("Finger: %li down - x: %f, y: %f\n",event.tfinger.fingerId, printf("Finger: %li down - x: %i, y: %i\n",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y); event.tfinger.x,event.tfinger.y);
for(i = 0;i<MAXFINGERS;i++) for(i = 0;i<MAXFINGERS;i++)
...@@ -384,7 +382,7 @@ int main(int argc, char* argv[]) ...@@ -384,7 +382,7 @@ int main(int argc, char* argv[])
finger[i].p.y = event.tfinger.y; finger[i].p.y = event.tfinger.y;
break; break;
case SDL_FINGERUP: case SDL_FINGERUP:
printf("Figner: %li up - x: %f, y: %f\n",event.tfinger.fingerId, printf("Figner: %li up - x: %i, y: %i\n",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y); event.tfinger.x,event.tfinger.y);
for(i = 0;i<MAXFINGERS;i++) for(i = 0;i<MAXFINGERS;i++)
if(index2fingerid[i] == event.tfinger.fingerId) { if(index2fingerid[i] == event.tfinger.fingerId) {
......
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