src/events/SDL_touch.c
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Wed, 17 Jul 2019 23:20:57 -0400
changeset 12950 05dddfb66b85
parent 12934 d03900e991a2
child 12979 bbbb30026158
permissions -rw-r--r--
Copypaste SDL_NSLog to UIKit backend, document it as such
jim@4640
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
jim@4640
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
jim@4640
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
jim@4640
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
jim@4640
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
jim@4640
    22
jim@4640
    23
/* General touch handling code for SDL */
jim@4640
    24
slouken@6951
    25
#include "SDL_assert.h"
jim@4640
    26
#include "SDL_events.h"
jim@4640
    27
#include "SDL_events_c.h"
slouken@10880
    28
#include "../video/SDL_sysvideo.h"
jimtla@4648
    29
jim@4640
    30
jim@4640
    31
static int SDL_num_touch = 0;
slouken@6951
    32
static SDL_Touch **SDL_touchDevices = NULL;
jim@4640
    33
sylvain@12676
    34
/* for mapping touch events to mice */
icculus@12855
    35
icculus@12855
    36
#define SYNTHESIZE_TOUCH_TO_MOUSE 1
icculus@12855
    37
icculus@12855
    38
#if SYNTHESIZE_TOUCH_TO_MOUSE
sylvain@12676
    39
static SDL_bool finger_touching = SDL_FALSE;
sylvain@12687
    40
static SDL_FingerID track_fingerid;
sylvain@12687
    41
static SDL_TouchID  track_touchid;
icculus@12855
    42
#endif
jim@4640
    43
jim@4640
    44
/* Public functions */
jim@4640
    45
int
jim@4640
    46
SDL_TouchInit(void)
jim@4640
    47
{
slouken@6951
    48
    return (0);
jim@4640
    49
}
jim@4642
    50
slouken@6951
    51
int
philipp@7170
    52
SDL_GetNumTouchDevices(void)
jim@4640
    53
{
slouken@6951
    54
    return SDL_num_touch;
jim@4640
    55
}
jim@4640
    56
slouken@6951
    57
SDL_TouchID
slouken@6951
    58
SDL_GetTouchDevice(int index)
jim@4641
    59
{
jim@4642
    60
    if (index < 0 || index >= SDL_num_touch) {
slouken@10880
    61
        SDL_SetError("Unknown touch device index %d", index);
slouken@6951
    62
        return 0;
jim@4642
    63
    }
slouken@6951
    64
    return SDL_touchDevices[index]->id;
jim@4641
    65
}
jim@4641
    66
slouken@6044
    67
static int
slouken@6951
    68
SDL_GetTouchIndex(SDL_TouchID id)
jim@4640
    69
{
jim@4640
    70
    int index;
jim@4640
    71
    SDL_Touch *touch;
jim@4640
    72
jim@4640
    73
    for (index = 0; index < SDL_num_touch; ++index) {
slouken@6951
    74
        touch = SDL_touchDevices[index];
jim@4640
    75
        if (touch->id == id) {
jim@4640
    76
            return index;
jim@4640
    77
        }
jim@4640
    78
    }
jim@4640
    79
    return -1;
jim@4640
    80
}
jim@4640
    81
slouken@6951
    82
SDL_Touch *
slouken@6951
    83
SDL_GetTouch(SDL_TouchID id)
slouken@6951
    84
{
slouken@6951
    85
    int index = SDL_GetTouchIndex(id);
slouken@6951
    86
    if (index < 0 || index >= SDL_num_touch) {
slouken@10880
    87
        if (SDL_GetVideoDevice()->ResetTouch != NULL) {
slouken@10880
    88
            SDL_SetError("Unknown touch id %d, resetting", (int) id);
slouken@10880
    89
            (SDL_GetVideoDevice()->ResetTouch)(SDL_GetVideoDevice());
slouken@10880
    90
        } else {
slouken@10880
    91
            SDL_SetError("Unknown touch device id %d, cannot reset", (int) id);
slouken@10880
    92
        }
slouken@6951
    93
        return NULL;
slouken@6951
    94
    }
slouken@6951
    95
    return SDL_touchDevices[index];
slouken@6951
    96
}
slouken@6951
    97
