Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to in…
Browse files Browse the repository at this point in the history
…teger cioordinates (<- not working).
  • Loading branch information
jimtla committed Jul 31, 2010
1 parent 9c24bb5 commit 7fffc6c
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 89 deletions.
18 changes: 9 additions & 9 deletions include/SDL_events.h
Expand Up @@ -288,15 +288,15 @@ typedef struct SDL_TouchFingerEvent
Uint32 type; /**< ::SDL_FINGERMOTION OR
SDL_FINGERDOWN OR SDL_FINGERUP*/
Uint32 windowID; /**< The window with mouse focus, if any */
long touchId; /**< The touch device id */
long fingerId;
SDL_TouchID touchId; /**< The touch device id */
SDL_FingerID fingerId;
Uint8 state; /**< The current button state */
Uint8 padding1;
Uint8 padding2;
Uint8 padding3;
float x;
float y;
int pressure;
Uint16 x;
Uint16 y;
Uint16 pressure;
} SDL_TouchFingerEvent;


Expand All @@ -307,7 +307,7 @@ typedef struct SDL_TouchButtonEvent
{
Uint32 type; /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
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 button; /**< The button changing state */
Uint8 padding1;
Expand All @@ -323,7 +323,7 @@ typedef struct SDL_MultiGestureEvent
{
Uint32 type; /**< ::SDL_MULTIGESTURE */
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 dDist;
float x; //currently 0...1. Change to screen coords?
Expand All @@ -335,8 +335,8 @@ typedef struct SDL_DollarGestureEvent
{
Uint32 type; /**< ::SDL_DOLLARGESTURE */
Uint32 windowID; /**< The window with mouse focus, if any */
long touchId; /**< The touch device index */
unsigned long gestureId;
SDL_TouchID touchId; /**< The touch device index */
SDL_GestureID gestureId;
float error;
/*
//TODO: Enable to give location?
Expand Down
11 changes: 8 additions & 3 deletions include/SDL_gesture.h
Expand Up @@ -33,6 +33,9 @@
#include "SDL_error.h"
#include "SDL_video.h"

#include "SDL_touch.h"


#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
Expand All @@ -41,6 +44,7 @@ extern "C" {
/* *INDENT-ON* */
#endif

typedef Uint64 SDL_GestureID;

/* Function prototypes */

Expand All @@ -49,7 +53,7 @@ extern "C" {
*
*
*/
extern DECLSPEC int SDLCALL SDL_RecordGesture(int touchId);
extern DECLSPEC int SDLCALL SDL_RecordGesture(SDL_TouchID touchId);


/**
Expand All @@ -65,15 +69,16 @@ extern "C" {
*
*/
extern DECLSPEC int
SDLCALL SDL_SaveDollarTemplate(unsigned long gestureId,SDL_RWops *src);
SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_RWops *src);


/**
* \brief Load Dollar Gesture templates from a file
*
*
*/
extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(int touchId, SDL_RWops *src);
extern DECLSPEC
int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src);



Expand Down
28 changes: 17 additions & 11 deletions include/SDL_touch.h
Expand Up @@ -42,15 +42,19 @@ extern "C" {
#endif


typedef Uint64 SDL_TouchID;
typedef Uint64 SDL_FingerID;


struct SDL_Finger {
long id;
float x;
float y;
float xdelta;
float ydelta;
float last_x, last_y,last_pressure; /* the last reported coordinates */
SDL_FingerID id;
Uint16 x;
Uint16 y;
Uint16 xdelta;
Uint16 ydelta;
Uint16 last_x, last_y,last_pressure; /* the last reported coordinates */
SDL_bool down;
float pressure;
Uint16 pressure;
};

typedef struct SDL_Touch SDL_Touch;
Expand All @@ -66,12 +70,13 @@ struct SDL_Touch {
float pressure_max, pressure_min;
float x_max,x_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 rotation; /* for future use */

/* Data common to all touch */
long id;
SDL_TouchID id;
SDL_Window *focus;

char *name;
Expand All @@ -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);



Expand All @@ -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++ */
#ifdef __cplusplus
Expand Down
19 changes: 10 additions & 9 deletions src/events/SDL_gesture.c
Expand Up @@ -46,7 +46,7 @@ typedef struct {
typedef struct {
Point p;
float pressure;
int id;
SDL_FingerID id;
} Finger;


Expand All @@ -71,7 +71,7 @@ typedef struct {
} DollarTemplate;

typedef struct {
int id;
SDL_GestureID id;
Point res;
Point centroid;
TouchPoint gestureLast[MAXFINGERS];
Expand All @@ -87,7 +87,7 @@ GestureTouch gestureTouch[MAXTOUCHES];
int numGestureTouches = 0;
SDL_bool recordAll;

int SDL_RecordGesture(int touchId) {
int SDL_RecordGesture(SDL_TouchID touchId) {
int i;
if(touchId < 0) recordAll = SDL_TRUE;
for(i = 0;i < numGestureTouches; i++) {
Expand Down Expand Up @@ -143,7 +143,7 @@ int SDL_SaveAllDollarTemplates(SDL_RWops *src) {
return rtrn;
}

int SDL_SaveDollarTemplate(unsigned long gestureId, SDL_RWops *src) {
int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) {
int i,j;
for(i = 0; i < numGestureTouches; i++) {
GestureTouch* touch = &gestureTouch[i];
Expand Down Expand Up @@ -185,7 +185,7 @@ static int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
return -1;
}

int SDL_LoadDollarTemplates(int touchId, SDL_RWops *src) {
int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) {
if(src == NULL) return 0;
int i,loaded = 0;
GestureTouch *touch = NULL;
Expand Down Expand Up @@ -394,7 +394,7 @@ int SDL_GestureAddTouch(SDL_Touch* touch) {
return 0;
}

GestureTouch * SDL_GetGestureTouch(int id) {
GestureTouch * SDL_GetGestureTouch(SDL_TouchID id) {
int i;
for(i = 0;i < numGestureTouches; i++) {
//printf("%i ?= %i\n",gestureTouch[i].id,id);
Expand All @@ -414,7 +414,8 @@ int SDL_SendGestureMulti(GestureTouch* touch,float dTheta,float dDist) {
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;
event.dgesture.type = SDL_DOLLARGESTURE;
event.dgesture.touchId = touch->id;
Expand All @@ -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;
event.dgesture.type = SDL_DOLLARRECORD;
event.dgesture.touchId = touch->id;
Expand Down Expand Up @@ -489,7 +490,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
&bestTempl,inTouch);
if(bestTempl >= 0){
//Send Event
int gestureId = inTouch->dollarTemplate[bestTempl].hash;
unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
SDL_SendGestureDollar(inTouch,gestureId,error);
printf("Dollar error: %f\n",error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/events/SDL_gesture_c.h
Expand Up @@ -26,7 +26,7 @@

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);

Expand Down

0 comments on commit 7fffc6c

Please sign in to comment.