src/events/SDL_touch.c
author Jim Grandpre
Tue, 25 May 2010 23:23:23 -0400
changeset 4640 f068a6dfc858
child 4641 49a97daea6ec
permissions -rw-r--r--
Added SDL_touch.c/SDL_touch_c.h as slightly modifeind SDL_mouse*. Made reads in touchSimp non-blocking.
jim@4640
     1
/*
jim@4640
     2
    SDL - Simple DirectMedia Layer
jim@4640
     3
    Copyright (C) 1997-2010 Sam Lantinga
jim@4640
     4
jim@4640
     5
    This library is free software; you can redistribute it and/or
jim@4640
     6
    modify it under the terms of the GNU Lesser General Public
jim@4640
     7
    License as published by the Free Software Foundation; either
jim@4640
     8
    version 2.1 of the License, or (at your option) any later version.
jim@4640
     9
jim@4640
    10
    This library is distributed in the hope that it will be useful,
jim@4640
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
jim@4640
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
jim@4640
    13
    Lesser General Public License for more details.
jim@4640
    14
jim@4640
    15
    You should have received a copy of the GNU Lesser General Public
jim@4640
    16
    License along with this library; if not, write to the Free Software
jim@4640
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
jim@4640
    18
jim@4640
    19
    Sam Lantinga
jim@4640
    20
    slouken@libsdl.org
jim@4640
    21
*/
jim@4640
    22
#include "SDL_config.h"
jim@4640
    23
jim@4640
    24
/* General touch handling code for SDL */
jim@4640
    25
jim@4640
    26
#include "SDL_events.h"
jim@4640
    27
#include "SDL_events_c.h"
jim@4640
    28
#include "../video/SDL_sysvideo.h"
jim@4640
    29
jim@4640
    30
jim@4640
    31
static int SDL_num_touch = 0;
jim@4640
    32
static int SDL_current_touch = -1;
jim@4640
    33
static SDL_Touch **SDL_touch = NULL;
jim@4640
    34
jim@4640
    35
jim@4640
    36
/* Public functions */
jim@4640
    37
int
jim@4640
    38
SDL_TouchInit(void)
jim@4640
    39
{
jim@4640
    40
    return (0);
jim@4640
    41
}
jim@4640
    42
jim@4640
    43
SDL_Touch *
jim@4640
    44
SDL_GetTouch(int index)
jim@4640
    45
{
jim@4640
    46
    if (index < 0 || index >= SDL_num_touch) {
jim@4640
    47
        return NULL;
jim@4640
    48
    }
jim@4640
    49
    return SDL_touch[index];
jim@4640
    50
}
jim@4640
    51
jim@4640
    52
static int
jim@4640
    53
SDL_GetTouchIndexId(int id)
jim@4640
    54
{
jim@4640
    55
    int index;
jim@4640
    56
    SDL_Touch *touch;
jim@4640
    57
jim@4640
    58
    for (index = 0; index < SDL_num_touch; ++index) {
jim@4640
    59
        touch = SDL_GetTouch(index);
jim@4640
    60
        if (touch->id == id) {
jim@4640
    61
            return index;
jim@4640
    62
        }
jim@4640
    63
    }
jim@4640
    64
    return -1;
jim@4640
    65
}
jim@4640
    66
jim@4640
    67
int
jim@4640
    68
SDL_AddTouch(const SDL_Touch * touch, char *name, int pressure_max,
jim@4640
    69
             int pressure_min, int ends)
jim@4640
    70
{
jim@4640
    71
    SDL_Touch **touch;
jim@4640
    72
    int selected_touch;
jim@4640
    73
    int index;
jim@4640
    74
    size_t length;
jim@4640
    75
jim@4640
    76
    if (SDL_GetTouchIndexId(touch->id) != -1) {
jim@4640
    77
        SDL_SetError("Touch ID already in use");
jim@4640
    78
    }
jim@4640
    79
jim@4640
    80
    /* Add the touch to the list of touch */
jim@4640
    81
    touch = (SDL_Touch **) SDL_realloc(SDL_touch,
jim@4640
    82
                                      (SDL_num_touch + 1) * sizeof(*touch));
jim@4640
    83
    if (!touch) {
jim@4640
    84
        SDL_OutOfMemory();
jim@4640
    85
        return -1;
jim@4640
    86
    }
jim@4640
    87
jim@4640
    88
    SDL_touch = touch;
jim@4640
    89
    index = SDL_num_touch++;
jim@4640
    90
jim@4640
    91
    SDL_touch[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touch[index]));