slime73@12404
    98
SDL_TouchDeviceType
slime73@12404
    99
SDL_GetTouchDeviceType(SDL_TouchID id)
slime73@12404
   100
{
slime73@12404
   101
    SDL_Touch *touch = SDL_GetTouch(id);
slime73@12404
   102
    if (touch) {
slime73@12404
   103
        return touch->type;
slime73@12404
   104
    }
slime73@12404
   105
    return SDL_TOUCH_DEVICE_INVALID;
slime73@12404
   106
}
slime73@12404
   107
slouken@6951
   108
static int
slouken@6951
   109
SDL_GetFingerIndex(const SDL_Touch * touch, SDL_FingerID fingerid)
slouken@6951
   110
{
slouken@6951
   111
    int index;
slouken@6951
   112
    for (index = 0; index < touch->num_fingers; ++index) {
slouken@6951
   113
        if (touch->fingers[index]->id == fingerid) {
slouken@6951
   114
            return index;
slouken@6951
   115
        }
slouken@6951
   116
    }
slouken@6951
   117
    return -1;
slouken@6951
   118
}
slouken@6951
   119
slouken@10609
   120
static SDL_Finger *
slouken@6951
   121
SDL_GetFinger(const SDL_Touch * touch, SDL_FingerID id)
slouken@6951
   122
{
slouken@6951
   123
    int index = SDL_GetFingerIndex(touch, id);
slouken@6951
   124
    if (index < 0 || index >= touch->num_fingers) {
slouken@6951
   125
        return NULL;
slouken@6951
   126
    }
slouken@6951
   127
    return touch->fingers[index];
slouken@6951
   128
}
slouken@6951
   129
jim@4640
   130
int
slouken@6951
   131
SDL_GetNumTouchFingers(SDL_TouchID touchID)
jim@4640
   132
{
slouken@6951
   133
    SDL_Touch *touch = SDL_GetTouch(touchID);
slouken@6951
   134
    if (touch) {
slouken@6951
   135
        return touch->num_fingers;
slouken@6951
   136
    }
slouken@6951
   137
    return 0;
slouken@6951
   138
}
slouken@6951
   139
slouken@6951
   140
SDL_Finger *
slouken@6951
   141
SDL_GetTouchFinger(SDL_TouchID touchID, int index)
slouken@6951
   142
{
slouken@6951
   143
    SDL_Touch *touch = SDL_GetTouch(touchID);
slouken@6951
   144
    if (!touch) {
slouken@6951
   145
        return NULL;
slouken@6951
   146
    }
slouken@6951
   147
    if (index < 0 || index >= touch->num_fingers) {
slouken@6951
   148
        SDL_SetError("Unknown touch finger");
slouken@6951
   149
        return NULL;
slouken@6951
   150
    }
slouken@6951
   151
    return touch->fingers[index];
slouken@6951
   152
}
slouken@6951
   153
slouken@6951
   154
int
slime73@12404
   155
SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
slouken@6951
   156
{
slouken@6951
   157
    SDL_Touch **touchDevices;
slouken@5076
   158
    int index;
jim@4640
   159
slouken@6951
   160
    index = SDL_GetTouchIndex(touchID);
slouken@6951
   161
    if (index >= 0) {
slouken@6951
   162
        return index;
jim@4640
   163
    }
jim@4640
   164
jim@4640
   165
    /* Add the touch to the list of touch */
slouken@6951
   166
    touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
slouken@6951
   167
                                      (SDL_num_touch + 1) * sizeof(*touchDevices));
slouken@6951
   168
    if (!touchDevices) {
icculus@7037
   169
        return SDL_OutOfMemory();
jim@4640
   170
    }
jim@4640
   171
slouken@6951
   172
    SDL_touchDevices = touchDevices;
philipp@9730
   173
    index = SDL_num_touch;
jim@4640
   174
slouken@6951
   175
    SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index]));
