From 61d71a0a4acc51c5d15c4bb5f04821ab77322880 Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Thu, 23 May 2013 17:20:29 -0700 Subject: [PATCH 01/18] Add key map config screen --- UI/MenuScreens.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ UI/MenuScreens.h | 16 +++++++++++++ 2 files changed, 76 insertions(+) diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 5606c4c585..7981d06623 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -49,6 +49,7 @@ namespace MainWindow { #include "UIShader.h" #include "Common/StringUtils.h" +#include "Common/KeyMap.h" #include "Core/System.h" #include "Core/CoreParameter.h" #include "GPU/ge_constants.h" @@ -544,6 +545,7 @@ void SettingsScreen::render() { UIEnd(); } +// TODO: Move these into a superclass void DeveloperScreen::update(InputState &input) { if (input.pad_buttons_down & PAD_BUTTON_BACK) { g_Config.Save(); @@ -586,6 +588,13 @@ void ControlsScreen::update(InputState &input) { } } +void KeyMappingScreen::update(InputState &input) { + if (input.pad_buttons_down & PAD_BUTTON_BACK) { + g_Config.Save(); + screenManager()->finishDialog(this, DR_OK); + } +} + void LanguageScreen::update(InputState &input) { if (input.pad_buttons_down & PAD_BUTTON_BACK) { g_Config.Save(); @@ -980,6 +989,57 @@ void ControlsScreen::render() { } UICheckBox(GEN_ID, x, y += stride, c->T("Tilt", "Tilt to Analog (horizontal)"), ALIGN_TOPLEFT, &g_Config.bAccelerometerToAnalogHoriz); + // Button to KeyMapping screen + I18NCategory *keyI18N = GetI18NCategory("KeyMapping"); + if (UIButton(GEN_ID, Pos(10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, keyI18N->T("Key Mapping"), ALIGN_BOTTOMLEFT)) { + screenManager()->push(new KeyMappingScreen()); + } + + UIEnd(); +} + +void KeyMappingScreen::render() { + UIShader_Prepare(); + UIBegin(UIShader_Get()); + DrawBackground(1.0f); + + I18NCategory *keyI18N = GetI18NCategory("KeyMapping"); + I18NCategory *generalI18N = GetI18NCategory("General"); + + // TODO: use unicode symbols + + + +#define KeyBtn(x, y, symbol) \ + UIButton(GEN_ID, Pos(x, y), 50, 0, symbol , ALIGN_TOPLEFT); + + int pad = 150; + int hlfpad = pad / 2; + + int left = 30; + KeyBtn(left, 30, "L"); + KeyBtn(dp_yres, 30, "R"); + + int top = 100; + KeyBtn(left+hlfpad, top, "^"); // ^ + KeyBtn(left, top+hlfpad, "<"); // < + KeyBtn(left+pad, top+hlfpad, ">"); // < + KeyBtn(left+hlfpad, top+pad, "V"); // < + + left = dp_yres; + KeyBtn(left+hlfpad, top, "^"); // Triangle + KeyBtn(left, top+hlfpad, "H"); // Square + KeyBtn(left+pad, top+hlfpad, "O"); // Circle + KeyBtn(left+hlfpad, top+pad, "X"); // Cross + + top += pad; + left = dp_yres /2; + KeyBtn(left, top, "start"); + KeyBtn(left + pad, top, "select"); + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { + screenManager()->finishDialog(this, DR_OK); + } UIEnd(); } diff --git a/UI/MenuScreens.h b/UI/MenuScreens.h index e766bcaaff..14b68c495d 100644 --- a/UI/MenuScreens.h +++ b/UI/MenuScreens.h @@ -123,6 +123,22 @@ public: void render(); }; +class KeyMappingScreen : public Screen +{ +public: + void update(InputState &input); + void render(); +}; +/* +// Dialog box, meant to be pushed +class KeyMappingNewKeyDialog : public Screen +{ +public: + void update(InputState &input); + void render(); + virtual void sendMessage(const char *msg, const char *value); +};*/ + struct FileSelectScreenOptions { const char* filter; // Enforced extension filter. Case insensitive, extensions separated by ":". bool allowChooseDirectory; From 8584dfe5019707bb4a6a3fac5f7198b309be907e Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Thu, 23 May 2013 18:07:01 -0700 Subject: [PATCH 02/18] Add key mapping set dialog mockup --- UI/MenuScreens.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++--- UI/MenuScreens.h | 5 ++-- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 7981d06623..b7986f1458 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -595,6 +595,13 @@ void KeyMappingScreen::update(InputState &input) { } } +void KeyMappingNewKeyDialog::update(InputState &input) { + if (input.pad_buttons_down & PAD_BUTTON_BACK) { + g_Config.Save(); + screenManager()->finishDialog(this, DR_OK); + } +} + void LanguageScreen::update(InputState &input) { if (input.pad_buttons_down & PAD_BUTTON_BACK) { g_Config.Save(); @@ -1006,12 +1013,12 @@ void KeyMappingScreen::render() { I18NCategory *keyI18N = GetI18NCategory("KeyMapping"); I18NCategory *generalI18N = GetI18NCategory("General"); - // TODO: use unicode symbols - - #define KeyBtn(x, y, symbol) \ - UIButton(GEN_ID, Pos(x, y), 50, 0, symbol , ALIGN_TOPLEFT); + if (UIButton(GEN_ID, Pos(x, y), 50, 0, symbol , ALIGN_TOPLEFT)) {\ + screenManager()->push(new KeyMappingNewKeyDialog(), 0); \ + UIReset(); \ + } int pad = 150; int hlfpad = pad / 2; @@ -1020,6 +1027,7 @@ void KeyMappingScreen::render() { KeyBtn(left, 30, "L"); KeyBtn(dp_yres, 30, "R"); + // TODO: use unicode symbols int top = 100; KeyBtn(left+hlfpad, top, "^"); // ^ KeyBtn(left, top+hlfpad, "<"); // < @@ -1036,6 +1044,7 @@ void KeyMappingScreen::render() { left = dp_yres /2; KeyBtn(left, top, "start"); KeyBtn(left + pad, top, "select"); +#undef KeyBtn if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { screenManager()->finishDialog(this, DR_OK); @@ -1043,6 +1052,50 @@ void KeyMappingScreen::render() { UIEnd(); } +void KeyMappingNewKeyDialog::render() { + UIShader_Prepare(); + UIBegin(UIShader_Get()); + DrawBackground(1.0f); + + I18NCategory *keyI18N = GetI18NCategory("KeyMapping"); + I18NCategory *generalI18N = GetI18NCategory("General"); + +#define KeyText(x, y, sentence) \ + ui_draw2d.DrawText(UBUNTU24, (sentence), x, y, 0xFFFFFFFF, ALIGN_TOPLEFT); +#define KeyScale(width) \ + ui_draw2d.SetFontScale(width, width); + + int top = 10; + int left = 10; + int stride = 70; + KeyScale(1.6f); + KeyText(left, top, keyI18N->T("Set a new key mapping")); + KeyScale(1.3f); + KeyText(left, top += stride, keyI18N->T("Current key")); + KeyScale(2.0f); + KeyText(left, top + stride, "X"); + + int right = dp_yres ; + KeyScale(1.4f); + KeyText(right, top, keyI18N->T("New Key")); + KeyScale(2.0f); + KeyText(right, top + stride, "Y"); + + KeyScale(1.0f); +#undef KeyText +#undef KeyScale + + // Save & cancel buttons + if (UIButton(GEN_ID, Pos(10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, keyI18N->T("Save Mapping"), ALIGN_LEFT | ALIGN_BOTTOM)) { + screenManager()->finishDialog(this, DR_OK); + } + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Cancel"), ALIGN_RIGHT | ALIGN_BOTTOM)) { + screenManager()->finishDialog(this, DR_OK); + } + UIEnd(); +} + class FileListAdapter : public UIListAdapter { public: FileListAdapter(const FileSelectScreenOptions &options, const std::vector *items, UIContext *ctx) diff --git a/UI/MenuScreens.h b/UI/MenuScreens.h index 14b68c495d..32107e9597 100644 --- a/UI/MenuScreens.h +++ b/UI/MenuScreens.h @@ -129,15 +129,14 @@ public: void update(InputState &input); void render(); }; -/* + // Dialog box, meant to be pushed class KeyMappingNewKeyDialog : public Screen { public: void update(InputState &input); void render(); - virtual void sendMessage(const char *msg, const char *value); -};*/ +}; struct FileSelectScreenOptions { const char* filter; // Enforced extension filter. Case insensitive, extensions separated by ":". From b219dee8b4f152bbe703bd0543d16c5e2721d27d Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Thu, 23 May 2013 21:05:41 -0700 Subject: [PATCH 03/18] Fix static keyword hiding functions --- Common/KeyMap.cpp | 585 +++++++++++++++++++++++----------------------- Common/KeyMap.h | 18 +- 2 files changed, 302 insertions(+), 301 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 6e224f12c1..7e5f624603 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -22,316 +22,317 @@ #include "Core/Config.h" #include "KeyMap.h" -using namespace KeyMap; +namespace KeyMap { -// Platform specific -// default -std::map *platform_keymap = NULL; + // 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() + // 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() + { + 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_UP] = PAD_BUTTON_JOY_UP; + m[KEY_ANALOG_DOWN] = PAD_BUTTON_JOY_DOWN; + m[KEY_ANALOG_LEFT] = PAD_BUTTON_JOY_LEFT; + m[KEY_ANALOG_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_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_FASTFORWARD, "Fast foward"}, + + {KEY_ARROW_LEFT, "Left"}, + {KEY_ARROW_UP, "Up"}, + {KEY_ARROW_RIGHT, "Right"}, + {KEY_ARROW_DOWN, "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"}, + {KEY_ANALOG_ALT_RIGHT, "Alt analog Right"}, + {KEY_ANALOG_ALT_DOWN, "Alt analog 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, "○"}, + {PAD_BUTTON_B, "⨯"}, + {PAD_BUTTON_X, "□"}, + {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) { - 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_UP] = PAD_BUTTON_JOY_UP; - m[KEY_ANALOG_DOWN] = PAD_BUTTON_JOY_DOWN; - m[KEY_ANALOG_LEFT] = PAD_BUTTON_JOY_LEFT; - m[KEY_ANALOG_RIGHT] = PAD_BUTTON_JOY_RIGHT; - m[KEY_CTRL_LEFT] = PAD_BUTTON_LEFT_THUMB; - m[KEY_ALT_LEFT] = PAD_BUTTON_RIGHT_THUMB; - return m; + for (int i = 0; i < size; i++) + if (list[i].key == key) + return list[i].name; + + return unknown_key_name; } - static std::map KeyMap; -}; -std::map DefaultKeyMap::KeyMap = DefaultKeyMap::init(); + std::string GetKeyName(KeyMap::Key key) + { + return FindName((int)key, key_names, key_names_count); + } -// 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"}, + std::string GetPspButtonName(int btn) + { + return FindName(btn, key_names, key_names_count); + } - {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_FASTFORWARD, "Fast foward"}, - - {KEY_ARROW_LEFT, "Left"}, - {KEY_ARROW_UP, "Up"}, - {KEY_ARROW_RIGHT, "Right"}, - {KEY_ARROW_DOWN, "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"}, - {KEY_ANALOG_ALT_RIGHT, "Alt analog Right"}, - {KEY_ANALOG_ALT_DOWN, "Alt analog 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, "○"}, - {PAD_BUTTON_B, "⨯"}, - {PAD_BUTTON_X, "□"}, - {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; + 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 >= 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; + 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; } - *map_id = -1; - return false; -} + int KeyToPspButton(const KeyMap::Key key) + { + int search_start_layer = 0; + int psp_button; -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; - 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; + return KEYMAP_ERROR_UNKNOWN_KEY; + } + + bool IsMappedKey(Key key) + { + return KeyMap::KeyToPspButton(key) != KEYMAP_ERROR_UNKNOWN_KEY; + } + + + std::string NamePspButtonFromKey(KeyMap::Key key) + { + return KeyMap::GetPspButtonName(KeyMap::KeyToPspButton(key)); + } + + std::string 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; + } + + int SetKeyMapping(KeyMap::Key key, int btn) + { + if (KeyMap::IsMappedKey(key)) + return KEYMAP_ERROR_KEY_ALREADY_USED; + + g_Config.iMappingMap[key] = btn; + } + + int RegisterPlatformDefaultKeyMap(std::map *overriding_map) + { + if (overriding_map == NULL) + return 1; + platform_keymap = overriding_map; + return 0; + } + + void DeregisterPlatformDefaultKeyMap(void) + { + platform_keymap = NULL; + return; } - // 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; -} - -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 62435dccdc..5a8d2d4cdf 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -176,8 +176,8 @@ namespace KeyMap { // These functions are not // fast, do not call them // a million times. - static std::string GetKeyName(Key); - static std::string GetPspButtonName(int); + std::string GetKeyName(Key); + std::string GetPspButtonName(int); // Use if to translate // KeyMap Keys to PSP @@ -189,18 +189,18 @@ namespace KeyMap { // // Returns KEYMAP_ERROR_UNKNOWN_KEY // for any unmapped key - static int KeyToPspButton(Key); + int KeyToPspButton(Key); - static bool IsMappedKey(Key); + bool IsMappedKey(Key); // Might be usful if you want // to provide hints to users // upon mapping conflicts - static std::string NamePspButtonFromKey(Key); + std::string NamePspButtonFromKey(Key); // Use for showing the existing // key mapping. - static std::string NameKeyFromPspButton(int); + std::string NameKeyFromPspButton(int); // Configure the key mapping. // Any configuration will @@ -209,7 +209,7 @@ namespace KeyMap { // // Returns KEYMAP_ERROR_KEY_ALREADY_USED // for mapping conflicts. 0 otherwise. - static int SetKeyMapping(Key, int); + int SetKeyMapping(Key, int); // Platform specific keymaps // override KeyMap's defaults. @@ -220,7 +220,7 @@ namespace KeyMap { // all psp buttons. // Any buttons missing will // fallback to KeyMap's keymap. - static int RegisterPlatformDefaultKeyMap(std::map *); - static void DeregisterPlatformDefaultKeyMap(void); + int RegisterPlatformDefaultKeyMap(std::map *); + void DeregisterPlatformDefaultKeyMap(void); } From 5b8a1174eaad4d6d80ba7295050772de03db9e65 Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Thu, 23 May 2013 21:06:27 -0700 Subject: [PATCH 04/18] Make KeyMap screen display current key mappings --- UI/MenuScreens.cpp | 34 ++++++++++++++++++---------------- UI/MenuScreens.h | 5 +++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index b7986f1458..8213d2c92d 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -1015,35 +1015,37 @@ void KeyMappingScreen::render() { #define KeyBtn(x, y, symbol) \ - if (UIButton(GEN_ID, Pos(x, y), 50, 0, symbol , ALIGN_TOPLEFT)) {\ - screenManager()->push(new KeyMappingNewKeyDialog(), 0); \ + if (UIButton(GEN_ID, Pos(x, y), 50, 0, (KeyMap::GetPspButtonName(symbol)).c_str(), \ + ALIGN_TOPLEFT)) {\ + screenManager()->push(new KeyMappingNewKeyDialog(symbol), 0); \ UIReset(); \ } + KeyMap::DeregisterPlatformDefaultKeyMap(); + int pad = 150; int hlfpad = pad / 2; int left = 30; - KeyBtn(left, 30, "L"); - KeyBtn(dp_yres, 30, "R"); + KeyBtn(left, 30, PAD_BUTTON_LBUMPER); + KeyBtn(dp_yres, 30, PAD_BUTTON_RBUMPER); - // TODO: use unicode symbols int top = 100; - KeyBtn(left+hlfpad, top, "^"); // ^ - KeyBtn(left, top+hlfpad, "<"); // < - KeyBtn(left+pad, top+hlfpad, ">"); // < - KeyBtn(left+hlfpad, top+pad, "V"); // < + KeyBtn(left+hlfpad, top, PAD_BUTTON_UP); // ^ + KeyBtn(left, top+hlfpad, PAD_BUTTON_LEFT);// < + KeyBtn(left+pad, top+hlfpad, PAD_BUTTON_RIGHT); // > + KeyBtn(left+hlfpad, top+pad, PAD_BUTTON_DOWN); // < left = dp_yres; - KeyBtn(left+hlfpad, top, "^"); // Triangle - KeyBtn(left, top+hlfpad, "H"); // Square - KeyBtn(left+pad, top+hlfpad, "O"); // Circle - KeyBtn(left+hlfpad, top+pad, "X"); // Cross + KeyBtn(left+hlfpad, top, PAD_BUTTON_Y); // Triangle + KeyBtn(left, top+hlfpad, PAD_BUTTON_X); // Square + KeyBtn(left+pad, top+hlfpad, PAD_BUTTON_A); // Circle + KeyBtn(left+hlfpad, top+pad, PAD_BUTTON_B); // Cross top += pad; left = dp_yres /2; - KeyBtn(left, top, "start"); - KeyBtn(left + pad, top, "select"); + KeyBtn(left, top, PAD_BUTTON_START); + KeyBtn(left + pad, top, PAD_BUTTON_SELECT); #undef KeyBtn if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { @@ -1075,7 +1077,7 @@ void KeyMappingNewKeyDialog::render() { KeyScale(2.0f); KeyText(left, top + stride, "X"); - int right = dp_yres ; + int right = dp_yres; KeyScale(1.4f); KeyText(right, top, keyI18N->T("New Key")); KeyScale(2.0f); diff --git a/UI/MenuScreens.h b/UI/MenuScreens.h index 32107e9597..33bfdccecf 100644 --- a/UI/MenuScreens.h +++ b/UI/MenuScreens.h @@ -133,7 +133,12 @@ public: // Dialog box, meant to be pushed class KeyMappingNewKeyDialog : public Screen { +private: + int pspBtn; public: + KeyMappingNewKeyDialog(int btn) { + pspBtn = btn; + } void update(InputState &input); void render(); }; From b890e52c4df7b7d2aff92880f183189b8b45884b Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Thu, 23 May 2013 21:11:52 -0700 Subject: [PATCH 05/18] Make keymap new key dialog display current key --- UI/MenuScreens.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 8213d2c92d..10e6227dfb 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -1075,7 +1075,7 @@ void KeyMappingNewKeyDialog::render() { KeyScale(1.3f); KeyText(left, top += stride, keyI18N->T("Current key")); KeyScale(2.0f); - KeyText(left, top + stride, "X"); + KeyText(left, top + stride, (KeyMap::GetPspButtonName(this.pspBtn)).c_str()); int right = dp_yres; KeyScale(1.4f); From a9d6916cde7689d710a15faf487341971b345db3 Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Sat, 25 May 2013 20:29:52 -0700 Subject: [PATCH 06/18] Fix key map resolution only checking user settings Alone the way a few other bugs got squashed --- Common/KeyMap.cpp | 20 ++++++++++---------- UI/MenuScreens.cpp | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 7e5f624603..ebe1217722 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -230,13 +230,13 @@ namespace KeyMap { std::string GetPspButtonName(int btn) { - return FindName(btn, key_names, key_names_count); + return FindName(btn, psp_button_names, psp_button_names_count); } static bool FindKeyMapping(int key, int *map_id, int *psp_button) { std::map::iterator it; - if (*map_id >= 0) { + if (*map_id <= 0) { // check user configuration std::map user_map = g_Config.iMappingMap; it = user_map.find(key); @@ -247,7 +247,7 @@ namespace KeyMap { } } - if (*map_id >= 1 && platform_keymap != NULL) { + if (*map_id <= 1 && platform_keymap != NULL) { // check optional platform specific keymap std::map port_map = *platform_keymap; it = port_map.find(key); @@ -258,13 +258,13 @@ namespace KeyMap { } } - if (*map_id >= 2) { + 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()) { + const std::map::const_iterator const_it = default_map.find(key); + if (const_it != default_map.end()) { *map_id = 2; - *psp_button = it->second; + *psp_button = const_it->second; return true; } } @@ -302,9 +302,9 @@ namespace KeyMap { // 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; + 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 diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 10e6227dfb..8ed8d2d042 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -1075,7 +1075,7 @@ void KeyMappingNewKeyDialog::render() { KeyScale(1.3f); KeyText(left, top += stride, keyI18N->T("Current key")); KeyScale(2.0f); - KeyText(left, top + stride, (KeyMap::GetPspButtonName(this.pspBtn)).c_str()); + KeyText(left, top + stride, (KeyMap::NameKeyFromPspButton(this->pspBtn)).c_str()); int right = dp_yres; KeyScale(1.4f); From 79e6d4975b237e02184a562fd14a2ef3673a2cba Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Thu, 13 Jun 2013 20:30:02 -0700 Subject: [PATCH 07/18] Fix inconsistent namespace usage --- Common/KeyMap.cpp | 591 +++++++++++++++++++++++----------------------- 1 file changed, 295 insertions(+), 296 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index ebe1217722..77badcf5e3 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -22,317 +22,316 @@ #include "Core/Config.h" #include "KeyMap.h" -namespace KeyMap { +using namespace KeyMap - // Platform specific - // default - std::map *platform_keymap = NULL; +// 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() - { - 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_UP] = PAD_BUTTON_JOY_UP; - m[KEY_ANALOG_DOWN] = PAD_BUTTON_JOY_DOWN; - m[KEY_ANALOG_LEFT] = PAD_BUTTON_JOY_LEFT; - m[KEY_ANALOG_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_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_FASTFORWARD, "Fast foward"}, - - {KEY_ARROW_LEFT, "Left"}, - {KEY_ARROW_UP, "Up"}, - {KEY_ARROW_RIGHT, "Right"}, - {KEY_ARROW_DOWN, "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"}, - {KEY_ANALOG_ALT_RIGHT, "Alt analog Right"}, - {KEY_ANALOG_ALT_DOWN, "Alt analog 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, "○"}, - {PAD_BUTTON_B, "⨯"}, - {PAD_BUTTON_X, "□"}, - {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) +// 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() { - for (int i = 0; i < size; i++) - if (list[i].key == key) - return list[i].name; - - return unknown_key_name; + 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_UP] = PAD_BUTTON_JOY_UP; + m[KEY_ANALOG_DOWN] = PAD_BUTTON_JOY_DOWN; + m[KEY_ANALOG_LEFT] = PAD_BUTTON_JOY_LEFT; + m[KEY_ANALOG_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::string GetKeyName(KeyMap::Key key) - { - return FindName((int)key, key_names, key_names_count); - } +std::map DefaultKeyMap::KeyMap = DefaultKeyMap::init(); - std::string GetPspButtonName(int btn) - { - return FindName(btn, psp_button_names, psp_button_names_count); - } +// 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"}, - 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; - } - } + {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"}, - 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 const_it = default_map.find(key); - if (const_it != default_map.end()) { - *map_id = 2; - *psp_button = const_it->second; - return true; - } - } - - *map_id = -1; - return false; - } + {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"}, - int KeyToPspButton(const KeyMap::Key key) - { - int search_start_layer = 0; - int psp_button; + {KEY_VOLUME_UP, "Vol Up"}, + {KEY_VOLUME_DOWN, "Vol Down"}, + {KEY_HOME, "Home"}, + {KEY_CALL_START, "Start Call"}, + {KEY_CALL_END, "End Call"}, - if (FindKeyMapping((int)key, &search_start_layer, &psp_button)) - return psp_button; + {KEY_FASTFORWARD, "Fast foward"}, - return KEYMAP_ERROR_UNKNOWN_KEY; - } + {KEY_ARROW_LEFT, "Left"}, + {KEY_ARROW_UP, "Up"}, + {KEY_ARROW_RIGHT, "Right"}, + {KEY_ARROW_DOWN, "Down"}, - bool IsMappedKey(Key key) - { - return KeyMap::KeyToPspButton(key) != KEYMAP_ERROR_UNKNOWN_KEY; - } + {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"}, + {KEY_ANALOG_ALT_RIGHT, "Alt analog Right"}, + {KEY_ANALOG_ALT_DOWN, "Alt analog 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, "○"}, + {PAD_BUTTON_B, "⨯"}, + {PAD_BUTTON_X, "□"}, + {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]); - std::string NamePspButtonFromKey(KeyMap::Key key) - { - return KeyMap::GetPspButtonName(KeyMap::KeyToPspButton(key)); - } - - std::string 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; - } - - int SetKeyMapping(KeyMap::Key key, int btn) - { - if (KeyMap::IsMappedKey(key)) - return KEYMAP_ERROR_KEY_ALREADY_USED; - - g_Config.iMappingMap[key] = btn; - } - - int RegisterPlatformDefaultKeyMap(std::map *overriding_map) - { - if (overriding_map == NULL) - return 1; - platform_keymap = overriding_map; - return 0; - } - - void DeregisterPlatformDefaultKeyMap(void) - { - platform_keymap = NULL; - return; - } +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; } + +std::string GetKeyName(KeyMap::Key key) +{ + return FindName((int)key, key_names, key_names_count); +} + +std::string GetPspButtonName(int btn) +{ + return FindName(btn, psp_button_names, psp_button_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 const_it = default_map.find(key); + if (const_it != default_map.end()) { + *map_id = 2; + *psp_button = const_it->second; + return true; + } + } + + *map_id = -1; + return false; +} + + + +int 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; +} + +bool IsMappedKey(Key key) +{ + return KeyMap::KeyToPspButton(key) != KEYMAP_ERROR_UNKNOWN_KEY; +} + + +std::string NamePspButtonFromKey(KeyMap::Key key) +{ + return KeyMap::GetPspButtonName(KeyMap::KeyToPspButton(key)); +} + +std::string 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; +} + +int SetKeyMapping(KeyMap::Key key, int btn) +{ + if (KeyMap::IsMappedKey(key)) + return KEYMAP_ERROR_KEY_ALREADY_USED; + + g_Config.iMappingMap[key] = btn; +} + +int RegisterPlatformDefaultKeyMap(std::map *overriding_map) +{ + if (overriding_map == NULL) + return 1; + platform_keymap = overriding_map; + return 0; +} + +void DeregisterPlatformDefaultKeyMap(void) +{ + platform_keymap = NULL; + return; +} + From f79de79a9d343992abc425cb7d54867623b9267e Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Thu, 13 Jun 2013 20:37:50 -0700 Subject: [PATCH 08/18] Fix missing ; --- Common/KeyMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 4a1c74335a..49b89640b1 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -19,7 +19,7 @@ #include "Core/Config.h" #include "KeyMap.h" -using namespace KeyMap +using namespace KeyMap; // Platform specific // default From 7d4ab6e78643620b4b468d953ef2a54d8112d8f1 Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Sun, 23 Jun 2013 21:18:00 -0700 Subject: [PATCH 09/18] Fix function declarations missing from namespace --- Common/KeyMap.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 49b89640b1..0318dc4f89 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -220,12 +220,12 @@ static std::string FindName(int key, const KeyMap_IntStrPair list[], int size) return unknown_key_name; } -std::string GetKeyName(KeyMap::Key key) +std::string KeyMap::GetKeyName(KeyMap::Key key) { return FindName((int)key, key_names, key_names_count); } -std::string GetPspButtonName(int btn) +std::string KeyMap::GetPspButtonName(int btn) { return FindName(btn, psp_button_names, psp_button_names_count); } @@ -272,7 +272,7 @@ static bool FindKeyMapping(int key, int *map_id, int *psp_button) -int KeyToPspButton(const KeyMap::Key key) +int KeyMap::KeyToPspButton(const KeyMap::Key key) { int search_start_layer = 0; int psp_button; @@ -283,18 +283,18 @@ int KeyToPspButton(const KeyMap::Key key) return KEYMAP_ERROR_UNKNOWN_KEY; } -bool IsMappedKey(Key key) +bool KeyMap::IsMappedKey(Key key) { return KeyMap::KeyToPspButton(key) != KEYMAP_ERROR_UNKNOWN_KEY; } -std::string NamePspButtonFromKey(KeyMap::Key key) +std::string KeyMap::NamePspButtonFromKey(KeyMap::Key key) { return KeyMap::GetPspButtonName(KeyMap::KeyToPspButton(key)); } -std::string NameKeyFromPspButton(int btn) +std::string KeyMap::NameKeyFromPspButton(int btn) { // We drive our iteration // with the list of key names. @@ -310,7 +310,7 @@ std::string NameKeyFromPspButton(int btn) return unknown_key_name; } -int SetKeyMapping(KeyMap::Key key, int btn) +int KeyMap::SetKeyMapping(KeyMap::Key key, int btn) { if (KeyMap::IsMappedKey(key)) return KEYMAP_ERROR_KEY_ALREADY_USED; @@ -319,7 +319,7 @@ int SetKeyMapping(KeyMap::Key key, int btn) return btn; } -int RegisterPlatformDefaultKeyMap(std::map *overriding_map) +int KeyMap::RegisterPlatformDefaultKeyMap(std::map *overriding_map) { if (overriding_map == NULL) return 1; @@ -327,7 +327,7 @@ int RegisterPlatformDefaultKeyMap(std::map *overriding_map) return 0; } -void DeregisterPlatformDefaultKeyMap(void) +void KeyMap::DeregisterPlatformDefaultKeyMap(void) { platform_keymap = NULL; return; From 83a5609f2221558ad469e1f20e39072566c138bc Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Sun, 23 Jun 2013 22:08:45 -0700 Subject: [PATCH 10/18] Move keyboard key codes into native --- Common/KeyMap.cpp | 13 +++-- Common/KeyMap.h | 143 ++-------------------------------------------- native | 2 +- 3 files changed, 14 insertions(+), 144 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 0318dc4f89..b91207b7e8 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -18,6 +18,7 @@ #include "input/input_state.h" #include "Core/Config.h" #include "KeyMap.h" +#include "input/keyboard_keys.h" using namespace KeyMap; @@ -220,7 +221,7 @@ static std::string FindName(int key, const KeyMap_IntStrPair list[], int size) return unknown_key_name; } -std::string KeyMap::GetKeyName(KeyMap::Key key) +std::string KeyMap::GetKeyName(kb_key_t key) { return FindName((int)key, key_names, key_names_count); } @@ -272,7 +273,7 @@ static bool FindKeyMapping(int key, int *map_id, int *psp_button) -int KeyMap::KeyToPspButton(const KeyMap::Key key) +int KeyMap::KeyToPspButton(const kb_key_t key) { int search_start_layer = 0; int psp_button; @@ -283,13 +284,13 @@ int KeyMap::KeyToPspButton(const KeyMap::Key key) return KEYMAP_ERROR_UNKNOWN_KEY; } -bool KeyMap::IsMappedKey(Key key) +bool KeyMap::IsMappedKey(kb_key_t key) { return KeyMap::KeyToPspButton(key) != KEYMAP_ERROR_UNKNOWN_KEY; } -std::string KeyMap::NamePspButtonFromKey(KeyMap::Key key) +std::string KeyMap::NamePspButtonFromKey(kb_key_t key) { return KeyMap::GetPspButtonName(KeyMap::KeyToPspButton(key)); } @@ -300,7 +301,7 @@ std::string KeyMap::NameKeyFromPspButton(int btn) // 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))) + if (btn == KeyMap::KeyToPspButton((kb_key_t)(key_name.key))) return key_name.name; } @@ -310,7 +311,7 @@ std::string KeyMap::NameKeyFromPspButton(int btn) return unknown_key_name; } -int KeyMap::SetKeyMapping(KeyMap::Key key, int btn) +int KeyMap::SetKeyMapping(kb_key_t key, int btn) { if (KeyMap::IsMappedKey(key)) return KEYMAP_ERROR_KEY_ALREADY_USED; diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 5a8d2d4cdf..3feb64d404 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -19,6 +19,7 @@ #include #include +#include "input/keyboard_keys.h" #define KEYMAP_ERROR_KEY_ALREADY_USED -1 #define KEYMAP_ERROR_UNKNOWN_KEY 0 @@ -38,145 +39,13 @@ // 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, - - // 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, - 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_LEFT, - KEY_ANALOG_RIGHT, - KEY_ANALOG_UP, - KEY_ANALOG_DOWN, - - KEY_ANALOG_ALT_LEFT, - KEY_ANALOG_ALT_RIGHT, - KEY_ANALOG_ALT_UP, - KEY_ANALOG_ALT_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, - - // Special PPSSPP keys - KEY_FASTFORWARD, - - // 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 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. - std::string GetKeyName(Key); + std::string GetKeyName(kb_key_t); std::string GetPspButtonName(int); // Use if to translate @@ -189,14 +58,14 @@ namespace KeyMap { // // Returns KEYMAP_ERROR_UNKNOWN_KEY // for any unmapped key - int KeyToPspButton(Key); + int KeyToPspButton(kb_key_t); - bool IsMappedKey(Key); + bool IsMappedKey(kb_key_t); // Might be usful if you want // to provide hints to users // upon mapping conflicts - std::string NamePspButtonFromKey(Key); + std::string NamePspButtonFromKey(kb_key_t); // Use for showing the existing // key mapping. @@ -209,7 +78,7 @@ namespace KeyMap { // // Returns KEYMAP_ERROR_KEY_ALREADY_USED // for mapping conflicts. 0 otherwise. - int SetKeyMapping(Key, int); + int SetKeyMapping(kb_key_t, int); // Platform specific keymaps // override KeyMap's defaults. diff --git a/native b/native index 80c85b1c60..4ed4b04379 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 80c85b1c604ccead734d595dd7f67656f3fd9d85 +Subproject commit 4ed4b043798943fe61421c982645151db315ff2a From 29271f67d75550232fbdff87bedfe7a439eb136c Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Mon, 24 Jun 2013 21:34:14 -0700 Subject: [PATCH 11/18] Sync KeyMap to native changes --- CMakeLists.txt | 2 ++ Common/KeyMap.cpp | 1 - Common/KeyMap.h | 13 +++++++------ UI/EmuScreen.cpp | 10 ++++++++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f322208a13..bc1a94816f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -599,7 +599,9 @@ add_library(native STATIC native/image/zim_save.h native/input/gesture_detector.cpp native/input/gesture_detector.h + native/input/keycodes.h native/input/input_state.h + native/input/input_state.cpp native/json/json_writer.cpp native/json/json_writer.h native/math/curves.cpp diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index b91207b7e8..36d248bb1a 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -18,7 +18,6 @@ #include "input/input_state.h" #include "Core/Config.h" #include "KeyMap.h" -#include "input/keyboard_keys.h" using namespace KeyMap; diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 3feb64d404..c72c2d45fa 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -19,7 +19,8 @@ #include #include -#include "input/keyboard_keys.h" +#include "input/keycodes.h" // keyboard keys +#include "Core/HLE/sceCtrl.h" // psp keys #define KEYMAP_ERROR_KEY_ALREADY_USED -1 #define KEYMAP_ERROR_UNKNOWN_KEY 0 @@ -45,7 +46,7 @@ namespace KeyMap { // These functions are not // fast, do not call them // a million times. - std::string GetKeyName(kb_key_t); + std::string GetKeyName(int); std::string GetPspButtonName(int); // Use if to translate @@ -58,14 +59,14 @@ namespace KeyMap { // // Returns KEYMAP_ERROR_UNKNOWN_KEY // for any unmapped key - int KeyToPspButton(kb_key_t); + int KeyToPspButton(int); - bool IsMappedKey(kb_key_t); + bool IsMappedKey(int); // Might be usful if you want // to provide hints to users // upon mapping conflicts - std::string NamePspButtonFromKey(kb_key_t); + std::string NamePspButtonFromKey(int); // Use for showing the existing // key mapping. @@ -78,7 +79,7 @@ namespace KeyMap { // // Returns KEYMAP_ERROR_KEY_ALREADY_USED // for mapping conflicts. 0 otherwise. - int SetKeyMapping(kb_key_t, int); + int SetKeyMapping(int kb_key, int psp_key); // Platform specific keymaps // override KeyMap's defaults. diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 3636cc027f..73a2e7d288 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -190,6 +190,7 @@ void EmuScreen::update(InputState &input) { } #endif + /* // Then translate pad input into PSP pad input. Also, add in tilt. static const int mapping[12][2] = { {PAD_BUTTON_A, CTRL_CROSS}, @@ -214,6 +215,15 @@ void EmuScreen::update(InputState &input) { __CtrlButtonUp(mapping[i][1]); } } + */ + + // TODO: remove the above dead code + for (int i = 0; i < MAX_KEYQUEUESIZE; i++) { + int key = input.key_queue[i]; + if (key != 0) { + // TODO: find proper Ctrl* internal function + } + } float stick_x = input.pad_lstick_x; float stick_y = input.pad_lstick_y; From 6294e36c959fce9f3da9c6c9f7640d5315a1eb1e Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Mon, 24 Jun 2013 22:08:23 -0700 Subject: [PATCH 12/18] Make KeyMap use native keycodes and Core PS btns --- Common/KeyMap.cpp | 247 +++++++++++++++++----------------------------- native | 2 +- 2 files changed, 90 insertions(+), 159 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 36d248bb1a..10a00aa819 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -35,26 +35,18 @@ struct DefaultKeyMap { 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_UP] = PAD_BUTTON_JOY_UP; - m[KEY_ANALOG_DOWN] = PAD_BUTTON_JOY_DOWN; - m[KEY_ANALOG_LEFT] = PAD_BUTTON_JOY_LEFT; - m[KEY_ANALOG_RIGHT] = PAD_BUTTON_JOY_RIGHT; - m[KEY_CTRL_LEFT] = PAD_BUTTON_LEFT_THUMB; - m[KEY_ALT_LEFT] = PAD_BUTTON_RIGHT_THUMB; + m[KEYCODE_X] = CTRL_SQUARE; + m[KEYCODE_Z] = CTRL_TRIANGLE; + m[KEYCODE_S] = CTRL_CIRCLE; + m[KEYCODE_A] = CTRL_CROSS; + m[KEYCODE_Q] = CTRL_LTRIGGER; + m[KEYCODE_W] = CTRL_RTRIGGER; + m[KEYCODE_SPACE] = CTRL_START; + m[KEYCODE_ENTER] = CTRL_SELECT; + m[KEYCODE_DPAD_UP] = CTRL_UP; + m[KEYCODE_DPAD_DOWN] = CTRL_DOWN; + m[KEYCODE_DPAD_LEFT] = CTRL_LEFT; + m[KEYCODE_DPAD_RIGHT] = CTRL_RIGHT; return m; } static std::map KeyMap; @@ -68,145 +60,84 @@ struct KeyMap_IntStrPair { 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"}, + {KEYCODE_A, "A"}, + {KEYCODE_B, "B"}, + {KEYCODE_C, "C"}, + {KEYCODE_D, "D"}, + {KEYCODE_E, "E"}, + {KEYCODE_F, "F"}, + {KEYCODE_G, "G"}, + {KEYCODE_H, "H"}, + {KEYCODE_I, "I"}, + {KEYCODE_J, "J"}, + {KEYCODE_K, "K"}, + {KEYCODE_L, "L"}, + {KEYCODE_M, "M"}, + {KEYCODE_N, "N"}, + {KEYCODE_O, "O"}, + {KEYCODE_P, "P"}, + {KEYCODE_Q, "Q"}, + {KEYCODE_R, "R"}, + {KEYCODE_S, "S"}, + {KEYCODE_T, "T"}, + {KEYCODE_U, "U"}, + {KEYCODE_V, "V"}, + {KEYCODE_W, "W"}, + {KEYCODE_X, "X"}, + {KEYCODE_Y, "Y"}, + {KEYCODE_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"}, - {KEY_4, "4"}, - {KEY_5, "5"}, - {KEY_6, "6"}, - {KEY_7, "7"}, - {KEY_8, "8"}, - {KEY_9, "9"}, - {KEY_0, "0"}, + {KEYCODE_1, "1"}, + {KEYCODE_2, "2"}, + {KEYCODE_3, "3"}, + {KEYCODE_4, "4"}, + {KEYCODE_5, "5"}, + {KEYCODE_6, "6"}, + {KEYCODE_7, "7"}, + {KEYCODE_8, "8"}, + {KEYCODE_9, "9"}, + {KEYCODE_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"}, + {KEYCODE_BACK, "Back"}, + {KEYCODE_TAB, "Tab"}, + {KEYCODE_ENTER, "Enter"}, + {KEYCODE_SHIFT_LEFT, "Shift"}, + {KEYCODE_SHIFT_RIGHT, "Shift"}, + {KEYCODE_CTRL_LEFT, "Ctrl"}, + {KEYCODE_CTRL_RIGHT, "Ctrl"}, + {KEYCODE_ALT_LEFT, "Alt"}, + {KEYCODE_ALT_RIGHT, "Alt"}, + {KEYCODE_SPACE, "Space"}, + {KEYCODE_WINDOW, "Windows"}, + {KEYCODE_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"}, + {KEYCODE_VOLUME_UP, "Vol Up"}, + {KEYCODE_VOLUME_DOWN, "Vol Down"}, + {KEYCODE_HOME, "Home"}, + {KEYCODE_CALL, "Start Call"}, + {KEYCODE_ENDCALL, "End Call"}, - {KEY_FASTFORWARD, "Fast foward"}, - - {KEY_ARROW_LEFT, "Left"}, - {KEY_ARROW_UP, "Up"}, - {KEY_ARROW_RIGHT, "Right"}, - {KEY_ARROW_DOWN, "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"}, - {KEY_ANALOG_ALT_RIGHT, "Alt analog Right"}, - {KEY_ANALOG_ALT_DOWN, "Alt analog 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"}, + {KEYCODE_DPAD_LEFT, "Left"}, + {KEYCODE_DPAD_UP, "Up"}, + {KEYCODE_DPAD_RIGHT, "Right"}, + {KEYCODE_DPAD_DOWN, "Down"}, }; 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, "○"}, - {PAD_BUTTON_B, "⨯"}, - {PAD_BUTTON_X, "□"}, - {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"}, + {CTRL_CIRCLE, "○"}, + {CTRL_CROSS, "⨯"}, + {CTRL_SQUARE, "□"}, + {CTRL_TRIANGLE, "△"}, + {CTRL_LTRIGGER, "L"}, + {CTRL_RTRIGGER, "R"}, + {CTRL_START, "Start"}, + {CTRL_SELECT, "Select"}, + {CTRL_UP, "Up"}, + {CTRL_DOWN, "Down"}, + {CTRL_LEFT, "Left"}, + {CTRL_RIGHT, "Right"}, }; static int psp_button_names_count = sizeof(psp_button_names) / sizeof(psp_button_names[0]); @@ -220,9 +151,9 @@ static std::string FindName(int key, const KeyMap_IntStrPair list[], int size) return unknown_key_name; } -std::string KeyMap::GetKeyName(kb_key_t key) +std::string KeyMap::GetKeyName(int key) { - return FindName((int)key, key_names, key_names_count); + return FindName(key, key_names, key_names_count); } std::string KeyMap::GetPspButtonName(int btn) @@ -272,24 +203,24 @@ static bool FindKeyMapping(int key, int *map_id, int *psp_button) -int KeyMap::KeyToPspButton(const kb_key_t key) +int KeyMap::KeyToPspButton(const int key) { int search_start_layer = 0; int psp_button; - if (FindKeyMapping((int)key, &search_start_layer, &psp_button)) + if (FindKeyMapping(key, &search_start_layer, &psp_button)) return psp_button; return KEYMAP_ERROR_UNKNOWN_KEY; } -bool KeyMap::IsMappedKey(kb_key_t key) +bool KeyMap::IsMappedKey(int key) { return KeyMap::KeyToPspButton(key) != KEYMAP_ERROR_UNKNOWN_KEY; } -std::string KeyMap::NamePspButtonFromKey(kb_key_t key) +std::string KeyMap::NamePspButtonFromKey(int key) { return KeyMap::GetPspButtonName(KeyMap::KeyToPspButton(key)); } @@ -300,7 +231,7 @@ std::string KeyMap::NameKeyFromPspButton(int btn) // 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((kb_key_t)(key_name.key))) + if (btn == KeyMap::KeyToPspButton(key_name.key)) return key_name.name; } @@ -310,7 +241,7 @@ std::string KeyMap::NameKeyFromPspButton(int btn) return unknown_key_name; } -int KeyMap::SetKeyMapping(kb_key_t key, int btn) +int KeyMap::SetKeyMapping(int key, int btn) { if (KeyMap::IsMappedKey(key)) return KEYMAP_ERROR_KEY_ALREADY_USED; diff --git a/native b/native index 4ed4b04379..824f4fb457 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 4ed4b043798943fe61421c982645151db315ff2a +Subproject commit 824f4fb4573026188dddae7042fd336b5cfe882a From 14bce01a33a08fce8c8f061077025ba1a2655f28 Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Wed, 26 Jun 2013 20:22:45 -0700 Subject: [PATCH 13/18] Fix key map settings screen using wrong enums --- Common/KeyMap.cpp | 1 - UI/MenuScreens.cpp | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 10a00aa819..2c183fe26e 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -110,7 +110,6 @@ const KeyMap_IntStrPair key_names[] = { {KEYCODE_ALT_RIGHT, "Alt"}, {KEYCODE_SPACE, "Space"}, {KEYCODE_WINDOW, "Windows"}, - {KEYCODE_SPACE, "Space"}, {KEYCODE_VOLUME_UP, "Vol Up"}, {KEYCODE_VOLUME_DOWN, "Vol Down"}, diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 9e1bdbc867..59e0b703aa 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -1369,25 +1369,25 @@ void KeyMappingScreen::render() { int hlfpad = pad / 2; int left = 30; - KeyBtn(left, 30, PAD_BUTTON_LBUMPER); - KeyBtn(dp_yres, 30, PAD_BUTTON_RBUMPER); + KeyBtn(left, 30, CTRL_LTRIGGER); + KeyBtn(dp_yres, 30, CTRL_RTRIGGER); int top = 100; - KeyBtn(left+hlfpad, top, PAD_BUTTON_UP); // ^ - KeyBtn(left, top+hlfpad, PAD_BUTTON_LEFT);// < - KeyBtn(left+pad, top+hlfpad, PAD_BUTTON_RIGHT); // > - KeyBtn(left+hlfpad, top+pad, PAD_BUTTON_DOWN); // < + KeyBtn(left+hlfpad, top, CTRL_UP); // ^ + KeyBtn(left, top+hlfpad, CTRL_LEFT);// < + KeyBtn(left+pad, top+hlfpad, CTRL_RIGHT); // > + KeyBtn(left+hlfpad, top+pad, CTRL_DOWN); // < left = dp_yres; - KeyBtn(left+hlfpad, top, PAD_BUTTON_Y); // Triangle - KeyBtn(left, top+hlfpad, PAD_BUTTON_X); // Square - KeyBtn(left+pad, top+hlfpad, PAD_BUTTON_A); // Circle - KeyBtn(left+hlfpad, top+pad, PAD_BUTTON_B); // Cross + KeyBtn(left+hlfpad, top, CTRL_TRIANGLE); // Triangle + KeyBtn(left, top+hlfpad, CTRL_SQUARE); // Square + KeyBtn(left+pad, top+hlfpad, CTRL_CIRCLE); // Circle + KeyBtn(left+hlfpad, top+pad, CTRL_CROSS); // Cross top += pad; left = dp_yres /2; - KeyBtn(left, top, PAD_BUTTON_START); - KeyBtn(left + pad, top, PAD_BUTTON_SELECT); + KeyBtn(left, top, CTRL_START); + KeyBtn(left + pad, top, CTRL_SELECT); #undef KeyBtn if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { From d1e015b6ae60578fbf028ebe9d81d4a39f969c9a Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Thu, 27 Jun 2013 20:05:54 -0700 Subject: [PATCH 14/18] Make set key map screen show last pressed key --- UI/MenuScreens.cpp | 4 +++- UI/MenuScreens.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 59e0b703aa..76edc71e05 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -655,6 +655,7 @@ void KeyMappingScreen::update(InputState &input) { } void KeyMappingNewKeyDialog::update(InputState &input) { + last_kb_key = input.key_queue[0]; if (input.pad_buttons_down & PAD_BUTTON_BACK) { g_Config.Save(); screenManager()->finishDialog(this, DR_OK); @@ -1423,7 +1424,8 @@ void KeyMappingNewKeyDialog::render() { KeyScale(1.4f); KeyText(right, top, keyI18N->T("New Key")); KeyScale(2.0f); - KeyText(right, top + stride, "Y"); + if (last_kb_key != 0) + KeyText(right, top + stride, KeyMap::GetKeyName(last_kb_key).c_str()); KeyScale(1.0f); #undef KeyText diff --git a/UI/MenuScreens.h b/UI/MenuScreens.h index 8f87548bf3..56f4380b95 100644 --- a/UI/MenuScreens.h +++ b/UI/MenuScreens.h @@ -142,9 +142,11 @@ class KeyMappingNewKeyDialog : public Screen { private: int pspBtn; + int last_kb_key; public: KeyMappingNewKeyDialog(int btn) { pspBtn = btn; + last_kb_key = 0; } void update(InputState &input); void render(); From a7a4ad5f06bacd1c11de46a0aefe0a81c488e11e Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Sat, 29 Jun 2013 19:20:23 -0700 Subject: [PATCH 15/18] Fix key map screen forgeting last pressed key --- CMakeLists.txt | 1 + UI/MenuScreens.cpp | 6 +++++- native | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc1a94816f..b00768389c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -661,6 +661,7 @@ add_library(native STATIC native/util/random/rng.h native/util/text/utf8.h native/util/text/utf8.cpp + native/util/const_map.h native/ext/rapidxml/rapidxml.hpp native/ext/rapidxml/rapidxml_iterators.hpp native/ext/rapidxml/rapidxml_print.hpp diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 76edc71e05..e8d81e2c90 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -655,7 +655,11 @@ void KeyMappingScreen::update(InputState &input) { } void KeyMappingNewKeyDialog::update(InputState &input) { - last_kb_key = input.key_queue[0]; + int new_key = input.key_queue[0]; + + if (new_key != 0) + last_kb_key = new_key; + if (input.pad_buttons_down & PAD_BUTTON_BACK) { g_Config.Save(); screenManager()->finishDialog(this, DR_OK); diff --git a/native b/native index 824f4fb457..a51474d255 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 824f4fb4573026188dddae7042fd336b5cfe882a +Subproject commit a51474d255b2a607c178ebdf7732716781b3bccf From 643133238f71e36268508c0227115ec4a0c151e4 Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Sun, 30 Jun 2013 21:43:01 -0700 Subject: [PATCH 16/18] Make emu core use key mapped keys --- UI/EmuScreen.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 73a2e7d288..d27e89076b 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -25,6 +25,8 @@ #include "ui/ui.h" #include "i18n/i18n.h" +#include "Common/KeyMap.h" + #include "Core/Config.h" #include "Core/CoreTiming.h" #include "Core/CoreParameter.h" @@ -190,7 +192,18 @@ void EmuScreen::update(InputState &input) { } #endif - /* +// Daniel: +// Sorry I know it is pretensious of me to +// ask platforms to define a "legacy" def +// just becasue I am changing things on +// other platforms. +// Please be patient with me, I will try +// to migrate other platforms as time goes +// on. +// TODO: Migrate all platforms to "modern" +// key mapping +#ifdef LEGACY_KEY_MAPPING + // Legacy key mapping // Then translate pad input into PSP pad input. Also, add in tilt. static const int mapping[12][2] = { {PAD_BUTTON_A, CTRL_CROSS}, @@ -215,15 +228,21 @@ void EmuScreen::update(InputState &input) { __CtrlButtonUp(mapping[i][1]); } } - */ - // TODO: remove the above dead code +#else + // Modern key mapping + __CtrlButtonUp(-1); // blanks all buttons + uint32_t pressed = 0; for (int i = 0; i < MAX_KEYQUEUESIZE; i++) { int key = input.key_queue[i]; - if (key != 0) { - // TODO: find proper Ctrl* internal function - } + if (key == 0) + break; + + // TODO: Add virt_sce_* codes for analog sticks + pressed |= KeyMap::KeyToPspButton(key); } + __CtrlButtonDown(pressed); +#endif float stick_x = input.pad_lstick_x; float stick_y = input.pad_lstick_y; From 20399b9d6c67d3d783f799f1e902c02e21965b66 Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Sun, 30 Jun 2013 22:48:15 -0700 Subject: [PATCH 17/18] Make key mapping screen save changes --- Common/KeyMap.cpp | 7 +------ UI/MenuScreens.cpp | 17 ++++++++++++++--- native | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 2c183fe26e..55956ac61d 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -25,12 +25,7 @@ using namespace KeyMap; // 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. +// TODO: Make use const_map.h from native struct DefaultKeyMap { static std::map init() { diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index e8d81e2c90..7c788b7c76 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -1418,7 +1418,8 @@ void KeyMappingNewKeyDialog::render() { int left = 10; int stride = 70; KeyScale(1.6f); - KeyText(left, top, keyI18N->T("Set a new key mapping")); + KeyText(left, top, keyI18N->T("Map a new key for button: ")); + KeyText(left, top += stride, (KeyMap::GetPspButtonName(this->pspBtn)).c_str()); KeyScale(1.3f); KeyText(left, top += stride, keyI18N->T("Current key")); KeyScale(2.0f); @@ -1428,8 +1429,16 @@ void KeyMappingNewKeyDialog::render() { KeyScale(1.4f); KeyText(right, top, keyI18N->T("New Key")); KeyScale(2.0f); - if (last_kb_key != 0) - KeyText(right, top + stride, KeyMap::GetKeyName(last_kb_key).c_str()); + if (last_kb_key != 0) { + bool key_used = KeyMap::IsMappedKey(last_kb_key); + if (!key_used) { + KeyText(right, top + stride, KeyMap::GetKeyName(last_kb_key).c_str()); + } else { + KeyScale(1.0f); + KeyText(left + stride, top + 2*stride, + keyI18N->T("Error: Key is already used")); + } + } KeyScale(1.0f); #undef KeyText @@ -1437,6 +1446,8 @@ void KeyMappingNewKeyDialog::render() { // Save & cancel buttons if (UIButton(GEN_ID, Pos(10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, keyI18N->T("Save Mapping"), ALIGN_LEFT | ALIGN_BOTTOM)) { + KeyMap::SetKeyMapping(this->last_kb_key, this->pspBtn); + g_Config.Save(); screenManager()->finishDialog(this, DR_OK); } diff --git a/native b/native index a51474d255..91114ba605 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit a51474d255b2a607c178ebdf7732716781b3bccf +Subproject commit 91114ba60554713da98d4c23aeb533e2da650397 From 770456156de43d8280c1fb077d4c42fa17337a7d Mon Sep 17 00:00:00 2001 From: Daniel Dressler Date: Tue, 2 Jul 2013 20:49:30 -0700 Subject: [PATCH 18/18] Make both modern and legacy key mapping input work --- UI/EmuScreen.cpp | 27 ++++++--------------------- native | 2 +- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index d27e89076b..bbb6124a16 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -192,17 +192,10 @@ void EmuScreen::update(InputState &input) { } #endif -// Daniel: -// Sorry I know it is pretensious of me to -// ask platforms to define a "legacy" def -// just becasue I am changing things on -// other platforms. -// Please be patient with me, I will try -// to migrate other platforms as time goes -// on. -// TODO: Migrate all platforms to "modern" -// key mapping -#ifdef LEGACY_KEY_MAPPING + // Set Keys ---- + __CtrlButtonUp(-1); // blanks all buttons + uint32_t pressed = 0; + // Legacy key mapping // Then translate pad input into PSP pad input. Also, add in tilt. static const int mapping[12][2] = { @@ -221,18 +214,10 @@ void EmuScreen::update(InputState &input) { }; for (int i = 0; i < 12; i++) { - if (input.pad_buttons_down & mapping[i][0]) { - __CtrlButtonDown(mapping[i][1]); - } - if (input.pad_buttons_up & mapping[i][0]) { - __CtrlButtonUp(mapping[i][1]); - } + pressed |= input.pad_buttons_down & mapping[i][0]; } -#else // Modern key mapping - __CtrlButtonUp(-1); // blanks all buttons - uint32_t pressed = 0; for (int i = 0; i < MAX_KEYQUEUESIZE; i++) { int key = input.key_queue[i]; if (key == 0) @@ -242,7 +227,7 @@ void EmuScreen::update(InputState &input) { pressed |= KeyMap::KeyToPspButton(key); } __CtrlButtonDown(pressed); -#endif + // End Set Keys -- float stick_x = input.pad_lstick_x; float stick_y = input.pad_lstick_y; diff --git a/native b/native index 91114ba605..cace0b3a65 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 91114ba60554713da98d4c23aeb533e2da650397 +Subproject commit cace0b3a65e8f3edb6c765526b285a9d97f609db