jim@4640
    92
    if (!SDL_touch[index]) {
jim@4640
    93
        SDL_OutOfMemory();
jim@4640
    94
        return -1;
jim@4640
    95
    }
jim@4640
    96
    *SDL_touch[index] = *touch;
jim@4640
    97
jim@4640
    98
    /* we're setting the touch properties */
jim@4640
    99
    length = 0;
jim@4640
   100
    length = SDL_strlen(name);
jim@4640
   101
    SDL_touch[index]->focus = 0;
jim@4640
   102
    SDL_touch[index]->name = SDL_malloc((length + 2) * sizeof(char));
jim@4640
   103
    SDL_strlcpy(SDL_touch[index]->name, name, length + 1);
jim@4640
   104
    SDL_touch[index]->pressure_max = pressure_max;
jim@4640
   105
    SDL_touch[index]->pressure_min = pressure_min;
jim@4640
   106
    SDL_touch[index]->cursor_shown = SDL_TRUE;
jim@4640
   107
    selected_touch = SDL_SelectTouch(index);
jim@4640
   108
    SDL_touch[index]->cur_cursor = NULL;
jim@4640
   109
    SDL_touch[index]->def_cursor =
jim@4640
   110
    /* we're assuming that all touch are in the computer sensing zone */
jim@4640
   111
    SDL_touch[index]->proximity = SDL_TRUE;
jim@4640
   112
    /* we're assuming that all touch are working in the absolute position mode
jim@4640
   113
       thanx to that, the users that don't want to use many touch don't have to
jim@4640
   114
       worry about anything */
jim@4640
   115
    SDL_touch[index]->relative_mode = SDL_FALSE;
jim@4640
   116
    SDL_touch[index]->current_end = 0;
jim@4640
   117
    SDL_touch[index]->total_ends = ends;
jim@4640
   118
    SDL_SelectTouch(selected_touch);
jim@4640
   119
jim@4640
   120
    return index;
jim@4640
   121
}
jim@4640
   122
jim@4640
   123
void
jim@4640
   124
SDL_DelTouch(int index)
jim@4640
   125
{
jim@4640
   126
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   127
jim@4640
   128
    if (!touch) {
jim@4640
   129
        return;
jim@4640
   130
    }
jim@4640
   131
jim@4640
   132
    touch->def_cursor = NULL;
jim@4640
   133
    SDL_free(touch->name);
jim@4640
   134
 
jim@4640
   135
    if (touch->FreeTouch) {
jim@4640
   136
        touch->FreeTouch(touch);
jim@4640
   137
    }
jim@4640
   138
    SDL_free(touch);
jim@4640
   139
jim@4640
   140
    SDL_touch[index] = NULL;
jim@4640
   141
}
jim@4640
   142
jim@4640
   143
void
jim@4640
   144
SDL_ResetTouch(int index)
jim@4640
   145
{
jim@4640
   146
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   147
jim@4640
   148
    if (!touch) {
jim@4640
   149
        return;
jim@4640
   150
    }
jim@4640
   151
jim@4640
   152
    /* FIXME */
jim@4640
   153
}
jim@4640
   154
jim@4640
   155
void
jim@4640
   156
SDL_TouchQuit(void)
jim@4640
   157
{
jim@4640
   158
    int i;
jim@4640
   159
jim@4640
   160
    for (i = 0; i < SDL_num_touch; ++i) {
jim@4640
   161
        SDL_DelTouch(i);
jim@4640
   162
    }
jim@4640
   163
    SDL_num_touch = 0;
jim@4640
   164
    SDL_current_touch = -1;
jim@4640
   165
jim@4640
   166
    if (SDL_touch) {
jim@4640
   167
        SDL_free(SDL_touch);
jim@4640
   168
        SDL_touch = NULL;
jim@4640
   169
    }
jim@4640
   170
}
jim@4640
   171
jim@4640
   172
int
jim@4640
   173
SDL_GetNumTouch(void)
jim@4640
   174
{
jim@4640
   175
    return SDL_num_touch;
jim@4640
   176
}
jim@4640
   177
jim@4640
   178
int
jim@4640
   179
SDL_SelectTouch(int index)
jim@4640
   180
{
jim@4640
   181
    if (index >= 0 && index < SDL_num_touch) {
jim@4640
   182
        SDL_current_touch = index;
jim@4640
   183
    }
jim@4640
   184
    return SDL_current_touch;
jim@4640
   185
}
jim@4640
   186
