From 068943445fc637fde1f614ddacab2e4d8078cdb8 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 19 Jan 2015 18:16:34 +0100 Subject: [PATCH] (Input) Add input remapping files --- Makefile.common | 1 + griffin/griffin.c | 1 + input/input_remapping.c | 115 ++++++++++++++++++++++++++++++++++++++++ input/input_remapping.h | 49 +++++++++++++++++ menu/menu_entries_cbs.c | 30 +---------- menu/menu_input.c | 50 +---------------- 6 files changed, 170 insertions(+), 76 deletions(-) create mode 100644 input/input_remapping.c create mode 100644 input/input_remapping.h diff --git a/Makefile.common b/Makefile.common index 7836b00348..6cfe32ab86 100644 --- a/Makefile.common +++ b/Makefile.common @@ -122,6 +122,7 @@ OBJ += frontend/frontend.o \ input/input_joypad.o \ input/input_common.o \ input/input_keymaps.o \ + input/input_remapping.o \ input/input_sensor.o \ input/keyboard_line.o \ input/input_overlay.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index 8b0cefb591..75da20386c 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -291,6 +291,7 @@ INPUT #include "../input/input_joypad.c" #include "../input/input_common.c" #include "../input/input_keymaps.c" +#include "../input/input_remapping.c" #include "../input/input_sensor.c" #include "../input/keyboard_line.c" diff --git a/input/input_remapping.c b/input/input_remapping.c new file mode 100644 index 0000000000..423329fb44 --- /dev/null +++ b/input/input_remapping.c @@ -0,0 +1,115 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2015 - Daniel De Matteis + * + * 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 . + */ + +#include "input_remapping.h" +#include +#include +#include +#include + +#include +#include + +#include "../general.h" + +/** + * input_remapping_load_file: + * @path : Path to remapping file (absolute path). + * + * Loads a remap file from disk to memory. + * + * Returns: true (1) if successful, otherwise false (0). + **/ +bool input_remapping_load_file(const char *path) +{ + unsigned i, j; + config_file_t *conf = config_file_new(path); + + if (!conf) + return false; + + for (i = 0; i < MAX_USERS; i++) + { + char buf[64]; + char key_ident[RARCH_FIRST_META_KEY][128]; + char key_strings[RARCH_FIRST_META_KEY][128] = { "b", "y", "select", "start", + "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3"}; + + snprintf(buf, sizeof(buf), "input_player%u", i + 1); + + for (j = 0; j < RARCH_FIRST_META_KEY; j++) + { + int key_remap = -1; + + snprintf(key_ident[j], sizeof(key_ident[j]), "%s_%s", buf, key_strings[j]); + if (config_get_int(conf, key_ident[j], &key_remap)) + g_settings.input.remap_ids[i][j] = key_remap; + } + } + + config_file_free(conf); + + return true; +} + +/** + * input_remapping_save_file: + * @path : Path to remapping file (relative path). + * + * Saves remapping values to file. + **/ +void input_remapping_save_file(const char *path) +{ + unsigned i, j; + char buf[PATH_MAX_LENGTH]; + char remap_file[PATH_MAX_LENGTH]; + config_file_t *conf = NULL; + + fill_pathname_join(buf, g_settings.input_remapping_directory, + path, sizeof(buf)); + + fill_pathname_noext(remap_file, buf, ".rmp", sizeof(remap_file)); + + conf = config_file_new(remap_file); + + if (!conf) + conf = config_file_new(NULL); + + if (!conf) + return; + + for (i = 0; i < g_settings.input.max_users; i++) + { + char buf[64]; + char key_ident[RARCH_FIRST_META_KEY][128]; + char key_strings[RARCH_FIRST_META_KEY][128] = { "b", "y", "select", "start", + "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3"}; + + snprintf(buf, sizeof(buf), "input_player%u", i + 1); + + for (j = 0; j < RARCH_FIRST_META_KEY; j++) + { + snprintf(key_ident[j], sizeof(key_ident[j]), "%s_%s", buf, key_strings[j]); + config_set_int(conf, key_ident[j], g_settings.input.remap_ids[i][j]); + } + } + + if (!config_file_write(conf, remap_file)) + { + RARCH_ERR("Could not write remapping file to disk.\n"); + } + + config_file_free(conf); +} diff --git a/input/input_remapping.h b/input/input_remapping.h new file mode 100644 index 0000000000..e632175e53 --- /dev/null +++ b/input/input_remapping.h @@ -0,0 +1,49 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2015 - Daniel De Matteis + * + * 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 . + */ + +#ifndef _INPUT_REMAPPING_H +#define _INPUT_REMAPPING_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * input_remapping_load_file: + * @path : Path to remapping file (absolute path). + * + * Loads a remap file from disk to memory. + * + * Returns: true (1) if successful, otherwise false (0). + **/ +bool input_remapping_load_file(const char *path); + +/** + * input_remapping_save_file: + * @path : Path to remapping file (relative path). + * + * Saves remapping values to file. + **/ +void input_remapping_save_file(const char *path); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/menu/menu_entries_cbs.c b/menu/menu_entries_cbs.c index 62ba7a2b8d..c1f5805e5b 100644 --- a/menu/menu_entries_cbs.c +++ b/menu/menu_entries_cbs.c @@ -28,7 +28,7 @@ #include "../retroarch.h" #include "../performance.h" -#include +#include "../input/input_remapping.h" #ifdef GEKKO enum @@ -335,34 +335,8 @@ static int action_ok_remap_file_load(const char *path, NULL); fill_pathname_join(remap_path, menu_path, path, sizeof(remap_path)); + input_remapping_load_file(remap_path); - conf = config_file_new(remap_path); - - if (!conf) - goto exit; - - for (i = 0; i < MAX_USERS; i++) - { - char buf[64]; - char key_ident[RARCH_FIRST_META_KEY][128]; - char key_strings[RARCH_FIRST_META_KEY][128] = { "b", "y", "select", "start", - "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3"}; - - snprintf(buf, sizeof(buf), "input_player%u", i + 1); - - for (j = 0; j < RARCH_FIRST_META_KEY; j++) - { - int key_remap = -1; - - snprintf(key_ident[j], sizeof(key_ident[j]), "%s_%s", buf, key_strings[j]); - if (config_get_int(conf, key_ident[j], &key_remap)) - g_settings.input.remap_ids[i][j] = key_remap; - } - } - - config_file_free(conf); - -exit: menu_list_flush_stack_by_needle(driver.menu->menu_list, "core_input_remapping_options"); return 0; diff --git a/menu/menu_input.c b/menu/menu_input.c index e0820fcc52..b9829b238d 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -31,53 +31,7 @@ #include "../performance.h" #include "../settings_data.h" #include "../input/input_joypad.h" - -#include -#include - -static void menu_input_remapping_save_file(const char *path) -{ - unsigned i, j; - char buf[PATH_MAX_LENGTH]; - char remap_file[PATH_MAX_LENGTH]; - config_file_t *conf = NULL; - - fill_pathname_join(buf, g_settings.input_remapping_directory, - path, sizeof(buf)); - - fill_pathname_noext(remap_file, buf, ".rmp", sizeof(remap_file)); - - conf = config_file_new(remap_file); - - if (!conf) - conf = config_file_new(NULL); - - if (!conf) - return; - - for (i = 0; i < g_settings.input.max_users; i++) - { - char buf[64]; - char key_ident[RARCH_FIRST_META_KEY][128]; - char key_strings[RARCH_FIRST_META_KEY][128] = { "b", "y", "select", "start", - "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3"}; - - snprintf(buf, sizeof(buf), "input_player%u", i + 1); - - for (j = 0; j < RARCH_FIRST_META_KEY; j++) - { - snprintf(key_ident[j], sizeof(key_ident[j]), "%s_%s", buf, key_strings[j]); - config_set_int(conf, key_ident[j], g_settings.input.remap_ids[i][j]); - } - } - - if (!config_file_write(conf, remap_file)) - { - RARCH_ERR("Could not write remapping file to disk.\n"); - } - - config_file_free(conf); -} +#include "../input/input_remapping.h" void menu_input_key_start_line(void *data, const char *label, const char *label_setting, unsigned type, unsigned idx, @@ -154,7 +108,7 @@ void menu_input_st_string_callback(void *userdata, const char *str) if (!strcmp(menu->keyboard.label_setting, "video_shader_preset_save_as")) menu_shader_manager_save_preset(str, false); else if (!strcmp(menu->keyboard.label_setting, "remap_file_save_as")) - menu_input_remapping_save_file(str); + input_remapping_save_file(str); } }