src/events/SDL_touch.c
author Jim Grandpre <jim.tla@gmail.com>
Wed, 07 Jul 2010 04:13:08 -0700
changeset 4657 eed063a0bf5b
parent 4655 4c94f2023d62
child 4667 0ecdbabdd7e7
permissions -rw-r--r--
Moved Multi finger gesture recognition into the library.
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
jimtla@4648
    30
#include <stdio.h>
jimtla@4648
    31
jim@4640
    32
jim@4640
    33
static int SDL_num_touch = 0;
jim@4641
    34
static SDL_Touch **SDL_touchPads = NULL;
jim@4640
    35
jim@4640
    36
jim@4640
    37
/* Public functions */
jim@4640
    38
int
jim@4640
    39
SDL_TouchInit(void)
jim@4640
    40
{
jim@4642
    41
    
jim@4640
    42
    return (0);
jim@4640
    43
}
jim@4642
    44
jim@4640
    45
SDL_Touch *
jim@4641
    46
SDL_GetTouch(int id)
jim@4640
    47
{
jim@4641
    48
    int index = SDL_GetTouchIndexId(id);
jim@4640
    49
    if (index < 0 || index >= SDL_num_touch) {
jim@4640
    50
        return NULL;
jim@4640
    51
    }
jim@4641
    52
    return SDL_touchPads[index];
jim@4640
    53
}
jim@4640
    54
jim@4642
    55
SDL_Touch *
jim@4642
    56
SDL_GetTouchIndex(int index)
jim@4641
    57
{
jim@4642
    58
    if (index < 0 || index >= SDL_num_touch) {
jim@4642
    59
        return NULL;
jim@4642
    60
    }
jim@4642
    61
    return SDL_touchPads[index];
jim@4641
    62
}
jim@4641
    63
jim@4641
    64
int
jim@4641
    65
SDL_GetFingerIndexId(SDL_Touch* touch,int fingerid)
jim@4641
    66
{
jim@4641
    67
    int i;
jim@4641
    68
    for(i = 0;i < touch->num_fingers;i++)
jim@4641
    69
	if(touch->fingers[i]->id == fingerid)
jim@4641
    70
	    return i;
jim@4641
    71
    return -1;
jim@4641
    72
}
jim@4641
    73
jim@4642
    74
jim@4642
    75
SDL_Finger *
jim@4642
    76
SDL_GetFinger(SDL_Touch* touch,int id)
jim@4642
    77
{
jim@4642
    78
    int index = SDL_GetFingerIndexId(touch,id);
jim@4642
    79
    if(index < 0 || index >= touch->num_fingers)
jim@4642
    80
	return NULL;
jim@4642
    81
    return touch->fingers[index];
jim@4642
    82
}
jim@4642
    83
jim@4642
    84
jim@4641
    85
int
jim@4640
    86
SDL_GetTouchIndexId(int id)
jim@4640
    87
{
jim@4640
    88
    int index;
jim@4640
    89
    SDL_Touch *touch;
jim@4640
    90
jim@4640
    91
    for (index = 0; index < SDL_num_touch; ++index) {
jim@4641
    92
        touch = SDL_touchPads[index];
jim@4640
    93
        if (touch->id == id) {
jim@4640
    94
            return index;
jim@4640
    95
        }
jim@4640
    96
    }
jim@4640
    97
    return -1;
jim@4640
    98
}
jim@4640
    99
jim@4640
   100
int
jim@4642
   101
SDL_AddTouch(const SDL_Touch * touch, char *name)
jim@4640
   102
{
jim@4641
   103
    SDL_Touch **touchPads;
jimtla@4648
   104
    int index,length;
jim@4640
   105
jim@4640
   106
    if (SDL_GetTouchIndexId(touch->id) != -1) {
jim@4640
   107
        SDL_SetError("Touch ID already in use");
jim@4640
   108
    }
jim@4640
   109
jim@4640
   110
    /* Add the touch to the list of touch */
jim@4641
   111
    touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads,
jim@4640
   112
                                      (SDL_num_touch + 1) * sizeof(*touch));
jim@4641
   113
    if (!touchPads) {
jim@4640
   114
        SDL_OutOfMemory();
jim@4640
   115
        return -1;
jim@4640
   116
    }
jim@4640
   117
jim@4641
   118
    SDL_touchPads = touchPads;
jim@4640
   119
    index = SDL_num_touch++;
jim@4640
   120
jim@4641
   121
    SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index]));
jim@4641
   122
    if (!SDL_touchPads[index]) {
jim@4640
   123
        SDL_OutOfMemory();
jim@4640
   124
        return -1;
jim@4640
   125
    }
