/* * input_poll_overlay: * * Poll pressed buttons/keys on currently active overlay. **/ void input_poll_overlay(float opacity) { input_overlay_state_t old_key_state; unsigned i, j, device; uint16_t key_mod = 0; bool polled = false; settings_t *settings = config_get_ptr(); input_overlay_state_t *ol_state = &overlay_st_ptr; if (!input_overlay_is_alive() || !ol_state) return; memcpy(old_key_state.keys, ol_state->keys, sizeof(ol_state->keys)); memset(ol_state, 0, sizeof(*ol_state)); device = input_overlay_full_screen() ? RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER; for (i = 0; input_driver_state(NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_PRESSED); i++) { input_overlay_state_t polled_data; int16_t x = input_driver_state(NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_X); int16_t y = input_driver_state(NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_Y); input_overlay_poll(&polled_data, x, y); ol_state->buttons |= polled_data.buttons; for (j = 0; j < ARRAY_SIZE(ol_state->keys); j++) ol_state->keys[j] |= polled_data.keys[j]; /* Fingers pressed later take prio and matched up * with overlay poll priorities. */ for (j = 0; j < 4; j++) if (polled_data.analog[j]) ol_state->analog[j] = polled_data.analog[j]; polled = true; } if (OVERLAY_GET_KEY(ol_state, RETROK_LSHIFT) || OVERLAY_GET_KEY(ol_state, RETROK_RSHIFT)) key_mod |= RETROKMOD_SHIFT; if (OVERLAY_GET_KEY(ol_state, RETROK_LCTRL) || OVERLAY_GET_KEY(ol_state, RETROK_RCTRL)) key_mod |= RETROKMOD_CTRL; if (OVERLAY_GET_KEY(ol_state, RETROK_LALT) || OVERLAY_GET_KEY(ol_state, RETROK_RALT)) key_mod |= RETROKMOD_ALT; if (OVERLAY_GET_KEY(ol_state, RETROK_LMETA) || OVERLAY_GET_KEY(ol_state, RETROK_RMETA)) key_mod |= RETROKMOD_META; /* CAPSLOCK SCROLLOCK NUMLOCK */ for (i = 0; i < ARRAY_SIZE(ol_state->keys); i++) { if (ol_state->keys[i] != old_key_state.keys[i]) { uint32_t orig_bits = old_key_state.keys[i]; uint32_t new_bits = ol_state->keys[i]; for (j = 0; j < 32; j++) if ((orig_bits & (1 << j)) != (new_bits & (1 << j))) input_keyboard_event(new_bits & (1 << j), i * 32 + j, 0, key_mod, RETRO_DEVICE_POINTER); } } /* Map "analog" buttons to analog axes like regular input drivers do. */ for (j = 0; j < 4; j++) { unsigned bind_plus = RARCH_ANALOG_LEFT_X_PLUS + 2 * j; unsigned bind_minus = bind_plus + 1; if (ol_state->analog[j]) continue; if (input_overlay_key_pressed(bind_plus)) ol_state->analog[j] += 0x7fff; if (input_overlay_key_pressed(bind_minus)) ol_state->analog[j] -= 0x7fff; } /* Check for analog_dpad_mode. * Map analogs to d-pad buttons when configured. */ switch (settings->input.analog_dpad_mode[0]) { case ANALOG_DPAD_LSTICK: case ANALOG_DPAD_RSTICK: { float analog_x, analog_y; unsigned analog_base = 2; if (settings->input.analog_dpad_mode[0] == ANALOG_DPAD_LSTICK) analog_base = 0; analog_x = (float)ol_state->analog[analog_base + 0] / 0x7fff; analog_y = (float)ol_state->analog[analog_base + 1] / 0x7fff; if (analog_x <= -settings->input.axis_threshold) ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_LEFT); if (analog_x >= settings->input.axis_threshold) ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_RIGHT); if (analog_y <= -settings->input.axis_threshold) ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_UP); if (analog_y >= settings->input.axis_threshold) ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_DOWN); break; } default: break; } if (polled) input_overlay_post_poll(opacity); else input_overlay_poll_clear(opacity); }
/** * input_state: * @port : user number. * @device : device identifier of user. * @idx : index value of user. * @id : identifier of key pressed by user. * * Input state callback function. * * Returns: Non-zero if the given key (identified by @id) was pressed by the user * (assigned to @port). **/ static int16_t input_state(unsigned port, unsigned device, unsigned idx, unsigned id) { size_t i; const struct retro_keybind *libretro_input_binds[MAX_USERS]; int16_t res = 0; settings_t *settings = config_get_ptr(); driver_t *driver = driver_get_ptr(); global_t *global = global_get_ptr(); for (i = 0; i < MAX_USERS; i++) libretro_input_binds[i] = settings->input.binds[i]; device &= RETRO_DEVICE_MASK; if (global->bsv.movie && global->bsv.movie_playback) { int16_t ret; if (bsv_movie_get_input(global->bsv.movie, &ret)) return ret; global->bsv.movie_end = true; } if (settings->input.remap_binds_enable) input_remapping_state(port, &device, &idx, &id); if (!driver->block_libretro_input) { if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD))) res = input_driver_state(libretro_input_binds, port, device, idx, id); #ifdef HAVE_OVERLAY if (port == 0) { switch (device) { case RETRO_DEVICE_JOYPAD: if (driver->overlay_state.buttons & (UINT64_C(1) << id)) res |= 1; break; case RETRO_DEVICE_KEYBOARD: if (id < RETROK_LAST) { if (OVERLAY_GET_KEY(&driver->overlay_state, id)) res |= 1; } break; case RETRO_DEVICE_ANALOG: { unsigned base = 0; if (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT) base = 2; if (id == RETRO_DEVICE_ID_ANALOG_Y) base += 1; if (driver->overlay_state.analog[base]) res = driver->overlay_state.analog[base]; } break; } } #endif } /* flushing_input will be cleared in rarch_main_iterate. */ if (driver->flushing_input) res = 0; /* Don't allow turbo for D-pad. */ if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP || id > RETRO_DEVICE_ID_JOYPAD_RIGHT)) res = input_apply_turbo(port, id, res); if (global->bsv.movie && !global->bsv.movie_playback) bsv_movie_set_input(global->bsv.movie, res); return res; }
static int menu_input_mouse(unsigned *action) { const struct retro_keybind *binds[MAX_USERS]; driver_t *driver = driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr(); settings_t *settings = config_get_ptr(); video_viewport_t vp; if (!menu) return -1; if (!settings->menu.mouse.enable #ifdef HAVE_OVERLAY || (settings->input.overlay_enable && driver && driver->overlay) #endif ) { menu->mouse.left = 0; menu->mouse.right = 0; menu->mouse.wheelup = 0; menu->mouse.wheeldown = 0; menu->mouse.hwheelup = 0; menu->mouse.hwheeldown = 0; menu->mouse.dx = 0; menu->mouse.dy = 0; menu->mouse.x = 0; menu->mouse.y = 0; menu->mouse.screen_x = 0; menu->mouse.screen_y = 0; menu->mouse.scrollup = 0; menu->mouse.scrolldown = 0; return 0; } if (!video_driver_viewport_info(&vp)) return -1; if (menu->mouse.hwheeldown) { *action = MENU_ACTION_LEFT; menu->mouse.hwheeldown = false; return 0; } if (menu->mouse.hwheelup) { *action = MENU_ACTION_RIGHT; menu->mouse.hwheelup = false; return 0; } menu->mouse.left = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT); menu->mouse.right = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT); menu->mouse.wheelup = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP); menu->mouse.wheeldown = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN); menu->mouse.hwheelup = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP); menu->mouse.hwheeldown = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN); menu->mouse.dx = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); menu->mouse.dy = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); menu->mouse.screen_x += menu->mouse.dx; menu->mouse.screen_y += menu->mouse.dy; menu->mouse.x = ((int)menu->mouse.screen_x * (int)menu->frame_buf.width) / (int)vp.width; menu->mouse.y = ((int)menu->mouse.screen_y * (int)menu->frame_buf.height) / (int)vp.height; if (menu->mouse.x < 5) menu->mouse.x = 5; if (menu->mouse.y < 5) menu->mouse.y = 5; if (menu->mouse.x > (int)menu->frame_buf.width - 5) menu->mouse.x = menu->frame_buf.width - 5; if (menu->mouse.y > (int)menu->frame_buf.height - 5) menu->mouse.y = menu->frame_buf.height - 5; menu->mouse.scrollup = (menu->mouse.y == 5); menu->mouse.scrolldown = (menu->mouse.y == (int)menu->frame_buf.height - 5); if (menu->mouse.dx != 0 || menu->mouse.dy !=0 || menu->mouse.left || menu->mouse.wheelup || menu->mouse.wheeldown || menu->mouse.hwheelup || menu->mouse.hwheeldown || menu->mouse.scrollup || menu->mouse.scrolldown) menu->animation_is_active = true; return 0; }
static int menu_input_mouse(unsigned *action) { video_viewport_t vp; const struct retro_keybind *binds[MAX_USERS]; menu_animation_t *anim = menu_animation_get_ptr(); menu_input_t *menu_input = menu_input_get_ptr(); menu_framebuf_t *frame_buf= menu_display_fb_get_ptr(); settings_t *settings = config_get_ptr(); if (!settings->menu.mouse.enable #ifdef HAVE_OVERLAY || (settings->input.overlay_enable && input_overlay_is_alive()) #endif ) { memset(&menu_input->mouse, 0, sizeof(menu_input->mouse)); return 0; } if (!video_driver_viewport_info(&vp)) return -1; if (menu_input->mouse.hwheeldown) { *action = MENU_ACTION_LEFT; menu_input->mouse.hwheeldown = false; return 0; } if (menu_input->mouse.hwheelup) { *action = MENU_ACTION_RIGHT; menu_input->mouse.hwheelup = false; return 0; } menu_input->mouse.left = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT); menu_input->mouse.right = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT); menu_input->mouse.wheelup = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP); menu_input->mouse.wheeldown = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN); menu_input->mouse.hwheelup = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP); menu_input->mouse.hwheeldown = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN); menu_input->mouse.dx = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); menu_input->mouse.dy = input_driver_state(binds, 0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); menu_input->mouse.screen_x += menu_input->mouse.dx; menu_input->mouse.screen_y += menu_input->mouse.dy; menu_input->mouse.x = ((int)menu_input->mouse.screen_x * (int)frame_buf->width) / (int)vp.width; menu_input->mouse.y = ((int)menu_input->mouse.screen_y * (int)frame_buf->height) / (int)vp.height; if (menu_input->mouse.x < 5) menu_input->mouse.x = 5; if (menu_input->mouse.y < 5) menu_input->mouse.y = 5; if (menu_input->mouse.x > (int)frame_buf->width - 5) menu_input->mouse.x = frame_buf->width - 5; if (menu_input->mouse.y > (int)frame_buf->height - 5) menu_input->mouse.y = frame_buf->height - 5; menu_input->mouse.scrollup = (menu_input->mouse.y == 5); menu_input->mouse.scrolldown = (menu_input->mouse.y == (int)frame_buf->height - 5); if ( (menu_input->mouse.dx != 0) || (menu_input->mouse.dy !=0) || menu_input->mouse.left || menu_input->mouse.wheelup || menu_input->mouse.wheeldown || menu_input->mouse.hwheelup || menu_input->mouse.hwheeldown || menu_input->mouse.scrollup || menu_input->mouse.scrolldown ) menu_animation_set_active(anim); return 0; }
static int menu_input_pointer(unsigned *action) { int pointer_device, pointer_x, pointer_y, screen_x, screen_y; const struct retro_keybind *binds[MAX_USERS]; menu_handle_t *menu = menu_driver_get_ptr(); runloop_t *runloop = rarch_main_get_ptr(); settings_t *settings = config_get_ptr(); driver_t *driver = driver_get_ptr(); if (!menu) return -1; if (!settings->menu.pointer.enable) { memset(&menu->pointer, 0, sizeof(menu->pointer)); return 0; } #if defined(HAVE_XMB) if (driver->menu_ctx == &menu_ctx_xmb) return 0; #endif pointer_device = driver->menu_ctx->set_texture? RETRO_DEVICE_POINTER : RARCH_DEVICE_POINTER_SCREEN; menu->pointer.pressed[0] = input_driver_state(binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_PRESSED); menu->pointer.pressed[1] = input_driver_state(binds, 0, pointer_device, 1, RETRO_DEVICE_ID_POINTER_PRESSED); menu->pointer.back = input_driver_state(binds, 0, pointer_device, 0, RARCH_DEVICE_ID_POINTER_BACK); pointer_x = input_driver_state(binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); pointer_y = input_driver_state(binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); /* by multiple presses, the main press will be the one closest to the previous coordinates */ if(menu->pointer.pressed[1]) { int pointer_x2, pointer_y2, dist1, dist2; pointer_x2 = input_driver_state(binds, 0, pointer_device, 1, RETRO_DEVICE_ID_POINTER_X); pointer_y2 = input_driver_state(binds, 0, pointer_device, 1, RETRO_DEVICE_ID_POINTER_Y); dist1 = (pointer_x - menu->pointer.old_x) * (pointer_x - menu->pointer.old_x) + (pointer_y - menu->pointer.old_y) * (pointer_y - menu->pointer.old_y); dist2 = (pointer_x2 - menu->pointer.old_x) * (pointer_x2 - menu->pointer.old_x) + (pointer_y2 - menu->pointer.old_y) * (pointer_y2 - menu->pointer.old_y); if (dist2 < dist1) { int temp; pointer_x = pointer_x2; pointer_y = pointer_y2; temp = menu->pointer.pressed[0]; menu->pointer.pressed[0] = menu->pointer.pressed[1]; menu->pointer.pressed[1] = temp; } } menu->pointer.old_x = pointer_x; menu->pointer.old_y = pointer_y; screen_x = ((pointer_x + 0x7fff) * (int)menu->frame_buf.width) / 0xFFFF; screen_y = ((pointer_y + 0x7fff) * (int)menu->frame_buf.height) / 0xFFFF; if (menu->pointer.pressed[0]) { menu->mouse.x = screen_x; menu->mouse.y = screen_y; if (menu->mouse.x < 5) menu->mouse.x = 5; if (menu->mouse.y < 5) menu->mouse.y = 5; if (menu->mouse.x > (int)menu->frame_buf.width - 5) menu->mouse.x = menu->frame_buf.width - 5; if (menu->mouse.y > (int)menu->frame_buf.height - 5) menu->mouse.y = menu->frame_buf.height - 5; menu->mouse.scrollup = (menu->mouse.y == 5); menu->mouse.scrolldown = (menu->mouse.y == (int)menu->frame_buf.height - 5); menu->pointer.cancel = false; if(menu->pointer.oldpressed[1] && !menu->pointer.pressed[1]) menu->pointer.back = true; } else menu->pointer.cancel = screen_x < 5 || screen_x > (int)menu->frame_buf.width - 5 || screen_x < 5 || screen_x > (int)menu->frame_buf.height - 5; menu->pointer.oldpressed[1] = menu->pointer.pressed[1]; if (menu->pointer.pressed[0] || menu->pointer.back || menu->mouse.x != screen_x || menu->mouse.y != screen_y) runloop->frames.video.current.menu.animation.is_active = true; return 0; }