Exemple #1
0
SDL_Finger *
SDL_GetFinger(SDL_Touch* touch,SDL_FingerID id)
{
    int index = SDL_GetFingerIndexId(touch,id);
    if(index < 0 || index >= touch->num_fingers)
        return NULL;
    return touch->fingers[index];
}
int
SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid)
{
    int index = SDL_GetFingerIndexId(touch,fingerid);
    SDL_Finger* finger = SDL_GetFinger(touch,fingerid);

    if (!finger) {
        return -1;
    }

    SDL_free(finger);
    touch->num_fingers--;
    touch->fingers[index] = touch->fingers[touch->num_fingers];
    return 0;
}
Exemple #3
0
int 
SDL_AddFinger(SDL_Touch* touch,SDL_Finger *finger)
{
    int index;
    SDL_Finger **fingers;
    //printf("Adding Finger...\n");
    if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
        SDL_SetError("Finger ID already in use");
        }

    /* Add the touch to the list of touch */
    if(touch->num_fingers  >= touch->max_fingers){
                //printf("Making room for it!\n");
                fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
                                                     (touch->num_fingers + 1) * sizeof(SDL_Finger *));
                touch->max_fingers = touch->num_fingers+1;
                if (!fingers) {
                        SDL_OutOfMemory();
                        return -1;
                } else {
                        touch->max_fingers = touch->num_fingers+1;
                        touch->fingers = fingers;
                }
        }

    index = touch->num_fingers;
    //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);

    touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
    if (!touch->fingers[index]) {
        SDL_OutOfMemory();
        return -1;
    }
    *(touch->fingers[index]) = *finger;
    touch->num_fingers++;

    return index;
}