jim@4641
   126
    *SDL_touchPads[index] = *touch;
jim@4640
   127
jim@4640
   128
    /* we're setting the touch properties */
jim@4640
   129
    length = 0;
jim@4640
   130
    length = SDL_strlen(name);
jim@4641
   131
    SDL_touchPads[index]->focus = 0;
jim@4641
   132
    SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
jim@4642
   133
    SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);   
jim@4642
   134
jim@4642
   135
    SDL_touchPads[index]->num_fingers = 0;
jim@4646
   136
    SDL_touchPads[index]->max_fingers = 1;
jim@4646
   137
    SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
jim@4646
   138
    SDL_touchPads[index]->fingers[0] = NULL;
jim@4642
   139
    SDL_touchPads[index]->buttonstate = 0;
jim@4642
   140
    SDL_touchPads[index]->relative_mode = SDL_FALSE;
jim@4642
   141
    SDL_touchPads[index]->flush_motion = SDL_FALSE;
jim@4641
   142
    
jim@4657
   143
    //Do I want this here? Probably
jim@4657
   144
    SDL_GestureAddTouch(SDL_touchPads[index]);
jim@4657
   145
jim@4640
   146
    return index;
jim@4640
   147
}
jim@4640
   148
jim@4640
   149
void
jim@4641
   150
SDL_DelTouch(int id)
jim@4640
   151
{
jim@4641
   152
    int index = SDL_GetTouchIndexId(id);
jim@4641
   153
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   154
jim@4640
   155
    if (!touch) {
jim@4640
   156
        return;
jim@4640
   157
    }
jim@4640
   158
jim@4641
   159
    
jim@4640
   160
    SDL_free(touch->name);
jim@4640
   161
 
jim@4640
   162
    if (touch->FreeTouch) {
jim@4640
   163
        touch->FreeTouch(touch);
jim@4640
   164
    }
jim@4640
   165
    SDL_free(touch);
jim@4640
   166
jim@4641
   167
    SDL_num_touch--;
jim@4641
   168
    SDL_touchPads[index] = SDL_touchPads[SDL_num_touch];
jim@4640
   169
}
jim@4640
   170
jim@4640
   171
void
jim@4640
   172
SDL_TouchQuit(void)
jim@4640
   173
{
jim@4640
   174
    int i;
jim@4640
   175
jim@4641
   176
    for (i = SDL_num_touch-1; i > 0 ; --i) {
jim@4640
   177
        SDL_DelTouch(i);
jim@4640
   178
    }
jim@4640
   179
    SDL_num_touch = 0;
jim@4640
   180
jim@4641
   181
    if (SDL_touchPads) {
jim@4641
   182
        SDL_free(SDL_touchPads);
jim@4641
   183
        SDL_touchPads = NULL;
jim@4640
   184
    }
jim@4640
   185
}
jim@4640
   186
jim@4640
   187
int
jim@4640
   188
SDL_GetNumTouch(void)
jim@4640
   189
{
jim@4640
   190
    return SDL_num_touch;
jim@4640
   191
}
jim@4641
   192
SDL_Window *
jim@4641
   193
SDL_GetTouchFocusWindow(int id)
jim@4640
   194
{
jim@4641
   195
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   196
jim@4640
   197
    if (!touch) {
jim@4640
   198
        return 0;
jim@4640
   199
    }
jim@4640
   200
    return touch->focus;
jim@4640
   201
}
jim@4640
   202
jim@4640
   203
void
jim@4640
   204
SDL_SetTouchFocus(int id, SDL_Window * window)
jim@4640
   205
{
jim@4640
   206
    int index = SDL_GetTouchIndexId(id);
jim@4641
   207
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   208
    int i;
jim@4640
   209
    SDL_bool focus;
jim@4640
   210
jim@4640
   211
    if (!touch || (touch->focus == window)) {
jim@4640
   212
        return;
jim@4640
   213
    }
jim@4640
   214
jim@4640
   215
    /* See if the current window has lost focus */
jim@4640
   216
    if (touch->focus) {
jim@4640
   217
        focus = SDL_FALSE;
jim@4640
   218
        for (i = 0; i < SDL_num_touch; ++i) {
jim@4640
   219
            SDL_Touch *check;
jim@4640
   220
            if (i != index) {
jim@4641
   221
                check = SDL_touchPads[i];
jim@4640
   222
                if (check && check->focus == touch->focus) {
jim@4640
   223
                    focus = SDL_TRUE;
jim@4640
   224
                    break;
jim@4640
   225
                }
jim@4640
   226
            }
jim@4640
   227
        }
jim@4640
   228
        if (!focus) {
jim@4640
   229
            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
jim@4640
   230
        }
jim@4640
   231
    }
jim@4640
   232
jim@4640
   233
    touch->focus = window;
jim@4640
   234
jim@4640
   235
    if (touch->focus) {
jim@4640
   236
        focus = SDL_FALSE;
jim@4640
   237
        for (i = 0; i < SDL_num_touch; ++i) {
jim@4640
   238
            SDL_Touch *check;
jim@4640
   239
            if (i != index) {
jim@4641
   240
                check = SDL_touchPads[i];
jim@4640
   241
                if (check && check->focus == touch->focus) {
jim@4640
   242
                    focus = SDL_TRUE;
jim@4640
   243
                    break;
jim@4640
   244
                }
jim@4640
   245
            }
jim@4640
   246
        }
jim@4640
   247
        if (!focus) {
jim@4640
   248
            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
jim@4640
   249
        }
jim@4640
   250
    }
jim@4640
   251
}
jim@4640
   252