slouken@6951
   176
    if (!SDL_touchDevices[index]) {
icculus@7037
   177
        return SDL_OutOfMemory();
jim@4640
   178
    }
jim@4640
   179
philipp@9730
   180
    /* Added touch to list */
philipp@9730
   181
    ++SDL_num_touch;
philipp@9730
   182
jim@4640
   183
    /* we're setting the touch properties */
slouken@6951
   184
    SDL_touchDevices[index]->id = touchID;
slime73@12404
   185
    SDL_touchDevices[index]->type = type;
slouken@6951
   186
    SDL_touchDevices[index]->num_fingers = 0;
slouken@6951
   187
    SDL_touchDevices[index]->max_fingers = 0;
slouken@6951
   188
    SDL_touchDevices[index]->fingers = NULL;
jim@4642
   189
slouken@6951
   190
    /* Record this touch device for gestures */
slouken@6951
   191
    /* We could do this on the fly in the gesture code if we wanted */
slouken@6951
   192
    SDL_GestureAddTouch(touchID);
jim@4657
   193
jim@4640
   194
    return index;
jim@4640
   195
}
jim@4640
   196
slouken@7191
   197
static int
slouken@6951
   198
SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure)
slouken@6951
   199
{
slouken@6951
   200
    SDL_Finger *finger;
slouken@6951
   201
slouken@6951
   202
    if (touch->num_fingers == touch->max_fingers) {
slouken@6951
   203
        SDL_Finger **new_fingers;
slouken@6951
   204
        new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers));
slouken@6951
   205
        if (!new_fingers) {
icculus@7037
   206
            return SDL_OutOfMemory();
slouken@6951
   207
        }
slouken@6951
   208
        touch->fingers = new_fingers;
slouken@6951
   209
        touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger));
slouken@6951
   210
        if (!touch->fingers[touch->max_fingers]) {
icculus@7037
   211
            return SDL_OutOfMemory();
slouken@6951
   212
        }
slouken@6951
   213
        touch->max_fingers++;
slouken@6951
   214
    }
slouken@6951
   215
slouken@6951
   216
    finger = touch->fingers[touch->num_fingers++];
slouken@6951
   217
    finger->id = fingerid;
slouken@6951
   218
    finger->x = x;
slouken@6951
   219
    finger->y = y;
slouken@6951
   220
    finger->pressure = pressure;
slouken@6951
   221
    return 0;
slouken@6951
   222
}
slouken@6951
   223
slouken@6951
   224
static int
slouken@6951
   225
SDL_DelFinger(SDL_Touch* touch, SDL_FingerID fingerid)
slouken@6951
   226
{
slouken@6951
   227
    SDL_Finger *temp;
slouken@6951
   228
slouken@6951
   229
    int index = SDL_GetFingerIndex(touch, fingerid);
slouken@6951
   230
    if (index < 0) {
slouken@6951
   231
        return -1;
slouken@6951
   232
    }
slouken@6951
   233
slouken@6951
   234
    touch->num_fingers--;
slouken@6951
   235
    temp = touch->fingers[index];
slouken@6951
   236
    touch->fingers[index] = touch->fingers[touch->num_fingers];
slouken@6951
   237
    touch->fingers[touch->num_fingers] = temp;
slouken@6951
   238
    return 0;
slouken@6951
   239
}
slouken@6951
   240
slouken@6951
   241
int
slouken@6951
   242
SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
slouken@6951
   243
              SDL_bool down, float x, float y, float pressure)