jim@4640
   187
SDL_Window *
jim@4640
   188
SDL_GetTouchFocusWindow(int index)
jim@4640
   189
{
jim@4640
   190
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   191
jim@4640
   192
    if (!touch) {
jim@4640
   193
        return 0;
jim@4640
   194
    }
jim@4640
   195
    return touch->focus;
jim@4640
   196
}
jim@4640
   197
jim@4640
   198
static int SDLCALL
jim@4640
   199
FlushTouchMotion(void *param, SDL_Event * event)
jim@4640
   200
{
jim@4640
   201
    if (event->type == SDL_TOUCHMOTION
jim@4640
   202
        && event->motion.which == (Uint8) SDL_current_touch) {
jim@4640
   203
        return 0;
jim@4640
   204
    } else {
jim@4640
   205
        return 1;
jim@4640
   206
    }
jim@4640
   207
}
jim@4640
   208
jim@4640
   209
int
jim@4640
   210
SDL_SetRelativeTouchMode(int index, SDL_bool enabled)
jim@4640
   211
{
jim@4640
   212
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   213
jim@4640
   214
    if (!touch) {
jim@4640
   215
        return -1;
jim@4640
   216
    }
jim@4640
   217
jim@4640
   218
    /* Flush pending touch motion */
jim@4640
   219
    touch->flush_motion = SDL_TRUE;
jim@4640
   220
    SDL_PumpEvents();
jim@4640
   221
    touch->flush_motion = SDL_FALSE;
jim@4640
   222
    SDL_FilterEvents(FlushTouchMotion, touch);
jim@4640
   223
jim@4640
   224
    /* Set the relative mode */
jim@4640
   225
    touch->relative_mode = enabled;
jim@4640
   226
jim@4640
   227
jim@4640
   228
jim@4640
   229
    if (!enabled) {
jim@4640
   230
        /* Restore the expected touch position */
jim@4640
   231
        SDL_WarpTouchInWindow(touch->focus, touch->x, touch->y);
jim@4640
   232
    }
jim@4640
   233
    return 0;
jim@4640
   234
}
jim@4640
   235
jim@4640
   236
SDL_bool
jim@4640
   237
SDL_GetRelativeTouchMode(int index)
jim@4640
   238
{
jim@4640
   239
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   240
jim@4640
   241
    if (!touch) {
jim@4640
   242
        return SDL_FALSE;
jim@4640
   243
    }
jim@4640
   244
    return touch->relative_mode;
jim@4640
   245
}
jim@4640
   246
jim@4640
   247
Uint8
jim@4640
   248
SDL_GetTouchState(int *x, int *y)
jim@4640
   249
{
jim@4640
   250
    SDL_Touch *touch = SDL_GetTouch(SDL_current_touch);
jim@4640
   251
jim@4640
   252
    if (!touch) {
jim@4640
   253
        if (x) {
jim@4640
   254
            *x = 0;
jim@4640
   255
        }
jim@4640
   256
        if (y) {
jim@4640
   257
            *y = 0;
jim@4640
   258
        }
jim@4640
   259
        return 0;
jim@4640
   260
    }
jim@4640
   261
jim@4640
   262
    if (x) {
jim@4640
   263
        *x = touch->x;
jim@4640
   264
    }
jim@4640
   265
    if (y) {
jim@4640
   266
        *y = touch->y;
jim@4640
   267
    }
jim@4640
   268
    return touch->buttonstate;
jim@4640
   269
}
jim@4640
   270
jim@4640
   271
Uint8
jim@4640
   272
SDL_GetRelativeTouchState(int index, int *x, int *y)
jim@4640
   273
{
jim@4640
   274
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   275
jim@4640
   276
    if (!touch) {
jim@4640
   277
        if (x) {
jim@4640
   278
            *x = 0;
jim@4640
   279
        }
jim@4640
   280
        if (y) {
jim@4640
   281
            *y = 0;
jim@4640
   282
        }
jim@4640
   283
        return 0;
jim@4640
   284
    }
jim@4640
   285
jim@4640
   286
    if (x) {
jim@4640
   287
        *x = touch->xdelta;
jim@4640
   288
    }
jim@4640
   289
    if (y) {
jim@4640
   290
        *y = touch->ydelta;
jim@4640
   291
    }
jim@4640
   292
    touch->xdelta = 0;
jim@4640
   293
    touch->ydelta = 0;
jim@4640
   294
    return touch->buttonstate;
jim@4640
   295
}
jim@4640
   296