jim@4641
   253
int 
jim@4641
   254
SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger)
jim@4640
   255
{
jim@4641
   256
    int index;
jim@4641
   257
    SDL_Finger **fingers;
jim@4646
   258
    //printf("Adding Finger...\n");
jim@4641
   259
    if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
jim@4641
   260
        SDL_SetError("Finger ID already in use");
jim@4642
   261
	}
jim@4640
   262
jim@4641
   263
    /* Add the touch to the list of touch */
jim@4646
   264
    if(touch->num_fingers  >= touch->max_fingers){
jimtla@4648
   265
		//printf("Making room for it!\n");
jimtla@4648
   266
		fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
jimtla@4648
   267
  						   (touch->num_fingers + 1) * sizeof(SDL_Finger *));
jimtla@4648
   268
		touch->max_fingers = touch->num_fingers+1;
jimtla@4648
   269
		if (!fingers) {
jimtla@4648
   270
			SDL_OutOfMemory();
jimtla@4648
   271
			return -1;
jimtla@4648
   272
		} else {
jimtla@4648
   273
			touch->max_fingers = touch->num_fingers+1;
jimtla@4648
   274
			touch->fingers = fingers;
jimtla@4648
   275
		}
jim@4646
   276
	}
jim@4645
   277
jim@4646
   278
    index = touch->num_fingers;
jim@4646
   279
    //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);
jim@4641
   280
jim@4646
   281
    touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
jim@4641
   282
    if (!touch->fingers[index]) {
jim@4641
   283
        SDL_OutOfMemory();
jim@4641
   284
        return -1;
jim@4641
   285
    }
jim@4646
   286
    *(touch->fingers[index]) = *finger;
jim@4646
   287
    touch->num_fingers++;
jim@4641
   288
jim@4641
   289
    return index;
jim@4640
   290
}
jim@4640
   291
jim@4640
   292
int
jim@4641
   293
SDL_DelFinger(SDL_Touch* touch,int fingerid)
jim@4641
   294
{
jim@4642
   295
    int index = SDL_GetFingerIndexId(touch,fingerid);
jim@4641
   296
    SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
jim@4641
   297
jim@4641
   298
    if (!finger) {
jimtla@4648
   299
        return -1;
jim@4641
   300
    }
jim@4641
   301
 
jim@4641
   302
jim@4641
   303
    SDL_free(finger);
jim@4641
   304
    touch->num_fingers--;
jim@4641
   305
    touch->fingers[index] = touch->fingers[touch->num_fingers];
jim@4655
   306
    return 0;
jim@4641
   307
}
jim@4641
   308
jim@4641
   309
jim@4641
   310
int
jim@4641
   311
SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure)
jim@4641
   312
{
jim@4643
   313
    int posted;
jim@4641
   314
    SDL_Touch* touch = SDL_GetTouch(id);
jim@4643
   315
jim@4641
   316
    if(down) {
jim@4655
   317
	SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
jim@4655
   318
	if(finger == NULL) {
jim@4655
   319
	    SDL_Finger nf;
jim@4655
   320
	    nf.id = fingerid;
jim@4655
   321
	    nf.x = x;
jim@4655
   322
	    nf.y = y;
jim@4655
   323
	    nf.pressure = pressure;
jim@4655
   324
	    nf.xdelta = 0;
jim@4655
   325
	    nf.ydelta = 0;
jim@4655
   326
	    nf.last_x = x;
jim@4655
   327
	    nf.last_y = y;
jim@4655
   328
	    nf.last_pressure = pressure;
jim@4655
   329
	    nf.down = SDL_FALSE;
jim@4655
   330
	    SDL_AddFinger(touch,&nf);
jim@4655
   331
	    finger = &nf;
jim@4655
   332
	}
jim@4655
   333
	else if(finger->down) return 0;
jim@4655
   334
	if(x < 0 || y < 0) return 0; //should defer if only a partial input
jim@4641
   335
	posted = 0;
jim@4641
   336
	if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
jim@4641
   337
	    SDL_Event event;
jim@4641
   338
	    event.tfinger.type = SDL_FINGERDOWN;
jim@4641
   339
	    event.tfinger.touchId = (Uint8) id;
jim@4642
   340
	    event.tfinger.x = x;
jim@4642
   341
	    event.tfinger.y = y;
jim@4641
   342
	    event.tfinger.state = touch->buttonstate;
jim@4641
   343
	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
jim@4643
   344
	    event.tfinger.fingerId = fingerid;
jim@4641
   345
	    posted = (SDL_PushEvent(&event) > 0);
jim@4641
   346
	}
jim@4655
   347
	if(posted) finger->down = SDL_TRUE;
jim@4641
   348
	return posted;
jim@4641
   349
    }
jim@4641
   350
    else {
jim@4655
   351
	if(SDL_DelFinger(touch,fingerid) < 0) return 0;
jim@4641
   352
	posted = 0;
jim@4641
   353
	if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
jim@4641
   354
	    SDL_Event event;
jim@4641
   355
	    event.tfinger.type = SDL_FINGERUP;
jim@4641
   356
	    event.tfinger.touchId = (Uint8) id;
jim@4641
   357
	    event.tfinger.state = touch->buttonstate;
jim@4641
   358
	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
jim@4643
   359
	    event.tfinger.fingerId = fingerid;
jim@4641
   360
	    posted = (SDL_PushEvent(&event) > 0);
jim@4641
   361
	}
jim@4641
   362
	return posted;
jim@4641
   363
    }
jim@4641
   364
}
jim@4641
   365
jim@4641
   366
int
jim@4641
   367
SDL_SendTouchMotion(int id, int fingerid, int relative, 
jim@4641
   368
		    int x, int y, int pressure)
jim@4640
   369
{
jim@4640
   370
    int index = SDL_GetTouchIndexId(id);
jim@4641
   371
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4641
   372
    SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
jim@4640
   373
    int posted;
jim@4640
   374
    int xrel;
jim@4640
   375
    int yrel;
jim@4640
   376
    int x_max = 0, y_max = 0;
jim@4655
   377
    
jim@4640
   378
    if (!touch || touch->flush_motion) {
jim@4655
   379
	return 0;
jim@4640
   380
    }
jim@4654
   381
    
jim@4655
   382
    if(finger == NULL || !finger->down) {
jim@4655
   383
	return SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure);	
jim@4654
   384
    } else {
jim@4655
   385
	/* the relative motion is calculated regarding the last position */
jim@4655
   386
	if (relative) {
jim@4655
   387
	    xrel = x;
jim@4655
   388
	    yrel = y;
jim@4655
   389
	    x = (finger->last_x + x);
jim@4655
   390
	    y = (finger->last_y + y);
jim@4655
   391
	} else {
jim@4655
   392
	    if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
jim@4655
   393
	    if(y < 0) y = finger->last_y; /*The other is marked as -1*/
jim@4655
   394
	    if(pressure < 0) pressure = finger->last_pressure;
jim@4655
   395
	    xrel = x - finger->last_x;
jim@4655
   396
	    yrel = y - finger->last_y;
jim@4655
   397
	}
jim@4655
   398
	
jim@4655
   399
	/* Drop events that don't change state */
jim@4655
   400
	if (!xrel && !yrel) {
jim@4654
   401
#if 0
jim@4655
   402
	    printf("Touch event didn't change state - dropped!\n");
jim@4654
   403
#endif
jim@4655
   404
	    return 0;
jim@4642
   405
	}
jim@4655
   406
	
jim@4655
   407
	/* Update internal touch coordinates */
jim@4655
   408
	
jim@4655
   409
	finger->x = x;
jim@4655
   410
	finger->y = y;
jim@4655
   411
	
jim@4655
   412
	/*Should scale to window? Normalize? Maintain Aspect?*/
jim@4655
   413
	//SDL_GetWindowSize(touch->focus, &x_max, &y_max);
jim@4655
   414
	
jim@4655
   415
	/* make sure that the pointers find themselves inside the windows */
jim@4655
   416
	/* only check if touch->xmax is set ! */
jim@4655
   417
	/*
jim@4655
   418
	  if (x_max && touch->x > x_max) {
jim@4655
   419
	  touch->x = x_max;
jim@4655
   420
	  } else if (touch->x < 0) {
jim@4655
   421
	  touch->x = 0;
jim@4655
   422
	  }
jim@4655
   423
	  
jim@4655
   424
	  if (y_max && touch->y > y_max) {
jim@4655
   425
	  touch->y = y_max;
jim@4655
   426
	  } else if (touch->y < 0) {
jim@4655
   427
	  touch->y = 0;
jim@4655
   428
	  }
jim@4655
   429
	*/
jim@4655
   430
	finger->xdelta = xrel;
jim@4655
   431
	finger->ydelta = yrel;
jim@4655
   432
	finger->pressure = pressure;
jim@4655
   433
	
jim@4655
   434
	
jim@4655
   435
	
jim@4655
   436
	/* Post the event, if desired */
jim@4655
   437
	posted = 0;
jim@4655
   438
	if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
jim@4655
   439
	    SDL_Event event;
jim@4655
   440
	    event.tfinger.type = SDL_FINGERMOTION;
jim@4655
   441
	    event.tfinger.touchId = (Uint8) id;
jim@4655
   442
	    event.tfinger.fingerId = (Uint8) fingerid;
jim@4655
   443
	    event.tfinger.x = x;
jim@4655
   444
	    event.tfinger.y = y;
jim@4655
   445
	    event.tfinger.pressure = pressure;
jim@4655
   446
	    event.tfinger.state = touch->buttonstate;
jim@4655
   447
	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
jim@4655
   448
	    posted = (SDL_PushEvent(&event) > 0);
jim@4655
   449
	}