slouken@6951
   244
{
slouken@6951
   245
    int posted;
slouken@6951
   246
    SDL_Finger *finger;
sylvain@12934
   247
    SDL_Mouse *mouse;
slouken@6951
   248
slouken@6951
   249
    SDL_Touch* touch = SDL_GetTouch(id);
slouken@6951
   250
    if (!touch) {
slouken@6951
   251
        return -1;
slouken@6951
   252
    }
slouken@6951
   253
sylvain@12934
   254
    mouse = SDL_GetMouse();
sylvain@12934
   255
icculus@12855
   256
#if SYNTHESIZE_TOUCH_TO_MOUSE
sylvain@12687
   257
    /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
sylvain@12676
   258
    {
sylvain@12687
   259
        if (mouse->touch_mouse_events) {
sylvain@12688
   260
            /* FIXME: maybe we should only restrict to a few SDL_TouchDeviceType */
sylvain@12688
   261
            if (id != SDL_MOUSE_TOUCHID) {
sylvain@12688
   262
                SDL_Window *window = SDL_GetMouseFocus();
slime73@12867
   263
                if (window == NULL) {
slime73@12867
   264
                    /* Mouse focus may have been lost by e.g. the window resizing
slime73@12867
   265
                     * due to device orientation change while the mouse state is
slime73@12867
   266
                     * pressed (because its position is now out of the window).
slime73@12867
   267
                     * SendMouse* will update mouse focus again after that, but
slime73@12867
   268
                     * if those are never called then SDL might think the
slime73@12867
   269
                     * 'mouse' has no focus at all. */
slime73@12867
   270
                    window = SDL_GetKeyboardFocus();
slime73@12867
   271
                }
sylvain@12688
   272
                if (window) {
sylvain@12688
   273
                    if (down) {
sylvain@12688
   274
                        if (finger_touching == SDL_FALSE) {
sylvain@12688
   275
                            int pos_x = (int)(x * (float)window->w);
sylvain@12688
   276
                            int pos_y = (int)(y * (float)window->h);
sylvain@12701
   277
                            if (pos_x < 0) pos_x = 0;
sylvain@12701
   278
                            if (pos_x > window->w - 1) pos_x = window->w - 1;
sylvain@12701
   279
                            if (pos_y < 0) pos_y = 0;
sylvain@12701
   280
                            if (pos_y > window->h - 1) pos_y = window->h - 1;
sylvain@12701
   281
                            SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
sylvain@12701
   282
                            SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
sylvain@12688
   283
                        }
sylvain@12688
   284
                    } else {
sylvain@12688
   285
                        if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
sylvain@12701
   286
                            SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
sylvain@12688
   287
                        }
sylvain@12687
   288
                    }
sylvain@12676
   289
                }
sylvain@12697
   290
                if (down) {
sylvain@12697
   291
                    if (finger_touching == SDL_FALSE) {
sylvain@12697
   292
                        finger_touching = SDL_TRUE;
sylvain@12697
   293
                        track_touchid = id;
sylvain@12697
   294
                        track_fingerid = fingerid;
sylvain@12697
   295
                    }
sylvain@12697
   296
                } else {
sylvain@12697
   297
                    if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
sylvain@12697
   298
                        finger_touching = SDL_FALSE;
sylvain@12697
   299
                    }
sylvain@12697
   300
                }
sylvain@12676
   301
            }
sylvain@12676
   302
        }
sylvain@12676
   303
    }
icculus@12855
   304
#endif
sylvain@12676
   305
sylvain@12934
   306
    /* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
sylvain@12934
   307
    if (mouse->mouse_touch_events == 0) {
sylvain@12934
   308
        if (id == SDL_MOUSE_TOUCHID) {
sylvain@12934
   309
            return 0;
sylvain@12934
   310
        }
sylvain@12934
   311
    }
sylvain@12934
   312
slouken@6951
   313
    finger = SDL_GetFinger(touch, fingerid);
slouken@6951
   314
    if (down) {
slouken@6951
   315
        if (finger) {
slouken@6951
   316
            /* This finger is already down */
slouken@6951
   317
            return 0;
slouken@6951
   318
        }
slouken@6951
   319
slouken@6951
   320
        if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
slouken@6951
   321
            return 0;
slouken@6951
   322
        }
slouken@6951
   323
slouken@6951
   324
        posted = 0;
slouken@6951
   325
        if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
slouken@6951
   326
            SDL_Event event;
slouken@6951
   327
            event.tfinger.type = SDL_FINGERDOWN;
slouken@6951
   328
            event.tfinger.touchId = id;
slouken@6951
   329
            event.tfinger.fingerId = fingerid;
