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

◆ SDL_AddTouch()

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.

137 {
138  SDL_Touch **touchDevices;
139  int index;
140 
141  index = SDL_GetTouchIndex(touchID);
142  if (index >= 0) {
143  return index;
144  }
145 
146  /* Add the touch to the list of touch */
147  touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
148  (SDL_num_touch + 1) * sizeof(*touchDevices));
149  if (!touchDevices) {
150  return SDL_OutOfMemory();
151  }
152 
153  SDL_touchDevices = touchDevices;
154  index = SDL_num_touch;
155 
157  if (!SDL_touchDevices[index]) {
158  return SDL_OutOfMemory();
159  }
160 
161  /* Added touch to list */
162  ++SDL_num_touch;
163 
164  /* we're setting the touch properties */
165  SDL_touchDevices[index]->id = touchID;
169 
170  /* Record this touch device for gestures */
171  /* We could do this on the fly in the gesture code if we wanted */
172  SDL_GestureAddTouch(touchID);
173 
174  return index;
175 }
static int SDL_num_touch
Definition: SDL_touch.c:31
int max_fingers
Definition: SDL_touch_c.h:31
SDL_Finger ** fingers
Definition: SDL_touch_c.h:32
#define SDL_realloc
SDL_TouchID id
Definition: SDL_touch_c.h:29
static int SDL_GetTouchIndex(SDL_TouchID id)
Definition: SDL_touch.c:59
int SDL_GestureAddTouch(SDL_TouchID touchId)
Definition: SDL_gesture.c:448
GLuint index
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
int num_fingers
Definition: SDL_touch_c.h:30
#define SDL_malloc
static SDL_Touch ** SDL_touchDevices
Definition: SDL_touch.c:32

◆ SDL_DelTouch()

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().

338 {
339  int i;
340  int index = SDL_GetTouchIndex(id);
341  SDL_Touch *touch = SDL_GetTouch(id);
342 
343  if (!touch) {
344  return;
345  }
346 
347  for (i = 0; i < touch->max_fingers; ++i) {
348  SDL_free(touch->fingers[i]);
349  }
350  SDL_free(touch->fingers);
351  SDL_free(touch);
352 
353  SDL_num_touch--;
355 
356  /* Delete this touch device for gestures */
358 }
static int SDL_num_touch
Definition: SDL_touch.c:31
int max_fingers
Definition: SDL_touch_c.h:31
int SDL_GestureDelTouch(SDL_TouchID touchId)
Definition: SDL_gesture.c:466
SDL_Finger ** fingers
Definition: SDL_touch_c.h:32
static int SDL_GetTouchIndex(SDL_TouchID id)
Definition: SDL_touch.c:59
#define SDL_free
GLuint index
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
static SDL_Touch ** SDL_touchDevices
Definition: SDL_touch.c:32
SDL_Touch * SDL_GetTouch(SDL_TouchID id)
Definition: SDL_touch.c:74

◆ SDL_GetTouch()

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().

75 {
76  int index = SDL_GetTouchIndex(id);
78  if (SDL_GetVideoDevice()->ResetTouch != NULL) {
79  SDL_SetError("Unknown touch id %d, resetting", (int) id);
81  } else {
82  SDL_SetError("Unknown touch device id %d, cannot reset", (int) id);
83  }
84  return NULL;
85  }
86  return SDL_touchDevices[index];
87 }
static int SDL_num_touch
Definition: SDL_touch.c:31
static int SDL_GetTouchIndex(SDL_TouchID id)
Definition: SDL_touch.c:59
GLuint index
void(* ResetTouch)(_THIS)
Definition: SDL_sysvideo.h:171
#define NULL
Definition: begin_code.h:164
#define SDL_SetError
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:586
static SDL_Touch ** SDL_touchDevices
Definition: SDL_touch.c:32

◆ SDL_SendTouch()

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().