jim@4640
   297
void
jim@4640
   298
SDL_SetTouchFocus(int id, SDL_Window * window)
jim@4640
   299
{
jim@4640
   300
    int index = SDL_GetTouchIndexId(id);
jim@4640
   301
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   302
    int i;
jim@4640
   303
    SDL_bool focus;
jim@4640
   304
jim@4640
   305
    if (!touch || (touch->focus == window)) {
jim@4640
   306
        return;
jim@4640
   307
    }
jim@4640
   308
jim@4640
   309
    /* See if the current window has lost focus */
jim@4640
   310
    if (touch->focus) {
jim@4640
   311
        focus = SDL_FALSE;
jim@4640
   312
        for (i = 0; i < SDL_num_touch; ++i) {
jim@4640
   313
            SDL_Touch *check;
jim@4640
   314
            if (i != index) {
jim@4640
   315
                check = SDL_GetTouch(i);
jim@4640
   316
                if (check && check->focus == touch->focus) {
jim@4640
   317
                    focus = SDL_TRUE;
jim@4640
   318
                    break;
jim@4640
   319
                }
jim@4640
   320
            }
jim@4640
   321
        }
jim@4640
   322
        if (!focus) {
jim@4640
   323
            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
jim@4640
   324
        }
jim@4640
   325
    }
jim@4640
   326
jim@4640
   327
    touch->focus = window;
jim@4640
   328
jim@4640
   329
    if (touch->focus) {
jim@4640
   330
        focus = SDL_FALSE;
jim@4640
   331
        for (i = 0; i < SDL_num_touch; ++i) {
jim@4640
   332
            SDL_Touch *check;
jim@4640
   333
            if (i != index) {
jim@4640
   334
                check = SDL_GetTouch(i);
jim@4640
   335
                if (check && check->focus == touch->focus) {
jim@4640
   336
                    focus = SDL_TRUE;
jim@4640
   337
                    break;
jim@4640
   338
                }
jim@4640
   339
            }
jim@4640
   340
        }
jim@4640
   341
        if (!focus) {
jim@4640
   342
            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
jim@4640
   343
        }
jim@4640
   344
    }
jim@4640
   345
}
jim@4640
   346
jim@4640
   347
int
jim@4640
   348
SDL_SendProximity(int id, int x, int y, int type)
jim@4640
   349
{
jim@4640
   350
    int index = SDL_GetTouchIndexId(id);
jim@4640
   351
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   352
    int posted = 0;
jim@4640
   353
jim@4640
   354
    if (!touch) {
jim@4640
   355
        return 0;
jim@4640
   356
    }
jim@4640
   357
jim@4640
   358
    touch->last_x = x;
jim@4640
   359
    touch->last_y = y;
jim@4640
   360
    if (SDL_GetEventState(type) == SDL_ENABLE) {
jim@4640
   361
        SDL_Event event;
jim@4640
   362
        event.proximity.which = (Uint8) index;
jim@4640
   363
        event.proximity.x = x;
jim@4640
   364
        event.proximity.y = y;
jim@4640
   365
        event.proximity.cursor = touch->current_end;
jim@4640
   366
        event.proximity.type = type;
jim@4640
   367
        /* FIXME: is this right? */
jim@4640
   368
        event.proximity.windowID = touch->focus ? touch->focus->id : 0;
jim@4640
   369
        posted = (SDL_PushEvent(&event) > 0);
jim@4640
   370
        if (type == SDL_PROXIMITYIN) {
jim@4640
   371
            touch->proximity = SDL_TRUE;
jim@4640
   372
        } else {
jim@4640
   373
            touch->proximity = SDL_FALSE;
jim@4640
   374
        }
jim@4640
   375
    }
jim@4640
   376
    return posted;
jim@4640
   377
}
jim@4640
   378
jim@4640
   379
int
jim@4640
   380
