aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl
diff options
context:
space:
mode:
Diffstat (limited to 'src/libui_sdl')
-rw-r--r--src/libui_sdl/DlgInputConfig.cpp107
-rw-r--r--src/libui_sdl/libui/windows/area.cpp4
-rw-r--r--src/libui_sdl/main.cpp3
3 files changed, 102 insertions, 12 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));
}
diff --git a/src/libui_sdl/libui/windows/area.cpp b/src/libui_sdl/libui/windows/area.cpp
index ab69ff1..3257631 100644
--- a/src/libui_sdl/libui/windows/area.cpp
+++ b/src/libui_sdl/libui/windows/area.cpp
@@ -56,8 +56,8 @@ uiWindowsControlAllDefaults(uiArea)
static void uiAreaMinimumSize(uiWindowsControl *c, int *width, int *height)
{
// TODO
- *width = 0;
- *height = 0;
+ *width = 1;
+ *height = 1;
}
ATOM registerAreaClass(HICON hDefaultIcon, HCURSOR hDefaultCursor)
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index b985b7d..1493d03 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -232,12 +232,10 @@ void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* ev
void OnAreaMouseCrossed(uiAreaHandler* handler, uiArea* area, int left)
{
- //
}
void OnAreaDragBroken(uiAreaHandler* handler, uiArea* area)
{
- //
}
int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt)
@@ -539,7 +537,6 @@ int main(int argc, char** argv)
uiMenuItemDisable(MenuItem_Stop);
uiAreaHandler areahandler;
-
areahandler.Draw = OnAreaDraw;
areahandler.MouseEvent = OnAreaMouseEvent;
areahandler.MouseCrossed = OnAreaMouseCrossed;