unsigned menu_event(retro_input_t input, retro_input_t trigger_input) { menu_animation_ctx_delta_t delta; float delta_time; /* Used for key repeat */ static float delay_timer = 0.0f; static float delay_count = 0.0f; unsigned ret = MENU_ACTION_NOOP; static bool initial_held = true; static bool first_held = false; bool set_scroll = false; bool mouse_enabled = false; size_t new_scroll_accel = 0; menu_input_t *menu_input = NULL; settings_t *settings = config_get_ptr(); if (input.state) { if (!first_held) { /* don't run anything first frame, only capture held inputs * for old_input_state. */ first_held = true; delay_timer = initial_held ? 12 : 6; delay_count = 0; } if (delay_count >= delay_timer) { retro_input_t input_repeat = {0}; BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_UP); BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_DOWN); BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_LEFT); BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_RIGHT); BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_B); BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_A); BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_L); BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_R); set_scroll = true; first_held = false; trigger_input.state |= input.state & input_repeat.state; menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &new_scroll_accel); new_scroll_accel = MIN(new_scroll_accel + 1, 64); } initial_held = false; } else { set_scroll = true; first_held = false; initial_held = true; } if (set_scroll) menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL, &new_scroll_accel); menu_animation_ctl(MENU_ANIMATION_CTL_DELTA_TIME, &delta_time); delta.current = delta_time; if (menu_animation_ctl(MENU_ANIMATION_CTL_IDEAL_DELTA_TIME_GET, &delta)) delay_count += delta.ideal; if (menu_input_dialog_get_display_kb()) { static unsigned ti_char = 64; static bool ti_next = false; if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) { if (ti_char > 32) ti_char--; if (! ti_next) input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); input_keyboard_event(true, ti_char, ti_char, 0, RETRO_DEVICE_KEYBOARD); ti_next = false; } if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) { if (ti_char < 125) ti_char++; if (! ti_next) input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); input_keyboard_event(true, ti_char, ti_char, 0, RETRO_DEVICE_KEYBOARD); ti_next = false; } if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A)) { ti_char = 64; ti_next = true; } if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B)) { input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); ti_char = 64; ti_next = false; } /* send return key to close keyboard input window */ if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START)) input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); trigger_input.state = 0; } if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) ret = MENU_ACTION_UP; else if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) ret = MENU_ACTION_DOWN; else if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT)) ret = MENU_ACTION_LEFT; else if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT)) ret = MENU_ACTION_RIGHT; else if (trigger_input.state & (UINT64_C(1) << settings->menu_scroll_up_btn)) ret = MENU_ACTION_SCROLL_UP; else if (trigger_input.state & (UINT64_C(1) << settings->menu_scroll_down_btn)) ret = MENU_ACTION_SCROLL_DOWN; else if (trigger_input.state & (UINT64_C(1) << settings->menu_cancel_btn)) ret = MENU_ACTION_CANCEL; else if (trigger_input.state & (UINT64_C(1) << settings->menu_ok_btn)) ret = MENU_ACTION_OK; else if (trigger_input.state & (UINT64_C(1) << settings->menu_search_btn)) ret = MENU_ACTION_SEARCH; else if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y)) ret = MENU_ACTION_SCAN; else if (trigger_input.state & (UINT64_C(1) << settings->menu_default_btn)) ret = MENU_ACTION_START; else if (trigger_input.state & (UINT64_C(1) << settings->menu_info_btn)) ret = MENU_ACTION_INFO; else if (trigger_input.state & (UINT64_C(1) << RARCH_MENU_TOGGLE)) ret = MENU_ACTION_TOGGLE; mouse_enabled = settings->menu.mouse.enable; #ifdef HAVE_OVERLAY if (!mouse_enabled) mouse_enabled = !(settings->input.overlay_enable && input_overlay_is_alive(NULL)); #endif if (!(menu_input = menu_input_get_ptr())) return 0; if (!mouse_enabled) menu_input->mouse.ptr = 0; if (settings->menu.pointer.enable) menu_event_pointer(&ret); else memset(&menu_input->pointer, 0, sizeof(menu_input->pointer)); return ret; }
unsigned menu_event(uint64_t input, uint64_t trigger_input) { menu_animation_ctx_delta_t delta; float delta_time; /* Used for key repeat */ static float delay_timer = 0.0f; static float delay_count = 0.0f; unsigned ret = MENU_ACTION_NOOP; static bool initial_held = true; static bool first_held = false; bool set_scroll = false; bool mouse_enabled = false; size_t new_scroll_accel = 0; menu_input_t *menu_input = NULL; settings_t *settings = config_get_ptr(); static unsigned ok_old = 0; unsigned menu_ok_btn = settings->input.menu_swap_ok_cancel_buttons ? RETRO_DEVICE_ID_JOYPAD_B : RETRO_DEVICE_ID_JOYPAD_A; unsigned menu_cancel_btn = settings->input.menu_swap_ok_cancel_buttons ? RETRO_DEVICE_ID_JOYPAD_A : RETRO_DEVICE_ID_JOYPAD_B; unsigned ok_current = input & UINT64_C(1) << menu_ok_btn; unsigned ok_trigger = ok_current & ~ok_old; ok_old = ok_current; if (input) { if (!first_held) { /* don't run anything first frame, only capture held inputs * for old_input_state. */ first_held = true; delay_timer = initial_held ? 12 : 6; delay_count = 0; } if (delay_count >= delay_timer) { uint64_t input_repeat = 0; BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_UP); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_DOWN); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_LEFT); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_RIGHT); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_L); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_R); set_scroll = true; first_held = false; trigger_input |= input & input_repeat; menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &new_scroll_accel); new_scroll_accel = MIN(new_scroll_accel + 1, 64); } initial_held = false; } else { set_scroll = true; first_held = false; initial_held = true; } if (set_scroll) menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL, &new_scroll_accel); menu_animation_ctl(MENU_ANIMATION_CTL_DELTA_TIME, &delta_time); delta.current = delta_time; if (menu_animation_ctl(MENU_ANIMATION_CTL_IDEAL_DELTA_TIME_GET, &delta)) delay_count += delta.ideal; if (menu_input_dialog_get_display_kb()) { switch (osk_idx) { case OSK_HIRAGANA_PAGE1: { memcpy(osk_grid, hiragana_page1_grid, sizeof(hiragana_page1_grid)); break; } case OSK_HIRAGANA_PAGE2: { memcpy(osk_grid, hiragana_page2_grid, sizeof(hiragana_page2_grid)); break; } case OSK_KATAKANA_PAGE1: { memcpy(osk_grid, katakana_page1_grid, sizeof(katakana_page1_grid)); break; } case OSK_KATAKANA_PAGE2: { memcpy(osk_grid, katakana_page2_grid, sizeof(katakana_page2_grid)); break; } case OSK_UPPERCASE_LATIN: { memcpy(osk_grid, uppercase_grid, sizeof(uppercase_grid)); break; } case OSK_LOWERCASE_LATIN: default: { memcpy(osk_grid, lowercase_grid, sizeof(lowercase_grid)); break; } } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) { if (osk_ptr < 33) osk_ptr = osk_ptr + OSK_CHARS_PER_LINE; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) { if (osk_ptr >= OSK_CHARS_PER_LINE) osk_ptr = osk_ptr - OSK_CHARS_PER_LINE; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT)) { if (osk_ptr < 43) osk_ptr = osk_ptr + 1; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT)) { if (osk_ptr >= 1) osk_ptr = osk_ptr - 1; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L)) { if (osk_idx > OSK_TYPE_UNKNOWN + 1) osk_idx = (enum osk_type)(osk_idx - 1); else osk_idx = (enum osk_type)(OSK_TYPE_LAST - 1); } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R)) { if (osk_idx < OSK_TYPE_LAST - 1) osk_idx = (enum osk_type)(osk_idx + 1); else osk_idx = (enum osk_type)(OSK_TYPE_UNKNOWN + 1); } if (trigger_input & (UINT64_C(1) << menu_ok_btn)) { if (osk_ptr >= 0) { menu_event_osk_append(osk_ptr); } } if (trigger_input & (UINT64_C(1) << menu_cancel_btn)) { input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); } /* send return key to close keyboard input window */ if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START)) input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); trigger_input = 0; ok_trigger = 0; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) ret = MENU_ACTION_UP; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) ret = MENU_ACTION_DOWN; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT)) ret = MENU_ACTION_LEFT; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT)) ret = MENU_ACTION_RIGHT; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L)) ret = MENU_ACTION_SCROLL_UP; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R)) ret = MENU_ACTION_SCROLL_DOWN; else if (ok_trigger) ret = MENU_ACTION_OK; else if (trigger_input & (UINT64_C(1) << menu_cancel_btn)) ret = MENU_ACTION_CANCEL; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X)) ret = MENU_ACTION_SEARCH; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y)) ret = MENU_ACTION_SCAN; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START)) ret = MENU_ACTION_START; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT)) ret = MENU_ACTION_INFO; else if (trigger_input & (UINT64_C(1) << RARCH_MENU_TOGGLE)) ret = MENU_ACTION_TOGGLE; if (menu_keyboard_key_state[RETROK_F11]) { command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL); menu_keyboard_key_state[RETROK_F11] = false; } if (runloop_cmd_press(trigger_input, RARCH_QUIT_KEY)) return MENU_ACTION_QUIT; mouse_enabled = settings->menu.mouse.enable; #ifdef HAVE_OVERLAY if (!mouse_enabled) mouse_enabled = !(settings->input.overlay_enable && input_overlay_is_alive(overlay_ptr)); #endif if (!(menu_input = menu_input_get_ptr())) return 0; if (!mouse_enabled) menu_input->mouse.ptr = 0; if (settings->menu.pointer.enable) menu_event_pointer(&ret); else { menu_input->pointer.x = 0; menu_input->pointer.y = 0; menu_input->pointer.dx = 0; menu_input->pointer.dy = 0; menu_input->pointer.accel = 0; menu_input->pointer.pressed[0] = false; menu_input->pointer.pressed[1] = false; menu_input->pointer.back = false; menu_input->pointer.ptr = 0; } return ret; }
static void xui_render(void *data, bool is_idle) { size_t end, i, selection, fb_pitch; unsigned fb_width, fb_height; char title[PATH_MAX_LENGTH] = {0}; const char *dir = NULL; const char *label = NULL; unsigned menu_type = 0; uint64_t frame_count = xui_frame_count; bool msg_force = menu_display_get_msg_force(); menu_display_get_fb_size(&fb_width, &fb_height, &fb_pitch); if ( menu_entries_ctl(MENU_ENTRIES_CTL_NEEDS_REFRESH, NULL) && menu_driver_is_alive() && !msg_force ) return; menu_display_unset_framebuffer_dirty_flag(); menu_animation_ctl(MENU_ANIMATION_CTL_CLEAR_ACTIVE, NULL); xui_render_background(); if (XuiHandleIsValid(m_menutitle)) { menu_animation_ctx_ticker_t ticker; menu_entries_get_title(title, sizeof(title)); mbstowcs(strw_buffer, title, sizeof(strw_buffer) / sizeof(wchar_t)); XuiTextElementSetText(m_menutitle, strw_buffer); ticker.s = title; ticker.len = RXUI_TERM_WIDTH(fb_width) - 3; ticker.idx = (unsigned int)frame_count / 15; ticker.str = title; ticker.selected = true; menu_animation_ticker(&ticker); } if (XuiHandleIsValid(m_menutitle)) { if ( menu_entries_get_core_title(title, sizeof(title)) == 0) { mbstowcs(strw_buffer, title, sizeof(strw_buffer) / sizeof(wchar_t)); XuiTextElementSetText(m_menutitlebottom, strw_buffer); } } end = menu_entries_get_size(); for (i = 0; i < end; i++) { menu_entry_t entry; char *entry_path = NULL; char entry_value[PATH_MAX_LENGTH] = {0}; wchar_t msg_right[PATH_MAX_LENGTH] = {0}; wchar_t msg_left[PATH_MAX_LENGTH] = {0}; menu_entry_init(&entry); menu_entry_get(&entry, 0, i, NULL, true); menu_entry_get_value(&entry, entry_value, sizeof(entry_value)); entry_path = menu_entry_get_path(&entry); mbstowcs(msg_left, entry_path, sizeof(msg_left) / sizeof(wchar_t)); mbstowcs(msg_right, entry_value, sizeof(msg_right) / sizeof(wchar_t)); xui_set_list_text(i, msg_left, msg_right); menu_entry_free(&entry); if (!string_is_empty(entry_path)) free(entry_path); } selection = menu_navigation_get_selection(); XuiListSetCurSelVisible(m_menulist, selection); if (menu_input_dialog_get_display_kb()) { char msg[1024] = {0}; const char *str = menu_input_dialog_get_buffer(); const char *label = menu_input_dialog_get_label_buffer(); snprintf(msg, sizeof(msg), "%s\n%s", label, str); xui_render_messagebox(NULL, msg); } }
unsigned menu_event(uint64_t input, uint64_t trigger_input) { menu_animation_ctx_delta_t delta; float delta_time; /* Used for key repeat */ static float delay_timer = 0.0f; static float delay_count = 0.0f; unsigned ret = MENU_ACTION_NOOP; static bool initial_held = true; static bool first_held = false; bool set_scroll = false; bool mouse_enabled = false; size_t new_scroll_accel = 0; menu_input_t *menu_input = NULL; settings_t *settings = config_get_ptr(); if (input) { if (!first_held) { /* don't run anything first frame, only capture held inputs * for old_input_state. */ first_held = true; delay_timer = initial_held ? 12 : 6; delay_count = 0; } if (delay_count >= delay_timer) { uint64_t input_repeat = 0; BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_UP); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_DOWN); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_LEFT); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_RIGHT); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_L); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_R); set_scroll = true; first_held = false; trigger_input |= input & input_repeat; menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &new_scroll_accel); new_scroll_accel = MIN(new_scroll_accel + 1, 64); } initial_held = false; } else { set_scroll = true; first_held = false; initial_held = true; } if (set_scroll) menu_navigation_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL, &new_scroll_accel); menu_animation_ctl(MENU_ANIMATION_CTL_DELTA_TIME, &delta_time); delta.current = delta_time; if (menu_animation_ctl(MENU_ANIMATION_CTL_IDEAL_DELTA_TIME_GET, &delta)) delay_count += delta.ideal; if (menu_input_dialog_get_display_kb()) { if (kbd_upper) strlcpy(kbd_grid, "!@#$%^&*()QWERTYUIOPASDFGHJKL:ZXCVBNM <>?", sizeof(kbd_grid)); else strlcpy(kbd_grid, "1234567890qwertyuiopasdfghjkl:zxcvbnm ,./", sizeof(kbd_grid)); if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) { if (kbd_index < 30) kbd_index = kbd_index + 10; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) { if (kbd_index >= 10) kbd_index = kbd_index - 10; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT)) { if (kbd_index < 39) kbd_index = kbd_index + 1; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT)) { if (kbd_index >= 1) kbd_index = kbd_index - 1; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y)) { kbd_upper = ! kbd_upper; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A)) { input_keyboard_event(true, kbd_grid[kbd_index], kbd_grid[kbd_index], 0, RETRO_DEVICE_KEYBOARD); } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B)) { input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); } /* send return key to close keyboard input window */ if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START)) input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); trigger_input = 0; } if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) ret = MENU_ACTION_UP; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) ret = MENU_ACTION_DOWN; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT)) ret = MENU_ACTION_LEFT; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT)) ret = MENU_ACTION_RIGHT; else if (trigger_input & (UINT64_C(1) << settings->menu_scroll_up_btn)) ret = MENU_ACTION_SCROLL_UP; else if (trigger_input & (UINT64_C(1) << settings->menu_scroll_down_btn)) ret = MENU_ACTION_SCROLL_DOWN; else if (trigger_input & (UINT64_C(1) << settings->menu_cancel_btn)) ret = MENU_ACTION_CANCEL; else if (trigger_input & (UINT64_C(1) << settings->menu_ok_btn)) ret = MENU_ACTION_OK; else if (trigger_input & (UINT64_C(1) << settings->menu_search_btn)) ret = MENU_ACTION_SEARCH; else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y)) ret = MENU_ACTION_SCAN; else if (trigger_input & (UINT64_C(1) << settings->menu_default_btn)) ret = MENU_ACTION_START; else if (trigger_input & (UINT64_C(1) << settings->menu_info_btn)) ret = MENU_ACTION_INFO; else if (trigger_input & (UINT64_C(1) << RARCH_MENU_TOGGLE)) ret = MENU_ACTION_TOGGLE; mouse_enabled = settings->menu.mouse.enable; #ifdef HAVE_OVERLAY if (!mouse_enabled) mouse_enabled = !(settings->input.overlay_enable && input_overlay_is_alive(NULL)); #endif if (!(menu_input = menu_input_get_ptr())) return 0; if (!mouse_enabled) menu_input->mouse.ptr = 0; if (settings->menu.pointer.enable) menu_event_pointer(&ret); else { menu_input->pointer.x = 0; menu_input->pointer.y = 0; menu_input->pointer.dx = 0; menu_input->pointer.dy = 0; menu_input->pointer.accel = 0; menu_input->pointer.pressed[0] = false; menu_input->pointer.pressed[1] = false; menu_input->pointer.back = false; menu_input->pointer.ptr = 0; } return ret; }
static int menu_input_pointer_post_iterate( menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { static bool pointer_oldpressed[2]; static bool pointer_oldback = false; static int16_t start_x = 0; static int16_t start_y = 0; static int16_t pointer_old_x = 0; static int16_t pointer_old_y = 0; int ret = 0; menu_input_t *menu_input = &menu_input_state; settings_t *settings = config_get_ptr(); if (!menu_input || !settings) return -1; #ifdef HAVE_OVERLAY /* If we have overlays enabled, overlay controls take * precedence and we don't want regular menu * pointer controls to be handled */ if (( settings->bools.input_overlay_enable && input_overlay_is_alive(overlay_ptr))) return 0; #endif if (menu_input->pointer.pressed[0]) { gfx_ctx_metrics_t metrics; float dpi; static float accel0 = 0.0f; static float accel1 = 0.0f; int16_t pointer_x = menu_input_pointer_state(MENU_POINTER_X_AXIS); int16_t pointer_y = menu_input_pointer_state(MENU_POINTER_Y_AXIS); metrics.type = DISPLAY_METRIC_DPI; metrics.value = &dpi; menu_input->pointer.counter++; if (menu_input->pointer.counter == 1 && !menu_input_ctl(MENU_INPUT_CTL_IS_POINTER_DRAGGED, NULL)) { menu_ctx_pointer_t point; point.x = pointer_x; point.y = pointer_y; point.ptr = menu_input->pointer.ptr; point.cbs = cbs; point.entry = entry; point.action = action; menu_driver_ctl(RARCH_MENU_CTL_POINTER_DOWN, &point); } if (!pointer_oldpressed[0]) { menu_input->pointer.accel = 0; accel0 = 0; accel1 = 0; start_x = pointer_x; start_y = pointer_y; pointer_old_x = pointer_x; pointer_old_y = pointer_y; pointer_oldpressed[0] = true; } else if (video_context_driver_get_metrics(&metrics)) { if (abs(pointer_x - start_x) > (dpi / 10) || abs(pointer_y - start_y) > (dpi / 10)) { float s; menu_input_ctl(MENU_INPUT_CTL_SET_POINTER_DRAGGED, NULL); menu_input->pointer.dx = pointer_x - pointer_old_x; menu_input->pointer.dy = pointer_y - pointer_old_y; pointer_old_x = pointer_x; pointer_old_y = pointer_y; s = menu_input->pointer.dy; menu_input->pointer.accel = (accel0 + accel1 + s) / 3; accel0 = accel1; accel1 = menu_input->pointer.accel; } } } else { if (pointer_oldpressed[0]) { if (!menu_input_ctl(MENU_INPUT_CTL_IS_POINTER_DRAGGED, NULL)) { menu_ctx_pointer_t point; point.x = start_x; point.y = start_y; point.ptr = menu_input->pointer.ptr; point.cbs = cbs; point.entry = entry; point.action = action; if (menu_input_dialog_get_display_kb()) { menu_driver_ctl(RARCH_MENU_CTL_OSK_PTR_AT_POS, &point); if (point.retcode > -1) { menu_event_set_osk_ptr(point.retcode); menu_event_osk_append(point.retcode); } } else { if (menu_input->pointer.counter > 32) { size_t selection = menu_navigation_get_selection(); if (cbs && cbs->action_start) return menu_entry_action(entry, (unsigned)selection, MENU_ACTION_START); } else { menu_driver_ctl(RARCH_MENU_CTL_POINTER_UP, &point); menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point); ret = point.retcode; } } } pointer_oldpressed[0] = false; start_x = 0; start_y = 0; pointer_old_x = 0; pointer_old_y = 0; menu_input->pointer.dx = 0; menu_input->pointer.dy = 0; menu_input->pointer.counter = 0; menu_input_ctl(MENU_INPUT_CTL_UNSET_POINTER_DRAGGED, NULL); } } if (menu_input->pointer.back) { if (!pointer_oldback) { pointer_oldback = true; menu_entry_action(entry, (unsigned)menu_navigation_get_selection(), MENU_ACTION_CANCEL); } } pointer_oldback = menu_input->pointer.back; return ret; }
static int menu_input_mouse_frame( menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { bool mouse_activity = false; bool no_mouse_activity = false; uint64_t mouse_state = MENU_MOUSE_ACTION_NONE; int ret = 0; settings_t *settings = config_get_ptr(); menu_input_t *menu_input = &menu_input_state; bool mouse_enable = settings->bools.menu_mouse_enable; if (mouse_enable) ret = menu_input_mouse_post_iterate(&mouse_state, cbs, action, &mouse_activity); if ((settings->bools.menu_pointer_enable || mouse_enable)) { menu_ctx_pointer_t point; point.x = menu_input_mouse_state(MENU_MOUSE_X_AXIS); point.y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS); point.ptr = 0; point.cbs = NULL; point.entry = NULL; point.action = 0; point.retcode = 0; if (menu_input_dialog_get_display_kb()) menu_driver_ctl(RARCH_MENU_CTL_OSK_PTR_AT_POS, &point); if (rarch_timer_is_running(&mouse_activity_timer)) rarch_timer_tick(&mouse_activity_timer); if (mouse_old_x != point.x || mouse_old_y != point.y) { if (!rarch_timer_is_running(&mouse_activity_timer)) mouse_activity = true; menu_event_set_osk_ptr(point.retcode); } else { if (rarch_timer_has_expired(&mouse_activity_timer)) no_mouse_activity = true; } mouse_old_x = point.x; mouse_old_y = point.y; } if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_BUTTON_L)) { menu_ctx_pointer_t point; point.x = menu_input_mouse_state(MENU_MOUSE_X_AXIS); point.y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS); point.ptr = menu_input->mouse.ptr; point.cbs = cbs; point.entry = entry; point.action = action; if (menu_input_dialog_get_display_kb()) { menu_driver_ctl(RARCH_MENU_CTL_OSK_PTR_AT_POS, &point); if (point.retcode > -1) { menu_event_set_osk_ptr(point.retcode); menu_event_osk_append(point.retcode); } } else { menu_driver_ctl(RARCH_MENU_CTL_POINTER_UP, &point); menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point); ret = point.retcode; } } if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_BUTTON_R)) { size_t selection = menu_navigation_get_selection(); menu_entry_action(entry, (unsigned)selection, MENU_ACTION_CANCEL); } if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_WHEEL_DOWN)) { unsigned increment_by = 1; menu_driver_ctl(MENU_NAVIGATION_CTL_INCREMENT, &increment_by); } if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_WHEEL_UP)) { unsigned decrement_by = 1; menu_driver_ctl(MENU_NAVIGATION_CTL_DECREMENT, &decrement_by); } if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_HORIZ_WHEEL_UP)) { /* stub */ } if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_HORIZ_WHEEL_DOWN)) { /* stub */ } if (mouse_activity) { menu_ctx_environment_t menu_environ; rarch_timer_begin(&mouse_activity_timer, 4); menu_environ.type = MENU_ENVIRON_ENABLE_MOUSE_CURSOR; menu_environ.data = NULL; menu_driver_ctl(RARCH_MENU_CTL_ENVIRONMENT, &menu_environ); } if (no_mouse_activity) { menu_ctx_environment_t menu_environ; rarch_timer_end(&mouse_activity_timer); menu_environ.type = MENU_ENVIRON_DISABLE_MOUSE_CURSOR; menu_environ.data = NULL; menu_driver_ctl(RARCH_MENU_CTL_ENVIRONMENT, &menu_environ); } return ret; }
/* * This function gets called in order to process all input events * for the current frame. * * Sends input code to menu for one frame. * * It uses as input the local variables' input' and 'trigger_input'. * * Mouse and touch input events get processed inside this function. * * NOTE: 'input' and 'trigger_input' is sourced from the keyboard and/or * the gamepad. It does not contain input state derived from the mouse * and/or touch - this gets dealt with separately within this function. * * TODO/FIXME - maybe needs to be overhauled so we can send multiple * events per frame if we want to, and we shouldn't send the * entire button state either but do a separate event per button * state. */ unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_input) { /* Used for key repeat */ static float delay_timer = 0.0f; static float delay_count = 0.0f; static unsigned ok_old = 0; unsigned ret = MENU_ACTION_NOOP; static bool initial_held = true; static bool first_held = false; bool set_scroll = false; bool mouse_enabled = false; size_t new_scroll_accel = 0; menu_input_t *menu_input = NULL; settings_t *settings = config_get_ptr(); bool swap_ok_cancel_btns = settings->bools.input_menu_swap_ok_cancel_buttons; bool input_swap_override = input_autoconfigure_get_swap_override(); unsigned menu_ok_btn = (!input_swap_override && swap_ok_cancel_btns) ? RETRO_DEVICE_ID_JOYPAD_B : RETRO_DEVICE_ID_JOYPAD_A; unsigned menu_cancel_btn = (!input_swap_override && swap_ok_cancel_btns) ? RETRO_DEVICE_ID_JOYPAD_A : RETRO_DEVICE_ID_JOYPAD_B; unsigned ok_current = BIT256_GET_PTR(p_input, menu_ok_btn ); unsigned ok_trigger = ok_current & ~ok_old; ok_old = ok_current; if (bits_any_set(p_input->data, ARRAY_SIZE(p_input->data))) { if (!first_held) { /* don't run anything first frame, only capture held inputs * for old_input_state. */ first_held = true; delay_timer = initial_held ? 200 : 100; delay_count = 0; } if (delay_count >= delay_timer) { uint32_t input_repeat = 0; BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_UP); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_DOWN); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_LEFT); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_RIGHT); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_L); BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_R); set_scroll = true; first_held = false; p_trigger_input->data[0] |= p_input->data[0] & input_repeat; menu_driver_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &new_scroll_accel); new_scroll_accel = MIN(new_scroll_accel + 1, 64); } initial_held = false; } else { set_scroll = true; first_held = false; initial_held = true; } if (set_scroll) menu_driver_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL, &new_scroll_accel); delay_count += menu_animation_get_delta_time(); if (menu_input_dialog_get_display_kb()) { menu_event_osk_iterate(); if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_DOWN)) { if (menu_event_get_osk_ptr() < 33) menu_event_set_osk_ptr(menu_event_get_osk_ptr() + OSK_CHARS_PER_LINE); } if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_UP)) { if (menu_event_get_osk_ptr() >= OSK_CHARS_PER_LINE) menu_event_set_osk_ptr(menu_event_get_osk_ptr() - OSK_CHARS_PER_LINE); } if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_RIGHT)) { if (menu_event_get_osk_ptr() < 43) menu_event_set_osk_ptr(menu_event_get_osk_ptr() + 1); } if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_LEFT)) { if (menu_event_get_osk_ptr() >= 1) menu_event_set_osk_ptr(menu_event_get_osk_ptr() - 1); } if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L)) { if (menu_event_get_osk_idx() > OSK_TYPE_UNKNOWN + 1) menu_event_set_osk_idx((enum osk_type)( menu_event_get_osk_idx() - 1)); else menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_LAST - 1)); } if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R)) { if (menu_event_get_osk_idx() < OSK_TYPE_LAST - 1) menu_event_set_osk_idx((enum osk_type)( menu_event_get_osk_idx() + 1)); else menu_event_set_osk_idx((enum osk_type)(OSK_TYPE_UNKNOWN + 1)); } if (BIT256_GET_PTR(p_trigger_input, menu_ok_btn)) { if (menu_event_get_osk_ptr() >= 0) menu_event_osk_append(menu_event_get_osk_ptr()); } if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn)) input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); /* send return key to close keyboard input window */ if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_START)) input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); BIT256_CLEAR_ALL_PTR(p_trigger_input); } else { if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_UP)) ret = MENU_ACTION_UP; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_DOWN)) ret = MENU_ACTION_DOWN; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_LEFT)) ret = MENU_ACTION_LEFT; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_RIGHT)) ret = MENU_ACTION_RIGHT; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_L)) ret = MENU_ACTION_SCROLL_UP; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_R)) ret = MENU_ACTION_SCROLL_DOWN; else if (ok_trigger) ret = MENU_ACTION_OK; else if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn)) ret = MENU_ACTION_CANCEL; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_X)) ret = MENU_ACTION_SEARCH; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_Y)) ret = MENU_ACTION_SCAN; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_START)) ret = MENU_ACTION_START; else if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) ret = MENU_ACTION_INFO; else if (BIT256_GET_PTR(p_trigger_input, RARCH_MENU_TOGGLE)) ret = MENU_ACTION_TOGGLE; } if (menu_event_kb_is_set(RETROK_F11)) { command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL); menu_event_kb_set_internal(RETROK_F11, 0); } mouse_enabled = settings->bools.menu_mouse_enable; #ifdef HAVE_OVERLAY if (!mouse_enabled) mouse_enabled = !(settings->bools.input_overlay_enable && input_overlay_is_alive(overlay_ptr)); #endif menu_input = &menu_input_state; if (!mouse_enabled) menu_input->mouse.ptr = 0; if (settings->bools.menu_pointer_enable) menu_event_pointer(&ret); else { menu_input->pointer.x = 0; menu_input->pointer.y = 0; menu_input->pointer.dx = 0; menu_input->pointer.dy = 0; menu_input->pointer.accel = 0; menu_input->pointer.pressed[0] = false; menu_input->pointer.pressed[1] = false; menu_input->pointer.back = false; menu_input->pointer.ptr = 0; } return ret; }
static int menu_input_pointer_post_iterate( menu_file_list_cbs_t *cbs, menu_entry_t *entry, unsigned action) { static bool pointer_oldpressed[2]; static bool pointer_oldback = false; static int16_t start_x = 0; static int16_t start_y = 0; static int16_t pointer_old_x = 0; static int16_t pointer_old_y = 0; int ret = 0; bool check_overlay = false; menu_input_t *menu_input = menu_input_get_ptr(); settings_t *settings = config_get_ptr(); if (!menu_input || !settings) return -1; check_overlay = !settings->menu.pointer.enable; #ifdef HAVE_OVERLAY if (!check_overlay) check_overlay = (settings->input.overlay_enable && input_overlay_is_alive(overlay_ptr)); #endif if (check_overlay) return 0; if (menu_input->pointer.pressed[0]) { gfx_ctx_metrics_t metrics; float dpi; static float accel0 = 0.0f; static float accel1 = 0.0f; int16_t pointer_x = menu_input_pointer_state(MENU_POINTER_X_AXIS); int16_t pointer_y = menu_input_pointer_state(MENU_POINTER_Y_AXIS); metrics.type = DISPLAY_METRIC_DPI; metrics.value = &dpi; video_context_driver_get_metrics(&metrics); if (!pointer_oldpressed[0]) { menu_input->pointer.accel = 0; accel0 = 0; accel1 = 0; start_x = pointer_x; start_y = pointer_y; pointer_old_x = pointer_x; pointer_old_y = pointer_y; pointer_oldpressed[0] = true; } else if (abs(pointer_x - start_x) > (dpi / 10) || abs(pointer_y - start_y) > (dpi / 10)) { float s, delta_time; menu_input_ctl(MENU_INPUT_CTL_SET_POINTER_DRAGGED, NULL); menu_input->pointer.dx = pointer_x - pointer_old_x; menu_input->pointer.dy = pointer_y - pointer_old_y; pointer_old_x = pointer_x; pointer_old_y = pointer_y; menu_animation_ctl(MENU_ANIMATION_CTL_DELTA_TIME, &delta_time); s = (menu_input->pointer.dy * 550000000.0 ) / ( dpi * delta_time ); menu_input->pointer.accel = (accel0 + accel1 + s) / 3; accel0 = accel1; accel1 = menu_input->pointer.accel; } } else { if (pointer_oldpressed[0]) { if (!menu_input_ctl(MENU_INPUT_CTL_IS_POINTER_DRAGGED, NULL)) { menu_ctx_pointer_t point; point.x = start_x; point.y = start_y; point.ptr = menu_input->pointer.ptr; point.cbs = cbs; point.entry = entry; point.action = action; if (menu_input_dialog_get_display_kb()) { menu_driver_ctl(RARCH_MENU_CTL_OSK_PTR_AT_POS, &point); if (point.retcode > -1) { menu_event_set_osk_ptr(point.retcode); menu_event_osk_append(point.retcode); } } else { menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point); ret = point.retcode; } } pointer_oldpressed[0] = false; start_x = 0; start_y = 0; pointer_old_x = 0; pointer_old_y = 0; menu_input->pointer.dx = 0; menu_input->pointer.dy = 0; menu_input_ctl(MENU_INPUT_CTL_UNSET_POINTER_DRAGGED, NULL); } } if (menu_input->pointer.back) { if (!pointer_oldback) { size_t selection; pointer_oldback = true; menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection); menu_entry_action(entry, selection, MENU_ACTION_CANCEL); } } pointer_oldback = menu_input->pointer.back; return ret; }