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, SDL_TouchDeviceType type, const char *name)
 
SDL_TouchSDL_GetTouch (SDL_TouchID id)
 
int SDL_SendTouch (SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, SDL_bool down, float x, float y, float pressure)
 
int SDL_SendTouchMotion (SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, 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,
SDL_TouchDeviceType  type,
const char *  name 
)

Definition at line 155 of file SDL_touch.c.

156 {
157  SDL_Touch **touchDevices;
158  int index;
159 
160  index = SDL_GetTouchIndex(touchID);
161  if (index >= 0) {
162  return index;
163  }
164 
165  /* Add the touch to the list of touch */
166  touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
167  (SDL_num_touch + 1) * sizeof(*touchDevices));
168  if (!touchDevices) {
169  return SDL_OutOfMemory();
170  }
171 
172  SDL_touchDevices = touchDevices;
174 
176  if (!SDL_touchDevices[index]) {
177  return SDL_OutOfMemory();
178  }
179 
180  /* Added touch to list */
181  ++SDL_num_touch;
182 
183  /* we're setting the touch properties */
184  SDL_touchDevices[index]->id = touchID;
189 
190  /* Record this touch device for gestures */
191  /* We could do this on the fly in the gesture code if we wanted */
192  SDL_GestureAddTouch(touchID);
193 
194  return index;
195 }

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, SDL_realloc, SDL_touchDevices, and SDL_Touch::type.

Referenced by SDL_MouseTouchEventsChanged().

◆ SDL_DelTouch()

void SDL_DelTouch ( SDL_TouchID  id)

Definition at line 441 of file SDL_touch.c.

442 {
443  int i;
444  int index = SDL_GetTouchIndex(id);
445  SDL_Touch *touch = SDL_GetTouch(id);
446 
447  if (!touch) {
448  return;
449  }
450 
451  for (i = 0; i < touch->max_fingers; ++i) {
452  SDL_free(touch->fingers[i]);
453  }
454  SDL_free(touch->fingers);
455  SDL_free(touch);
456 
457  SDL_num_touch--;
459 
460  /* Delete this touch device for gestures */
462 }

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

Referenced by SDL_TouchQuit().

◆ SDL_GetTouch()

SDL_Touch* SDL_GetTouch ( SDL_TouchID  id)

Definition at line 83 of file SDL_touch.c.

84 {
85  int index = SDL_GetTouchIndex(id);
87  if (SDL_GetVideoDevice()->ResetTouch != NULL) {
88  SDL_SetError("Unknown touch id %d, resetting", (int) id);
90  } else {
91  SDL_SetError("Unknown touch device id %d, cannot reset", (int) id);
92  }
93  return NULL;
94  }
95  return SDL_touchDevices[index];
96 }

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

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

◆ SDL_SendTouch()

int SDL_SendTouch ( SDL_TouchID  id,
SDL_FingerID  fingerid,
SDL_Window window,
SDL_bool  down,
float  x,
float  y,
float  pressure 
)

Definition at line 242 of file SDL_touch.c.

244 {
245  int posted;
246  SDL_Finger *finger;
247  SDL_Mouse *mouse;
248 
249  SDL_Touch* touch = SDL_GetTouch(id);
250  if (!touch) {
251  return -1;
252  }
253 
254  mouse = SDL_GetMouse();
255 
256 #if SYNTHESIZE_TOUCH_TO_MOUSE
257  /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
258  {
259  if (mouse->touch_mouse_events) {
260  /* FIXME: maybe we should only restrict to a few SDL_TouchDeviceType */
261  if (id != SDL_MOUSE_TOUCHID) {
262  if (window) {
263  if (down) {
264  if (finger_touching == SDL_FALSE) {
265  int pos_x = (int)(x * (float)window->w);
266  int pos_y = (int)(y * (float)window->h);
267  if (pos_x < 0) pos_x = 0;
268  if (pos_x > window->w - 1) pos_x = window->w - 1;
269  if (pos_y < 0) pos_y = 0;
270  if (pos_y > window->h - 1) pos_y = window->h - 1;
271  SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
273  }
274  } else {
275  if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
277  }
278  }
279  }
280  if (down) {
281  if (finger_touching == SDL_FALSE) {
283  track_touchid = id;
284  track_fingerid = fingerid;
285  }
286  } else {
287  if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
289  }
290  }
291  }
292  }
293  }
294 #endif
295 
296  /* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
297  if (mouse->mouse_touch_events == 0) {
298  if (id == SDL_MOUSE_TOUCHID) {
299  return 0;
300  }
301  }
302 
303  finger = SDL_GetFinger(touch, fingerid);
304  if (down) {
305  if (finger) {
306  /* This finger is already down */
307  return 0;
308  }
309 
310  if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
311  return 0;
312  }
313 
314  posted = 0;
317  event.tfinger.type = SDL_FINGERDOWN;
318  event.tfinger.touchId = id;
319  event.tfinger.fingerId = fingerid;
320  event.tfinger.x = x;
321  event.tfinger.y = y;
322  event.tfinger.dx = 0;
323  event.tfinger.dy = 0;
324  event.tfinger.pressure = pressure;
325  event.tfinger.windowID = window ? SDL_GetWindowID(window) : 0;
326  posted = (SDL_PushEvent(&event) > 0);
327  }
328  } else {
329  if (!finger) {
330  /* This finger is already up */
331  return 0;
332  }
333 
334  posted = 0;
337  event.tfinger.type = SDL_FINGERUP;
338  event.tfinger.touchId = id;
339  event.tfinger.fingerId = fingerid;
340  /* I don't trust the coordinates passed on fingerUp */
341  event.tfinger.x = finger->x;
342  event.tfinger.y = finger->y;
343  event.tfinger.dx = 0;
344  event.tfinger.dy = 0;
345  event.tfinger.pressure = pressure;
346  event.tfinger.windowID = window ? SDL_GetWindowID(window) : 0;
347  posted = (SDL_PushEvent(&event) > 0);
348  }
349 
350  SDL_DelFinger(touch, fingerid);
351  }
352  return posted;
353 }

