From 8ea13cd3edfd16e911b32ad13d569c0af211bd58 Mon Sep 17 00:00:00 2001 From: danieru Date: Fri, 19 Apr 2013 22:52:54 -0600 Subject: [PATCH 1/8] Add KeyMap key translation layer --- CMakeLists.txt | 2 + Common/KeyMap.cpp | 285 ++++++++++++++++++++++++++++++++++++++++++++++ Common/KeyMap.h | 188 ++++++++++++++++++++++++++++++ 3 files changed, 475 insertions(+) create mode 100644 Common/KeyMap.cpp create mode 100644 Common/KeyMap.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bdbc68825d..ceed216b95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,6 +244,8 @@ add_library(Common STATIC Common/FileUtil.h Common/Hash.cpp Common/Hash.h + Common/KeyMap.cpp + Common/KeyMap.h Common/LogManager.cpp Common/LogManager.h Common/MathUtil.cpp diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp new file mode 100644 index 0000000000..854411edaf --- /dev/null +++ b/Common/KeyMap.cpp @@ -0,0 +1,285 @@ +// Copyright (c) 2013- PPSSPP Project. + +// This program 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 Foundation, version 2.0 or later versions. + +// This program 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 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include +#include + +#include "input/input_state.h" +#include "Core/Config.h" +#include "KeyMap.h" + +using namespace KeyMap; + +/* Platform specific + * default */ +std::map *platform_keymap = NULL; + +/* Default key mapping */ +/* Ugly, yet the cleanest way + * I could find to create a + * static map. + * Still nicer than what + * I once did in C. */ +struct DefaultKeyMap { + static std::map init() + // TODO: Fix this indentation, spaces to tabs + { + std::map m; + m[KEY_x] = PAD_BUTTON_A; + m[KEY_z] = PAD_BUTTON_B; + m[KEY_s] = PAD_BUTTON_X; + m[KEY_a] = PAD_BUTTON_Y; + m[KEY_q] = PAD_BUTTON_LBUMPER; + m[KEY_w] = PAD_BUTTON_RBUMPER; + m[KEY_SPACE] = PAD_BUTTON_START; + m[KEY_ENTER] = PAD_BUTTON_SELECT; + m[KEY_ARROW_UP] = PAD_BUTTON_UP; + m[KEY_ARROW_DOWN] = PAD_BUTTON_DOWN; + m[KEY_ARROW_LEFT] = PAD_BUTTON_LEFT; + m[KEY_ARROW_RIGHT] = PAD_BUTTON_RIGHT; + m[KEY_TAB] = PAD_BUTTON_MENU; + m[KEY_BACKSPACE] = PAD_BUTTON_BACK; + m[KEY_ANALOG_FAKE_UP] = PAD_BUTTON_JOY_UP; + m[KEY_ANALOG_FAKE_DOWN] = PAD_BUTTON_JOY_DOWN; + m[KEY_ANALOG_FAKE_LEFT] = PAD_BUTTON_JOY_LEFT; + m[KEY_ANALOG_FAKE_RIGHT] = PAD_BUTTON_JOY_RIGHT; + m[KEY_CTRL_LEFT] = PAD_BUTTON_LEFT_THUMB; + m[KEY_ALT_LEFT] = PAD_BUTTON_RIGHT_THUMB; + return m; + } + static std::map KeyMap; + +}; + +std::map DefaultKeyMap::KeyMap = DefaultKeyMap::init(); + +/* Key & Button names */ +struct KeyMap_IntStrPair { + int key; + std::string name; +}; +const KeyMap_IntStrPair key_names[] = { + {KEY_a, "a"}, + {KEY_b, "B"}, + {KEY_c, "c"}, + {KEY_d, "d"}, + {KEY_e, "e"}, + {KEY_f, "f"}, + {KEY_g, "g"}, + {KEY_h, "h"}, + {KEY_i, "i"}, + {KEY_j, "j"}, + {KEY_k, "k"}, + {KEY_l, "l"}, + {KEY_m, "m"}, + {KEY_n, "n"}, + {KEY_o, "o"}, + {KEY_p, "p"}, + {KEY_q, "q"}, + {KEY_r, "r"}, + {KEY_s, "s"}, + {KEY_t, "t"}, + {KEY_u, "u"}, + {KEY_v, "v"}, + {KEY_w, "w"}, + {KEY_x, "x"}, + {KEY_y, "y"}, + {KEY_z, "z"}, + {KEY_1, "1"}, + {KEY_2, "2"}, + {KEY_3, "3"}, + {KEY_4, "4"}, + {KEY_5, "5"}, + {KEY_6, "6"}, + {KEY_7, "7"}, + {KEY_8, "8"}, + {KEY_9, "9"}, + {KEY_0, "0"}, + + {KEY_BACKSPACE, "Backspace"}, + {KEY_TAB, "Tab"}, + {KEY_ENTER, "Enter"}, + {KEY_SHIFT_LEFT, "Shift"}, + {KEY_SHIFT_RIGHT, "Shift"}, + {KEY_CTRL_LEFT, "Ctrl"}, + {KEY_CTRL_RIGHT, "Ctrl"}, + {KEY_ALT_LEFT, "Alt"}, + {KEY_ALT_RIGHT, "Alt"}, + {KEY_SPACE, "Space"}, + {KEY_SUPER, "Super"}, + {KEY_SPACE, "Space"}, + + {KEY_VOLUME_UP, "Vol Up"}, + {KEY_VOLUME_DOWN, "Vol Down"}, + {KEY_HOME, "Home"}, + {KEY_CALL_START, "Start Call"}, + {KEY_CALL_END, "End Call"}, + + {KEY_ARROW_LEFT, "Left"}, + {KEY_ARROW_UP, "Up"}, + {KEY_ARROW_RIGHT, "Right"}, + {KEY_ARROW_DOWN, "Down"}, + + {KEY_EXTRA1, "Extra1"}, + {KEY_EXTRA2, "Extra2"}, + {KEY_EXTRA3, "Extra3"}, + {KEY_EXTRA4, "Extra4"}, + {KEY_EXTRA5, "Extra5"}, + {KEY_EXTRA6, "Extra6"}, + {KEY_EXTRA7, "Extra7"}, + {KEY_EXTRA8, "Extra8"}, + {KEY_EXTRA9, "Extra9"}, + {KEY_EXTRA0, "Extra0"}, +}; +static int key_names_count = sizeof(key_names) / sizeof(key_names[0]); +static std::string unknown_key_name = "Unknown"; +const KeyMap_IntStrPair psp_button_names[] = { + {PAD_BUTTON_A, "O"}, + {PAD_BUTTON_B, "X"}, + {PAD_BUTTON_X, "[]"}, // TODO: use proper unicode symbol + {PAD_BUTTON_Y, "^"}, + {PAD_BUTTON_LBUMPER, "L"}, + {PAD_BUTTON_RBUMPER, "R"}, + {PAD_BUTTON_START, "Start"}, + {PAD_BUTTON_SELECT, "Select"}, + {PAD_BUTTON_UP, "Up"}, + {PAD_BUTTON_DOWN, "Down"}, + {PAD_BUTTON_LEFT, "Left"}, + {PAD_BUTTON_RIGHT, "Right"}, + + {PAD_BUTTON_MENU, "Menu"}, + {PAD_BUTTON_BACK, "Back"}, + + {PAD_BUTTON_JOY_UP, "Analog Up"}, + {PAD_BUTTON_JOY_DOWN, "Analog Down"}, + {PAD_BUTTON_JOY_LEFT, "Analog Left"}, + {PAD_BUTTON_JOY_RIGHT, "Analog Right"}, + + {PAD_BUTTON_LEFT_THUMB, "Left analog click"}, + {PAD_BUTTON_RIGHT_THUMB, "Right analog click"}, +}; +static int psp_button_names_count = sizeof(psp_button_names) / sizeof(psp_button_names[0]); + + +static std::string FindName(int key, const KeyMap_IntStrPair list[], int size) +{ + for (int i = 0; i < size; i++) + if (list[i].key == key) + return list[i].name; + + return unknown_key_name; +} + +static std::string KeyMap::GetKeyName(KeyMap::Key key) +{ + return FindName((int)key, key_names, key_names_count); +} + +static std::string KeyMap::GetPspButtonName(int btn) +{ + return FindName(btn, key_names, key_names_count); +} + +static bool FindKeyMapping(int key, int *map_id, int *psp_button) +{ + std::map::iterator it; + if (*map_id >= 0) { + // check user configuration + std::map user_map = g_Config.iMappingMap; + it = user_map.find(key); + if (it != user_map.end()) { + *map_id = 0; + *psp_button = it->second; + return true; + } + } + + if (*map_id >= 1 && platform_keymap != NULL) { + // check optional platform specific keymap + std::map port_map = *platform_keymap; + it = port_map.find(key); + if (it != port_map.end()) { + *map_id = 1; + *psp_button = it->second; + return true; + } + } + + if (*map_id >= 2) { + // check default keymap + const std::map default_map = DefaultKeyMap::KeyMap; + const std::map::const_iterator it = default_map.find(key); + if (it != default_map.end()) { + *map_id = 2; + *psp_button = it->second; + return true; + } + } + + *map_id = -1; + return false; +} + + + +static int KeyMap::KeyToPspButton(const KeyMap::Key key) +{ + int search_start_layer = 0; + int psp_button; + + if (FindKeyMapping((int)key, &search_start_layer, &psp_button)) + return psp_button; + + return KEYMAP_ERROR_UNKNOWN_KEY; +} + +static bool KeyMap::IsMappedKey(Key key) +{ + return KeyMap::KeyToPspButton(key) != KEYMAP_ERROR_UNKNOWN_KEY; +} + + +static std::string KeyMap::NamePspButtonFromKey(KeyMap::Key key) +{ + return KeyMap::GetPspButtonName(KeyMap::KeyToPspButton(key)); +} + +static std::string KeyMap::NameKeyFromPspButton(int btn) +{ + // We drive our iteration + // with the list of key names. + for (int i = 0; i < key_names_count; i++) { + const struct KeyMap_IntStrPair *key_name = key_names + i; + if (btn == KeyMap::KeyToPspButton((KeyMap::Key)key_name->key)) + return key_name->name; + } + + // all psp buttons are mapped from some key + // but it appears we do not have a name + // for this key. + return unknown_key_name; +} + +static int KeyMap::SetKeyMapping(KeyMap::Key key, int btn) +{ + if (KeyMap::IsMappedKey(key)) + return KEYMAP_ERROR_KEY_ALREADY_USED; + + g_Config.iMappingMap[key] = btn; +} + +// TODO: implement RegisterPlatformDefaultKeyMap() diff --git a/Common/KeyMap.h b/Common/KeyMap.h new file mode 100644 index 0000000000..01e476bfd3 --- /dev/null +++ b/Common/KeyMap.h @@ -0,0 +1,188 @@ +// Copyright (c) 2013- PPSSPP Project. + +// This program 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 Foundation, version 2.0 or later versions. + +// This program 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 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#pragma once + +#include +#include + +#define KEYMAP_ERROR_KEY_ALREADY_USED -1 +#define KEYMAP_ERROR_UNKNOWN_KEY 0 + +/* KeyMap + * A translation layer for + * key assignment. Provides + * integration with Core's + * config state. + * + * Does not handle input + * state managment. + * + * Platform ports should + * map their platform's + * keys to KeyMap's keys. + * Then have KeyMap transform + * those into psp buttons. + */ +namespace KeyMap { + enum Key { + /* Lower class latin */ + KEY_q = 1, // top row + KEY_w, + KEY_e, + KEY_r, + KEY_t, + KEY_y, + KEY_u, + KEY_i, + KEY_o, + KEY_p, + + KEY_a, // mid row + KEY_s, + KEY_d, + KEY_f, + KEY_g, + KEY_h, + KEY_j, + KEY_k, + KEY_l, + + KEY_z, // low row + KEY_x, + KEY_c, + KEY_v, + KEY_b, + KEY_n, + KEY_m, + + /* Numeric */ + KEY_1, + KEY_2, + KEY_3, + KEY_4, + KEY_5, + KEY_6, + KEY_7, + KEY_8, + KEY_9, + KEY_0, + + /* Special keys */ + KEY_ARROW_LEFT, + KEY_ARROW_RIGHT, + KEY_ARROW_UP, + KEY_ARROW_DOWN, + + KEY_ANALOG_FAKE_LEFT, + KEY_ANALOG_FAKE_RIGHT, + KEY_ANALOG_FAKE_UP, + KEY_ANALOG_FAKE_DOWN, + + KEY_SPACE, + KEY_ENTER, + KEY_CTRL_LEFT, + KEY_CTRL_RIGHT, + KEY_SHIFT_LEFT, + KEY_SHIFT_RIGHT, + KEY_ALT_LEFT, + KEY_ALT_RIGHT, + KEY_BACKSPACE, + KEY_SUPER, + KEY_TAB, + + /* Mobile Keys */ + KEY_VOLUME_UP, + KEY_VOLUME_DOWN, + KEY_HOME, + KEY_CALL_START, + KEY_CALL_END, + + /* Extra keys + * Use for platform specific keys. + * Example: android's back btn */ + KEY_EXTRA1, + KEY_EXTRA2, + KEY_EXTRA3, + KEY_EXTRA4, + KEY_EXTRA5, + KEY_EXTRA6, + KEY_EXTRA7, + KEY_EXTRA8, + KEY_EXTRA9, + KEY_EXTRA0, + + // TODO: Add fastforward key + // TODO: Add any missing keys. + // Many can be found in the + // window's port's keyboard + // files. + }; + + /* Use if you need to + * display the textual + * name + * These functions are not + * fast, do not call them + * a million times. */ + static std::string GetKeyName(Key); + static std::string GetPspButtonName(int); + + /* Use if to translate + * KeyMap Keys to PSP + * buttons. + * You should have + * already translated + * your platform's keys + * to KeyMap keys. + * + * Returns KEYMAP_ERROR_UNKNOWN_KEY + * for any unmapped key */ + static int KeyToPspButton(Key); + + static bool IsMappedKey(Key); + + /* Might be usful if you want + * to provide hints to users + * upon mapping conflicts */ + static std::string NamePspButtonFromKey(Key); + + /* Use for showing the existing + * key mapping. */ + static std::string NameKeyFromPspButton(int); + + /* Configure the key mapping. + * Any configuration will + * be saved to the Core + * config. + * + * Returns KEYMAP_ERROR_KEY_ALREADY_USED + * for mapping conflicts. 0 otherwise. */ + static int SetKeyMapping(Key, int); + + /* Platform specific keymaps + * override KeyMap's defaults. + * They do not override user's + * configuration. + * A platform default keymap + * does not need to cover + * all psp buttons. + * Any buttons missing will + * fallback to KeyMap's keymap. */ + static int RegisterPlatformDefaultKeyMap(std::map *); +} + From c2cf28e4b814f924eda2330ec98160644eceef16 Mon Sep 17 00:00:00 2001 From: danieru Date: Sat, 20 Apr 2013 12:54:40 -0600 Subject: [PATCH 2/8] Fix typo capitalization of lower case b's name --- Common/KeyMap.cpp | 2 +- Common/KeyMap.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 854411edaf..81bcc54b31 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -74,7 +74,7 @@ struct KeyMap_IntStrPair { }; const KeyMap_IntStrPair key_names[] = { {KEY_a, "a"}, - {KEY_b, "B"}, + {KEY_b, "b"}, {KEY_c, "c"}, {KEY_d, "d"}, {KEY_e, "e"}, diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 01e476bfd3..76d0f3c0b5 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -126,6 +126,7 @@ namespace KeyMap { KEY_EXTRA9, KEY_EXTRA0, + // TODO: Add second set of joysticks // TODO: Add fastforward key // TODO: Add any missing keys. // Many can be found in the From cbbed0f18b38b5b43272570a45335b794f77b166 Mon Sep 17 00:00:00 2001 From: danieru Date: Sat, 20 Apr 2013 13:01:15 -0600 Subject: [PATCH 3/8] Implement platform specific keymap registration --- Common/KeyMap.cpp | 15 ++++++++++++++- Common/KeyMap.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 81bcc54b31..b3bc09c164 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -282,4 +282,17 @@ static int KeyMap::SetKeyMapping(KeyMap::Key key, int btn) g_Config.iMappingMap[key] = btn; } -// TODO: implement RegisterPlatformDefaultKeyMap() +static int KeyMap::RegisterPlatformDefaultKeyMap(std::map *overriding_map) +{ + if (overriding_map == NULL) + return 1; + platform_keymap = overriding_map; + return 0; +} + +static void KeyMap::DeregisterPlatformDefaultKeyMap(void) +{ + platform_keymap = NULL; + return; +} + diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 76d0f3c0b5..2d10d140de 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -185,5 +185,6 @@ namespace KeyMap { * Any buttons missing will * fallback to KeyMap's keymap. */ static int RegisterPlatformDefaultKeyMap(std::map *); + static void DeregisterPlatformDefaultKeyMap(void); } From 6121819856465049cce9d13d0fa7a89b54266db5 Mon Sep 17 00:00:00 2001 From: danieru Date: Sat, 20 Apr 2013 13:09:56 -0600 Subject: [PATCH 4/8] Extend KeyMap supported keys Uppercase latin, Fastforward, Alt analog stick, --- Common/KeyMap.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ Common/KeyMap.h | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index b3bc09c164..dc4019496d 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -99,6 +99,34 @@ const KeyMap_IntStrPair key_names[] = { {KEY_x, "x"}, {KEY_y, "y"}, {KEY_z, "z"}, + + {KEY_A, "A"}, + {KEY_B, "B"}, + {KEY_C, "C"}, + {KEY_D, "D"}, + {KEY_E, "E"}, + {KEY_F, "F"}, + {KEY_G, "G"}, + {KEY_H, "H"}, + {KEY_I, "I"}, + {KEY_J, "J"}, + {KEY_K, "K"}, + {KEY_L, "L"}, + {KEY_M, "M"}, + {KEY_N, "N"}, + {KEY_O, "O"}, + {KEY_P, "P"}, + {KEY_Q, "Q"}, + {KEY_R, "R"}, + {KEY_S, "S"}, + {KEY_T, "T"}, + {KEY_U, "U"}, + {KEY_V, "V"}, + {KEY_W, "W"}, + {KEY_X, "X"}, + {KEY_Y, "Y"}, + {KEY_Z, "Z"}, + {KEY_1, "1"}, {KEY_2, "2"}, {KEY_3, "3"}, @@ -110,6 +138,7 @@ const KeyMap_IntStrPair key_names[] = { {KEY_9, "9"}, {KEY_0, "0"}, + {KEY_BACKSPACE, "Backspace"}, {KEY_TAB, "Tab"}, {KEY_ENTER, "Enter"}, @@ -129,11 +158,23 @@ const KeyMap_IntStrPair key_names[] = { {KEY_CALL_START, "Start Call"}, {KEY_CALL_END, "End Call"}, + {KEY_FASTFORWARD, "Fast foward"}, + {KEY_ARROW_LEFT, "Left"}, {KEY_ARROW_UP, "Up"}, {KEY_ARROW_RIGHT, "Right"}, {KEY_ARROW_DOWN, "Down"}, + {KEY_ANALOG_FAKE_LEFT, "Analog Left"}, + {KEY_ANALOG_FAKE_UP, "Analog Up"}, + {KEY_ANALOG_FAKE_RIGHT, "Analog Right"}, + {KEY_ANALOG_FAKE_DOWN, "Analog Down"}, + + {KEY_ANALOG_ALT_LEFT, "Alt analog Left"}, + {KEY_ANALOG_ALT_UP, "Alt analog Up"}, + {KEY_ANALOG_ALT_RIGHT, "Alt analog Right"}, + {KEY_ANALOG_ALT_DOWN, "Alt analog Down"}, + {KEY_EXTRA1, "Extra1"}, {KEY_EXTRA2, "Extra2"}, {KEY_EXTRA3, "Extra3"}, diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 2d10d140de..b993810224 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -70,6 +70,37 @@ namespace KeyMap { KEY_n, KEY_m, + /* Upper class latin */ + KEY_Q, // top row + KEY_W, + KEY_E, + KEY_R, + KEY_T, + KEY_Y, + KEY_U, + KEY_I, + KEY_O, + KEY_P, + + KEY_A, // mid row + KEY_S, + KEY_D, + KEY_F, + KEY_G, + KEY_H, + KEY_J, + KEY_K, + KEY_L, + + KEY_Z, // low row + KEY_X, + KEY_C, + KEY_V, + KEY_B, + KEY_N, + KEY_M, + + /* Numeric */ KEY_1, KEY_2, @@ -93,6 +124,11 @@ namespace KeyMap { KEY_ANALOG_FAKE_UP, KEY_ANALOG_FAKE_DOWN, + KEY_ANALOG_ALT_LEFT, + KEY_ANALOG_ALT_RIGHT, + KEY_ANALOG_ALT_UP, + KEY_ANALOG_ALT_DOWN, + KEY_SPACE, KEY_ENTER, KEY_CTRL_LEFT, @@ -112,6 +148,9 @@ namespace KeyMap { KEY_CALL_START, KEY_CALL_END, + /* Special PPSSPP keys */ + KEY_FASTFORWARD, + /* Extra keys * Use for platform specific keys. * Example: android's back btn */ @@ -126,8 +165,6 @@ namespace KeyMap { KEY_EXTRA9, KEY_EXTRA0, - // TODO: Add second set of joysticks - // TODO: Add fastforward key // TODO: Add any missing keys. // Many can be found in the // window's port's keyboard From f63ea38af82e73d1379d26abdf8b47f68d04cf00 Mon Sep 17 00:00:00 2001 From: danieru Date: Sat, 20 Apr 2013 13:11:51 -0600 Subject: [PATCH 5/8] Remove "FAKE" modifier for primary analog keys Since KeyMap only handles descrete keys it is inaccurate to call them analog. Let no developer should get confused since the cardinal directions indicate the descrete natures. --- Common/KeyMap.cpp | 8 ++++---- Common/KeyMap.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index dc4019496d..6062bf1fe9 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -165,10 +165,10 @@ const KeyMap_IntStrPair key_names[] = { {KEY_ARROW_RIGHT, "Right"}, {KEY_ARROW_DOWN, "Down"}, - {KEY_ANALOG_FAKE_LEFT, "Analog Left"}, - {KEY_ANALOG_FAKE_UP, "Analog Up"}, - {KEY_ANALOG_FAKE_RIGHT, "Analog Right"}, - {KEY_ANALOG_FAKE_DOWN, "Analog Down"}, + {KEY_ANALOG_LEFT, "Analog Left"}, + {KEY_ANALOG_UP, "Analog Up"}, + {KEY_ANALOG_RIGHT, "Analog Right"}, + {KEY_ANALOG_DOWN, "Analog Down"}, {KEY_ANALOG_ALT_LEFT, "Alt analog Left"}, {KEY_ANALOG_ALT_UP, "Alt analog Up"}, diff --git a/Common/KeyMap.h b/Common/KeyMap.h index b993810224..2bb4eaa45f 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -119,10 +119,10 @@ namespace KeyMap { KEY_ARROW_UP, KEY_ARROW_DOWN, - KEY_ANALOG_FAKE_LEFT, - KEY_ANALOG_FAKE_RIGHT, - KEY_ANALOG_FAKE_UP, - KEY_ANALOG_FAKE_DOWN, + KEY_ANALOG_LEFT, + KEY_ANALOG_RIGHT, + KEY_ANALOG_UP, + KEY_ANALOG_DOWN, KEY_ANALOG_ALT_LEFT, KEY_ANALOG_ALT_RIGHT, From 26c2a6a1732daba88cf3ff57069ff11c3bb74e93 Mon Sep 17 00:00:00 2001 From: danieru Date: Sat, 20 Apr 2013 13:19:13 -0600 Subject: [PATCH 6/8] Use unicode symbols for psp button names Instead of approximating with ansi chars. --- Common/KeyMap.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 6062bf1fe9..19d7cb1bdd 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -189,10 +189,10 @@ const KeyMap_IntStrPair key_names[] = { static int key_names_count = sizeof(key_names) / sizeof(key_names[0]); static std::string unknown_key_name = "Unknown"; const KeyMap_IntStrPair psp_button_names[] = { - {PAD_BUTTON_A, "O"}, - {PAD_BUTTON_B, "X"}, - {PAD_BUTTON_X, "[]"}, // TODO: use proper unicode symbol - {PAD_BUTTON_Y, "^"}, + {PAD_BUTTON_A, "○"}, + {PAD_BUTTON_B, "⨯"}, + {PAD_BUTTON_X, "□"}, + {PAD_BUTTON_Y, "△"}, {PAD_BUTTON_LBUMPER, "L"}, {PAD_BUTTON_RBUMPER, "R"}, {PAD_BUTTON_START, "Start"}, From 432f10b9bfd79112e69ceaa43358701f8cef7e15 Mon Sep 17 00:00:00 2001 From: danieru Date: Sat, 20 Apr 2013 14:33:12 -0600 Subject: [PATCH 7/8] Fix comment syntax --- Common/KeyMap.cpp | 18 +++---- Common/KeyMap.h | 121 +++++++++++++++++++++++----------------------- 2 files changed, 69 insertions(+), 70 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 19d7cb1bdd..4207652454 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -24,16 +24,16 @@ using namespace KeyMap; -/* Platform specific - * default */ +// Platform specific +// default std::map *platform_keymap = NULL; -/* Default key mapping */ -/* Ugly, yet the cleanest way - * I could find to create a - * static map. - * Still nicer than what - * I once did in C. */ +// Default key mapping +// Ugly, yet the cleanest way +// I could find to create a +// static map. +// Still nicer than what +// I once did in C. struct DefaultKeyMap { static std::map init() // TODO: Fix this indentation, spaces to tabs @@ -67,7 +67,7 @@ struct DefaultKeyMap { std::map DefaultKeyMap::KeyMap = DefaultKeyMap::init(); -/* Key & Button names */ +// Key & Button names struct KeyMap_IntStrPair { int key; std::string name; diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 2bb4eaa45f..62435dccdc 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -23,24 +23,23 @@ #define KEYMAP_ERROR_KEY_ALREADY_USED -1 #define KEYMAP_ERROR_UNKNOWN_KEY 0 -/* KeyMap - * A translation layer for - * key assignment. Provides - * integration with Core's - * config state. - * - * Does not handle input - * state managment. - * - * Platform ports should - * map their platform's - * keys to KeyMap's keys. - * Then have KeyMap transform - * those into psp buttons. - */ +// KeyMap +// A translation layer for +// key assignment. Provides +// integration with Core's +// config state. +// +// Does not handle input +// state managment. +// +// Platform ports should +// map their platform's +// keys to KeyMap's keys. +// Then have KeyMap transform +// those into psp buttons. namespace KeyMap { enum Key { - /* Lower class latin */ + // Lower class latin KEY_q = 1, // top row KEY_w, KEY_e, @@ -70,7 +69,7 @@ namespace KeyMap { KEY_n, KEY_m, - /* Upper class latin */ + // Upper class latin KEY_Q, // top row KEY_W, KEY_E, @@ -101,7 +100,7 @@ namespace KeyMap { KEY_M, - /* Numeric */ + // Numeric KEY_1, KEY_2, KEY_3, @@ -113,7 +112,7 @@ namespace KeyMap { KEY_9, KEY_0, - /* Special keys */ + // Special keys KEY_ARROW_LEFT, KEY_ARROW_RIGHT, KEY_ARROW_UP, @@ -141,19 +140,19 @@ namespace KeyMap { KEY_SUPER, KEY_TAB, - /* Mobile Keys */ + // Mobile Keys KEY_VOLUME_UP, KEY_VOLUME_DOWN, KEY_HOME, KEY_CALL_START, KEY_CALL_END, - /* Special PPSSPP keys */ + // Special PPSSPP keys KEY_FASTFORWARD, - /* Extra keys - * Use for platform specific keys. - * Example: android's back btn */ + // Extra keys + // Use for platform specific keys. + // Example: android's back btn KEY_EXTRA1, KEY_EXTRA2, KEY_EXTRA3, @@ -171,56 +170,56 @@ namespace KeyMap { // files. }; - /* Use if you need to - * display the textual - * name - * These functions are not - * fast, do not call them - * a million times. */ + // Use if you need to + // display the textual + // name + // These functions are not + // fast, do not call them + // a million times. static std::string GetKeyName(Key); static std::string GetPspButtonName(int); - /* Use if to translate - * KeyMap Keys to PSP - * buttons. - * You should have - * already translated - * your platform's keys - * to KeyMap keys. - * - * Returns KEYMAP_ERROR_UNKNOWN_KEY - * for any unmapped key */ + // Use if to translate + // KeyMap Keys to PSP + // buttons. + // You should have + // already translated + // your platform's keys + // to KeyMap keys. + // + // Returns KEYMAP_ERROR_UNKNOWN_KEY + // for any unmapped key static int KeyToPspButton(Key); static bool IsMappedKey(Key); - /* Might be usful if you want - * to provide hints to users - * upon mapping conflicts */ + // Might be usful if you want + // to provide hints to users + // upon mapping conflicts static std::string NamePspButtonFromKey(Key); - /* Use for showing the existing - * key mapping. */ + // Use for showing the existing + // key mapping. static std::string NameKeyFromPspButton(int); - /* Configure the key mapping. - * Any configuration will - * be saved to the Core - * config. - * - * Returns KEYMAP_ERROR_KEY_ALREADY_USED - * for mapping conflicts. 0 otherwise. */ + // Configure the key mapping. + // Any configuration will + // be saved to the Core + // config. + // + // Returns KEYMAP_ERROR_KEY_ALREADY_USED + // for mapping conflicts. 0 otherwise. static int SetKeyMapping(Key, int); - /* Platform specific keymaps - * override KeyMap's defaults. - * They do not override user's - * configuration. - * A platform default keymap - * does not need to cover - * all psp buttons. - * Any buttons missing will - * fallback to KeyMap's keymap. */ + // Platform specific keymaps + // override KeyMap's defaults. + // They do not override user's + // configuration. + // A platform default keymap + // does not need to cover + // all psp buttons. + // Any buttons missing will + // fallback to KeyMap's keymap. static int RegisterPlatformDefaultKeyMap(std::map *); static void DeregisterPlatformDefaultKeyMap(void); } From 16bbae440fdbd9e7574ebe6aeece57bf0ed96ae5 Mon Sep 17 00:00:00 2001 From: danieru Date: Sat, 20 Apr 2013 14:35:25 -0600 Subject: [PATCH 8/8] Fix inconsistent indentation --- Common/KeyMap.cpp | 54 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 4207652454..a44c33f372 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -35,34 +35,32 @@ std::map *platform_keymap = NULL; // Still nicer than what // I once did in C. struct DefaultKeyMap { - static std::map init() - // TODO: Fix this indentation, spaces to tabs - { - std::map m; - m[KEY_x] = PAD_BUTTON_A; - m[KEY_z] = PAD_BUTTON_B; - m[KEY_s] = PAD_BUTTON_X; - m[KEY_a] = PAD_BUTTON_Y; - m[KEY_q] = PAD_BUTTON_LBUMPER; - m[KEY_w] = PAD_BUTTON_RBUMPER; - m[KEY_SPACE] = PAD_BUTTON_START; - m[KEY_ENTER] = PAD_BUTTON_SELECT; - m[KEY_ARROW_UP] = PAD_BUTTON_UP; - m[KEY_ARROW_DOWN] = PAD_BUTTON_DOWN; - m[KEY_ARROW_LEFT] = PAD_BUTTON_LEFT; - m[KEY_ARROW_RIGHT] = PAD_BUTTON_RIGHT; - m[KEY_TAB] = PAD_BUTTON_MENU; - m[KEY_BACKSPACE] = PAD_BUTTON_BACK; - m[KEY_ANALOG_FAKE_UP] = PAD_BUTTON_JOY_UP; - m[KEY_ANALOG_FAKE_DOWN] = PAD_BUTTON_JOY_DOWN; - m[KEY_ANALOG_FAKE_LEFT] = PAD_BUTTON_JOY_LEFT; - m[KEY_ANALOG_FAKE_RIGHT] = PAD_BUTTON_JOY_RIGHT; - m[KEY_CTRL_LEFT] = PAD_BUTTON_LEFT_THUMB; - m[KEY_ALT_LEFT] = PAD_BUTTON_RIGHT_THUMB; - return m; - } - static std::map KeyMap; - + static std::map init() + { + std::map m; + m[KEY_x] = PAD_BUTTON_A; + m[KEY_z] = PAD_BUTTON_B; + m[KEY_s] = PAD_BUTTON_X; + m[KEY_a] = PAD_BUTTON_Y; + m[KEY_q] = PAD_BUTTON_LBUMPER; + m[KEY_w] = PAD_BUTTON_RBUMPER; + m[KEY_SPACE] = PAD_BUTTON_START; + m[KEY_ENTER] = PAD_BUTTON_SELECT; + m[KEY_ARROW_UP] = PAD_BUTTON_UP; + m[KEY_ARROW_DOWN] = PAD_BUTTON_DOWN; + m[KEY_ARROW_LEFT] = PAD_BUTTON_LEFT; + m[KEY_ARROW_RIGHT] = PAD_BUTTON_RIGHT; + m[KEY_TAB] = PAD_BUTTON_MENU; + m[KEY_BACKSPACE] = PAD_BUTTON_BACK; + m[KEY_ANALOG_FAKE_UP] = PAD_BUTTON_JOY_UP; + m[KEY_ANALOG_FAKE_DOWN] = PAD_BUTTON_JOY_DOWN; + m[KEY_ANALOG_FAKE_LEFT] = PAD_BUTTON_JOY_LEFT; + m[KEY_ANALOG_FAKE_RIGHT] = PAD_BUTTON_JOY_RIGHT; + m[KEY_CTRL_LEFT] = PAD_BUTTON_LEFT_THUMB; + m[KEY_ALT_LEFT] = PAD_BUTTON_RIGHT_THUMB; + return m; + } + static std::map KeyMap; }; std::map DefaultKeyMap::KeyMap = DefaultKeyMap::init();