Ejemplo n.º 1
0
int
SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
              SDL_bool down, float x, float y, float pressure)
{
    int posted;
    SDL_Finger *finger;

    SDL_Touch* touch = SDL_GetTouch(id);
    if (!touch) {
        return -1;
    }

    finger = SDL_GetFinger(touch, fingerid);
    if (down) {
        if (finger) {
            /* This finger is already down */
            return 0;
        }

        if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
            return 0;
        }

        posted = 0;
        if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
            SDL_Event event;
            event.tfinger.type = SDL_FINGERDOWN;
            event.tfinger.touchId = id;
            event.tfinger.fingerId = fingerid;
            event.tfinger.x = x;
            event.tfinger.y = y;
            event.tfinger.dx = 0;
            event.tfinger.dy = 0;
            event.tfinger.pressure = pressure;
            posted = (SDL_PushEvent(&event) > 0);
        }
    } else {
        if (!finger) {
            /* This finger is already up */
            return 0;
        }

        posted = 0;
        if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
            SDL_Event event;
            event.tfinger.type = SDL_FINGERUP;
            event.tfinger.touchId =  id;
            event.tfinger.fingerId = fingerid;
            /* I don't trust the coordinates passed on fingerUp */
            event.tfinger.x = finger->x;
            event.tfinger.y = finger->y;
            event.tfinger.dx = 0;
            event.tfinger.dy = 0;
            event.tfinger.pressure = pressure;
            posted = (SDL_PushEvent(&event) > 0);
        }

        SDL_DelFinger(touch, fingerid);
    }
    return posted;
}
Ejemplo n.º 2
0
int
SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, 
                   float xin, float yin, float pressurein)
{
    int posted;
        Uint16 x;
        Uint16 y;
        Uint16 pressure;
        SDL_Finger *finger;

    SDL_Touch* touch = SDL_GetTouch(id);

    if(!touch) {
      return SDL_TouchNotFoundError(id);
    }

    
    //scale to Integer coordinates
    x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
    y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
    pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
    
    finger = SDL_GetFinger(touch,fingerid);
    if(down) {
        if(finger == NULL) {
            SDL_Finger nf;
            nf.id = fingerid;
            nf.x = x;
            nf.y = y;
            nf.pressure = pressure;
            nf.xdelta = 0;
            nf.ydelta = 0;
            nf.last_x = x;
            nf.last_y = y;
            nf.last_pressure = pressure;
            nf.down = SDL_FALSE;
            if(SDL_AddFinger(touch,&nf) < 0) return 0;
            finger = SDL_GetFinger(touch,fingerid);
        }
        else if(finger->down) return 0;
        if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input
        posted = 0;
        if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
            SDL_Event event;
            event.tfinger.type = SDL_FINGERDOWN;
            event.tfinger.touchId = id;
            event.tfinger.x = x;
            event.tfinger.y = y;
            event.tfinger.dx = 0;
            event.tfinger.dy = 0;
            event.tfinger.pressure = pressure;
            event.tfinger.state = touch->buttonstate;
            event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
            event.tfinger.fingerId = fingerid;
            posted = (SDL_PushEvent(&event) > 0);
        }
        if(posted) finger->down = SDL_TRUE;
        return posted;
    }
    else {
        if(finger == NULL) {
            SDL_SetError("Finger not found.");
            return 0;
        }      
        posted = 0;
        if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
            SDL_Event event;
            event.tfinger.type = SDL_FINGERUP;
            event.tfinger.touchId =  id;
            event.tfinger.state = touch->buttonstate;
            event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
            event.tfinger.fingerId = fingerid;
            //I don't trust the coordinates passed on fingerUp
            event.tfinger.x = finger->x; 
            event.tfinger.y = finger->y;
            event.tfinger.dx = 0;
            event.tfinger.dy = 0;
            event.tfinger.pressure = pressure;

            if(SDL_DelFinger(touch,fingerid) < 0) return 0;
            posted = (SDL_PushEvent(&event) > 0);
        }        
        return posted;
    }
}