src/events/SDL_touch.c
author Jim Grandpre <jim.tla@gmail.com>
Thu, 17 Jun 2010 03:41:27 -0400
changeset 4654 7dbcd71216df
parent 4648 0350b634c044
child 4655 4c94f2023d62
permissions -rw-r--r--
Added $1 gesture recognition.
Functional.
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@4640
   143
    return index;
jim@4640
   144
}
jim@4640
   145
jim@4640
   146
void
jim@4641
   147
SDL_DelTouch(int id)
jim@4640
   148
{
jim@4641
   149
    int index = SDL_GetTouchIndexId(id);
jim@4641
   150
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   151
jim@4640
   152
    if (!touch) {
jim@4640
   153
        return;
jim@4640
   154
    }
jim@4640
   155
jim@4641
   156
    
jim@4640
   157
    SDL_free(touch->name);
jim@4640
   158
 
jim@4640
   159
    if (touch->FreeTouch) {
jim@4640
   160
        touch->FreeTouch(touch);
jim@4640
   161
    }
jim@4640
   162
    SDL_free(touch);
jim@4640
   163
jim@4641
   164
    SDL_num_touch--;
jim@4641
   165
    SDL_touchPads[index] = SDL_touchPads[SDL_num_touch];
jim@4640
   166
}
jim@4640
   167
jim@4640
   168
void
jim@4640
   169
SDL_TouchQuit(void)
jim@4640
   170
{
jim@4640
   171
    int i;
jim@4640
   172
jim@4641
   173
    for (i = SDL_num_touch-1; i > 0 ; --i) {
jim@4640
   174
        SDL_DelTouch(i);
jim@4640
   175
    }
jim@4640
   176
    SDL_num_touch = 0;
jim@4640
   177
jim@4641
   178
    if (SDL_touchPads) {
jim@4641
   179
        SDL_free(SDL_touchPads);
jim@4641
   180
        SDL_touchPads = NULL;
jim@4640
   181
    }
jim@4640
   182
}
jim@4640
   183
jim@4640
   184
int
jim@4640
   185
SDL_GetNumTouch(void)
jim@4640
   186
{
jim@4640
   187
    return SDL_num_touch;
jim@4640
   188
}
jim@4641
   189
SDL_Window *
jim@4641
   190
SDL_GetTouchFocusWindow(int id)
jim@4640
   191
{
jim@4641
   192
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   193
jim@4640
   194
    if (!touch) {
jim@4640
   195
        return 0;
jim@4640
   196
    }
jim@4640
   197
    return touch->focus;
jim@4640
   198
}
jim@4640
   199
jim@4640
   200
void
jim@4640
   201
SDL_SetTouchFocus(int id, SDL_Window * window)
jim@4640
   202
{
jim@4640
   203
    int index = SDL_GetTouchIndexId(id);
jim@4641
   204
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   205
    int i;
jim@4640
   206
    SDL_bool focus;
jim@4640
   207
jim@4640
   208
    if (!touch || (touch->focus == window)) {
jim@4640
   209
        return;
jim@4640
   210
    }
jim@4640
   211
jim@4640
   212
    /* See if the current window has lost focus */
jim@4640
   213
    if (touch->focus) {
jim@4640
   214
        focus = SDL_FALSE;
jim@4640
   215
        for (i = 0; i < SDL_num_touch; ++i) {
jim@4640
   216
            SDL_Touch *check;
jim@4640
   217
            if (i != index) {
jim@4641
   218
                check = SDL_touchPads[i];
jim@4640
   219
                if (check && check->focus == touch->focus) {
jim@4640
   220
                    focus = SDL_TRUE;
jim@4640
   221
                    break;
jim@4640
   222
                }
jim@4640
   223
            }
jim@4640
   224
        }
jim@4640
   225
        if (!focus) {
jim@4640
   226
            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
jim@4640
   227
        }
jim@4640
   228
    }
jim@4640
   229
jim@4640
   230
    touch->focus = window;
jim@4640
   231
jim@4640
   232
    if (touch->focus) {
jim@4640
   233
        focus = SDL_FALSE;
jim@4640
   234
        for (i = 0; i < SDL_num_touch; ++i) {
jim@4640
   235
            SDL_Touch *check;
jim@4640
   236
            if (i != index) {
jim@4641
   237
                check = SDL_touchPads[i];
jim@4640
   238
                if (check && check->focus == touch->focus) {
jim@4640
   239
                    focus = SDL_TRUE;
jim@4640
   240
                    break;
jim@4640
   241
                }
jim@4640
   242
            }
jim@4640
   243
        }
jim@4640
   244
        if (!focus) {
jim@4640
   245
            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
jim@4640
   246
        }
jim@4640
   247
    }
jim@4640
   248
}
jim@4640
   249
