1 /* RetroArch - A frontend for libretro. 2 * Copyright (C) 2010-2014 - Hans-Kristian Arntzen 3 * Copyright (C) 2011-2017 - Daniel De Matteis 4 * Copyright (C) 2016-2019 - Brad Parker 5 * 6 * RetroArch is free software: you can redistribute it and/or modify it under the terms 7 * of the GNU General Public License as published by the Free Software Found- 8 * ation, either version 3 of the License, or (at your option) any later version. 9 * 10 * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 * PURPOSE. See the GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along with RetroArch. 15 * If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef _MENU_INPUT_H 19 #define _MENU_INPUT_H 20 21 #include <stdint.h> 22 #include <compat/strl.h> 23 24 #include <retro_common_api.h> 25 #include <libretro.h> 26 27 #include "menu_defines.h" 28 #include "../input/input_types.h" 29 30 RETRO_BEGIN_DECLS 31 32 /* Mouse wheel tilt actions repeat at a very high 33 * frequency - we ignore any input that occurs 34 * with a period less than MENU_INPUT_HORIZ_WHEEL_DELAY */ 35 #define MENU_INPUT_HORIZ_WHEEL_DELAY 250000 /* 250 ms */ 36 37 /* Press directions are triggered as a pulse train. 38 * Pulse period starts at MENU_INPUT_PRESS_DIRECTION_DELAY_MAX, 39 * and decreases to MENU_INPUT_PRESS_DIRECTION_DELAY_MIN as 40 * the start/current delta offset increases from 41 * MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MIN to 42 * MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MAX */ 43 #define MENU_INPUT_PRESS_DIRECTION_DELAY_MIN 100000 /* 100 ms */ 44 #define MENU_INPUT_PRESS_DIRECTION_DELAY_MAX 500000 /* 500 ms */ 45 46 #define MENU_INPUT_HIDE_CURSOR_DELAY 4000000 /* 4 seconds */ 47 48 #define MENU_INPUT_PRESS_TIME_SHORT 200000 /* 200 ms */ 49 #define MENU_INPUT_PRESS_TIME_LONG 1000000 /* 1 second */ 50 /* (Anything less than 'short' is considered a tap) */ 51 52 /* Swipe gestures must be completed within a duration 53 * of MENU_INPUT_SWIPE_TIMEOUT ms (helps to minimise 54 * unwanted input if user 'zones out' and meanders on 55 * a touchscreen) */ 56 #define MENU_INPUT_SWIPE_TIMEOUT 500000 /* 500 ms */ 57 58 /* Standard behaviour (on Android, at least) is to stop 59 * scrolling when the user touches the screen. To prevent 60 * jerky stop/start scrolling, we wait MENU_INPUT_Y_ACCEL_RESET_DELAY 61 * ms before resetting y acceleration after a stationary 62 * pointer down event is detected */ 63 #define MENU_INPUT_Y_ACCEL_RESET_DELAY 50000 /* 50 ms */ 64 65 #define MENU_INPUT_Y_ACCEL_DECAY_FACTOR 0.96f 66 67 /* Pointer is considered stationary if dx/dy remain 68 * below (display DPI) * MENU_INPUT_DPI_THRESHOLD_DRAG */ 69 #define MENU_INPUT_DPI_THRESHOLD_DRAG 0.1f 70 71 /* Press direction detection: 72 * While holding the pointer down, a press in a 73 * specific direction (up, down, left, right) will 74 * be detected if: 75 * - Current delta (i.e. from start to current) in 76 * press direction is greater than 77 * (display DPI) * MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MIN 78 * - Current delta in perpendicular axis is less than 79 * (display DPI) * MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_TANGENT 80 * Press direction repeat rate is proportional to the current 81 * delta in press direction. 82 * Note: 'Tangent' is technically not the correct word here, 83 * but the alternatives look silly, and the actual meaning 84 * is transparent... */ 85 #define MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MIN 0.5f 86 #define MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MAX 1.4f 87 #define MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_TANGENT 0.35f 88 89 /* Swipe detection: 90 * A gesture will register as a swipe if: 91 * - Final start/current delta in swipe direction is 92 * greater than (display DPI) * MENU_INPUT_DPI_THRESHOLD_SWIPE 93 * - Maximum start/current delta in all other directions is 94 * less than (display DPI) * MENU_INPUT_DPI_THRESHOLD_SWIPE_TANGENT 95 * - Pointer was held for less than MENU_INPUT_SWIPE_TIMEOUT ms */ 96 #define MENU_INPUT_DPI_THRESHOLD_SWIPE 0.55f 97 #define MENU_INPUT_DPI_THRESHOLD_SWIPE_TANGENT 0.45f 98 99 enum menu_pointer_type 100 { 101 MENU_POINTER_DISABLED = 0, 102 MENU_POINTER_MOUSE, 103 MENU_POINTER_TOUCHSCREEN 104 }; 105 106 enum menu_input_mouse_hw_id 107 { 108 MENU_MOUSE_X_AXIS = 0, 109 MENU_MOUSE_Y_AXIS, 110 MENU_MOUSE_LEFT_BUTTON, 111 MENU_MOUSE_RIGHT_BUTTON, 112 MENU_MOUSE_WHEEL_UP, 113 MENU_MOUSE_WHEEL_DOWN, 114 MENU_MOUSE_HORIZ_WHEEL_UP, 115 MENU_MOUSE_HORIZ_WHEEL_DOWN 116 }; 117 118 enum menu_input_pointer_press_direction 119 { 120 MENU_INPUT_PRESS_DIRECTION_NONE = 0, 121 MENU_INPUT_PRESS_DIRECTION_UP, 122 MENU_INPUT_PRESS_DIRECTION_DOWN, 123 MENU_INPUT_PRESS_DIRECTION_LEFT, 124 MENU_INPUT_PRESS_DIRECTION_RIGHT 125 }; 126 127 enum menu_input_pointer_gesture 128 { 129 MENU_INPUT_GESTURE_NONE = 0, 130 MENU_INPUT_GESTURE_TAP, 131 MENU_INPUT_GESTURE_SHORT_PRESS, 132 MENU_INPUT_GESTURE_LONG_PRESS, 133 MENU_INPUT_GESTURE_SWIPE_UP, 134 MENU_INPUT_GESTURE_SWIPE_DOWN, 135 MENU_INPUT_GESTURE_SWIPE_LEFT, 136 MENU_INPUT_GESTURE_SWIPE_RIGHT 137 }; 138 139 /* Defines set of (abstracted) inputs/states 140 * common to mouse + touchscreen hardware */ 141 typedef struct menu_input_pointer_hw_state 142 { 143 int16_t x; 144 int16_t y; 145 bool active; 146 bool select_pressed; 147 bool cancel_pressed; 148 bool up_pressed; 149 bool down_pressed; 150 bool left_pressed; 151 bool right_pressed; 152 } menu_input_pointer_hw_state_t; 153 154 typedef struct menu_input_pointer 155 { 156 retro_time_t press_duration; /* int64_t alignment */ 157 float y_accel; 158 enum menu_pointer_type type; 159 enum menu_input_pointer_press_direction press_direction; 160 int16_t x; 161 int16_t y; 162 int16_t dx; 163 int16_t dy; 164 bool active; 165 bool pressed; 166 bool dragged; 167 } menu_input_pointer_t; 168 169 typedef struct menu_input 170 { 171 menu_input_pointer_t pointer; /* retro_time_t alignment */ 172 unsigned ptr; 173 bool select_inhibit; 174 bool cancel_inhibit; 175 } menu_input_t; 176 177 typedef struct menu_input_ctx_hitbox 178 { 179 int32_t x1; 180 int32_t x2; 181 int32_t y1; 182 int32_t y2; 183 } menu_input_ctx_hitbox_t; 184 185 /* Provides access to all pointer device parameters */ 186 void menu_input_get_pointer_state(menu_input_pointer_t *pointer); 187 188 /* Getters/setters for menu item (index) currently 189 * selected/highlighted (hovered over) by the pointer 190 * device 191 * Note: Each menu driver is responsible for setting this */ 192 unsigned menu_input_get_pointer_selection(void); 193 194 void menu_input_set_pointer_selection(unsigned selection); 195 196 /* Allows pointer y acceleration to be overridden 197 * (typically want to set acceleration to zero when 198 * calling populate entries) */ 199 void menu_input_set_pointer_y_accel(float y_accel); 200 201 RETRO_END_DECLS 202 203 #endif 204