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 154 of file SDL_touch.c.

155 {
156  SDL_Touch **touchDevices;
157  int index;
158 
159  index = SDL_GetTouchIndex(touchID);
160  if (index >= 0) {
161  return index;
162  }
163 
164  /* Add the touch to the list of touch */
165  touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
166  (SDL_num_touch + 1) * sizeof(*touchDevices));
167  if (!touchDevices) {
168  return SDL_OutOfMemory();
169  }
170 
171  SDL_touchDevices = touchDevices;
173 
175  if (!SDL_touchDevices[index]) {
176  return SDL_OutOfMemory();
177  }
178 
179  /* Added touch to list */
180  ++SDL_num_touch;
181 
182  /* we're setting the touch properties */
183  SDL_touchDevices[index]->id = touchID;
188 
189  /* Record this touch device for gestures */
190  /* We could do this on the fly in the gesture code if we wanted */
191  SDL_GestureAddTouch(touchID);
192 
193  return index;
194 }
#define SDL_malloc
#define SDL_realloc
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
int SDL_GestureAddTouch(SDL_TouchID touchId)
Definition: SDL_gesture.c:454
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
GLuint index
static SDL_Touch ** SDL_touchDevices
Definition: SDL_touch.c:31
static int SDL_GetTouchIndex(SDL_TouchID id)
Definition: SDL_touch.c:67
static int SDL_num_touch
Definition: SDL_touch.c:30
#define NULL
Definition: begin_code.h:163
int max_fingers
Definition: SDL_touch_c.h:32
SDL_Finger ** fingers
Definition: SDL_touch_c.h:33
SDL_TouchID id
Definition: SDL_touch_c.h:29
SDL_TouchDeviceType type
Definition: SDL_touch_c.h:30
int num_fingers
Definition: SDL_touch_c.h:31

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 440 of file SDL_touch.c.

441 {
442  int i;
443  int index = SDL_GetTouchIndex(id);
444  SDL_Touch *touch = SDL_GetTouch(id);
445 
446  if (!touch) {
447  return;
448  }
449 
450  for (i = 0; i < touch->max_fingers; ++i) {
451  SDL_free(touch->fingers[i]);
452  }
453  SDL_free(touch->fingers);
454  SDL_free(touch);
455 
456  SDL_num_touch--;
458 
459  /* Delete this touch device for gestures */
461 }
#define SDL_free
int SDL_GestureDelTouch(SDL_TouchID touchId)
Definition: SDL_gesture.c:472
SDL_Touch * SDL_GetTouch(SDL_TouchID id)
Definition: SDL_touch.c:82
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

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 82 of file SDL_touch.c.

83 {
84  int index = SDL_GetTouchIndex(id);
86  if (SDL_GetVideoDevice()->ResetTouch != NULL) {
87  SDL_SetError("Unknown touch id %d, resetting", (int) id);
89  } else {
90  SDL_SetError("Unknown touch device id %d, cannot reset", (int) id);
91  }
92  return NULL;
93  }
94  return SDL_touchDevices[index];
95 }
#define SDL_SetError
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:587
void(* ResetTouch)(_THIS)
Definition: SDL_sysvideo.h:173

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 241 of file SDL_touch.c.