jim@4655
   450
	finger->last_x = finger->x;
jim@4655
   451
	finger->last_y = finger->y;
jim@4655
   452
	finger->last_pressure = finger->pressure;
jim@4655
   453
	return posted;
jim@4655
   454
    }
jim@4640
   455
}
jim@4640
   456
int
jim@4640
   457
SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
jim@4640
   458
{
jim@4641
   459
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   460
    int posted;
jim@4640
   461
    Uint32 type;
jim@4640
   462
jim@4640
   463
    if (!touch) {
jim@4640
   464
        return 0;
jim@4640
   465
    }
jim@4640
   466
jim@4640
   467
    /* Figure out which event to perform */
jim@4640
   468
    switch (state) {
jim@4640
   469
    case SDL_PRESSED:
jim@4640
   470
        if (touch->buttonstate & SDL_BUTTON(button)) {
jim@4640
   471
            /* Ignore this event, no state change */
jim@4640
   472
            return 0;
jim@4640
   473
        }
jim@4640
   474
        type = SDL_TOUCHBUTTONDOWN;
jim@4640
   475
        touch->buttonstate |= SDL_BUTTON(button);
jim@4640
   476
        break;
jim@4640
   477
    case SDL_RELEASED:
jim@4640
   478
        if (!(touch->buttonstate & SDL_BUTTON(button))) {
jim@4640
   479
            /* Ignore this event, no state change */
jim@4640
   480
            return 0;
jim@4640
   481
        }
jim@4640
   482
        type = SDL_TOUCHBUTTONUP;
jim@4640
   483
        touch->buttonstate &= ~SDL_BUTTON(button);
jim@4640
   484
        break;
jim@4640
   485
    default:
jim@4640
   486
        /* Invalid state -- bail */
jim@4640
   487
        return 0;
jim@4640
   488
    }
jim@4640
   489
jim@4640
   490
    /* Post the event, if desired */
jim@4640
   491
    posted = 0;
jim@4640
   492
    if (SDL_GetEventState(type) == SDL_ENABLE) {
jim@4640
   493
        SDL_Event event;
jim@4640
   494
        event.type = type;
jimtla@4648
   495
        event.tbutton.touchId = (Uint8) touch->id;
jim@4641
   496
        event.tbutton.state = state;
jim@4641
   497
        event.tbutton.button = button;
jim@4641
   498
        event.tbutton.windowID = touch->focus ? touch->focus->id : 0;
jim@4640
   499
        posted = (SDL_PushEvent(&event) > 0);
jim@4640
   500
    }
jim@4640
   501
    return posted;
jim@4640
   502
}
jim@4640
   503
jim@4641
   504
char *
jim@4641
   505
SDL_GetTouchName(int id)
jim@4640
   506
{
jim@4641
   507
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   508
    if (!touch) {
jim@4640
   509
        return NULL;
jim@4640
   510
    }
jim@4640
   511
    return touch->name;
jim@4640
   512
}
jim@4640
   513
jim@4640
   514
/* vi: set ts=4 sw=4 expandtab: */