SDL_SendTouchMotion(int id, int relative, int x, int y, int pressure)
jim@4640
   381
{
jim@4640
   382
    int index = SDL_GetTouchIndexId(id);
jim@4640
   383
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   384
    int posted;
jim@4640
   385
    int xrel;
jim@4640
   386
    int yrel;
jim@4640
   387
    int x_max = 0, y_max = 0;
jim@4640
   388
jim@4640
   389
    if (!touch || touch->flush_motion) {
jim@4640
   390
        return 0;
jim@4640
   391
    }
jim@4640
   392
jim@4640
   393
    /* if the touch is out of proximity we don't to want to have any motion from it */
jim@4640
   394
    if (touch->proximity == SDL_FALSE) {
jim@4640
   395
        touch->last_x = x;
jim@4640
   396
        touch->last_y = y;
jim@4640
   397
        return 0;
jim@4640
   398
    }
jim@4640
   399
jim@4640
   400
    /* the relative motion is calculated regarding the system cursor last position */
jim@4640
   401
    if (relative) {
jim@4640
   402
        xrel = x;
jim@4640
   403
        yrel = y;
jim@4640
   404
        x = (touch->last_x + x);
jim@4640
   405
        y = (touch->last_y + y);
jim@4640
   406
    } else {
jim@4640
   407
        xrel = x - touch->last_x;
jim@4640
   408
        yrel = y - touch->last_y;
jim@4640
   409
    }
jim@4640
   410
jim@4640
   411
    /* Drop events that don't change state */
jim@4640
   412
    if (!xrel && !yrel) {
jim@4640
   413
#if 0
jim@4640
   414
        printf("Touch event didn't change state - dropped!\n");
jim@4640
   415
#endif
jim@4640
   416
        return 0;
jim@4640
   417
    }
jim@4640
   418
jim@4640
   419
    /* Update internal touch coordinates */
jim@4640
   420
    if (touch->relative_mode == SDL_FALSE) {
jim@4640
   421
        touch->x = x;
jim@4640
   422
        touch->y = y;
jim@4640
   423
    } else {
jim@4640
   424
        touch->x += xrel;
jim@4640
   425
        touch->y += yrel;
jim@4640
   426
    }
jim@4640
   427
jim@4640
   428
    SDL_GetWindowSize(touch->focus, &x_max, &y_max);
jim@4640
   429
jim@4640
   430
    /* make sure that the pointers find themselves inside the windows */
jim@4640
   431
    /* only check if touch->xmax is set ! */
jim@4640
   432
    if (x_max && touch->x > x_max) {
jim@4640
   433
        touch->x = x_max;
jim@4640
   434
    } else if (touch->x < 0) {
jim@4640
   435
        touch->x = 0;
jim@4640
   436
    }
jim@4640
   437
jim@4640
   438
    if (y_max && touch->y > y_max) {
jim@4640
   439
        touch->y = y_max;
jim@4640
   440
    } else if (touch->y < 0) {
jim@4640
   441
        touch->y = 0;
jim@4640
   442
    }
jim@4640
   443
jim@4640
   444
    touch->xdelta += xrel;
jim@4640
   445
    touch->ydelta += yrel;
jim@4640
   446
    touch->pressure = pressure;
jim@4640
   447
jim@4640
   448
jim@4640
   449
jim@4640
   450
    /* Post the event, if desired */
jim@4640
   451
    posted = 0;
jim@4640
   452
    if (SDL_GetEventState(SDL_TOUCHMOTION) == SDL_ENABLE &&
jim@4640
   453
        touch->proximity == SDL_TRUE) {
jim@4640
   454
        SDL_Event event;
jim@4640
   455
        event.motion.type = SDL_TOUCHMOTION;
jim@4640
   456
        event.motion.which = (Uint8) index;
jim@4640
   457
        event.motion.state = touch->buttonstate;
jim@4640
   458
        event.motion.x = touch->x;
jim@4640
   459
        event.motion.y = touch->y;
jim@4640
   460
        event.motion.z = touch->z;
jim@4640
   461
        event.motion.pressure = touch->pressure;
jim@4640
   462
        event.motion.pressure_max = touch->pressure_max;
jim@4640
   463
        event.motion.pressure_min = touch->pressure_min;
jim@4640
   464
        event.motion.rotation = 0;
jim@4640
   465
        event.motion.tilt_x = 0;
jim@4640
   466
        event.motion.tilt_y = 0;
jim@4640
   467
        event.motion.cursor = touch->current_end;
jim@4640
   468
        event.motion.xrel = xrel;
jim@4640
   469
        event.motion.yrel = yrel;
jim@4640
   470
        event.motion.windowID = touch->focus ? touch->focus->id : 0;
jim@4640
   471
        posted = (SDL_PushEvent(&event) > 0);
jim@4640
   472
    }
jim@4640
   473
    touch->last_x = touch->x;
jim@4640
   474
    touch->last_y = touch->y;
jim@4640
   475
    return posted;
jim@4640
   476
}
jim@4640
   477
jim@4640
   478
int
jim@4640
   479
SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
jim@4640
   480
{
jim@4640
   481
    int index = SDL_GetTouchIndexId(id);
jim@4640
   482
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   483
    int posted;
jim@4640
   484
    Uint32 type;
jim@4640
   485
jim@4640
   486
    if (!touch) {
jim@4640
   487
        return 0;
jim@4640
   488
    }
jim@4640
   489
jim@4640
   490
    /* Figure out which event to perform */
jim@4640
   491
    switch (state) {
jim@4640
   492
    case SDL_PRESSED:
jim@4640
   493
        if (touch->buttonstate & SDL_BUTTON(button)) {
jim@4640
   494
            /* Ignore this event, no state change */
jim@4640
   495
            return 0;
jim@4640
   496
        }
jim@4640
   497
        type = SDL_TOUCHBUTTONDOWN;
jim@4640
   498
        touch->buttonstate |= SDL_BUTTON(button);
jim@4640
   499
        break;
jim@4640
   500
    case SDL_RELEASED:
jim@4640
   501
        if (!(touch->buttonstate & SDL_BUTTON(button))) {
jim@4640
   502
            /* Ignore this event, no state change */
jim@4640
   503
            return 0;
jim@4640
   504
        }
jim@4640
   505
        type = SDL_TOUCHBUTTONUP;
jim@4640
   506
        touch->buttonstate &= ~SDL_BUTTON(button);
jim@4640
   507
        break;
jim@4640
   508
    default:
jim@4640
   509
        /* Invalid state -- bail */
jim@4640
   510
        return 0;
jim@4640
   511
    }
jim@4640
   512
jim@4640
   513
    /* Post the event, if desired */
jim@4640
   514
    posted = 0;
jim@4640
   515
    if (SDL_GetEventState(type) == SDL_ENABLE) {
jim@4640
   516
        SDL_Event event;
jim@4640
   517
        event.type = type;
jim@4640
   518
        event.button.which = (Uint8) index;
jim@4640
   519
        event.button.state = state;
jim@4640
   520
        event.button.button = button;
jim@4640
   521
        event.button.x = touch->x;
jim@4640
   522
        event.button.y = touch->y;
jim@4640
   523
        event.button.windowID = touch->focus ? touch->focus->id : 0;
jim@4640
   524
        posted = (SDL_PushEvent(&event) > 0);
jim@4640
   525
    }
jim@4640
   526
    return posted;
jim@4640
   527
}
jim@4640
   528
jim@4640
   529
int
jim@4640
   530
SDL_SendTouchWheel(int index, int x, int y)
jim@4640
   531
{
jim@4640
   532
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   533
    int posted;
jim@4640
   534
jim@4640
   535
    if (!touch || (!x && !y)) {
jim@4640
   536
        return 0;
jim@4640
   537
    }
jim@4640
   538
jim@4640
   539
    /* Post the event, if desired */
jim@4640
   540
    posted = 0;
jim@4640
   541
    if (SDL_GetEventState(SDL_TOUCHWHEEL) == SDL_ENABLE) {
jim@4640
   542
        SDL_Event event;
jim@4640
   543
        event.type = SDL_TOUCHWHEEL;
jim@4640
   544
        event.wheel.which = (Uint8) index;
jim@4640
   545
        event.wheel.x = x;
jim@4640
   546
        event.wheel.y = y;
jim@4640
   547
        event.wheel.windowID = touch->focus ? touch->focus->id : 0;
jim@4640
   548
        posted = (SDL_PushEvent(&event) > 0);
jim@4640
   549
    }
jim@4640
   550
    return posted;
jim@4640
   551
}
jim@4640
   552
jim@4640
   553
jim@4640
   554
char *
jim@4640
   555
SDL_GetTouchName(int index)
jim@4640
   556
{
jim@4640
   557
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   558
    if (!touch) {
jim@4640
   559
        return NULL;
jim@4640
   560
    }
jim@4640
   561
    return touch->name;
jim@4640
   562
}
jim@4640
   563
jim@4640
   564
void
jim@4640
   565
SDL_ChangeEnd(int id, int end)
jim@4640
   566
{
jim@4640
   567
    int index = SDL_GetTouchIndexId(id);
jim@4640
   568
    SDL_Touch *touch = SDL_GetTouch(index);
jim@4640
   569
jim@4640
   570
    if (touch) {
jim@4640
   571
        touch->current_end = end;
jim@4640
   572
    }
jim@4640
   573
}
jim@4640
   574
jim@4640
   575
/* vi: set ts=4 sw=4 expandtab: */