243 {
244  int posted;
245  SDL_Finger *finger;
246  SDL_Mouse *mouse;
247 
248  SDL_Touch* touch = SDL_GetTouch(id);
249  if (!touch) {
250  return -1;
251  }
252 
253  mouse = SDL_GetMouse();
254 
255 #if SYNTHESIZE_TOUCH_TO_MOUSE
256  /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
257  {
258  if (mouse->touch_mouse_events) {
259  /* FIXME: maybe we should only restrict to a few SDL_TouchDeviceType */
260  if (id != SDL_MOUSE_TOUCHID) {
261  if (window) {
262  if (down) {
263  if (finger_touching == SDL_FALSE) {
264  int pos_x = (int)(x * (float)window->w);
265  int pos_y = (int)(y * (float)window->h);
266  if (pos_x < 0) pos_x = 0;
267  if (pos_x > window->w - 1) pos_x = window->w - 1;
268  if (pos_y < 0) pos_y = 0;
269  if (pos_y > window->h - 1) pos_y = window->h - 1;
270  SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
272  }
273  } else {
274  if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
276  }
277  }
278  }
279  if (down) {
280  if (finger_touching == SDL_FALSE) {
282  track_touchid = id;
283  track_fingerid = fingerid;
284  }
285  } else {
286  if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
288  }
289  }
290  }
291  }
292  }
293 #endif
294 
295  /* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
296  if (mouse->mouse_touch_events == 0) {
297  if (id == SDL_MOUSE_TOUCHID) {
298  return 0;
299  }
300  }
301 
302  finger = SDL_GetFinger(touch, fingerid);
303  if (down) {
304  if (finger) {
305  /* This finger is already down */
306  return 0;
307  }
308 
309  if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
310  return 0;
311  }
312 
313  posted = 0;
316  event.tfinger.type = SDL_FINGERDOWN;
317  event.tfinger.touchId = id;
318  event.tfinger.fingerId = fingerid;
319  event.tfinger.x = x;
320  event.tfinger.y = y;
321  event.tfinger.dx = 0;
322  event.tfinger.dy = 0;
323  event.tfinger.pressure = pressure;
324  event.tfinger.windowID = window ? SDL_GetWindowID(window) : 0;
325  posted = (SDL_PushEvent(&event) > 0);
326  }
327  } else {
328  if (!finger) {
329  /* This finger is already up */
330  return 0;
331  }
332 
333  posted = 0;
336  event.tfinger.type = SDL_FINGERUP;
337  event.tfinger.touchId = id;
338  event.tfinger.fingerId = fingerid;
339  /* I don't trust the coordinates passed on fingerUp */
340  event.tfinger.x = finger->x;
341  event.tfinger.y = finger->y;
342  event.tfinger.dx = 0;
343  event.tfinger.dy = 0;
344  event.tfinger.pressure = pressure;
345  event.tfinger.windowID = window ? SDL_GetWindowID(window) : 0;
346  posted = (SDL_PushEvent(&event) > 0);
347  }
348 
349  SDL_DelFinger(touch, fingerid);
350  }
351  return posted;
352 }
#define SDL_PushEvent
#define SDL_GetWindowID
@ SDL_FINGERUP
Definition: SDL_events.h:135
@ SDL_FINGERDOWN
Definition: SDL_events.h:134
#define SDL_GetEventState(type)
Definition: SDL_events.h:808
#define SDL_RELEASED
Definition: SDL_events.h:49
#define SDL_ENABLE
Definition: SDL_events.h:795
#define SDL_PRESSED
Definition: SDL_events.h:50
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
Definition: SDL_mouse.c:599
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:175
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:298
#define SDL_BUTTON_LEFT
Definition: SDL_mouse.h:282
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
struct _cl_event * event
GLuint id
@ SDL_TRUE
Definition: SDL_stdinc.h:170
@ SDL_FALSE
Definition: SDL_stdinc.h:169
static int SDL_DelFinger(SDL_Touch *touch, SDL_FingerID fingerid)
Definition: SDL_touch.c:224
static SDL_TouchID track_touchid
Definition: SDL_touch.c:40
static SDL_FingerID track_fingerid
Definition: SDL_touch.c:39
static int SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure)
Definition: SDL_touch.c:197
static SDL_bool finger_touching
Definition: SDL_touch.c:38
static SDL_Finger * SDL_GetFinger(const SDL_Touch *touch, SDL_FingerID id)
Definition: SDL_touch.c:120
#define SDL_MOUSE_TOUCHID
Definition: SDL_touch.h:64
#define SDL_TOUCH_MOUSEID
Definition: SDL_touch.h:61
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
float y
Definition: SDL_touch.h:56
float x
Definition: SDL_touch.h:55
SDL_bool touch_mouse_events
Definition: SDL_mouse_c.h:95
SDL_bool mouse_touch_events
Definition: SDL_mouse_c.h:96
General event structure.
Definition: SDL_events.h:592
typedef int(__stdcall *FARPROC)()

References finger_touching, int(), 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 355 of file SDL_touch.c.

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

References finger_touching, int(), 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 45 of file SDL_touch.c.

46 {
47  return (0);
48 }

Referenced by SDL_VideoInit().

◆ SDL_TouchQuit()

void SDL_TouchQuit ( void  )

Definition at line 464 of file SDL_touch.c.

465 {
466  int i;
467 
468  for (i = SDL_num_touch; i--; ) {
470  }
472 
475  SDL_GestureQuit();
476 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
void SDL_GestureQuit()
Definition: SDL_gesture.c:106
void SDL_DelTouch(SDL_TouchID id)
Definition: SDL_touch.c:440

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

Referenced by SDL_VideoQuit().