diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-09-26 02:20:28 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-09-26 02:20:28 +0200 |
commit | cb284fbe2bf90759d53262d636ff5ba201ad08c8 (patch) | |
tree | 1756c89f2ed8a7fd56d943b5724d2e01a040c3a4 /src/libui_sdl | |
parent | 2084bacc22843cb74e6d0ae85115e2acd3ad92fb (diff) |
get the input dialog started
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/DlgInputConfig.cpp | 169 | ||||
-rw-r--r-- | src/libui_sdl/DlgInputConfig.h | 30 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 8 |
3 files changed, 207 insertions, 0 deletions
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp new file mode 100644 index 0000000..b729b35 --- /dev/null +++ b/src/libui_sdl/DlgInputConfig.cpp @@ -0,0 +1,169 @@ +/* + Copyright 2016-2017 StapleButter + + This file is part of melonDS. + + melonDS 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, either version 3 of the License, or (at your option) + any later version. + + melonDS 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 for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "libui/ui.h" + +#include "../types.h" +#include "../Config.h" + +#include "DlgInputConfig.h" + + +namespace DlgInputConfig +{ + +uiWindow* win; + +// + + +void JoyMappingName(int id, char* str) +{ + if (id < 0) + { + strcpy(str, "None"); + return; + } + + if (id & 0x100) + { + switch (id & 0xF) + { + case 0x1: strcpy(str, "Up"); break; + case 0x2: strcpy(str, "Right"); break; + case 0x4: strcpy(str, "Down"); break; + case 0x8: strcpy(str, "Left"); break; + } + } + else + { + sprintf(str, "Button %d", id+1); + } +} + + +int OnCloseWindow(uiWindow* window, void* blarg) +{ + return 1; +} + +void OnCancel(uiButton* btn, void* blarg) +{ + uiControlDestroy(uiControl(win)); +} + +void OnOk(uiButton* btn, void* blarg) +{ + // + + Config::Save(); + + uiControlDestroy(uiControl(win)); +} + +void Open() +{ + win = uiNewWindow("Input config - melonDS", 600, 400, 0); + uiWindowSetMargined(win, 1); + uiWindowOnClosing(win, OnCloseWindow, NULL); + + uiBox* top = uiNewVerticalBox(); + uiWindowSetChild(win, 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); + + + uiGroup* g_key = uiNewGroup("Keyboard"); + uiBoxAppend(in_ctrl, uiControl(g_key), 1); + uiBox* b_key = uiNewVerticalBox(); + uiGroupSetChild(g_key, uiControl(b_key)); + + for (int i = 0; i < 12; i++) + { + int j = keyorder[i]; + + uiBox* box = uiNewHorizontalBox(); + uiBoxAppend(b_key, uiControl(box), 0); + + uiLabel* label = uiNewLabel(keylabels[j]); + uiBoxAppend(box, uiControl(label), 1); + + char* keyname = uiKeyName(Config::KeyMapping[j]); + + uiButton* btn = uiNewButton(keyname); + uiBoxAppend(box, uiControl(btn), 1); + + uiFreeText(keyname); + } + + uiGroup* g_joy = uiNewGroup("Joystick"); + uiBoxAppend(in_ctrl, uiControl(g_joy), 1); + uiBox* b_joy = uiNewVerticalBox(); + uiGroupSetChild(g_joy, uiControl(b_joy)); + + for (int i = 0; i < 12; i++) + { + int j = keyorder[i]; + + uiBox* box = uiNewHorizontalBox(); + uiBoxAppend(b_joy, uiControl(box), 0); + + uiLabel* label = uiNewLabel(keylabels[j]); + uiBoxAppend(box, uiControl(label), 1); + + char keyname[16]; + JoyMappingName(Config::JoyMapping[j], keyname); + + uiButton* btn = uiNewButton(keyname); + uiBoxAppend(box, uiControl(btn), 1); + } + } + + { + uiBox* in_ctrl = uiNewHorizontalBox(); + uiBoxSetPadded(in_ctrl, 1); + uiBoxAppend(top, uiControl(in_ctrl), 0); + + uiLabel* dummy = uiNewLabel(""); + uiBoxAppend(in_ctrl, uiControl(dummy), 1); + + uiButton* btncancel = uiNewButton("Cancel"); + uiButtonOnClicked(btncancel, OnCancel, NULL); + uiBoxAppend(in_ctrl, uiControl(btncancel), 0); + + uiButton* btnok = uiNewButton("Ok"); + uiButtonOnClicked(btnok, OnOk, NULL); + uiBoxAppend(in_ctrl, uiControl(btnok), 0); + } + + // + + uiControlShow(uiControl(win)); +} + +} + diff --git a/src/libui_sdl/DlgInputConfig.h b/src/libui_sdl/DlgInputConfig.h new file mode 100644 index 0000000..33529c2 --- /dev/null +++ b/src/libui_sdl/DlgInputConfig.h @@ -0,0 +1,30 @@ +/* + Copyright 2016-2017 StapleButter + + This file is part of melonDS. + + melonDS 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, either version 3 of the License, or (at your option) + any later version. + + melonDS 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 for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DLGINPUTCONFIG_H +#define DLGINPUTCONFIG_H + +namespace DlgInputConfig +{ + +void Open(); + +} + +#endif // DLGINPUTCONFIG_H + diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index c36ae2d..b985b7d 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -28,6 +28,7 @@ #include "../Config.h" #include "DlgEmuSettings.h" +#include "DlgInputConfig.h" #include "../NDS.h" #include "../GPU.h" @@ -414,6 +415,11 @@ void OnOpenEmuSettings(uiMenuItem* item, uiWindow* window, void* blarg) DlgEmuSettings::Open(); } +void OnOpenInputConfig(uiMenuItem* item, uiWindow* window, void* blarg) +{ + DlgInputConfig::Open(); +} + void ApplyNewSettings() { @@ -516,6 +522,8 @@ int main(int argc, char** argv) menu = uiNewMenu("Config"); menuitem = uiMenuAppendItem(menu, "Emu settings"); uiMenuItemOnClicked(menuitem, OnOpenEmuSettings, NULL); + menuitem = uiMenuAppendItem(menu, "Input config"); + uiMenuItemOnClicked(menuitem, OnOpenInputConfig, NULL); MainWindow = uiNewWindow("melonDS " MELONDS_VERSION, 256, 384, 1); uiWindowOnClosing(MainWindow, OnCloseWindow, NULL); |