2014-03-02 05:24:57 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2019-02-22 16:31:54 -05:00
|
|
|
* Copyright (C) 2016-2019 - Brad Parker
|
2016-09-05 11:35:27 -04:00
|
|
|
*
|
2014-03-02 05:24:57 +01:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-06-13 22:57:55 +02:00
|
|
|
#ifndef _MENU_INPUT_H
|
|
|
|
#define _MENU_INPUT_H
|
2014-03-02 05:24:57 +01:00
|
|
|
|
2017-05-17 05:45:25 +02:00
|
|
|
#include <stdint.h>
|
2018-09-25 16:46:15 +02:00
|
|
|
#include <compat/strl.h>
|
|
|
|
|
2016-06-03 05:49:46 +02:00
|
|
|
#include <retro_common_api.h>
|
2018-09-25 16:46:15 +02:00
|
|
|
#include <libretro.h>
|
|
|
|
|
2019-01-31 20:36:39 +01:00
|
|
|
#include "menu_defines.h"
|
2018-09-25 16:46:15 +02:00
|
|
|
#include "../input/input_types.h"
|
2021-08-04 21:33:17 +02:00
|
|
|
#include "../input/input_driver.h"
|
2016-06-03 05:49:46 +02:00
|
|
|
|
|
|
|
RETRO_BEGIN_DECLS
|
2015-09-28 06:10:42 +02:00
|
|
|
|
2019-09-20 14:16:21 +01:00
|
|
|
/* Mouse wheel tilt actions repeat at a very high
|
|
|
|
* frequency - we ignore any input that occurs
|
|
|
|
* with a period less than MENU_INPUT_HORIZ_WHEEL_DELAY */
|
2019-09-30 16:54:19 +01:00
|
|
|
#define MENU_INPUT_HORIZ_WHEEL_DELAY 250000 /* 250 ms */
|
2019-09-20 14:16:21 +01:00
|
|
|
|
2019-09-30 16:54:19 +01:00
|
|
|
/* Press directions are triggered as a pulse train.
|
|
|
|
* Pulse period starts at MENU_INPUT_PRESS_DIRECTION_DELAY_MAX,
|
|
|
|
* and decreases to MENU_INPUT_PRESS_DIRECTION_DELAY_MIN as
|
|
|
|
* the start/current delta offset increases from
|
|
|
|
* MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MIN to
|
|
|
|
* MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MAX */
|
|
|
|
#define MENU_INPUT_PRESS_DIRECTION_DELAY_MIN 100000 /* 100 ms */
|
|
|
|
#define MENU_INPUT_PRESS_DIRECTION_DELAY_MAX 500000 /* 500 ms */
|
2019-09-19 16:50:55 +01:00
|
|
|
|
2019-09-30 16:54:19 +01:00
|
|
|
#define MENU_INPUT_HIDE_CURSOR_DELAY 4000000 /* 4 seconds */
|
|
|
|
|
|
|
|
#define MENU_INPUT_PRESS_TIME_SHORT 200000 /* 200 ms */
|
2019-11-20 18:09:02 +00:00
|
|
|
#define MENU_INPUT_PRESS_TIME_LONG 1000000 /* 1 second */
|
2019-09-30 16:54:19 +01:00
|
|
|
/* (Anything less than 'short' is considered a tap) */
|
2019-09-19 16:50:55 +01:00
|
|
|
|
2019-10-01 13:00:59 +01:00
|
|
|
/* Swipe gestures must be completed within a duration
|
|
|
|
* of MENU_INPUT_SWIPE_TIMEOUT ms (helps to minimise
|
|
|
|
* unwanted input if user 'zones out' and meanders on
|
|
|
|
* a touchscreen) */
|
|
|
|
#define MENU_INPUT_SWIPE_TIMEOUT 500000 /* 500 ms */
|
|
|
|
|
2019-11-05 12:23:09 +00:00
|
|
|
/* Standard behaviour (on Android, at least) is to stop
|
|
|
|
* scrolling when the user touches the screen. To prevent
|
|
|
|
* jerky stop/start scrolling, we wait MENU_INPUT_Y_ACCEL_RESET_DELAY
|
|
|
|
* ms before resetting y acceleration after a stationary
|
|
|
|
* pointer down event is detected */
|
|
|
|
#define MENU_INPUT_Y_ACCEL_RESET_DELAY 50000 /* 50 ms */
|
|
|
|
|
2019-09-19 16:50:55 +01:00
|
|
|
#define MENU_INPUT_Y_ACCEL_DECAY_FACTOR 0.96f
|
|
|
|
|
2019-09-30 16:54:19 +01:00
|
|
|
/* Pointer is considered stationary if dx/dy remain
|
|
|
|
* below (display DPI) * MENU_INPUT_DPI_THRESHOLD_DRAG */
|
|
|
|
#define MENU_INPUT_DPI_THRESHOLD_DRAG 0.1f
|
|
|
|
|
|
|
|
/* Press direction detection:
|
|
|
|
* While holding the pointer down, a press in a
|
|
|
|
* specific direction (up, down, left, right) will
|
|
|
|
* be detected if:
|
|
|
|
* - Current delta (i.e. from start to current) in
|
|
|
|
* press direction is greater than
|
|
|
|
* (display DPI) * MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MIN
|
|
|
|
* - Current delta in perpendicular axis is less than
|
|
|
|
* (display DPI) * MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_TANGENT
|
|
|
|
* Press direction repeat rate is proportional to the current
|
|
|
|
* delta in press direction.
|
|
|
|
* Note: 'Tangent' is technically not the correct word here,
|
|
|
|
* but the alternatives look silly, and the actual meaning
|
|
|
|
* is transparent... */
|
2019-10-01 13:00:59 +01:00
|
|
|
#define MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MIN 0.5f
|
|
|
|
#define MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_MAX 1.4f
|
2019-09-30 16:54:19 +01:00
|
|
|
#define MENU_INPUT_DPI_THRESHOLD_PRESS_DIRECTION_TANGENT 0.35f
|
|
|
|
|
|
|
|
/* Swipe detection:
|
|
|
|
* A gesture will register as a swipe if:
|
2019-10-01 13:00:59 +01:00
|
|
|
* - Final start/current delta in swipe direction is
|
|
|
|
* greater than (display DPI) * MENU_INPUT_DPI_THRESHOLD_SWIPE
|
|
|
|
* - Maximum start/current delta in all other directions is
|
|
|
|
* less than (display DPI) * MENU_INPUT_DPI_THRESHOLD_SWIPE_TANGENT
|
|
|
|
* - Pointer was held for less than MENU_INPUT_SWIPE_TIMEOUT ms */
|
|
|
|
#define MENU_INPUT_DPI_THRESHOLD_SWIPE 0.55f
|
|
|
|
#define MENU_INPUT_DPI_THRESHOLD_SWIPE_TANGENT 0.45f
|
2019-09-30 16:54:19 +01:00
|
|
|
|
2019-09-19 16:50:55 +01:00
|
|
|
enum menu_pointer_type
|
|
|
|
{
|
|
|
|
MENU_POINTER_DISABLED = 0,
|
|
|
|
MENU_POINTER_MOUSE,
|
|
|
|
MENU_POINTER_TOUCHSCREEN
|
|
|
|
};
|
|
|
|
|
|
|
|
enum menu_input_mouse_hw_id
|
|
|
|
{
|
|
|
|
MENU_MOUSE_X_AXIS = 0,
|
|
|
|
MENU_MOUSE_Y_AXIS,
|
|
|
|
MENU_MOUSE_LEFT_BUTTON,
|
|
|
|
MENU_MOUSE_RIGHT_BUTTON,
|
|
|
|
MENU_MOUSE_WHEEL_UP,
|
|
|
|
MENU_MOUSE_WHEEL_DOWN,
|
|
|
|
MENU_MOUSE_HORIZ_WHEEL_UP,
|
|
|
|
MENU_MOUSE_HORIZ_WHEEL_DOWN
|
|
|
|
};
|
|
|
|
|
2019-09-30 16:54:19 +01:00
|
|
|
enum menu_input_pointer_press_direction
|
|
|
|
{
|
|
|
|
MENU_INPUT_PRESS_DIRECTION_NONE = 0,
|
|
|
|
MENU_INPUT_PRESS_DIRECTION_UP,
|
|
|
|
MENU_INPUT_PRESS_DIRECTION_DOWN,
|
|
|
|
MENU_INPUT_PRESS_DIRECTION_LEFT,
|
|
|
|
MENU_INPUT_PRESS_DIRECTION_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum menu_input_pointer_gesture
|
|
|
|
{
|
|
|
|
MENU_INPUT_GESTURE_NONE = 0,
|
|
|
|
MENU_INPUT_GESTURE_TAP,
|
|
|
|
MENU_INPUT_GESTURE_SHORT_PRESS,
|
|
|
|
MENU_INPUT_GESTURE_LONG_PRESS,
|
|
|
|
MENU_INPUT_GESTURE_SWIPE_UP,
|
|
|
|
MENU_INPUT_GESTURE_SWIPE_DOWN,
|
|
|
|
MENU_INPUT_GESTURE_SWIPE_LEFT,
|
|
|
|
MENU_INPUT_GESTURE_SWIPE_RIGHT
|
|
|
|
};
|
|
|
|
|
2019-09-19 16:50:55 +01:00
|
|
|
/* Defines set of (abstracted) inputs/states
|
|
|
|
* common to mouse + touchscreen hardware */
|
|
|
|
typedef struct menu_input_pointer_hw_state
|
|
|
|
{
|
|
|
|
int16_t x;
|
|
|
|
int16_t y;
|
2020-08-14 18:19:57 +02:00
|
|
|
bool active;
|
2019-09-19 16:50:55 +01:00
|
|
|
bool select_pressed;
|
|
|
|
bool cancel_pressed;
|
|
|
|
bool up_pressed;
|
|
|
|
bool down_pressed;
|
|
|
|
bool left_pressed;
|
|
|
|
bool right_pressed;
|
|
|
|
} menu_input_pointer_hw_state_t;
|
|
|
|
|
|
|
|
typedef struct menu_input_pointer
|
|
|
|
{
|
2020-08-15 00:11:58 +02:00
|
|
|
retro_time_t press_duration; /* int64_t alignment */
|
2020-08-14 18:19:57 +02:00
|
|
|
float y_accel;
|
|
|
|
enum menu_pointer_type type;
|
2019-09-30 16:54:19 +01:00
|
|
|
enum menu_input_pointer_press_direction press_direction;
|
2019-09-19 16:50:55 +01:00
|
|
|
int16_t x;
|
|
|
|
int16_t y;
|
|
|
|
int16_t dx;
|
|
|
|
int16_t dy;
|
2020-08-14 18:19:57 +02:00
|
|
|
bool active;
|
|
|
|
bool pressed;
|
|
|
|
bool dragged;
|
2019-09-19 16:50:55 +01:00
|
|
|
} menu_input_pointer_t;
|
|
|
|
|
2016-09-16 16:39:30 +02:00
|
|
|
typedef struct menu_input
|
|
|
|
{
|
2020-08-15 19:43:17 +02:00
|
|
|
menu_input_pointer_t pointer; /* retro_time_t alignment */
|
2019-09-19 16:50:55 +01:00
|
|
|
unsigned ptr;
|
|
|
|
bool select_inhibit;
|
2019-11-22 15:09:04 +00:00
|
|
|
bool cancel_inhibit;
|
2016-09-16 16:39:30 +02:00
|
|
|
} menu_input_t;
|
|
|
|
|
2016-02-25 17:11:00 +01:00
|
|
|
typedef struct menu_input_ctx_hitbox
|
|
|
|
{
|
|
|
|
int32_t x1;
|
|
|
|
int32_t x2;
|
|
|
|
int32_t y1;
|
|
|
|
int32_t y2;
|
|
|
|
} menu_input_ctx_hitbox_t;
|
|
|
|
|
2021-07-13 14:51:59 -05:00
|
|
|
/**
|
|
|
|
* Copy parameters from the global menu_input_state to a menu_input_pointer_t
|
|
|
|
* in order to provide access to all pointer device parameters.
|
|
|
|
*
|
|
|
|
* @param copy_target menu_input_pointer_t struct where values will be copied
|
|
|
|
**/
|
|
|
|
void menu_input_get_pointer_state(menu_input_pointer_t *copy_target);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the menu item index currently selected or hovered over by the pointer.
|
|
|
|
*
|
|
|
|
* @return the selected menu index
|
|
|
|
**/
|
2019-09-19 16:50:55 +01:00
|
|
|
unsigned menu_input_get_pointer_selection(void);
|
2020-06-05 22:00:10 +02:00
|
|
|
|
2021-07-13 14:51:59 -05:00
|
|
|
/**
|
|
|
|
* Set the menu item index that is currently selected or hovered over by the
|
|
|
|
* pointer. Note: Each menu driver is responsible for setting this.
|
|
|
|
*
|
|
|
|
* @param selection the selected menu index
|
|
|
|
**/
|
2019-09-19 16:50:55 +01:00
|
|
|
void menu_input_set_pointer_selection(unsigned selection);
|
2015-09-24 17:29:46 +02:00
|
|
|
|
2021-07-13 14:51:59 -05:00
|
|
|
/**
|
|
|
|
* Allows the pointer's y acceleration to be overridden. For example, menu
|
|
|
|
* drivers typically set acceleration to zero when populating entries.
|
|
|
|
*
|
|
|
|
* @param y_accel
|
|
|
|
**/
|
2019-09-19 16:50:55 +01:00
|
|
|
void menu_input_set_pointer_y_accel(float y_accel);
|
2016-07-09 23:23:23 +02:00
|
|
|
|
2021-07-13 14:51:59 -05:00
|
|
|
typedef struct menu_input_ctx_line
|
|
|
|
{
|
|
|
|
const char *label;
|
|
|
|
const char *label_setting;
|
|
|
|
unsigned type;
|
|
|
|
unsigned idx;
|
|
|
|
input_keyboard_line_complete_t cb;
|
|
|
|
} menu_input_ctx_line_t;
|
|
|
|
|
|
|
|
bool menu_input_dialog_start(menu_input_ctx_line_t *line);
|
|
|
|
|
|
|
|
const char *menu_input_dialog_get_label_setting_buffer(void);
|
|
|
|
|
|
|
|
const char *menu_input_dialog_get_label_buffer(void);
|
|
|
|
|
|
|
|
const char *menu_input_dialog_get_buffer(void);
|
|
|
|
|
|
|
|
unsigned menu_input_dialog_get_kb_idx(void);
|
|
|
|
|
|
|
|
bool menu_input_dialog_start_search(void);
|
|
|
|
|
|
|
|
bool menu_input_dialog_get_display_kb(void);
|
|
|
|
|
|
|
|
void menu_input_dialog_end(void);
|
|
|
|
|
2021-09-03 06:31:40 +02:00
|
|
|
bool menu_input_key_bind_poll_find_hold(
|
|
|
|
unsigned max_users,
|
|
|
|
struct menu_bind_state *new_state,
|
|
|
|
struct retro_keybind * output);
|
|
|
|
|
2016-06-03 05:49:46 +02:00
|
|
|
RETRO_END_DECLS
|
2014-10-12 20:22:33 +02:00
|
|
|
|
2014-03-02 05:24:57 +01:00
|
|
|
#endif
|