224 {
225  int posted;
226  SDL_Finger *finger;
227 
228  SDL_Touch* touch = SDL_GetTouch(id);
229  if (!touch) {
230  return -1;
231  }
232 
233  finger = SDL_GetFinger(touch, fingerid);
234  if (down) {
235  if (finger) {
236  /* This finger is already down */
237  return 0;
238  }
239 
240  if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
241  return 0;
242  }
243 
244  posted = 0;
247  event.tfinger.type = SDL_FINGERDOWN;
248  event.tfinger.touchId = id;
249  event.tfinger.fingerId = fingerid;
250  event.tfinger.x = x;
251  event.tfinger.y = y;
252  event.tfinger.dx = 0;
253  event.tfinger.dy = 0;
254  event.tfinger.pressure = pressure;
255  posted = (SDL_PushEvent(&event) > 0);
256  }
257  } else {
258  if (!finger) {
259  /* This finger is already up */
260  return 0;
261  }
262 
263  posted = 0;
266  event.tfinger.type = SDL_FINGERUP;
267  event.tfinger.touchId = id;
268  event.tfinger.fingerId = fingerid;
269  /* I don't trust the coordinates passed on fingerUp */
270  event.tfinger.x = finger->x;
271  event.tfinger.y = finger->y;
272  event.tfinger.dx = 0;
273  event.tfinger.dy = 0;
274  event.tfinger.pressure = pressure;
275  posted = (SDL_PushEvent(&event) > 0);
276  }
277 
278  SDL_DelFinger(touch, fingerid);
279  }
280  return posted;
281 }
GLuint id
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
static int SDL_DelFinger(SDL_Touch *touch, SDL_FingerID fingerid)
Definition: SDL_touch.c:205
static SDL_Finger * SDL_GetFinger(const SDL_Touch *touch, SDL_FingerID id)
Definition: SDL_touch.c:102
#define SDL_ENABLE
Definition: SDL_events.h:722
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
static int SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure)
Definition: SDL_touch.c:178
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
float y
Definition: SDL_touch.h:48
General event structure.
Definition: SDL_events.h:525
SDL_Touch * SDL_GetTouch(SDL_TouchID id)
Definition: SDL_touch.c:74
float x
Definition: SDL_touch.h:47

◆ SDL_SendTouchMotion()

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.

286 {
287  SDL_Touch *touch;
288  SDL_Finger *finger;
289  int posted;
290  float xrel, yrel, prel;
291 
292  touch = SDL_GetTouch(id);
293  if (!touch) {
294  return -1;
295  }
296 
297  finger = SDL_GetFinger(touch,fingerid);
298  if (!finger) {
299  return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);
300  }
301 
302  xrel = x - finger->x;
303  yrel = y - finger->y;
304  prel = pressure - finger->pressure;
305 
306  /* Drop events that don't change state */
307  if (!xrel && !yrel && !prel) {
308 #if 0
309  printf("Touch event didn't change state - dropped!\n");
310 #endif
311  return 0;
312  }
313 
314  /* Update internal touch coordinates */
315  finger->x = x;
316  finger->y = y;
317  finger->pressure = pressure;
318 
319  /* Post the event, if desired */
320  posted = 0;
323  event.tfinger.type = SDL_FINGERMOTION;
324  event.tfinger.touchId = id;
325  event.tfinger.fingerId = fingerid;
326  event.tfinger.x = x;
327  event.tfinger.y = y;
328  event.tfinger.dx = xrel;
329  event.tfinger.dy = yrel;
330  event.tfinger.pressure = pressure;
331  posted = (SDL_PushEvent(&event) > 0);
332  }
333  return posted;
334 }
GLuint id
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
Definition: SDL_touch.c:222
static SDL_Finger * SDL_GetFinger(const SDL_Touch *touch, SDL_FingerID id)
Definition: SDL_touch.c:102
#define SDL_ENABLE
Definition: SDL_events.h:722
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
struct _cl_event * event
#define SDL_PushEvent
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
float y
Definition: SDL_touch.h:48
General event structure.
Definition: SDL_events.h:525
float pressure
Definition: SDL_touch.h:49
SDL_Touch * SDL_GetTouch(SDL_TouchID id)
Definition: SDL_touch.c:74
float x
Definition: SDL_touch.h:47

◆ SDL_TouchInit()

int SDL_TouchInit ( void  )

Definition at line 37 of file SDL_touch.c.

Referenced by SDL_VideoInit().

38 {
39  return (0);
40 }

◆ SDL_TouchQuit()

void SDL_TouchQuit ( void  )

Definition at line 361 of file SDL_touch.c.

References i, NULL, SDL_assert, SDL_DelTouch(), SDL_free, SDL_GestureQuit(), and SDL_num_touch.

Referenced by SDL_VideoQuit().

362 {
363  int i;
364 
365  for (i = SDL_num_touch; i--; ) {
367  }
369 
372  SDL_GestureQuit();
373 }
static int SDL_num_touch
Definition: SDL_touch.c:31
void SDL_GestureQuit()
Definition: SDL_gesture.c:104
#define SDL_free
void SDL_DelTouch(SDL_TouchID id)
Definition: SDL_touch.c:337
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:164
static SDL_Touch ** SDL_touchDevices
Definition: SDL_touch.c:32