int SDL_AddTouch(const SDL_Touch * touch, char *name) { SDL_Touch **touchPads; int index; size_t length; if (SDL_GetTouchIndexId(touch->id) != -1) { SDL_SetError("Touch ID already in use"); } /* Add the touch to the list of touch */ touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads, (SDL_num_touch + 1) * sizeof(*touch)); if (!touchPads) { SDL_OutOfMemory(); return -1; } SDL_touchPads = touchPads; index = SDL_num_touch++; SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index])); if (!SDL_touchPads[index]) { SDL_OutOfMemory(); return -1; } SDL_memcpy(SDL_touchPads[index], touch, sizeof(*touch)); /* we're setting the touch properties */ length = 0; length = SDL_strlen(name); SDL_touchPads[index]->focus = 0; SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char)); SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1); SDL_touchPads[index]->num_fingers = 0; SDL_touchPads[index]->max_fingers = 1; SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*)); SDL_touchPads[index]->fingers[0] = NULL; SDL_touchPads[index]->buttonstate = 0; SDL_touchPads[index]->relative_mode = SDL_FALSE; SDL_touchPads[index]->flush_motion = SDL_FALSE; SDL_touchPads[index]->xres = (1<<(16-1)); SDL_touchPads[index]->yres = (1<<(16-1)); SDL_touchPads[index]->pressureres = (1<<(16-1)); //Do I want this here? Probably SDL_GestureAddTouch(SDL_touchPads[index]); return index; }
int SDL_AddTouch(SDL_TouchID touchID, const char *name) { SDL_Touch **touchDevices; int index; index = SDL_GetTouchIndex(touchID); if (index >= 0) { return index; } /* Add the touch to the list of touch */ touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices, (SDL_num_touch + 1) * sizeof(*touchDevices)); if (!touchDevices) { return SDL_OutOfMemory(); } SDL_touchDevices = touchDevices; index = SDL_num_touch; SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index])); if (!SDL_touchDevices[index]) { return SDL_OutOfMemory(); } /* Added touch to list */ ++SDL_num_touch; /* we're setting the touch properties */ SDL_touchDevices[index]->id = touchID; SDL_touchDevices[index]->num_fingers = 0; SDL_touchDevices[index]->max_fingers = 0; SDL_touchDevices[index]->fingers = NULL; /* Record this touch device for gestures */ /* We could do this on the fly in the gesture code if we wanted */ SDL_GestureAddTouch(touchID); return index; }