mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
Move functiosn around
This commit is contained in:
parent
f4b61bd164
commit
28e035ec6b
@ -173,56 +173,6 @@ const char *input_bind_map_get_desc(unsigned i)
|
||||
return keybind->desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_translate_coord_viewport:
|
||||
* @mouse_x : Pointer X coordinate.
|
||||
* @mouse_y : Pointer Y coordinate.
|
||||
* @res_x : Scaled X coordinate.
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
**/
|
||||
bool input_translate_coord_viewport(int mouse_x, int mouse_y,
|
||||
int16_t *res_x, int16_t *res_y, int16_t *res_screen_x,
|
||||
int16_t *res_screen_y)
|
||||
{
|
||||
int scaled_screen_x, scaled_screen_y, scaled_x, scaled_y;
|
||||
struct video_viewport vp = {0};
|
||||
|
||||
if (!video_driver_viewport_info(&vp))
|
||||
return false;
|
||||
|
||||
scaled_screen_x = (2 * mouse_x * 0x7fff) / (int)vp.full_width - 0x7fff;
|
||||
scaled_screen_y = (2 * mouse_y * 0x7fff) / (int)vp.full_height - 0x7fff;
|
||||
if (scaled_screen_x < -0x7fff || scaled_screen_x > 0x7fff)
|
||||
scaled_screen_x = -0x8000; /* OOB */
|
||||
if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff)
|
||||
scaled_screen_y = -0x8000; /* OOB */
|
||||
|
||||
mouse_x -= vp.x;
|
||||
mouse_y -= vp.y;
|
||||
|
||||
scaled_x = (2 * mouse_x * 0x7fff) / (int)vp.width - 0x7fff;
|
||||
scaled_y = (2 * mouse_y * 0x7fff) / (int)vp.height - 0x7fff;
|
||||
if (scaled_x < -0x7fff || scaled_x > 0x7fff)
|
||||
scaled_x = -0x8000; /* OOB */
|
||||
if (scaled_y < -0x7fff || scaled_y > 0x7fff)
|
||||
scaled_y = -0x8000; /* OOB */
|
||||
|
||||
*res_x = scaled_x;
|
||||
*res_y = scaled_y;
|
||||
*res_screen_x = scaled_screen_x;
|
||||
*res_screen_y = scaled_screen_y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void input_config_parse_key(config_file_t *conf,
|
||||
const char *prefix, const char *btn,
|
||||
struct retro_keybind *bind)
|
||||
@ -492,120 +442,3 @@ void input_get_bind_string(char *buf, const struct retro_keybind *bind,
|
||||
strlcat(buf, keybuf, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* input_poll:
|
||||
*
|
||||
* Input polling callback function.
|
||||
**/
|
||||
void input_poll(void)
|
||||
{
|
||||
#ifdef HAVE_COMMAND
|
||||
driver_t *driver = driver_get_ptr();
|
||||
#endif
|
||||
#ifdef HAVE_OVERLAY
|
||||
settings_t *settings = config_get_ptr();
|
||||
#endif
|
||||
|
||||
input_driver_ctl(RARCH_INPUT_CTL_POLL, NULL);
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
input_poll_overlay(settings->input.overlay_opacity);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COMMAND
|
||||
if (driver->command)
|
||||
rarch_cmd_poll(driver->command);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETWORK_GAMEPAD
|
||||
if (driver->remote)
|
||||
rarch_remote_poll(driver->remote);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
**/
|
||||
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();
|
||||
const input_driver_t *input = driver ?
|
||||
(const input_driver_t*)driver->input : NULL;
|
||||
|
||||
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->flushing_input && !driver->block_libretro_input)
|
||||
{
|
||||
if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD)))
|
||||
res = input->input_state(driver->input_data, libretro_input_binds, port, device, idx, id);
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
input_state_overlay(&res, port, device, idx, id);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETWORK_GAMEPAD
|
||||
input_state_remote(&res, port, device, idx, id);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Don't allow turbo for D-pad. */
|
||||
if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP ||
|
||||
id > RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
||||
{
|
||||
/*
|
||||
* Apply turbo button if activated.
|
||||
*
|
||||
* If turbo button is held, all buttons pressed except
|
||||
* for D-pad will go into a turbo mode. Until the button is
|
||||
* released again, the input state will be modulated by a
|
||||
* periodic pulse defined by the configured duty cycle.
|
||||
*/
|
||||
if (res && global->turbo.frame_enable[port])
|
||||
global->turbo.enable[port] |= (1 << id);
|
||||
else if (!res)
|
||||
global->turbo.enable[port] &= ~(1 << id);
|
||||
|
||||
if (global->turbo.enable[port] & (1 << id))
|
||||
{
|
||||
/* if turbo button is enabled for this key ID */
|
||||
res = res && ((global->turbo.count % settings->input.turbo_period)
|
||||
< settings->input.turbo_duty_cycle);
|
||||
}
|
||||
}
|
||||
|
||||
if (global->bsv.movie && !global->bsv.movie_playback)
|
||||
bsv_movie_set_input(global->bsv.movie, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -29,25 +29,6 @@ const char *input_bind_map_get_desc(unsigned i);
|
||||
|
||||
bool input_bind_map_get_valid(unsigned i);
|
||||
|
||||
/**
|
||||
* input_translate_coord_viewport:
|
||||
* @mouse_x : Pointer X coordinate.
|
||||
* @mouse_y : Pointer Y coordinate.
|
||||
* @res_x : Scaled X coordinate.
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
**/
|
||||
bool input_translate_coord_viewport(int mouse_x, int mouse_y,
|
||||
int16_t *res_x, int16_t *res_y, int16_t *res_screen_x,
|
||||
int16_t *res_screen_y);
|
||||
|
||||
/* auto_bind can be NULL. */
|
||||
void input_get_bind_string(char *buf, const struct retro_keybind *bind,
|
||||
const struct retro_keybind *auto_bind, size_t size);
|
||||
@ -84,48 +65,4 @@ void input_config_parse_joy_button(config_file_t *conf, const char *prefix,
|
||||
void input_config_parse_joy_axis(config_file_t *conf, const char *prefix,
|
||||
const char *axis, struct retro_keybind *bind);
|
||||
|
||||
/**
|
||||
* input_push_analog_dpad:
|
||||
* @binds : Binds to modify.
|
||||
* @mode : Which analog stick to bind D-Pad to.
|
||||
* E.g:
|
||||
* ANALOG_DPAD_LSTICK
|
||||
* ANALOG_DPAD_RSTICK
|
||||
*
|
||||
* Push analog to D-Pad mappings to binds.
|
||||
**/
|
||||
void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode);
|
||||
|
||||
/**
|
||||
* input_pop_analog_dpad:
|
||||
* @binds : Binds to modify.
|
||||
*
|
||||
* Restores binds temporarily overridden by input_push_analog_dpad().
|
||||
**/
|
||||
void input_pop_analog_dpad(struct retro_keybind *binds);
|
||||
|
||||
retro_input_t input_keys_pressed(void);
|
||||
|
||||
/**
|
||||
* input_poll:
|
||||
*
|
||||
* Input polling callback function.
|
||||
**/
|
||||
void input_poll(void);
|
||||
|
||||
/**
|
||||
* 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).
|
||||
**/
|
||||
int16_t input_state(unsigned port, unsigned device,
|
||||
unsigned idx, unsigned id);
|
||||
|
||||
#endif
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "input_remapping.h"
|
||||
|
||||
#include "../general.h"
|
||||
#include "../string_list_special.h"
|
||||
#include "../verbosity.h"
|
||||
@ -353,6 +355,173 @@ void input_pop_analog_dpad(struct retro_keybind *binds)
|
||||
binds[i].joyaxis = binds[i].orig_joyaxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_translate_coord_viewport:
|
||||
* @mouse_x : Pointer X coordinate.
|
||||
* @mouse_y : Pointer Y coordinate.
|
||||
* @res_x : Scaled X coordinate.
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
**/
|
||||
bool input_translate_coord_viewport(int mouse_x, int mouse_y,
|
||||
int16_t *res_x, int16_t *res_y, int16_t *res_screen_x,
|
||||
int16_t *res_screen_y)
|
||||
{
|
||||
int scaled_screen_x, scaled_screen_y, scaled_x, scaled_y;
|
||||
struct video_viewport vp = {0};
|
||||
|
||||
if (!video_driver_viewport_info(&vp))
|
||||
return false;
|
||||
|
||||
scaled_screen_x = (2 * mouse_x * 0x7fff) / (int)vp.full_width - 0x7fff;
|
||||
scaled_screen_y = (2 * mouse_y * 0x7fff) / (int)vp.full_height - 0x7fff;
|
||||
if (scaled_screen_x < -0x7fff || scaled_screen_x > 0x7fff)
|
||||
scaled_screen_x = -0x8000; /* OOB */
|
||||
if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff)
|
||||
scaled_screen_y = -0x8000; /* OOB */
|
||||
|
||||
mouse_x -= vp.x;
|
||||
mouse_y -= vp.y;
|
||||
|
||||
scaled_x = (2 * mouse_x * 0x7fff) / (int)vp.width - 0x7fff;
|
||||
scaled_y = (2 * mouse_y * 0x7fff) / (int)vp.height - 0x7fff;
|
||||
if (scaled_x < -0x7fff || scaled_x > 0x7fff)
|
||||
scaled_x = -0x8000; /* OOB */
|
||||
if (scaled_y < -0x7fff || scaled_y > 0x7fff)
|
||||
scaled_y = -0x8000; /* OOB */
|
||||
|
||||
*res_x = scaled_x;
|
||||
*res_y = scaled_y;
|
||||
*res_screen_x = scaled_screen_x;
|
||||
*res_screen_y = scaled_screen_y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_poll:
|
||||
*
|
||||
* Input polling callback function.
|
||||
**/
|
||||
void input_poll(void)
|
||||
{
|
||||
#ifdef HAVE_COMMAND
|
||||
driver_t *driver = driver_get_ptr();
|
||||
#endif
|
||||
#ifdef HAVE_OVERLAY
|
||||
settings_t *settings = config_get_ptr();
|
||||
#endif
|
||||
|
||||
input_driver_ctl(RARCH_INPUT_CTL_POLL, NULL);
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
input_poll_overlay(settings->input.overlay_opacity);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COMMAND
|
||||
if (driver->command)
|
||||
rarch_cmd_poll(driver->command);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETWORK_GAMEPAD
|
||||
if (driver->remote)
|
||||
rarch_remote_poll(driver->remote);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
**/
|
||||
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();
|
||||
const input_driver_t *input = driver ?
|
||||
(const input_driver_t*)driver->input : NULL;
|
||||
|
||||
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->flushing_input && !driver->block_libretro_input)
|
||||
{
|
||||
if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD)))
|
||||
res = input->input_state(driver->input_data, libretro_input_binds, port, device, idx, id);
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
input_state_overlay(&res, port, device, idx, id);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETWORK_GAMEPAD
|
||||
input_state_remote(&res, port, device, idx, id);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Don't allow turbo for D-pad. */
|
||||
if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP ||
|
||||
id > RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
||||
{
|
||||
/*
|
||||
* Apply turbo button if activated.
|
||||
*
|
||||
* If turbo button is held, all buttons pressed except
|
||||
* for D-pad will go into a turbo mode. Until the button is
|
||||
* released again, the input state will be modulated by a
|
||||
* periodic pulse defined by the configured duty cycle.
|
||||
*/
|
||||
if (res && global->turbo.frame_enable[port])
|
||||
global->turbo.enable[port] |= (1 << id);
|
||||
else if (!res)
|
||||
global->turbo.enable[port] &= ~(1 << id);
|
||||
|
||||
if (global->turbo.enable[port] & (1 << id))
|
||||
{
|
||||
/* if turbo button is enabled for this key ID */
|
||||
res = res && ((global->turbo.count % settings->input.turbo_period)
|
||||
< settings->input.turbo_duty_cycle);
|
||||
}
|
||||
}
|
||||
|
||||
if (global->bsv.movie && !global->bsv.movie_playback)
|
||||
bsv_movie_set_input(global->bsv.movie, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* check_block_hotkey:
|
||||
* @enable_hotkey : Is hotkey enable key enabled?
|
||||
|
@ -191,6 +191,69 @@ bool input_sensor_set_state(unsigned port,
|
||||
|
||||
float input_sensor_get_input(unsigned port, unsigned id);
|
||||
|
||||
/**
|
||||
* input_translate_coord_viewport:
|
||||
* @mouse_x : Pointer X coordinate.
|
||||
* @mouse_y : Pointer Y coordinate.
|
||||
* @res_x : Scaled X coordinate.
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
**/
|
||||
bool input_translate_coord_viewport(int mouse_x, int mouse_y,
|
||||
int16_t *res_x, int16_t *res_y, int16_t *res_screen_x,
|
||||
int16_t *res_screen_y);
|
||||
|
||||
/**
|
||||
* input_push_analog_dpad:
|
||||
* @binds : Binds to modify.
|
||||
* @mode : Which analog stick to bind D-Pad to.
|
||||
* E.g:
|
||||
* ANALOG_DPAD_LSTICK
|
||||
* ANALOG_DPAD_RSTICK
|
||||
*
|
||||
* Push analog to D-Pad mappings to binds.
|
||||
**/
|
||||
void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode);
|
||||
|
||||
/**
|
||||
* input_pop_analog_dpad:
|
||||
* @binds : Binds to modify.
|
||||
*
|
||||
* Restores binds temporarily overridden by input_push_analog_dpad().
|
||||
**/
|
||||
void input_pop_analog_dpad(struct retro_keybind *binds);
|
||||
|
||||
/**
|
||||
* input_poll:
|
||||
*
|
||||
* Input polling callback function.
|
||||
**/
|
||||
void input_poll(void);
|
||||
|
||||
/**
|
||||
* 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).
|
||||
**/
|
||||
int16_t input_state(unsigned port, unsigned device,
|
||||
unsigned idx, unsigned id);
|
||||
|
||||
retro_input_t input_keys_pressed(void);
|
||||
|
||||
bool input_driver_ctl(enum rarch_input_ctl_state state, void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
x
Reference in New Issue
Block a user