jim@4641
   250
int 
jim@4641
   251
SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger)
jim@4640
   252
{
jim@4641
   253
    int index;
jim@4641
   254
    SDL_Finger **fingers;
jim@4646
   255
    //printf("Adding Finger...\n");
jim@4641
   256
    if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
jim@4641
   257
        SDL_SetError("Finger ID already in use");
jim@4642
   258
	}
jim@4640
   259
jim@4641
   260
    /* Add the touch to the list of touch */
jim@4646
   261
    if(touch->num_fingers  >= touch->max_fingers){
jimtla@4648
   262
		//printf("Making room for it!\n");
jimtla@4648
   263
		fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
jimtla@4648
   264
  						   (touch->num_fingers + 1) * sizeof(SDL_Finger *));
jimtla@4648
   265
		touch->max_fingers = touch->num_fingers+1;
jimtla@4648
   266
		if (!fingers) {
jimtla@4648
   267
			SDL_OutOfMemory();
jimtla@4648
   268
			return -1;
jimtla@4648
   269
		} else {
jimtla@4648
   270
			touch->max_fingers = touch->num_fingers+1;
jimtla@4648
   271
			touch->fingers = fingers;
jimtla@4648
   272
		}
jim@4646
   273
	}
jim@4645
   274
jim@4646
   275
    index = touch->num_fingers;
jim@4646
   276
    //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);
jim@4641
   277
jim@4646
   278
    touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
jim@4641
   279
    if (!touch->fingers[index]) {
jim@4641
   280
        SDL_OutOfMemory();
jim@4641
   281
        return -1;
jim@4641
   282
    }
jim@4646
   283
    *(touch->fingers[index]) = *finger;
jim@4646
   284
    touch->num_fingers++;
jim@4641
   285
jim@4641
   286
    return index;
jim@4640
   287
}
jim@4640
   288
jim@4640
   289
int
jim@4641
   290
SDL_DelFinger(SDL_Touch* touch,int fingerid)
jim@4641
   291
{
jim@4642
   292
    int index = SDL_GetFingerIndexId(touch,fingerid);
jim@4641
   293
    SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
jim@4641
   294
jim@4641
   295
    if (!finger) {
jimtla@4648
   296
        return -1;
jim@4641
   297
    }
jim@4641
   298
 
jim@4641
   299
jim@4641
   300
    SDL_free(finger);
jim@4641
   301
    touch->num_fingers--;
jim@4641
   302
    touch->fingers[index] = touch->fingers[touch->num_fingers];
jimtla@4648
   303
	return 0;
jim@4641
   304
}
jim@4641
   305
jim@4641
   306
jim@4641
   307
int
jim@4641
   308
SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure)
jim@4641
   309
{
jim@4643
   310
    int posted;
jim@4641
   311
    SDL_Touch* touch = SDL_GetTouch(id);
jim@4643
   312
jim@4641
   313
    if(down) {
jim@4641
   314
	SDL_Finger nf;
jim@4643
   315
	nf.id = fingerid;
jim@4641
   316
	nf.x = x;
jim@4641
   317
	nf.y = y;
jim@4641
   318
	nf.pressure = pressure;
jim@4641
   319
	nf.xdelta = 0;
jim@4641
   320
	nf.ydelta = 0;
jim@4641
   321
	nf.last_x = x;
jim@4641
   322
	nf.last_y = y;
jim@4646
   323
	nf.last_pressure = pressure;
jim@4641
   324
	SDL_AddFinger(touch,&nf);
jim@4654
   325
	//if(x < 0 || y < 0) return 0; //should defer if only a partial input
jim@4641
   326
	posted = 0;
jim@4641
   327
	if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
jim@4641
   328
	    SDL_Event event;
jim@4641
   329
	    event.tfinger.type = SDL_FINGERDOWN;
jim@4641
   330
	    event.tfinger.touchId = (Uint8) id;
jim@4642
   331
	    event.tfinger.x = x;
jim@4642
   332
	    event.tfinger.y = y;
jim@4641
   333
	    event.tfinger.state = touch->buttonstate;
jim@4641
   334
	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
jim@4643
   335
	    event.tfinger.fingerId = fingerid;
jim@4641
   336
	    posted = (SDL_PushEvent(&event) > 0);
jim@4641
   337
	}
jim@4641
   338
	return posted;
jim@4641
   339
    }