References finger_touching, SDL_Mouse::mouse_touch_events, SDL_AddFinger(), SDL_BUTTON_LEFT, SDL_DelFinger(), SDL_ENABLE, SDL_FALSE, SDL_FINGERDOWN, SDL_FINGERUP, SDL_GetEventState, SDL_GetFinger(), SDL_GetMouse(), SDL_GetTouch(), SDL_GetWindowID, SDL_MOUSE_TOUCHID, SDL_PRESSED, SDL_PushEvent, SDL_RELEASED, SDL_SendMouseButton(), SDL_SendMouseMotion(), SDL_TOUCH_MOUSEID, SDL_TRUE, SDL_Mouse::touch_mouse_events, track_fingerid, track_touchid, SDL_Finger::x, and SDL_Finger::y.

Referenced by SDL_PrivateSendMouseButton(), and SDL_SendTouchMotion().

◆ SDL_SendTouchMotion()

int SDL_SendTouchMotion ( SDL_TouchID  id,
SDL_FingerID  fingerid,
SDL_Window window,
float  x,
float  y,
float  pressure 
)

Definition at line 356 of file SDL_touch.c.

358 {
359  SDL_Touch *touch;
360  SDL_Finger *finger;
361  SDL_Mouse *mouse;
362  int posted;
363  float xrel, yrel, prel;
364 
365  touch = SDL_GetTouch(id);
366  if (!touch) {
367  return -1;
368  }
369 
370  mouse = SDL_GetMouse();
371 
372 #if SYNTHESIZE_TOUCH_TO_MOUSE
373  /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
374  {
375  if (mouse->touch_mouse_events) {
376  if (id != SDL_MOUSE_TOUCHID) {
377  if (window) {
378  if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
379  int pos_x = (int)(x * (float)window->w);
380  int pos_y = (int)(y * (float)window->h);
381  if (pos_x < 0) pos_x = 0;
382  if (pos_x > window->w - 1) pos_x = window->w - 1;
383  if (pos_y < 0) pos_y = 0;
384  if (pos_y > window->h - 1) pos_y = window->h - 1;
385  SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
386  }
387  }
388  }
389  }
390  }
391 #endif
392 
393  /* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
394  if (mouse->mouse_touch_events == 0) {
395  if (id == SDL_MOUSE_TOUCHID) {
396  return 0;
397  }
398  }
399 
400  finger = SDL_GetFinger(touch,fingerid);
401  if (!finger) {
402  return SDL_SendTouch(id, fingerid, window, SDL_TRUE, x, y, pressure);
403  }
404 
405  xrel = x - finger->x;
406  yrel = y - finger->y;
407  prel = pressure - finger->pressure;
408 
409  /* Drop events that don't change state */
410  if (xrel == 0.0f && yrel == 0.0f && prel == 0.0f) {
411 #if 0
412  printf("Touch event didn't change state - dropped!\n");
413 #endif
414  return 0;
415  }
416 
417  /* Update internal touch coordinates */
418  finger->x = x;
419  finger->y = y;
420  finger->pressure = pressure;
421 
422  /* Post the event, if desired */
423  posted = 0;
426  event.tfinger.type = SDL_FINGERMOTION;
427  event.tfinger.touchId = id;
428  event.tfinger.fingerId = fingerid;
429  event.tfinger.x = x;
430  event.tfinger.y = y;
431  event.tfinger.dx = xrel;
432  event.tfinger.dy = yrel;
433  event.tfinger.pressure = pressure;
434  event.tfinger.windowID = window ? SDL_GetWindowID(window) : 0;
435  posted = (SDL_PushEvent(&event) > 0);
436  }
437  return posted;
438 }

References finger_touching, SDL_Mouse::mouse_touch_events, SDL_Finger::pressure, SDL_ENABLE, SDL_FINGERMOTION, SDL_GetEventState, SDL_GetFinger(), SDL_GetMouse(), SDL_GetTouch(), SDL_GetWindowID, SDL_MOUSE_TOUCHID, SDL_PushEvent, SDL_SendMouseMotion(), SDL_SendTouch(), SDL_TOUCH_MOUSEID, SDL_TRUE, SDL_Mouse::touch_mouse_events, track_fingerid, track_touchid, SDL_Finger::x, and SDL_Finger::y.

