SDL  2.0
SDL_touch_c.h File Reference
+ Include dependency graph for SDL_touch_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_Touch

Functions

int SDL_TouchInit (void)
int SDL_AddTouch (SDL_TouchID id, const char *name)
SDL_TouchSDL_GetTouch (SDL_TouchID id)
int SDL_SendTouch (SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
int SDL_SendTouchMotion (SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
void SDL_DelTouch (SDL_TouchID id)
void SDL_TouchQuit (void)

Function Documentation

int SDL_AddTouch ( SDL_TouchID  id,
const char *  name 
)

Definition at line 136 of file SDL_touch.c.

References SDL_Touch::fingers, SDL_Touch::id, SDL_Touch::max_fingers, NULL, SDL_Touch::num_fingers, SDL_GestureAddTouch(), SDL_GetTouchIndex(), SDL_malloc, SDL_num_touch, SDL_OutOfMemory, and SDL_realloc.

{
SDL_Touch **touchDevices;
int index;
index = SDL_GetTouchIndex(touchID);
if (index >= 0) {
return index;
}
/* Add the touch to the list of touch */
touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
(SDL_num_touch + 1) * sizeof(*touchDevices));
if (!touchDevices) {
return SDL_OutOfMemory();
}
SDL_touchDevices = touchDevices;
index = SDL_num_touch;
if (!SDL_touchDevices[index]) {
return SDL_OutOfMemory();
}
/* Added touch to list */
/* we're setting the touch properties */
SDL_touchDevices[index]->id = touchID;
/* Record this touch device for gestures */
/* We could do this on the fly in the gesture code if we wanted */
return index;
}
void SDL_DelTouch ( SDL_TouchID  id)

Definition at line 337 of file SDL_touch.c.

References SDL_Touch::fingers, i, SDL_Touch::max_fingers, SDL_free, SDL_GestureDelTouch(), SDL_GetTouch(), SDL_GetTouchIndex(), and SDL_num_touch.

Referenced by SDL_TouchQuit().

{
int i;
SDL_Touch *touch = SDL_GetTouch(id);
if (!touch) {
return;
}
for (i = 0; i < touch->max_fingers; ++i) {
SDL_free(touch->fingers[i]);
}
SDL_free(touch->fingers);
SDL_free(touch);
/* Delete this touch device for gestures */
}
SDL_Touch* SDL_GetTouch ( SDL_TouchID  id)

Definition at line 74 of file SDL_touch.c.

References NULL, SDL_VideoDevice::ResetTouch, SDL_GetTouchIndex(), SDL_GetVideoDevice(), SDL_num_touch, and SDL_SetError.

Referenced by SDL_DelTouch(), SDL_GetNumTouchFingers(), SDL_GetTouchFinger(), SDL_SendTouch(), and SDL_SendTouchMotion().

{
if (SDL_GetVideoDevice()->ResetTouch != NULL) {
SDL_SetError("Unknown touch id %d, resetting", (int) id);
} else {
SDL_SetError("Unknown touch device id %d, cannot reset", (int) id);
}
return NULL;
}
}
int SDL_SendTouch ( SDL_TouchID  id,
SDL_FingerID  fingerid,
SDL_bool  down,
float  x,
float  y,
float  pressure 
)

Definition at line 222 of file SDL_touch.c.

References SDL_AddFinger(), SDL_DelFinger(), SDL_ENABLE, SDL_FINGERDOWN, SDL_FINGERUP, SDL_GetEventState, SDL_GetFinger(), SDL_GetTouch(), SDL_PushEvent, SDL_Finger::x, and SDL_Finger::y.

Referenced by SDL_SendTouchMotion().

{
int posted;
SDL_Finger *finger;
SDL_Touch* touch = SDL_GetTouch(id);
if (!touch) {
return -1;
}
finger = SDL_GetFinger(touch, fingerid);
if (down) {
if (finger) {
/* This finger is already down */
return 0;
}
if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
return 0;
}
posted = 0;
event.tfinger.type = SDL_FINGERDOWN;
event.tfinger.touchId = id;
event.tfinger.fingerId = fingerid;
event.tfinger.x = x;
event.tfinger.y = y;
event.tfinger.dx = 0;
event.tfinger.dy = 0;
event.tfinger.pressure = pressure;
posted = (SDL_PushEvent(&event) > 0);
}
} else {
if (!finger) {
/* This finger is already up */
return 0;
}
posted = 0;
event.tfinger.type = SDL_FINGERUP;
event.tfinger.touchId = id;
event.tfinger.fingerId = fingerid;
/* I don't trust the coordinates passed on fingerUp */
event.tfinger.x = finger->x;
event.tfinger.y = finger->y;
event.tfinger.dx = 0;
event.tfinger.dy = 0;
event.tfinger.pressure = pressure;
posted = (SDL_PushEvent(&event) > 0);
}
SDL_DelFinger(touch, fingerid);
}
return posted;
}
int SDL_SendTouchMotion ( SDL_TouchID  id,
SDL_FingerID  fingerid,
float  x,
float  y,
float  pressure 
)

Definition at line 284 of file SDL_touch.c.

References SDL_Finger::pressure, SDL_ENABLE, SDL_FINGERMOTION, SDL_GetEventState, SDL_GetFinger(), SDL_GetTouch(), SDL_PushEvent, SDL_SendTouch(), SDL_TRUE, SDL_Finger::x, and SDL_Finger::y.

{
SDL_Touch *touch;
SDL_Finger *finger;
int posted;
float xrel, yrel, prel;
touch = SDL_GetTouch(id);
if (!touch) {
return -1;
}
finger = SDL_GetFinger(touch,fingerid);
if (!finger) {
return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);
}
xrel = x - finger->x;
yrel = y - finger->y;
prel = pressure - finger->pressure;
/* Drop events that don't change state */
if (!xrel && !yrel && !prel) {
#if 0
printf("Touch event didn't change state - dropped!\n");
#endif
return 0;
}
/* Update internal touch coordinates */
finger->x = x;
finger->y = y;
finger->pressure = pressure;
/* Post the event, if desired */
posted = 0;
event.tfinger.type = SDL_FINGERMOTION;
event.tfinger.touchId = id;
event.tfinger.fingerId = fingerid;
event.tfinger.x = x;
event.tfinger.y = y;
event.tfinger.dx = xrel;
event.tfinger.dy = yrel;
event.tfinger.pressure = pressure;
posted = (SDL_PushEvent(&event) > 0);
}
return posted;
}
int SDL_TouchInit ( void  )

Definition at line 37 of file SDL_touch.c.

Referenced by SDL_VideoInit().

{
return (0);
}
void SDL_TouchQuit ( void  )