jim@4641
   340
    else {
jim@4643
   341
	SDL_DelFinger(touch,fingerid);
jim@4641
   342
	posted = 0;
jim@4641
   343
	if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
jim@4641
   344
	    SDL_Event event;
jim@4641
   345
	    event.tfinger.type = SDL_FINGERUP;
jim@4641
   346
	    event.tfinger.touchId = (Uint8) id;
jim@4641
   347
	    event.tfinger.state = touch->buttonstate;
jim@4641
   348
	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
jim@4643
   349
	    event.tfinger.fingerId = fingerid;
jim@4641
   350
	    posted = (SDL_PushEvent(&event) > 0);
jim@4641
   351
	}
jim@4641
   352
	return posted;
jim@4641
   353
    }
jim@4641
   354
}
jim@4641
   355
jim@4641
   356
int
jim@4641
   357
SDL_SendTouchMotion(int id, int fingerid, int relative, 
jim@4641
   358
		    int x, int y, int pressure)
jim@4640
   359
{
jim@4640
   360
    int index = SDL_GetTouchIndexId(id);
jim@4641
   361
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4641
   362
    SDL_Finger *finger = SDL_GetFinger(touch,fingerid);
jim@4640
   363
    int posted;
jim@4640
   364
    int xrel;
jim@4640
   365
    int yrel;
jim@4640
   366
    int x_max = 0, y_max = 0;
jim@4654
   367
	
jim@4640
   368
    if (!touch || touch->flush_motion) {
jim@4654
   369
		return 0;
jim@4640
   370
    }
jim@4654
   371
    
jim@4654
   372
    if(finger == NULL) {
jim@4654
   373
		return SDL_SendFingerDown(id,fingerid,SDL_TRUE,x,y,pressure);	
jim@4654
   374
    } else {
jimtla@4648
   375
		/* the relative motion is calculated regarding the last position */
jimtla@4648
   376
		if (relative) {
jimtla@4648
   377
			xrel = x;
jimtla@4648
   378
			yrel = y;
jimtla@4648
   379
			x = (finger->last_x + x);
jimtla@4648
   380
			y = (finger->last_y + y);
jimtla@4648
   381
		} else {
jimtla@4648
   382
			if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
jimtla@4648
   383
			if(y < 0) y = finger->last_y; /*The other is marked as -1*/
jimtla@4648
   384
			if(pressure < 0) pressure = finger->last_pressure;
jimtla@4648
   385
			xrel = x - finger->last_x;
jimtla@4648
   386
			yrel = y - finger->last_y;
jimtla@4648
   387
		}
jimtla@4648
   388
		
jimtla@4648
   389
		/* Drop events that don't change state */
jimtla@4648
   390
		if (!xrel && !yrel) {
jim@4654
   391
#if 0
jimtla@4648
   392
			printf("Touch event didn't change state - dropped!\n");
jim@4654
   393
#endif
jimtla@4648
   394
			return 0;
jimtla@4648
   395
		}
jimtla@4648
   396
		
jimtla@4648
   397
		/* Update internal touch coordinates */
jimtla@4648
   398
		
jimtla@4648
   399
		finger->x = x;
jimtla@4648
   400
		finger->y = y;
jimtla@4648
   401
		
jimtla@4648
   402
		/*Should scale to window? Normalize? Maintain Aspect?*/
jimtla@4648
   403
		//SDL_GetWindowSize(touch->focus, &x_max, &y_max);
jimtla@4648
   404
		
jimtla@4648
   405
		/* make sure that the pointers find themselves inside the windows */
jimtla@4648
   406
		/* only check if touch->xmax is set ! */
jimtla@4648
   407
		/*
jimtla@4648
   408
		  if (x_max && touch->x > x_max) {
jimtla@4648
   409
		  touch->x = x_max;
jimtla@4648
   410
		  } else if (touch->x < 0) {
jimtla@4648
   411
		  touch->x = 0;
jimtla@4648
   412
		  }
jimtla@4648
   413
		  
jimtla@4648
   414
		  if (y_max && touch->y > y_max) {
jimtla@4648
   415
		  touch->y = y_max;
jimtla@4648
   416
		  } else if (touch->y < 0) {
jimtla@4648
   417
		  touch->y = 0;
jimtla@4648
   418
		  }
jimtla@4648
   419
		*/
jimtla@4648
   420
		finger->xdelta = xrel;
jimtla@4648
   421
		finger->ydelta = yrel;
jimtla@4648
   422
		finger->pressure = pressure;
jimtla@4648
   423
		
jimtla@4648
   424
		
jimtla@4648
   425
		
jimtla@4648
   426
		/* Post the event, if desired */
jimtla@4648
   427
		posted = 0;
jimtla@4648
   428
		if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
jimtla@4648
   429
			SDL_Event event;
jimtla@4648
   430
			event.tfinger.type = SDL_FINGERMOTION;
jimtla@4648
   431
			event.tfinger.touchId = (Uint8) id;
jimtla@4648
   432
			event.tfinger.fingerId = (Uint8) fingerid;
jimtla@4648
   433
			event.tfinger.x = x;
jimtla@4648
   434
			event.tfinger.y = y;
jimtla@4648
   435
			event.tfinger.pressure = pressure;
jimtla@4648
   436
			event.tfinger.state = touch->buttonstate;
jimtla@4648
   437
			event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
jimtla@4648
   438
			posted = (SDL_PushEvent(&event) > 0);
jimtla@4648
   439
		}
jimtla@4648
   440
		finger->last_x = finger->x;
jimtla@4648
   441
		finger->last_y = finger->y;
jimtla@4648
   442
		finger->last_pressure = finger->pressure;
jimtla@4648
   443
		return posted;
jim@4642
   444
	}