Referenced by SDL_PrivateSendMouseMotion().

◆ SDL_TouchInit()

int SDL_TouchInit ( void  )

Definition at line 46 of file SDL_touch.c.

47 {
48  return (0);
49 }

Referenced by SDL_VideoInit().

◆ SDL_TouchQuit()

void SDL_TouchQuit ( void  )

Definition at line 465 of file SDL_touch.c.

466 {
467  int i;
468 
469  for (i = SDL_num_touch; i--; ) {
471  }
473 
476  SDL_GestureQuit();
477 }

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

Referenced by SDL_VideoQuit().

SDL_num_touch
static int SDL_num_touch
Definition: SDL_touch.c:31
SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:170
NULL
#define NULL
Definition: begin_code.h:167
SDL_Mouse::touch_mouse_events
SDL_bool touch_mouse_events
Definition: SDL_mouse_c.h:95
SDL_GetWindowID
#define SDL_GetWindowID
Definition: SDL_dynapi_overrides.h:516
track_fingerid
static SDL_FingerID track_fingerid
Definition: SDL_touch.c:40
SDL_SendTouch
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, SDL_bool down, float x, float y, float pressure)
Definition: SDL_touch.c:242
SDL_realloc
#define SDL_realloc
Definition: SDL_dynapi_overrides.h:376
finger_touching
static SDL_bool finger_touching
Definition: SDL_touch.c:39
SDL_GetFinger
static SDL_Finger * SDL_GetFinger(const SDL_Touch *touch, SDL_FingerID id)
Definition: SDL_touch.c:121
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:760
SDL_DelFinger
static int SDL_DelFinger(SDL_Touch *touch, SDL_FingerID fingerid)
Definition: SDL_touch.c:225
SDL_VideoDevice::ResetTouch
void(* ResetTouch)(_THIS)
Definition: SDL_sysvideo.h:173
index
GLuint index
Definition: SDL_opengl_glext.h:663
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_Finger
Definition: SDL_touch.h:53
SDL_TOUCH_MOUSEID
#define SDL_TOUCH_MOUSEID
Definition: SDL_touch.h:61
track_touchid
static SDL_TouchID track_touchid
Definition: SDL_touch.c:41
SDL_FINGERUP
@ SDL_FINGERUP
Definition: SDL_events.h:129
SDL_GetTouchIndex
static int SDL_GetTouchIndex(SDL_TouchID id)
Definition: SDL_touch.c:68
SDL_Mouse::mouse_touch_events
SDL_bool mouse_touch_events
Definition: SDL_mouse_c.h:96
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2652
SDL_FINGERDOWN
@ SDL_FINGERDOWN
Definition: SDL_events.h:128
SDL_BUTTON_LEFT
#define SDL_BUTTON_LEFT
Definition: SDL_mouse.h:282
SDL_GestureQuit
void SDL_GestureQuit()
Definition: SDL_gesture.c:106
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:773
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_SendMouseMotion
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:293
SDL_GestureDelTouch
int SDL_GestureDelTouch(SDL_TouchID touchId)
Definition: SDL_gesture.c:472
SDL_FINGERMOTION
@ SDL_FINGERMOTION
Definition: SDL_events.h:130
SDL_Touch::num_fingers
int num_fingers
Definition: SDL_touch_c.h:31
SDL_Mouse
Definition: SDL_mouse_c.h:44
SDL_Touch::fingers
SDL_Finger ** fingers
Definition: SDL_touch_c.h:33
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_DelTouch
void SDL_DelTouch(SDL_TouchID id)
Definition: SDL_touch.c:441
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
SDL_AddFinger
static int SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure)
Definition: SDL_touch.c:198
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_GestureAddTouch
int SDL_GestureAddTouch(SDL_TouchID touchId)
Definition: SDL_gesture.c:454
id
GLuint id
Definition: SDL_opengl_glext.h:531
SDL_MOUSE_TOUCHID
#define SDL_MOUSE_TOUCHID
Definition: SDL_touch.h:64
SDL_Touch
Definition: SDL_touch_c.h:28
SDL_Touch::max_fingers
int max_fingers
Definition: SDL_touch_c.h:32
SDL_Touch::id
SDL_TouchID id
Definition: SDL_touch_c.h:29
SDL_Finger::y
float y
Definition: SDL_touch.h:56
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_Finger::pressure
float pressure
Definition: SDL_touch.h:57
SDL_touchDevices
static SDL_Touch ** SDL_touchDevices
Definition: SDL_touch.c:32
SDL_Event
General event structure.
Definition: SDL_events.h:559
SDL_GetVideoDevice
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:586
SDL_Finger::x
float x
Definition: SDL_touch.h:55
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_Touch::type
SDL_TouchDeviceType type
Definition: SDL_touch_c.h:30
type
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
i
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
SDL_SendMouseButton
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
Definition: SDL_mouse.c:594
SDL_GetTouch
SDL_Touch * SDL_GetTouch(SDL_TouchID id)
Definition: SDL_touch.c:83