diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-09-30 18:58:13 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-09-30 18:58:13 +0200 |
commit | acc23f47cc54e1b0fee67b2c3b56e10ddf47e486 (patch) | |
tree | d546ea10fd2f7cd0d67b37c63367b9320e4c243e /src/libui_sdl/DlgInputConfig.cpp | |
parent | cb284fbe2bf90759d53262d636ff5ba201ad08c8 (diff) |
actually get the input dialog somewhere
Diffstat (limited to 'src/libui_sdl/DlgInputConfig.cpp')
-rw-r--r-- | src/libui_sdl/DlgInputConfig.cpp | 107 |
1 files changed, 100 insertions, 7 deletions
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp index b729b35..910486b 100644 --- a/src/libui_sdl/DlgInputConfig.cpp +++ b/src/libui_sdl/DlgInputConfig.cpp @@ -33,7 +33,17 @@ namespace DlgInputConfig uiWindow* win; -// +uiAreaHandler areahandler; +uiArea* keypresscatcher; + +int keyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 3, 2}; +char keylabels[12][8] = {"A:", "B:", "Select:", "Start:", "Right:", "Left:", "Up:", "Down:", "R:", "L:", "X:", "Y:"}; + +int keymap[12]; +int joymap[12]; + +int pollid; +uiButton* pollbtn; void JoyMappingName(int id, char* str) @@ -61,6 +71,72 @@ void JoyMappingName(int id, char* str) } +void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) +{ +} + +void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* evt) +{ +} + +void OnAreaMouseCrossed(uiAreaHandler* handler, uiArea* area, int left) +{ +} + +void OnAreaDragBroken(uiAreaHandler* handler, uiArea* area) +{ +} + +int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) +{ + if (pollid < 0 || pollid > 12) + return 0; + + if (evt->Scancode == 0x38) // ALT + return 0; + if (evt->Modifiers == 0x2) // ALT+key + return 0; + + if (!evt->Up) + { + // set key. + if (evt->Scancode != 0x1) // ESC + keymap[pollid] = evt->Scancode; + + char* keyname = uiKeyName(keymap[pollid]); + uiButtonSetText(pollbtn, keyname); + uiControlEnable(uiControl(pollbtn)); + uiFreeText(keyname); + + pollid = -1; + + uiControlSetFocus(uiControl(pollbtn)); + } + + return 1; +} + + +void OnKeyStartConfig(uiButton* btn, void* data) +{ + if (pollid != -1) + { + // TODO: handle this better? + uiControlSetFocus(uiControl(keypresscatcher)); + return; + } + + int id = *(int*)data; + pollid = id; + pollbtn = btn; + + uiButtonSetText(btn, "[press key]"); + uiControlDisable(uiControl(btn)); + + uiControlSetFocus(uiControl(keypresscatcher)); +} + + int OnCloseWindow(uiWindow* window, void* blarg) { return 1; @@ -73,7 +149,8 @@ void OnCancel(uiButton* btn, void* blarg) void OnOk(uiButton* btn, void* blarg) { - // + memcpy(Config::KeyMapping, keymap, sizeof(int)*12); + memcpy(Config::JoyMapping, joymap, sizeof(int)*12); Config::Save(); @@ -82,19 +159,28 @@ void OnOk(uiButton* btn, void* blarg) void Open() { + pollid = -1; + + memcpy(keymap, Config::KeyMapping, sizeof(int)*12); + memcpy(joymap, Config::JoyMapping, sizeof(int)*12); + win = uiNewWindow("Input config - melonDS", 600, 400, 0); uiWindowSetMargined(win, 1); uiWindowOnClosing(win, OnCloseWindow, NULL); + areahandler.Draw = OnAreaDraw; + areahandler.MouseEvent = OnAreaMouseEvent; + areahandler.MouseCrossed = OnAreaMouseCrossed; + areahandler.DragBroken = OnAreaDragBroken; + areahandler.KeyEvent = OnAreaKeyEvent; + uiBox* top = uiNewVerticalBox(); uiWindowSetChild(win, uiControl(top)); + uiControlHide(uiControl(top)); { - int keyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 3, 2}; - char keylabels[12][8] = {"A:", "B:", "Select:", "Start:", "Right:", "Left:", "Up:", "Down:", "R:", "L:", "X:", "Y:"}; - uiBox* in_ctrl = uiNewHorizontalBox(); - uiBoxAppend(top, uiControl(in_ctrl), 1); + uiBoxAppend(top, uiControl(in_ctrl), 0); uiGroup* g_key = uiNewGroup("Keyboard"); @@ -116,6 +202,7 @@ void Open() uiButton* btn = uiNewButton(keyname); uiBoxAppend(box, uiControl(btn), 1); + uiButtonOnClicked(btn, OnKeyStartConfig, &keyorder[i]); uiFreeText(keyname); } @@ -143,6 +230,9 @@ void Open() } } + uiLabel* filler = uiNewLabel(""); + uiBoxAppend(top, uiControl(filler), 1); + { uiBox* in_ctrl = uiNewHorizontalBox(); uiBoxSetPadded(in_ctrl, 1); @@ -151,6 +241,9 @@ void Open() uiLabel* dummy = uiNewLabel(""); uiBoxAppend(in_ctrl, uiControl(dummy), 1); + keypresscatcher = uiNewArea(&areahandler); + uiBoxAppend(in_ctrl, uiControl(keypresscatcher), 0); + uiButton* btncancel = uiNewButton("Cancel"); uiButtonOnClicked(btncancel, OnCancel, NULL); uiBoxAppend(in_ctrl, uiControl(btncancel), 0); @@ -160,7 +253,7 @@ void Open() uiBoxAppend(in_ctrl, uiControl(btnok), 0); } - // + uiControlShow(uiControl(top)); uiControlShow(uiControl(win)); } |