jim@4640
   445
}
jim@4640
   446
int
jim@4640
   447
SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
jim@4640
   448
{
jim@4641
   449
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   450
    int posted;
jim@4640
   451
    Uint32 type;
jim@4640
   452
jim@4640
   453
    if (!touch) {
jim@4640
   454
        return 0;
jim@4640
   455
    }
jim@4640
   456
jim@4640
   457
    /* Figure out which event to perform */
jim@4640
   458
    switch (state) {
jim@4640
   459
    case SDL_PRESSED:
jim@4640
   460
        if (touch->buttonstate & SDL_BUTTON(button)) {
jim@4640
   461
            /* Ignore this event, no state change */
jim@4640
   462
            return 0;
jim@4640
   463
        }
jim@4640
   464
        type = SDL_TOUCHBUTTONDOWN;
jim@4640
   465
        touch->buttonstate |= SDL_BUTTON(button);
jim@4640
   466
        break;
jim@4640
   467
    case SDL_RELEASED:
jim@4640
   468
        if (!(touch->buttonstate & SDL_BUTTON(button))) {
jim@4640
   469
            /* Ignore this event, no state change */
jim@4640
   470
            return 0;
jim@4640
   471
        }
jim@4640
   472
        type = SDL_TOUCHBUTTONUP;
jim@4640
   473
        touch->buttonstate &= ~SDL_BUTTON(button);
jim@4640
   474
        break;
jim@4640
   475
    default:
jim@4640
   476
        /* Invalid state -- bail */
jim@4640
   477
        return 0;
jim@4640
   478
    }
jim@4640
   479
jim@4640
   480
    /* Post the event, if desired */
jim@4640
   481
    posted = 0;
jim@4640
   482
    if (SDL_GetEventState(type) == SDL_ENABLE) {
jim@4640
   483
        SDL_Event event;
jim@4640
   484
        event.type = type;
jimtla@4648
   485
        event.tbutton.touchId = (Uint8) touch->id;
jim@4641
   486
        event.tbutton.state = state;
jim@4641
   487
        event.tbutton.button = button;
jim@4641
   488
        event.tbutton.windowID = touch->focus ? touch->focus->id : 0;
jim@4640
   489
        posted = (SDL_PushEvent(&event) > 0);
jim@4640
   490
    }
jim@4640
   491
    return posted;
jim@4640
   492
}
jim@4640
   493
jim@4641
   494
char *
jim@4641
   495
SDL_GetTouchName(int id)
jim@4640
   496
{
jim@4641
   497
    SDL_Touch *touch = SDL_GetTouch(id);
jim@4640
   498
    if (!touch) {
jim@4640
   499
        return NULL;
jim@4640
   500
    }
jim@4640
   501
    return touch->name;
jim@4640
   502
}
jim@4640
   503
jim@4640
   504
/* vi: set ts=4 sw=4 expandtab: */