diff options
author | Arisotura <thetotalworm@gmail.com> | 2019-06-04 15:44:40 +0200 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2019-06-04 15:44:40 +0200 |
commit | 3134c8fc66d1fbd5706930a3e3e64ce118406fe5 (patch) | |
tree | 25de5fffaaa399f385a2461b087bd99f1e6dd3a6 | |
parent | e3dc4e122a6ba822c860c09290925f98cc623532 (diff) |
add support for setting key mappings to none
-rw-r--r-- | src/libui_sdl/DlgInputConfig.cpp | 37 | ||||
-rw-r--r-- | src/libui_sdl/PlatformConfig.cpp | 2 |
2 files changed, 29 insertions, 10 deletions
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp index 98cdf8c..b77f8fe 100644 --- a/src/libui_sdl/DlgInputConfig.cpp +++ b/src/libui_sdl/DlgInputConfig.cpp @@ -64,6 +64,21 @@ int openedmask; InputDlgData inputdlg[2]; +void KeyMappingName(int id, char* str) +{ + if (id < 0) + { + strcpy(str, "None"); + return; + } + + char* keyname = uiKeyName(id); + strncpy(str, keyname, 31); + uiFreeText(keyname); + + str[31] = '\0'; +} + void JoyMappingName(int id, char* str) { if (id < 0) @@ -134,7 +149,7 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) return 1; } - char keyname[16]; + char keyname[32]; JoyMappingName(dlg->joymap[id], keyname); uiButtonSetText(dlg->pollbtn, keyname); uiControlEnable(uiControl(dlg->pollbtn)); @@ -150,12 +165,17 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) { // set key. if (evt->Scancode != 0x1) // ESC - dlg->keymap[dlg->pollid] = evt->Scancode; + { + if (evt->Scancode == 0xE) // backspace + dlg->keymap[dlg->pollid] = -1; + else + dlg->keymap[dlg->pollid] = evt->Scancode; + } - char* keyname = uiKeyName(dlg->keymap[dlg->pollid]); + char keyname[32]; + KeyMappingName(dlg->keymap[dlg->pollid], keyname); uiButtonSetText(dlg->pollbtn, keyname); uiControlEnable(uiControl(dlg->pollbtn)); - uiFreeText(keyname); dlg->pollid = -1; @@ -170,7 +190,7 @@ void FinishJoyMapping(void* param) InputDlgData* dlg = (InputDlgData*)param; int id = dlg->pollid & 0xFF; - char keyname[16]; + char keyname[32]; JoyMappingName(dlg->joymap[id], keyname); uiButtonSetText(dlg->pollbtn, keyname); uiControlEnable(uiControl(dlg->pollbtn)); @@ -386,15 +406,14 @@ void Open(int type) uiGridAppend(b_key, uiControl(label), 0, i, 1, 1, 1, uiAlignStart, 1, uiAlignCenter); uiControlSetMinSize(uiControl(label), width, 1); - char* keyname = uiKeyName(dlg->keymap[j]); + char keyname[32]; + KeyMappingName(dlg->keymap[j], keyname); uiButton* btn = uiNewButton(keyname); uiControl(btn)->UserData = dlg; uiGridAppend(b_key, uiControl(btn), 1, i, 1, 1, 1, uiAlignFill, 1, uiAlignCenter); uiButtonOnClicked(btn, OnKeyStartConfig, (type==0) ? &dskeyorder[i] : &identity[i]); uiControlSetMinSize(uiControl(btn), width, 1); - - uiFreeText(keyname); } uiGroup* g_joy = uiNewGroup("Joystick"); @@ -410,7 +429,7 @@ void Open(int type) uiGridAppend(b_joy, uiControl(label), 0, i, 1, 1, 1, uiAlignStart, 1, uiAlignCenter); uiControlSetMinSize(uiControl(label), width, 1); - char keyname[16]; + char keyname[32]; JoyMappingName(dlg->joymap[j], keyname); uiButton* btn = uiNewButton(keyname); diff --git a/src/libui_sdl/PlatformConfig.cpp b/src/libui_sdl/PlatformConfig.cpp index f700ecb..46e502d 100644 --- a/src/libui_sdl/PlatformConfig.cpp +++ b/src/libui_sdl/PlatformConfig.cpp @@ -88,7 +88,7 @@ ConfigEntry PlatformConfigFile[] = {"Joy_X", 0, &JoyMapping[10], -1, NULL, 0}, {"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0}, - {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0E, NULL, 0}, + {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0D, NULL, 0}, {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0}, {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0}, |