static void apple_input_poll(void *data) { uint32_t i; apple_input_data_t *apple = (apple_input_data_t*)data; if (!apple) return; for (i = 0; i < apple->touch_count; i++) { input_translate_coord_viewport(apple->touches[i].screen_x, apple->touches[i].screen_y, &apple->touches[i].fixed_x, &apple->touches[i].fixed_y, &apple->touches[i].full_x, &apple->touches[i].full_y); } if (apple->joypad) apple->joypad->poll(); if (icade_enabled) BIT32_SET(apple->buttons[0], icade_buttons); apple->mouse_delta[0] = 0; apple->mouse_delta[1] = 0; }
static int16_t dinput_pointer_state(struct dinput_input *di, unsigned index, unsigned id, bool screen) { if (index != 0) return 0; int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0; bool valid = input_translate_coord_viewport(di->mouse_x, di->mouse_y, &res_x, &res_y, &res_screen_x, &res_screen_y); if (!valid) return 0; if (screen) { res_x = res_screen_x; res_y = res_screen_y; } bool inside = (res_x >= -0x7fff) && (res_y >= -0x7fff); if (!inside) return 0; switch (id) { case RETRO_DEVICE_ID_POINTER_X: return res_x; case RETRO_DEVICE_ID_POINTER_Y: return res_y; case RETRO_DEVICE_ID_POINTER_PRESSED: return di->mouse_l; default: return 0; } }
static void cocoa_input_poll(void *data) { uint32_t i; cocoa_input_data_t *apple = (cocoa_input_data_t*)data; #ifndef IOS float backing_scale_factor = get_backing_scale_factor(); #endif for (i = 0; i < apple->touch_count; i++) { #ifndef IOS apple->touches[i].screen_x *= backing_scale_factor; apple->touches[i].screen_y *= backing_scale_factor; #endif input_translate_coord_viewport( apple->touches[i].screen_x, apple->touches[i].screen_y, &apple->touches[i].fixed_x, &apple->touches[i].fixed_y, &apple->touches[i].full_x, &apple->touches[i].full_y); } if (apple->joypad) apple->joypad->poll(); if (apple->sec_joypad) apple->sec_joypad->poll(); apple->mouse_x_last = apple->mouse_rel_x; apple->mouse_y_last = apple->mouse_rel_y; }
static int16_t dinput_pointer_state(struct dinput_input *di, unsigned idx, unsigned id, bool screen) { bool pointer_down, valid, inside; int x, y; int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0; unsigned num = 0; struct pointer_status *check_pos = di->pointer_head.next; while (check_pos && num < idx) { num++; check_pos = check_pos->next; } if (!check_pos && idx > 0) /* idx = 0 has mouse fallback. */ return 0; x = di->mouse_x; y = di->mouse_y; pointer_down = di->mouse_l; if (check_pos) { x = check_pos->pointer_x; y = check_pos->pointer_y; pointer_down = true; } valid = input_translate_coord_viewport(x, y, &res_x, &res_y, &res_screen_x, &res_screen_y); if (!valid) return 0; if (screen) { res_x = res_screen_x; res_y = res_screen_y; } inside = (res_x >= -0x7fff) && (res_y >= -0x7fff); if (!inside) return 0; switch (id) { case RETRO_DEVICE_ID_POINTER_X: return res_x; case RETRO_DEVICE_ID_POINTER_Y: return res_y; case RETRO_DEVICE_ID_POINTER_PRESSED: return pointer_down; default: break; } return 0; }
static void apple_input_poll(void *data) { int i; (void)data; #ifdef IOS apple_gamecontroller_poll_all(); #endif for (i = 0; i < g_current_input_data.touch_count; i ++) { input_translate_coord_viewport(g_current_input_data.touches[i].screen_x, g_current_input_data.touches[i].screen_y, &g_current_input_data.touches[i].fixed_x, &g_current_input_data.touches[i].fixed_y, &g_current_input_data.touches[i].full_x, &g_current_input_data.touches[i].full_y); } input_joypad_poll(joypad); g_current_input_data.pad_buttons[0] |= apple_input_get_icade_buttons(); g_current_input_data.mouse_delta[0] = 0; g_current_input_data.mouse_delta[1] = 0; }
static int16_t sdl_pointer_device_state(sdl_input_t *sdl, unsigned idx, unsigned id, bool screen) { bool valid, inside; int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0; if (idx != 0) return 0; valid = input_translate_coord_viewport(sdl->mouse_abs_x, sdl->mouse_abs_y, &res_x, &res_y, &res_screen_x, &res_screen_y); if (!valid) return 0; if (screen) { res_x = res_screen_x; res_y = res_screen_y; } inside = (res_x >= -0x7fff) && (res_y >= -0x7fff); if (!inside) return 0; switch (id) { case RETRO_DEVICE_ID_POINTER_X: return res_x; case RETRO_DEVICE_ID_POINTER_Y: return res_y; case RETRO_DEVICE_ID_POINTER_PRESSED: return sdl->mouse_l; } return 0; }
static void cocoa_input_poll(void *data) { uint32_t i; cocoa_input_data_t *apple = (cocoa_input_data_t*)data; for (i = 0; i < apple->touch_count; i++) input_translate_coord_viewport( apple->touches[i].screen_x, apple->touches[i].screen_y, &apple->touches[i].fixed_x, &apple->touches[i].fixed_y, &apple->touches[i].full_x, &apple->touches[i].full_y); if (apple->joypad) apple->joypad->poll(); if (apple->icade_enabled) BIT32_SET(apple->buttons[0], apple->icade_buttons); apple->mouse_x_last = apple->mouse_rel_x; apple->mouse_y_last = apple->mouse_rel_y; }
static void process_touch_event(screen_event_t event, int type) { int contact_id; int pos[2]; int i; screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, (int*)&contact_id); screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, pos); switch(type) { case SCREEN_EVENT_MTOUCH_TOUCH: //Find a free touch struct for(i=0;i<MAX_TOUCH;++i) { if(touch[i].contact_id == -1) { touch[i].contact_id = contact_id; input_translate_coord_viewport(pos[0], pos[1], &touch[i].x, &touch[i].y, &touch[i].full_x, &touch[i].full_y); //Add this touch to the map to signal it's valid touch[i].map = touch_count; touch_map[touch_count] = i; touch_count++; break; } } //printf("New Touch: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); //printf("Map: %d %d %d %d %d %d\n", touch_map[0], touch_map[1], touch_map[2], touch_map[3], touch_map[4], touch_map[5]);fflush(stdout); break; case SCREEN_EVENT_MTOUCH_RELEASE: for(i=0; i<MAX_TOUCH; ++i) { if(touch[i].contact_id == contact_id) { //Invalidate the finger touch[i].contact_id = -1; //Remove touch from map and shift remaining valid ones to the front touch_map[touch[i].map] = -1; int j; for(j=touch[i].map;j<touch_count;++j) { touch_map[j] = touch_map[j+1]; touch[touch_map[j+1]].map = j; touch_map[j+1] = -1; } touch_count--; break; } } //printf("Release: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); //printf("Map: %d %d %d %d %d %d\n", touch_map[0], touch_map[1], touch_map[2], touch_map[3], touch_map[4], touch_map[5]);fflush(stdout); break; case SCREEN_EVENT_MTOUCH_MOVE: //Find the finger we're tracking and update for(i=0; i<touch_count; ++i) { if(touch[i].contact_id == contact_id) { //During a move, we can go ~30 pixel into the bezel which gives negative //numbers or numbers larger than the screen res. Normalize. if(pos[0] < 0) pos[0] = 0; if(pos[0] > screen_width) pos[0] = screen_width; if(pos[1] < 0) pos[1] = 0; if(pos[1] > screen_height) pos[1] = screen_height; input_translate_coord_viewport(pos[0], pos[1], &touch[i].x, &touch[i].y, &touch[i].full_x, &touch[i].full_y); //printf("Move: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id);fflush(stdout); break; } } break; } }
static void qnx_process_touch_event( qnx_input_t *qnx, screen_event_t event, int type) { int contact_id, pos[2]; unsigned i, j; screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, (int*)&contact_id); screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, pos); switch(type) { case SCREEN_EVENT_MTOUCH_TOUCH: /* Find a free touch struct. */ for(i = 0; i < MAX_TOUCH; ++i) { if(qnx->pointer[i].contact_id == -1) { qnx->pointer[i].contact_id = contact_id; input_translate_coord_viewport(pos[0], pos[1], &qnx->pointer[i].x, &qnx->pointer[i].y, &qnx->pointer[i].full_x, &qnx->pointer[i].full_y); /* Add this pointer to the map to signal it's valid. */ qnx->pointer[i].map = qnx->pointer_count; qnx->touch_map[qnx->pointer_count] = i; qnx->pointer_count++; break; } } #if 0 printf("New Touch: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id); fflush(stdout); printf("Map: %d %d %d %d %d %d\n", qnx->touch_map[0], qnx->touch_map[1], qnx->touch_map[2], qnx->touch_map[3], qnx->touch_map[4], qnx->touch_map[5]); fflush(stdout); #endif break; case SCREEN_EVENT_MTOUCH_RELEASE: for(i = 0; i < MAX_TOUCH; ++i) { if(qnx->pointer[i].contact_id == contact_id) { /* Invalidate the finger. */ qnx->pointer[i].contact_id = -1; /* Remove pointer from map and shift * remaining valid ones to the front. */ qnx->touch_map[qnx->pointer[i].map] = -1; for(j = qnx->pointer[i].map; j < qnx->pointer_count; ++j) { qnx->touch_map[j] = qnx->touch_map[j+1]; qnx->pointer[qnx->touch_map[j+1]].map = j; qnx->touch_map[j+1] = -1; } qnx->pointer_count--; break; } } #if 0 printf("Release: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id); fflush(stdout); printf("Map: %d %d %d %d %d %d\n", qnx->touch_map[0], qnx->touch_map[1], qnx->touch_map[2], qnx->touch_map[3], qnx->touch_map[4], qnx->touch_map[5]); fflush(stdout); #endif break; case SCREEN_EVENT_MTOUCH_MOVE: /* Find the finger we're tracking and update. */ for(i = 0; i < qnx->pointer_count; ++i) { if(qnx->pointer[i].contact_id == contact_id) { #if 0 gl_t *gl = (gl_t*)video_driver_get_ptr(false); /*During a move, we can go ~30 pixel into the * bezel which gives negative numbers or * numbers larger than the screen resolution. * * Normalize. */ if(pos[0] < 0) pos[0] = 0; if(pos[0] > gl->full_x) pos[0] = gl->full_x; if(pos[1] < 0) pos[1] = 0; if(pos[1] > gl->full_y) pos[1] = gl->full_y; #endif input_translate_coord_viewport(pos[0], pos[1], &qnx->pointer[i].x, &qnx->pointer[i].y, &qnx->pointer[i].full_x, &qnx->pointer[i].full_y); #if 0 printf("Move: x:%d, y:%d, id:%d\n", pos[0], pos[1], contact_id); fflush(stdout); #endif break; } } break; } }
static void android_input_poll(void *data) { (void)data; RARCH_PERFORMANCE_INIT(input_poll); RARCH_PERFORMANCE_START(input_poll); bool debug_enable = g_settings.input.debug_enable; struct android_app* android_app = (struct android_app*)g_android; uint64_t *lifecycle_state = &g_extern.lifecycle_state; *lifecycle_state &= ~((1ULL << RARCH_RESET) | (1ULL << RARCH_REWIND) | (1ULL << RARCH_FAST_FORWARD_KEY) | (1ULL << RARCH_FAST_FORWARD_HOLD_KEY) | (1ULL << RARCH_MUTE) | (1ULL << RARCH_SAVE_STATE_KEY) | (1ULL << RARCH_LOAD_STATE_KEY) | (1ULL << RARCH_STATE_SLOT_PLUS) | (1ULL << RARCH_STATE_SLOT_MINUS)); // Read all pending events. while (AInputQueue_hasEvents(android_app->inputQueue) > 0) { AInputEvent* event = NULL; if (AInputQueue_getEvent(android_app->inputQueue, &event) < 0) break; bool long_msg_enable = false; int32_t handled = 1; int action = 0; char msg[128]; msg[0] = 0; int source = AInputEvent_getSource(event); int id = AInputEvent_getDeviceId(event); if (id == zeus_second_id) id = zeus_id; int keycode = AKeyEvent_getKeyCode(event); int type_event = AInputEvent_getType(event); int state_id = -1; if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD)) state_id = 0; // touch overlay is always player 1 else { for (unsigned i = 0; i < pads_connected; i++) if (state_device_ids[i] == id) state_id = i; } if (state_id < 0) { state_id = pads_connected; state_device_ids[pads_connected++] = id; input_autodetect_setup(android_app, msg, sizeof(msg), state_id, id, source); long_msg_enable = true; } if (keycode == AKEYCODE_BACK ) { int meta = AKeyEvent_getMetaState(event); if (!(meta & AMETA_ALT_ON)) { *lifecycle_state |= (1ULL << RARCH_QUIT_KEY); AInputQueue_finishEvent(android_app->inputQueue, event, handled); break; } } if (type_event == AINPUT_EVENT_TYPE_MOTION) { float x = 0.0f; float y = 0.0f; action = AMotionEvent_getAction(event); size_t motion_pointer = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; action &= AMOTION_EVENT_ACTION_MASK; if (source & ~(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE)) { if (g_settings.input.dpad_emulation[state_id] != DPAD_EMULATION_NONE) { uint64_t *state_cur = &state[state_id]; x = AMotionEvent_getX(event, motion_pointer); y = AMotionEvent_getY(event, motion_pointer); *state_cur &= ~((1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) | (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) | (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) | (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN)); *state_cur |= PRESSED_LEFT(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; *state_cur |= PRESSED_RIGHT(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; *state_cur |= PRESSED_UP(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0; *state_cur |= PRESSED_DOWN(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; } } else { bool keyup = (action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL || action == AMOTION_EVENT_ACTION_POINTER_UP) || (source == AINPUT_SOURCE_MOUSE && action != AMOTION_EVENT_ACTION_DOWN); if (keyup && motion_pointer < MAX_TOUCH) { memmove(pointer + motion_pointer, pointer + motion_pointer + 1, (MAX_TOUCH - motion_pointer - 1) * sizeof(struct input_pointer)); if (pointer_count > 0) pointer_count--; } else { int pointer_max = min(AMotionEvent_getPointerCount(event), MAX_TOUCH); for (motion_pointer = 0; motion_pointer < pointer_max; motion_pointer++) { x = AMotionEvent_getX(event, motion_pointer); y = AMotionEvent_getY(event, motion_pointer); input_translate_coord_viewport(x, y, &pointer[motion_pointer].x, &pointer[motion_pointer].y, &pointer[motion_pointer].full_x, &pointer[motion_pointer].full_y); pointer_count = max(pointer_count, motion_pointer + 1); } } } if (debug_enable) snprintf(msg, sizeof(msg), "Pad %d : x = %.2f, y = %.2f, src %d.\n", state_id, x, y, source); } else if (type_event == AINPUT_EVENT_TYPE_KEY)
static void android_input_poll(void *data) { (void)data; RARCH_PERFORMANCE_INIT(input_poll); RARCH_PERFORMANCE_START(input_poll); struct android_app* android_app = g_android.app; g_extern.lifecycle_state &= ~((1ULL << RARCH_RESET) | (1ULL << RARCH_REWIND) | (1ULL << RARCH_FAST_FORWARD_KEY) | (1ULL << RARCH_FAST_FORWARD_HOLD_KEY) | (1ULL << RARCH_MUTE) | (1ULL << RARCH_SAVE_STATE_KEY) | (1ULL << RARCH_LOAD_STATE_KEY) | (1ULL << RARCH_STATE_SLOT_PLUS) | (1ULL << RARCH_STATE_SLOT_MINUS)); // Read all pending events. while(AInputQueue_hasEvents(android_app->inputQueue)) { AInputEvent* event = NULL; AInputQueue_getEvent(android_app->inputQueue, &event); if (AInputQueue_preDispatchEvent(android_app->inputQueue, event)) continue; int32_t handled = 1; int source = AInputEvent_getSource(event); int id = AInputEvent_getDeviceId(event); int type_event = AInputEvent_getType(event); int state_id = state_device_ids[id]; if(state_id == -1) state_id = state_device_ids[id] = pads_connected++; int action = 0; #ifdef RARCH_INPUT_DEBUG char msg[128]; #endif if(type_event == AINPUT_EVENT_TYPE_MOTION) { action = AMotionEvent_getAction(event); int8_t motion_action = action & AMOTION_EVENT_ACTION_MASK; size_t motion_pointer = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; float x = AMotionEvent_getX(event, motion_pointer); float y = AMotionEvent_getY(event, motion_pointer); if(source & ~(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE)) { state[state_id] &= ~((1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) | (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) | (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) | (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN)); state[state_id] |= PRESSED_LEFT(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; state[state_id] |= PRESSED_RIGHT(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; state[state_id] |= PRESSED_UP(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0; state[state_id] |= PRESSED_DOWN(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; } else { bool mouse_is_not_dirty = (source == AINPUT_SOURCE_MOUSE && action != AMOTION_EVENT_ACTION_DOWN); bool pointer_is_not_dirty = (action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL || action == AMOTION_EVENT_ACTION_POINTER_UP); pointer_dirty = !(mouse_is_not_dirty || pointer_is_not_dirty); if (pointer_dirty) input_translate_coord_viewport(x, y, &pointer_x, &pointer_y); } #ifdef RARCH_INPUT_DEBUG snprintf(msg, sizeof(msg), "Pad %d : x = %.2f, y = %.2f, src %d.\n", state_id, x, y, source); #endif } else {