slouken@6951
   330
            event.tfinger.x = x;
slouken@6951
   331
            event.tfinger.y = y;
slouken@6951
   332
            event.tfinger.dx = 0;
slouken@6951
   333
            event.tfinger.dy = 0;
slouken@6951
   334
            event.tfinger.pressure = pressure;
slouken@6951
   335
            posted = (SDL_PushEvent(&event) > 0);
slouken@6951
   336
        }
slouken@6951
   337
    } else {
slouken@6951
   338
        if (!finger) {
slouken@6951
   339
            /* This finger is already up */
slouken@6951
   340
            return 0;
slouken@6951
   341
        }
slouken@6951
   342
slouken@6951
   343
        posted = 0;
slouken@6951
   344
        if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
slouken@6951
   345
            SDL_Event event;
slouken@6951
   346
            event.tfinger.type = SDL_FINGERUP;
slouken@6951
   347
            event.tfinger.touchId =  id;
slouken@6951
   348
            event.tfinger.fingerId = fingerid;
slouken@6951
   349
            /* I don't trust the coordinates passed on fingerUp */
slouken@7191
   350
            event.tfinger.x = finger->x;
slouken@6951
   351
            event.tfinger.y = finger->y;
slouken@6951
   352
            event.tfinger.dx = 0;
slouken@6951
   353
            event.tfinger.dy = 0;
slouken@6951
   354
            event.tfinger.pressure = pressure;
slouken@6951
   355
            posted = (SDL_PushEvent(&event) > 0);
slouken@6951
   356
        }
slouken@6951
   357
slouken@6951
   358
        SDL_DelFinger(touch, fingerid);
slouken@6951
   359
    }
slouken@6951
   360
    return posted;
slouken@6951
   361
}
slouken@6951
   362
slouken@6951
   363
int
slouken@6951
   364
SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
slouken@6951
   365
                    float x, float y, float pressure)
slouken@6951
   366
{
slouken@6951
   367
    SDL_Touch *touch;
slouken@6951
   368
    SDL_Finger *finger;
sylvain@12934
   369
    SDL_Mouse *mouse;
slouken@6951
   370
    int posted;
slouken@6951
   371
    float xrel, yrel, prel;
slouken@6951
   372
slouken@6951
   373
    touch = SDL_GetTouch(id);
slouken@6951
   374
    if (!touch) {
slouken@6951
   375
        return -1;
slouken@6951
   376
    }
slouken@6951
   377
sylvain@12934
   378
    mouse = SDL_GetMouse();
sylvain@12934
   379
icculus@12855
   380
#if SYNTHESIZE_TOUCH_TO_MOUSE
sylvain@12687
   381
    /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
sylvain@12676
   382
    {
sylvain@12687
   383
        if (mouse->touch_mouse_events) {
sylvain@12688
   384
            if (id != SDL_MOUSE_TOUCHID) {
sylvain@12688
   385
                SDL_Window *window = SDL_GetMouseFocus();
sylvain@12688
   386
                if (window) {
sylvain@12688
   387
                    if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
sylvain@12688
   388
                        int pos_x = (int)(x * (float)window->w);
sylvain@12688
   389
                        int pos_y = (int)(y * (float)window->h);
sylvain@12701
   390
                        if (pos_x < 0) pos_x = 0;
sylvain@12701
   391
                        if (pos_x > window->w - 1) pos_x = window->w - 1;
sylvain@12701
   392
                        if (pos_y < 0) pos_y = 0;
sylvain@12701
   393
                        if (pos_y > window->h - 1) pos_y = window->h - 1;
sylvain@12701
   394
                        SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
sylvain@12688
   395
                    }
sylvain@12687
   396
                }
sylvain@12676
   397
            }
sylvain@12676
   398
        }
sylvain@12676
   399
    }
icculus@12855
   400
#endif
sylvain@12676
   401
