V2i Application::normaliseTouch(SDL_TouchID device_id, V2i touch) { // There's only 1 touch device: memorise itss resolution upon initial call static V2i device_resolution = V2i(SDL_GetTouch(device_id)->xres, SDL_GetTouch(device_id)->yres); static V2i default_window_size = V2i(WINDOW_DEFAULT_W, WINDOW_DEFAULT_H); // Normalise the touch position return touch * default_window_size / device_resolution; }
int SDL_GetNumTouchFingers(SDL_TouchID touchID) { SDL_Touch *touch = SDL_GetTouch(touchID); if (touch) { return touch->num_fingers; } return 0; }
char * SDL_GetTouchName(SDL_TouchID id) { SDL_Touch *touch = SDL_GetTouch(id); if (!touch) { return NULL; } return touch->name; }
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p) { SDL_TouchID touchDeviceId = 0; SDL_FingerID fingerId = 0; int window_x, window_y; if (!Android_Window) { return; } touchDeviceId = (SDL_TouchID)touch_device_id_in; if (!SDL_GetTouch(touchDeviceId)) { if (SDL_AddTouch(touchDeviceId, "") < 0) { SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } } fingerId = (SDL_FingerID)pointer_finger_id_in; switch (action) { case ACTION_DOWN: case ACTION_POINTER_1_DOWN: if (!leftFingerDown) { Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); /* send mouse down event */ SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); leftFingerDown = fingerId; } SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p); break; case ACTION_MOVE: if (!leftFingerDown) { Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); } SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p); break; case ACTION_UP: case ACTION_POINTER_1_UP: if (fingerId == leftFingerDown) { /* send mouse up */ SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); leftFingerDown = 0; } SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; default: break; } }
SDL_Window * SDL_GetTouchFocusWindow(SDL_TouchID id) { SDL_Touch *touch = SDL_GetTouch(id); if (!touch) { return 0; } return touch->focus; }
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure) { SDL_Touch *touch; SDL_Finger *finger; int posted; float xrel, yrel, prel; touch = SDL_GetTouch(id); if (!touch) { return -1; } finger = SDL_GetFinger(touch,fingerid); if (!finger) { return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure); } xrel = x - finger->x; yrel = y - finger->y; prel = pressure - finger->pressure; /* Drop events that don't change state */ if (!xrel && !yrel && !prel) { #if 0 printf("Touch event didn't change state - dropped!\n"); #endif return 0; } /* Update internal touch coordinates */ finger->x = x; finger->y = y; finger->pressure = pressure; /* Post the event, if desired */ posted = 0; if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { SDL_Event event; event.tfinger.type = SDL_FINGERMOTION; event.tfinger.touchId = id; event.tfinger.fingerId = fingerid; event.tfinger.x = x; event.tfinger.y = y; event.tfinger.dx = xrel; event.tfinger.dy = yrel; event.tfinger.pressure = pressure; posted = (SDL_PushEvent(&event) > 0); } return posted; }
SDL_Finger * SDL_GetTouchFinger(SDL_TouchID touchID, int index) { SDL_Touch *touch = SDL_GetTouch(touchID); if (!touch) { return NULL; } if (index < 0 || index >= touch->num_fingers) { SDL_SetError("Unknown touch finger"); return NULL; } return touch->fingers[index]; }
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p) { SDL_TouchID touchDeviceId = 0; SDL_FingerID fingerId = 0; if (!Android_Window) { return; } touchDeviceId = (SDL_TouchID)touch_device_id_in; if (!SDL_GetTouch(touchDeviceId)) { SDL_Touch touch; memset( &touch, 0, sizeof(touch) ); touch.id = touchDeviceId; touch.x_min = 0.0f; touch.x_max = (float)Android_ScreenWidth; touch.native_xres = touch.x_max - touch.x_min; touch.y_min = 0.0f; touch.y_max = (float)Android_ScreenHeight; touch.native_yres = touch.y_max - touch.y_min; touch.pressure_min = 0.0f; touch.pressure_max = 1.0f; touch.native_pressureres = touch.pressure_max - touch.pressure_min; if (SDL_AddTouch(&touch, "") < 0) { SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } } fingerId = (SDL_FingerID)pointer_finger_id_in; switch (action) { case ACTION_DOWN: case ACTION_POINTER_1_DOWN: SDL_SendMouseMotion(Android_Window, 0, x, y); SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT); SDL_SendFingerDown(touchDeviceId, fingerId, SDL_TRUE, x, y, p); break; case ACTION_MOVE: SDL_SendMouseMotion(Android_Window, 0, x, y); SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; case ACTION_UP: case ACTION_POINTER_1_UP: SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT); SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; default: break; } }
void SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window) { int index = SDL_GetTouchIndexId(id); SDL_Touch *touch = SDL_GetTouch(id); int i; SDL_bool focus; if (!touch || (touch->focus == window)) { return; } /* See if the current window has lost focus */ if (touch->focus) { focus = SDL_FALSE; for (i = 0; i < SDL_num_touch; ++i) { SDL_Touch *check; if (i != index) { check = SDL_touchPads[i]; if (check && check->focus == touch->focus) { focus = SDL_TRUE; break; } } } if (!focus) { SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0); } } touch->focus = window; if (touch->focus) { focus = SDL_FALSE; for (i = 0; i < SDL_num_touch; ++i) { SDL_Touch *check; if (i != index) { check = SDL_touchPads[i]; if (check && check->focus == touch->focus) { focus = SDL_TRUE; break; } } } if (!focus) { SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0); } } }
int SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button) { SDL_Touch *touch; int posted; Uint32 type; touch = SDL_GetTouch(id); if (!touch) { return SDL_TouchNotFoundError(id); } /* Figure out which event to perform */ switch (state) { case SDL_PRESSED: if (touch->buttonstate & SDL_BUTTON(button)) { /* Ignore this event, no state change */ return 0; } type = SDL_TOUCHBUTTONDOWN; touch->buttonstate |= SDL_BUTTON(button); break; case SDL_RELEASED: if (!(touch->buttonstate & SDL_BUTTON(button))) { /* Ignore this event, no state change */ return 0; } type = SDL_TOUCHBUTTONUP; touch->buttonstate &= ~SDL_BUTTON(button); break; default: /* Invalid state -- bail */ return 0; } /* Post the event, if desired */ posted = 0; if (SDL_GetEventState(type) == SDL_ENABLE) { SDL_Event event; event.type = type; event.tbutton.touchId = touch->id; event.tbutton.state = state; event.tbutton.button = button; event.tbutton.windowID = touch->focus ? touch->focus->id : 0; posted = (SDL_PushEvent(&event) > 0); } return posted; }
void SDL_DelTouch(SDL_TouchID id) { int i; int index = SDL_GetTouchIndex(id); SDL_Touch *touch = SDL_GetTouch(id); if (!touch) { return; } for (i = 0; i < touch->max_fingers; ++i) { SDL_free(touch->fingers[i]); } SDL_free(touch->fingers); SDL_free(touch); SDL_num_touch--; SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch]; }
void SDL_DelTouch(SDL_TouchID id) { int index = SDL_GetTouchIndexId(id); SDL_Touch *touch = SDL_GetTouch(id); if (!touch) { return; } SDL_free(touch->name); if (touch->FreeTouch) { touch->FreeTouch(touch); } SDL_free(touch); SDL_num_touch--; SDL_touchPads[index] = SDL_touchPads[SDL_num_touch]; }
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, float xin, float yin, float pressurein) { SDL_Touch *touch; SDL_Finger *finger; int posted; Sint16 xrel, yrel; Uint16 x; Uint16 y; Uint16 pressure; 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)); if(touch->flush_motion) { return 0; } finger = SDL_GetFinger(touch,fingerid); if(finger == NULL || !finger->down) { return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein); } else { /* the relative motion is calculated regarding the last position */ if (relative) { xrel = x; yrel = y; x = (finger->last_x + x); y = (finger->last_y + y); } else { if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/ if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/ if(pressurein < touch->pressure_min) pressure = finger->last_pressure; xrel = x - finger->last_x; yrel = y - finger->last_y; //printf("xrel,yrel (%i,%i)\n",(int)xrel,(int)yrel); } /* Drop events that don't change state */ if (!xrel && !yrel) { #if 0 printf("Touch event didn't change state - dropped!\n"); #endif return 0; } /* Update internal touch coordinates */ finger->x = x; finger->y = y; /*Should scale to window? Normalize? Maintain Aspect?*/ //SDL_GetWindowSize(touch->focus, &x_max, &y_max); /* make sure that the pointers find themselves inside the windows */ /* only check if touch->xmax is set ! */ /* if (x_max && touch->x > x_max) { touch->x = x_max; } else if (touch->x < 0) { touch->x = 0; } if (y_max && touch->y > y_max) { touch->y = y_max; } else if (touch->y < 0) { touch->y = 0; } */ finger->xdelta = xrel; finger->ydelta = yrel; finger->pressure = pressure; /* Post the event, if desired */ posted = 0; if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { SDL_Event event; event.tfinger.type = SDL_FINGERMOTION; event.tfinger.touchId = id; event.tfinger.fingerId = fingerid; event.tfinger.x = x; event.tfinger.y = y; event.tfinger.dx = xrel; event.tfinger.dy = yrel; event.tfinger.pressure = pressure; event.tfinger.state = touch->buttonstate; event.tfinger.windowID = touch->focus ? touch->focus->id : 0; posted = (SDL_PushEvent(&event) > 0); } finger->last_x = finger->x; finger->last_y = finger->y; finger->last_pressure = finger->pressure; return posted; } }
static void touch_handle_touch(void *data, struct qt_touch_extension *qt_touch_extension, uint32_t time, uint32_t id, uint32_t state, int32_t x, int32_t y, int32_t normalized_x, int32_t normalized_y, int32_t width, int32_t height, uint32_t pressure, int32_t velocity_x, int32_t velocity_y, uint32_t flags, struct wl_array *rawdata) { /** * Event is assembled in QtWayland in TouchExtensionGlobal::postTouchEvent * (src/compositor/wayland_wrapper/qwltouch.cpp) **/ float FIXED_TO_FLOAT = 1. / 10000.; float xf = FIXED_TO_FLOAT * x; float yf = FIXED_TO_FLOAT * y; float PRESSURE_TO_FLOAT = 1. / 255.; float pressuref = PRESSURE_TO_FLOAT * pressure; uint32_t touchState = state & 0xFFFF; /* Other fields that are sent by the server (qwltouch.cpp), but not used at the moment can be decoded in this way: uint32_t sentPointCount = state >> 16; uint32_t touchFlags = flags & 0xFFFF; uint32_t capabilities = flags >> 16; */ SDL_TouchID deviceId = 0; if (!SDL_GetTouch(deviceId)) { if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) { SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } } switch (touchState) { case QtWaylandTouchPointPressed: case QtWaylandTouchPointReleased: SDL_SendTouch(deviceId, (SDL_FingerID)id, (touchState == QtWaylandTouchPointPressed) ? SDL_TRUE : SDL_FALSE, xf, yf, pressuref); break; case QtWaylandTouchPointMoved: SDL_SendTouchMotion(deviceId, (SDL_FingerID)id, xf, yf, pressuref); break; default: /* Should not happen */ break; } }
int handle_event(void) { SDL_Event event; SDL_Touch *state; // int i; int rx,ry; int ret; int jaxis_threshold=10000; int wm_joy_pl1,wm_joy_pl2; wm_joy_pl1=wm_joy_pl2=0; if (device_isIpad) { if (cur_width>cur_height) virtual_stick=virtual_stick_ipad_landscape; else virtual_stick=virtual_stick_ipad_portrait; } else { if (cur_width>cur_height) virtual_stick=virtual_stick_iphone_landscape; else virtual_stick=virtual_stick_iphone_portrait; } if (num_of_joys>=2) { if (wm_joy_pl2=iOS_wiimote_check(&(joys[1]))) virtual_stick_on=0; if (wm_joy_pl2!=wm_prev_joy_pl2) { wm_prev_joy_pl2=wm_joy_pl2; joy_state[1][GN_UP]=(wm_joy_pl2&WII_JOY_UP?1:0); joy_state[1][GN_DOWN]=(wm_joy_pl2&WII_JOY_DOWN?1:0); joy_state[1][GN_LEFT]=(wm_joy_pl2&WII_JOY_LEFT?1:0); joy_state[1][GN_RIGHT]=(wm_joy_pl2&WII_JOY_RIGHT?1:0); joy_state[1][GN_A]=(wm_joy_pl2&WII_JOY_A?1:0); joy_state[1][GN_B]=(wm_joy_pl2&WII_JOY_B?1:0); joy_state[1][GN_C]=(wm_joy_pl2&WII_JOY_C?1:0); joy_state[1][GN_D]=(wm_joy_pl2&WII_JOY_D?1:0); joy_state[1][GN_SELECT_COIN]=(wm_joy_pl2&WII_JOY_SELECT?1:0); joy_state[1][GN_START]=(wm_joy_pl2&WII_JOY_START?1:0); joy_state[1][GN_MENU_KEY]=(wm_joy_pl2&WII_JOY_HOME?1:0); joy_state[1][GN_TURBO]=(wm_joy_pl2&WII_JOY_E?1:0); } } if (num_of_joys>=1) { if (wm_joy_pl1=iOS_wiimote_check(&(joys[0]))) virtual_stick_on=0; if (wm_joy_pl1!=wm_prev_joy_pl1) { wm_prev_joy_pl1=wm_joy_pl1; joy_state[0][GN_UP]=(wm_joy_pl1&WII_JOY_UP?1:0); joy_state[0][GN_DOWN]=(wm_joy_pl1&WII_JOY_DOWN?1:0); joy_state[0][GN_LEFT]=(wm_joy_pl1&WII_JOY_LEFT?1:0); joy_state[0][GN_RIGHT]=(wm_joy_pl1&WII_JOY_RIGHT?1:0); joy_state[0][GN_A]=(wm_joy_pl1&WII_JOY_A?1:0); joy_state[0][GN_B]=(wm_joy_pl1&WII_JOY_B?1:0); joy_state[0][GN_C]=(wm_joy_pl1&WII_JOY_C?1:0); joy_state[0][GN_D]=(wm_joy_pl1&WII_JOY_D?1:0); joy_state[0][GN_SELECT_COIN]=(wm_joy_pl1&WII_JOY_SELECT?1:0); joy_state[0][GN_START]=(wm_joy_pl1&WII_JOY_START?1:0); joy_state[0][GN_MENU_KEY]=(wm_joy_pl1&WII_JOY_HOME?1:0); joy_state[0][GN_TURBO]=(wm_joy_pl1&WII_JOY_E?1:0); } } while (SDL_PollEvent(&event)) { if ((ret=handle_pdep_event(&event))!=0) { return ret; } switch (event.type) { case SDL_MOUSEMOTION: break; case SDL_MOUSEBUTTONDOWN: break; case SDL_MOUSEBUTTONUP: break; case SDL_FINGERMOTION: state = SDL_GetTouch(event.tfinger.touchId); rx = event.tfinger.x*cur_width / state->xres; ry = event.tfinger.y*cur_height / state->yres; //printf("delta: %d x %d\n",event.tfinger.dx*cur_width/ state->xres,event.tfinger.dy*cur_height/ state->yres); if ((event.tfinger.dy*100/ state->yres < -SLIDEY_CHANGE_RENDERMODE_MIN)&& (abs(event.tfinger.dx*100/ state->xres) < SLIDEX_CHANGE_RENDERMODE_MAX)) { slide_detected=1; } if (event.tfinger.fingerId==virtual_stick_padfinger) { //is it the finger on pad if (vstick_update_status(rx,ry)==0) virtual_stick_padfinger=0; joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0); joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0); joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0); joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0); joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0); joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0); joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0); joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0); } else if (virtual_stick_padfinger==0) { if (vstick_update_status(rx,ry)) virtual_stick_padfinger=event.tfinger.fingerId; joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0); joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0); joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0); joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0); joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0); joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0); joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0); joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0); } for (int i=0;i<VSTICK_NB_BUTTON;i++) { //is there a button already pressed with this finger ? if (virtual_stick[i].finger_id==event.tfinger.fingerId) { //a button was pressed and finger moved //check if finger is still in button area if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&& (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){ break; } else { //button not pressed anymore //do not break to check if finger moved to a new button virtual_stick[i].finger_id=0; joy_state[0][virtual_stick[i].button_id]=0; } } else { //did the finger move to a new button area ? if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&& (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){ joy_state[0][virtual_stick[i].button_id]=1; virtual_stick[i].finger_id=event.tfinger.fingerId; } } } break; case SDL_FINGERDOWN: virtual_stick_on=1; state = SDL_GetTouch(event.tfinger.touchId); rx = event.tfinger.x*cur_width / state->xres; ry = event.tfinger.y*cur_height / state->yres; if (vstick_update_status(rx,ry)) { //finger is on pad joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0); joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0); joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0); joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0); joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0); joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0); joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0); joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0); virtual_stick_padfinger=event.tfinger.fingerId; } else { //check if finger is on a button for (int i=0;i<VSTICK_NB_BUTTON;i++) { if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&& (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){ joy_state[0][virtual_stick[i].button_id]=1; virtual_stick[i].finger_id=event.tfinger.fingerId; break; } } } break; case SDL_FINGERUP: if (virtual_stick_padfinger==event.tfinger.fingerId) { virtual_stick_pad=0; joy_state[0][GN_UP]=0; joy_state[0][GN_DOWN]=0; joy_state[0][GN_LEFT]=0; joy_state[0][GN_RIGHT]=0; joy_state[0][GN_UPRIGHT]=0; joy_state[0][GN_DOWNRIGHT]=0; joy_state[0][GN_UPLEFT]=0; joy_state[0][GN_DOWNLEFT]=0; } for (int i=0;i<VSTICK_NB_BUTTON;i++) if (virtual_stick[i].finger_id==event.tfinger.fingerId) { virtual_stick[i].finger_id=0; joy_state[0][virtual_stick[i].button_id]=0; break; } if (slide_detected) { slide_detected=0; conf.rendermode++; if (conf.rendermode>3) conf.rendermode=0; } break; case SDL_KEYUP: //printf("%d\n",jmap->key[event.key.keysym.sym].player); switch (jmap->key[event.key.keysym.sym].player) { case 1: joy_state[0][jmap->key[event.key.keysym.sym].map]=0; break; case 2: joy_state[1][jmap->key[event.key.keysym.sym].map]=0; break; case 3: joy_state[1][jmap->key[event.key.keysym.sym].map]=0; joy_state[0][jmap->key[event.key.keysym.sym].map]=0; break; default: break; } break; case SDL_KEYDOWN: virtual_stick_on=0; icade_detected=1; // printf("%d %c\n", event.key.keysym.sym,event.key.keysym.sym); switch (jmap->key[event.key.keysym.sym].player) { case 1: joy_state[0][jmap->key[event.key.keysym.sym].map]=1; break; case 2: joy_state[1][jmap->key[event.key.keysym.sym].map]=1; break; case 3: joy_state[1][jmap->key[event.key.keysym.sym].map]=1; joy_state[0][jmap->key[event.key.keysym.sym].map]=1; break; default: break; } break; case SDL_JOYHATMOTION: /* Hat only support Joystick map */ { int player=jmap->jhat[event.jhat.which][event.jhat.hat].player; int map=jmap->jhat[event.jhat.which][event.jhat.hat].map; int i; if (player && map==GN_UP) { player-=1; for(i=GN_UP;i<=GN_RIGHT;i++) joy_state[player][i]=0; if (event.jhat.value&SDL_HAT_UP) joy_state[player][GN_UP]=1; if (event.jhat.value&SDL_HAT_DOWN) joy_state[player][GN_DOWN]=1; if (event.jhat.value&SDL_HAT_LEFT) joy_state[player][GN_LEFT]=1; if (event.jhat.value&SDL_HAT_RIGHT) joy_state[player][GN_RIGHT]=1; } //printf("SDL_JOYHATMOTION %d %d %d\n",event.jhat.which, //event.jhat.hat,event.jhat.value); } break; case SDL_JOYAXISMOTION: { int player=jmap->jaxe[event.jaxis.which][event.jaxis.axis].player; int map=jmap->jaxe[event.jaxis.which][event.jaxis.axis].map; int oldvalue=jmap->jaxe[event.jaxis.which][event.jaxis.axis].value; int value=0; //if (event.jaxis.axis!=6 &&event.jaxis.axis!=7 ) // printf("Axiw motions %d %d %d\n",event.jaxis.which,event.jaxis.axis,event.jaxis.value); if (player) { player-=1; value=event.jaxis.value*jmap->jaxe[event.jaxis.which][event.jaxis.axis].dir; //printf("%d %d %d\n",player,map,value); if (map==GN_UP || map==GN_DOWN) { if (value>jaxis_threshold) { joy_state[player][GN_UP]=1; joy_state[player][GN_DOWN]=0; } if (value<-jaxis_threshold) { joy_state[player][GN_DOWN]=1; joy_state[player][GN_UP]=0; } if (oldvalue>jaxis_threshold && value<=jaxis_threshold && value>=-jaxis_threshold) joy_state[player][GN_UP]=0; if (oldvalue<-jaxis_threshold && value>=-jaxis_threshold && value<=jaxis_threshold) joy_state[player][GN_DOWN]=0; } if (map==GN_LEFT || map==GN_RIGHT) { if (value>jaxis_threshold) { joy_state[player][GN_RIGHT]=1; joy_state[player][GN_LEFT]=0; } if (value<-jaxis_threshold) { joy_state[player][GN_LEFT]=1; joy_state[player][GN_RIGHT]=0; } if (oldvalue>jaxis_threshold && value<=jaxis_threshold && value>=-jaxis_threshold) joy_state[player][GN_RIGHT]=0; if (oldvalue<-jaxis_threshold && value>=-jaxis_threshold && value<=jaxis_threshold) joy_state[player][GN_LEFT]=0; } jmap->jaxe[event.jaxis.which][event.jaxis.axis].value=value; } /* if (abs(event.jaxis.value)>jaxis_threshold) printf("SDL_JOYAXISMOTION %d %d %d %d\n",event.jaxis.which, event.jaxis.axis,value,jmap->jaxe[event.jaxis.which][event.jaxis.axis].dir); * */ } break; case SDL_JOYBUTTONDOWN: { int player=jmap->jbutton[event.jbutton.which][event.jbutton.button].player; int map=jmap->jbutton[event.jbutton.which][event.jbutton.button].map; //printf("player %d map %d\n",player,map); if (player) { player-=1; joy_state[player][map]=1; } //printf("SDL_JOYBUTTONDOWN %d %d\n",event.jbutton.which,event.jbutton.button); } break; case SDL_JOYBUTTONUP: { int player=jmap->jbutton[event.jbutton.which][event.jbutton.button].player; int map=jmap->jbutton[event.jbutton.which][event.jbutton.button].map; if (player) { player-=1; joy_state[player][map]=0; } } break; case SDL_VIDEORESIZE: conf.res_x=event.resize.w; conf.res_y=event.resize.h; screen_resize(event.resize.w, event.resize.h); break; case SDL_QUIT: return 1; break; default: break; } } /* for(i=0;i<GN_MAX_KEY;i++) printf("%d",joy_state[0][i]); printf("|"); for(i=0;i<GN_MAX_KEY;i++) printf("%d",joy_state[1][i]); printf("\r"); */ /* Update coin data */ memory.intern_coin = 0x7; if (joy_state[0][GN_SELECT_COIN]) memory.intern_coin &= 0x6; if (joy_state[1][GN_SELECT_COIN]) memory.intern_coin &= 0x5; /* Update start data TODO: Select */ memory.intern_start = 0x8F; if (joy_state[0][GN_START]) memory.intern_start &= 0xFE; if (joy_state[1][GN_START]) memory.intern_start &= 0xFB; /* TURBO mode */ if (joy_state[0][GN_TURBO]) { gTurboMode=1; } else gTurboMode=0; /* Update P1 */ memory.intern_p1 = 0xFF; if ((joy_state[0][GN_UP]||joy_state[0][GN_UPLEFT]||joy_state[0][GN_UPRIGHT]) && ((!joy_state[0][GN_DOWN])||(!joy_state[0][GN_DOWNLEFT])||(!joy_state[0][GN_DOWNRIGHT]))) memory.intern_p1 &= 0xFE; if ((joy_state[0][GN_DOWN]||joy_state[0][GN_DOWNLEFT]||joy_state[0][GN_DOWNRIGHT]) && ((!joy_state[0][GN_UP])||(!joy_state[0][GN_UPLEFT])||(!joy_state[0][GN_UPRIGHT]))) memory.intern_p1 &= 0xFD; if ((joy_state[0][GN_LEFT]||joy_state[0][GN_UPLEFT]||joy_state[0][GN_DOWNLEFT]) && ((!joy_state[0][GN_RIGHT])||(!joy_state[0][GN_UPRIGHT])||(!joy_state[0][GN_DOWNRIGHT]))) memory.intern_p1 &= 0xFB; if ((joy_state[0][GN_RIGHT]||joy_state[0][GN_UPRIGHT]||joy_state[0][GN_DOWNRIGHT]) && ((!joy_state[0][GN_LEFT])||(!joy_state[0][GN_UPLEFT])||(!joy_state[0][GN_DOWNLEFT]))) memory.intern_p1 &= 0xF7; if (joy_state[0][GN_A]) memory.intern_p1 &= 0xEF; // A if (joy_state[0][GN_B]) memory.intern_p1 &= 0xDF; // B if (joy_state[0][GN_C]) memory.intern_p1 &= 0xBF; // C if (joy_state[0][GN_D]) memory.intern_p1 &= 0x7F; // D /* Update P1 */ memory.intern_p2 = 0xFF; if (joy_state[1][GN_UP] && (!joy_state[1][GN_DOWN])) memory.intern_p2 &= 0xFE; if (joy_state[1][GN_DOWN] && (!joy_state[1][GN_UP])) memory.intern_p2 &= 0xFD; if (joy_state[1][GN_LEFT] && (!joy_state[1][GN_RIGHT])) memory.intern_p2 &= 0xFB; if (joy_state[1][GN_RIGHT] && (!joy_state[1][GN_LEFT])) memory.intern_p2 &= 0xF7; if (joy_state[1][GN_A]) memory.intern_p2 &= 0xEF; // A if (joy_state[1][GN_B]) memory.intern_p2 &= 0xDF; // B if (joy_state[1][GN_C]) memory.intern_p2 &= 0xBF; // C if (joy_state[1][GN_D]) memory.intern_p2 &= 0x7F; // D #if defined(GP2X) || defined(WIZ) if (joy_state[0][GN_HOTKEY1] && joy_state[0][GN_HOTKEY2] && (joy_state[0][GN_START] || joy_state[0][GN_SELECT_COIN])) return 1; #endif if(joy_state[0][GN_MENU_KEY]==1) return 1; else return 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; }
int wait_event(void) { SDL_Event event; SDL_Touch *state; int i,a,rx,ry; //static int counter; //static int last=-1; //int last=-1; //for(i=0;i<GN_MAX_KEY;i++) // if (joy_state[0][i]) last=i; //SDL_WaitEvent(&event); //printf("wait event\n"); int wm_joy_pl1,wm_joy_pl2; wm_joy_pl1=wm_joy_pl2=0; if (device_isIpad) { if (cur_width>cur_height) virtual_stick=virtual_stick_ipad_landscape; else virtual_stick=virtual_stick_ipad_portrait; } else { if (cur_width>cur_height) virtual_stick=virtual_stick_iphone_landscape; else virtual_stick=virtual_stick_iphone_portrait; } if (num_of_joys>=2) { if (wm_joy_pl2=iOS_wiimote_check(&(joys[1]))) virtual_stick_on=0; if (wm_joy_pl2!=wm_prev_joy_pl2) { refresh_counter=1; wm_prev_joy_pl2=wm_joy_pl2; joy_state[1][GN_UP]=(wm_joy_pl2&WII_JOY_UP?1:0); joy_state[1][GN_DOWN]=(wm_joy_pl2&WII_JOY_DOWN?1:0); joy_state[1][GN_LEFT]=(wm_joy_pl2&WII_JOY_LEFT?1:0); joy_state[1][GN_RIGHT]=(wm_joy_pl2&WII_JOY_RIGHT?1:0); joy_state[1][GN_A]=(wm_joy_pl2&WII_JOY_A?1:0); joy_state[1][GN_B]=(wm_joy_pl2&WII_JOY_B?1:0); joy_state[1][GN_C]=(wm_joy_pl2&WII_JOY_C?1:0); joy_state[1][GN_D]=(wm_joy_pl2&WII_JOY_D?1:0); joy_state[1][GN_SELECT_COIN]=(wm_joy_pl2&WII_JOY_SELECT?1:0); joy_state[1][GN_START]=(wm_joy_pl2&WII_JOY_START?1:0); joy_state[1][GN_MENU_KEY]=(wm_joy_pl2&WII_JOY_HOME?1:0); joy_state[1][GN_TURBO]=(wm_joy_pl2&WII_JOY_E?1:0); } } if (num_of_joys>=1) { if (wm_joy_pl1=iOS_wiimote_check(&(joys[0]))) virtual_stick_on=0; if (wm_joy_pl1!=wm_prev_joy_pl1) { refresh_counter=1; wm_prev_joy_pl1=wm_joy_pl1; joy_state[0][GN_UP]=(wm_joy_pl1&WII_JOY_UP?1:0); joy_state[0][GN_DOWN]=(wm_joy_pl1&WII_JOY_DOWN?1:0); joy_state[0][GN_LEFT]=(wm_joy_pl1&WII_JOY_LEFT?1:0); joy_state[0][GN_RIGHT]=(wm_joy_pl1&WII_JOY_RIGHT?1:0); joy_state[0][GN_A]=(wm_joy_pl1&WII_JOY_A?1:0); joy_state[0][GN_B]=(wm_joy_pl1&WII_JOY_B?1:0); joy_state[0][GN_C]=(wm_joy_pl1&WII_JOY_C?1:0); joy_state[0][GN_D]=(wm_joy_pl1&WII_JOY_D?1:0); joy_state[0][GN_SELECT_COIN]=(wm_joy_pl1&WII_JOY_SELECT?1:0); joy_state[0][GN_START]=(wm_joy_pl1&WII_JOY_START?1:0); joy_state[0][GN_MENU_KEY]=(wm_joy_pl1&WII_JOY_HOME?1:0); joy_state[0][GN_TURBO]=(wm_joy_pl1&WII_JOY_E?1:0); } } while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEMOTION: break; case SDL_MOUSEBUTTONDOWN: break; case SDL_MOUSEBUTTONUP: break; case SDL_FINGERMOTION: refresh_counter=1; state = SDL_GetTouch(event.tfinger.touchId); rx = event.tfinger.x*cur_width / state->xres; ry = event.tfinger.y*cur_height / state->yres; //printf("delta: %d x %d\n",event.tfinger.dx*cur_width/ state->xres,event.tfinger.dy*cur_height/ state->yres); if ((event.tfinger.dy*100/ state->yres > SLIDEY_CHANGE_RENDERMODE_MIN)&& (abs(event.tfinger.dx*100/ state->xres) < SLIDEX_CHANGE_RENDERMODE_MAX)) { slide_detected=1; } if (event.tfinger.fingerId==virtual_stick_padfinger) { //is it the finger on pad if (vstick_update_status(rx,ry)==0) virtual_stick_padfinger=0; joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0); joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0); joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0); joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0); joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0); joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0); joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0); joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0); } else if (virtual_stick_padfinger==0) { if (vstick_update_status(rx,ry)) virtual_stick_padfinger=event.tfinger.fingerId; joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0); joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0); joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0); joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0); joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0); joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0); joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0); joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0); } for (int i=0;i<VSTICK_NB_BUTTON;i++) { //is there a button already pressed with this finger ? if (virtual_stick[i].finger_id==event.tfinger.fingerId) { //a button was pressed and finger moved //check if finger is still in button area if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&& (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){ break; } else { //button not pressed anymore //do not break to check if finger moved to a new button virtual_stick[i].finger_id=0; joy_state[0][virtual_stick[i].button_id]=0; } } else { //did the finger move to a new button area ? if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&& (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){ joy_state[0][virtual_stick[i].button_id]=1; virtual_stick[i].finger_id=event.tfinger.fingerId; } } } break; case SDL_FINGERDOWN: refresh_counter=1; virtual_stick_on=1; state = SDL_GetTouch(event.tfinger.touchId); rx = event.tfinger.x*cur_width / state->xres; ry = event.tfinger.y*cur_height / state->yres; if (vstick_update_status(rx,ry)) { //finger is on pad joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0); joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0); joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0); joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0); joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0); joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0); joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0); joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0); virtual_stick_padfinger=event.tfinger.fingerId; } else { //check if finger is on a button for (int i=0;i<VSTICK_NB_BUTTON;i++) { if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&& (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){ joy_state[0][virtual_stick[i].button_id]=1; virtual_stick[i].finger_id=event.tfinger.fingerId; break; } } } break; case SDL_FINGERUP: refresh_counter=1; if (virtual_stick_padfinger==event.tfinger.fingerId) { virtual_stick_pad=0; joy_state[0][GN_UP]=0; joy_state[0][GN_DOWN]=0; joy_state[0][GN_LEFT]=0; joy_state[0][GN_RIGHT]=0; joy_state[0][GN_UPRIGHT]=0; joy_state[0][GN_DOWNRIGHT]=0; joy_state[0][GN_UPLEFT]=0; joy_state[0][GN_DOWNLEFT]=0; } for (int i=0;i<VSTICK_NB_BUTTON;i++) if (virtual_stick[i].finger_id==event.tfinger.fingerId) { virtual_stick[i].finger_id=0; joy_state[0][virtual_stick[i].button_id]=0; break; } if (slide_detected) { slide_detected=0; conf.rendermode++; if (conf.rendermode>3) conf.rendermode=0; } last=-1; counter=40; break; case SDL_KEYDOWN: refresh_counter=1; virtual_stick_on=0; /* Some default keyboard standard key */ switch (event.key.keysym.sym) { case SDLK_TAB: joy_state[0][GN_MENU_KEY]=1; //last=GN_MENU_KEY; //return GN_MENU_KEY; break; case SDLK_UP: joy_state[0][GN_UP]=1; //last=GN_UP; //return GN_UP; break; case SDLK_DOWN: joy_state[0][GN_DOWN]=1; //last=GN_DOWN; //return GN_DOWN; break; case SDLK_LEFT: joy_state[0][GN_LEFT]=1; //last=GN_LEFT; //return GN_LEFT; break; case SDLK_RIGHT: joy_state[0][GN_RIGHT]=1; //last=GN_RIGHT; //return GN_RIGHT; break; case SDLK_ESCAPE: joy_state[0][GN_B]=1; //last=GN_A; //return GN_A; break; case SDLK_RETURN: case SDLK_KP_ENTER: joy_state[0][GN_A]=1; //last=GN_B; //return GN_B; break; default: SDL_PushEvent(&event); handle_event(); break; } break; case SDL_KEYUP: refresh_counter=1; //printf("KEYUPPPPP!!!\n"); for(i=0;i<GN_MAX_KEY;i++) joy_state[0][i]=0; last=-1; counter=40; break; default: SDL_PushEvent(&event); handle_event(); /* Simulate keyup */ a=0; for (i = 0; i < GN_MAX_KEY; i++) if (joy_state[0][i]) a++; if (a!=1) { for (i = 0; i < GN_MAX_KEY; i++) joy_state[0][i] = 0; last = -1; counter = 40; } break; } } /* } SDL_PushEvent(&event); handle_event(); */ if (last!=-1) { if (counter>0) counter--; if (counter==0) { counter=5; return last; } } else { for(i=0;i<GN_MAX_KEY;i++) if (joy_state[0][i]) { last=i; return i; } } /* for(i=0;i<GN_MAX_KEY;i++) if (joy_state[0][i] ) { if (i != last) { counter=30; last=i; return i; } else { counter--; if (counter==0) { counter=5; return i; } } } */ return 0; }
void ONScripter::runEventLoop() { SDL_Event event, tmp_event; while ( SDL_WaitEvent(&event) ) { bool ret = false; // ignore continous SDL_MOUSEMOTION while (event.type == SDL_MOUSEMOTION){ #if SDL_VERSION_ATLEAST(1, 3, 0) if ( SDL_PeepEvents( &tmp_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT ) == 0 ) break; if (tmp_event.type != SDL_MOUSEMOTION) break; SDL_PeepEvents( &tmp_event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT ); #else if ( SDL_PeepEvents( &tmp_event, 1, SDL_PEEKEVENT, SDL_ALLEVENTS ) == 0 ) break; if (tmp_event.type != SDL_MOUSEMOTION) break; SDL_PeepEvents( &tmp_event, 1, SDL_GETEVENT, SDL_ALLEVENTS ); #endif event = tmp_event; } switch (event.type) { #if defined(IOS) // || defined(ANDROID) case SDL_FINGERMOTION: { SDL_Touch *touch = SDL_GetTouch(event.tfinger.touchId); tmp_event.motion.x = device_width *event.tfinger.x/touch->xres - (device_width -screen_device_width)/2; tmp_event.motion.y = device_height*event.tfinger.y/touch->yres - (device_height-screen_device_height)/2; if (mouseMoveEvent( &tmp_event.motion )) return; if (btndown_flag){ event.button.type = SDL_MOUSEBUTTONDOWN; event.button.button = SDL_BUTTON_LEFT; if (touch->num_fingers >= 2) event.button.button = SDL_BUTTON_RIGHT; event.button.x = tmp_event.motion.x; event.button.y = tmp_event.motion.y; ret = mousePressEvent( &event.button ); if (ret) return; } } break; case SDL_FINGERDOWN: { SDL_Touch *touch = SDL_GetTouch(event.tfinger.touchId); tmp_event.motion.x = device_width *event.tfinger.x/touch->xres - (device_width -screen_device_width)/2; tmp_event.motion.y = device_height*event.tfinger.y/touch->yres - (device_height-screen_device_height)/2; if (mouseMoveEvent( &tmp_event.motion )) return; } if ( btndown_flag ){ SDL_Touch *touch = SDL_GetTouch(event.tfinger.touchId); tmp_event.button.type = SDL_MOUSEBUTTONDOWN; tmp_event.button.button = SDL_BUTTON_LEFT; if (touch->num_fingers >= 2) tmp_event.button.button = SDL_BUTTON_RIGHT; tmp_event.button.x = device_width *event.tfinger.x/touch->xres - (device_width -screen_device_width)/2; tmp_event.button.y = device_height*event.tfinger.y/touch->yres - (device_height-screen_device_height)/2; ret = mousePressEvent( &tmp_event.button ); } { SDL_Touch *touch = SDL_GetTouch(event.tfinger.touchId); num_fingers = touch->num_fingers; if (num_fingers >= 3){ tmp_event.key.keysym.sym = SDLK_LCTRL; ret |= keyDownEvent( &tmp_event.key ); } } if (ret) return; break; case SDL_FINGERUP: if (num_fingers == 0) break; { SDL_Touch *touch = SDL_GetTouch(event.tfinger.touchId); tmp_event.button.type = SDL_MOUSEBUTTONUP; tmp_event.button.button = SDL_BUTTON_LEFT; if (touch->num_fingers >= 1) tmp_event.button.button = SDL_BUTTON_RIGHT; tmp_event.button.x = device_width *event.tfinger.x/touch->xres - (device_width -screen_device_width)/2; tmp_event.button.y = device_height*event.tfinger.y/touch->yres - (device_height-screen_device_height)/2; ret = mousePressEvent( &tmp_event.button ); } tmp_event.key.keysym.sym = SDLK_LCTRL; keyUpEvent( &tmp_event.key ); num_fingers = 0; if (ret) return; break; #else case SDL_MOUSEMOTION: if (mouseMoveEvent( &event.motion )) return; if (btndown_flag){ if (event.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT)) tmp_event.button.button = SDL_BUTTON_LEFT; else if (event.motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) tmp_event.button.button = SDL_BUTTON_RIGHT; else break; tmp_event.button.type = SDL_MOUSEBUTTONDOWN; tmp_event.button.x = event.motion.x; tmp_event.button.y = event.motion.y; ret = mousePressEvent( &tmp_event.button ); if (ret) return; } break; case SDL_MOUSEBUTTONDOWN: if ( !btndown_flag ) break; case SDL_MOUSEBUTTONUP: ret = mousePressEvent( &event.button ); if (ret) return; break; #endif case SDL_JOYBUTTONDOWN: event.key.type = SDL_KEYDOWN; event.key.keysym.sym = transJoystickButton(event.jbutton.button); if(event.key.keysym.sym == SDLK_UNKNOWN) break; case SDL_KEYDOWN: event.key.keysym.sym = transKey(event.key.keysym.sym); ret = keyDownEvent( &event.key ); if ( btndown_flag ) ret |= keyPressEvent( &event.key ); if (ret) return; break; case SDL_JOYBUTTONUP: event.key.type = SDL_KEYUP; event.key.keysym.sym = transJoystickButton(event.jbutton.button); if(event.key.keysym.sym == SDLK_UNKNOWN) break; case SDL_KEYUP: event.key.keysym.sym = transKey(event.key.keysym.sym); keyUpEvent( &event.key ); ret = keyPressEvent( &event.key ); if (ret) return; break; case SDL_JOYAXISMOTION: { SDL_KeyboardEvent ke = transJoystickAxis(event.jaxis); if (ke.keysym.sym != SDLK_UNKNOWN){ if (ke.type == SDL_KEYDOWN){ keyDownEvent( &ke ); if (btndown_flag) keyPressEvent( &ke ); } else if (ke.type == SDL_KEYUP){ keyUpEvent( &ke ); keyPressEvent( &ke ); } } break; } case ONS_TIMER_EVENT: timerEvent(); break; case ONS_MUSIC_EVENT: case ONS_BGMFADE_EVENT: case ONS_CDAUDIO_EVENT: case ONS_MIDI_EVENT: flushEventSub( event ); break; case ONS_CHUNK_EVENT: flushEventSub( event ); //printf("ONS_CHUNK_EVENT %d: %x %d %x\n", event.user.code, wave_sample[0], automode_flag, event_mode); if ( event.user.code != 0 || !(event_mode & WAIT_VOICE_MODE) ) break; event_mode &= ~WAIT_VOICE_MODE; case ONS_BREAK_EVENT: if (event_mode & WAIT_VOICE_MODE && wave_sample[0]){ timerEvent(); break; } if (automode_flag || autoclick_time > 0) current_button_state.button = 0; else if ( usewheel_flag ){ current_button_state.button = -5; sprintf(current_button_state.str, "TIMEOUT"); } else{ current_button_state.button = -2; sprintf(current_button_state.str, "TIMEOUT"); } if (event_mode & (WAIT_INPUT_MODE | WAIT_BUTTON_MODE) && ( clickstr_state == CLICK_WAIT || clickstr_state == CLICK_NEWPAGE ) ){ playClickVoice(); stopAnimation( clickstr_state ); } return; case SDL_ACTIVEEVENT: if ( !event.active.gain ) break; #ifdef ANDROID if (event.active.state == SDL_APPACTIVE){ screen_surface = SDL_SetVideoMode( screen_width, screen_height, screen_bpp, DEFAULT_VIDEO_SURFACE_FLAG ); repaintCommand(); break; } #endif case SDL_VIDEOEXPOSE: #ifdef USE_SDL_RENDERER SDL_RenderPresent(renderer); #else SDL_UpdateRect( screen_surface, 0, 0, screen_width, screen_height ); #endif break; case SDL_QUIT: endCommand(); break; default: break; } } }
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; } }