sylvain@12934
   402
    /* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
sylvain@12934
   403
    if (mouse->mouse_touch_events == 0) {
sylvain@12934
   404
        if (id == SDL_MOUSE_TOUCHID) {
sylvain@12934
   405
            return 0;
sylvain@12934
   406
        }
sylvain@12934
   407
    }
sylvain@12934
   408
slouken@6951
   409
    finger = SDL_GetFinger(touch,fingerid);
slouken@6951
   410
    if (!finger) {
slouken@7191
   411
        return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);
slouken@6951
   412
    }
slouken@6951
   413
slouken@6951
   414
    xrel = x - finger->x;
slouken@6951
   415
    yrel = y - finger->y;
slouken@6951
   416
    prel = pressure - finger->pressure;
slouken@6951
   417
slouken@6951
   418
    /* Drop events that don't change state */
slouken@12466
   419
    if (xrel == 0.0f && yrel == 0.0f && prel == 0.0f) {
slouken@6951
   420
#if 0
slouken@6951
   421
        printf("Touch event didn't change state - dropped!\n");
slouken@6951
   422
#endif
slouken@6951
   423
        return 0;
slouken@6951
   424
    }
slouken@6951
   425
slouken@6951
   426
    /* Update internal touch coordinates */
slouken@6951
   427
    finger->x = x;
slouken@6951
   428
    finger->y = y;
slouken@6951
   429
    finger->pressure = pressure;
slouken@7191
   430
slouken@6951
   431
    /* Post the event, if desired */
slouken@6951
   432
    posted = 0;
slouken@6951
   433
    if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
slouken@6951
   434
        SDL_Event event;
slouken@6951
   435
        event.tfinger.type = SDL_FINGERMOTION;
slouken@6951
   436
        event.tfinger.touchId = id;
slouken@6951
   437
        event.tfinger.fingerId = fingerid;
slouken@6951
   438
        event.tfinger.x = x;
slouken@6951
   439
        event.tfinger.y = y;
slouken@6951
   440
        event.tfinger.dx = xrel;
slouken@7191
   441
        event.tfinger.dy = yrel;
slouken@6951
   442
        event.tfinger.pressure = pressure;
slouken@6951
   443
        posted = (SDL_PushEvent(&event) > 0);
slouken@6951
   444
    }
slouken@6951
   445
    return posted;
slouken@6951
   446
}
slouken@6951
   447
jim@4640
   448
void
jimtla@4678
   449
SDL_DelTouch(SDL_TouchID id)
jim@4640
   450
{
slouken@6951
   451
    int i;
slouken@6951
   452
    int index = SDL_GetTouchIndex(id);
jim@4641
   453
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   454
jim@4640
   455
    if (!touch) {
jim@4640
   456
        return;
jim@4640
   457
    }
jim@4640
   458
slouken@6951
   459
    for (i = 0; i < touch->max_fingers; ++i) {
slouken@6951
   460
        SDL_free(touch->fingers[i]);
jim@4640
   461
    }
slouken@6951
   462
    SDL_free(touch->fingers);
jim@4640
   463
    SDL_free(touch);
jim@4640
   464
jim@4641
   465
    SDL_num_touch--;
slouken@6951
   466
    SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch];
slouken@11290
   467
slouken@11290
   468
    /* Delete this touch device for gestures */
slouken@11290
   469
    SDL_GestureDelTouch(id);
jim@4640
   470
}
jim@4640
   471
jim@4640
   472
void
jim@4640
   473
SDL_TouchQuit(void)
jim@4640
   474
{
jim@4640
   475
    int i;
jim@4640
   476
slouken@6951
   477
    for (i = SDL_num_touch; i--; ) {
slouken@6951
   478
        SDL_DelTouch(SDL_touchDevices[i]->id);
jim@4640
   479
    }
slouken@6951
   480
    SDL_assert(SDL_num_touch == 0);
jim@4640
   481
slouken@7719
   482
    SDL_free(SDL_touchDevices);
slouken@7719
   483
    SDL_touchDevices = NULL;
slouken@11290
   484
    SDL_GestureQuit();
jim@4640
   485
}
jim@4640
   486
jim@4640
   487
/* vi: set ts=4 sw=4 expandtab: */