aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRSDuck <RSDuck@users.noreply.github.com>2023-03-02 14:41:46 +0100
committerRSDuck <RSDuck@users.noreply.github.com>2023-03-02 14:41:46 +0100
commit4ba7a2c5e6f6209eb240d37a4b0c780f618f8836 (patch)
tree31a4b803dd5c6f8a9b3845e85365f2127551c0e2 /src
parentca221381e977c3f4bd92416e405711952acb87ae (diff)
tiny refactoring around the input config dialog
Diffstat (limited to 'src')
-rw-r--r--src/frontend/qt_sdl/InputConfig/InputConfigDialog.cpp102
-rw-r--r--src/frontend/qt_sdl/InputConfig/InputConfigDialog.h60
2 files changed, 91 insertions, 71 deletions
diff --git a/src/frontend/qt_sdl/InputConfig/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfig/InputConfigDialog.cpp
index 396da29..b0672a0 100644
--- a/src/frontend/qt_sdl/InputConfig/InputConfigDialog.cpp
+++ b/src/frontend/qt_sdl/InputConfig/InputConfigDialog.cpp
@@ -25,7 +25,6 @@
#include "types.h"
#include "Platform.h"
-#include "Config.h"
#include "MapButton.h"
#include "Input.h"
@@ -38,51 +37,6 @@ InputConfigDialog* InputConfigDialog::currentDlg = nullptr;
const int dskeyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 2, 3};
const char* dskeylabels[12] = {"A", "B", "X", "Y", "Left", "Right", "Up", "Down", "L", "R", "Select", "Start"};
-const int hk_addons[] =
-{
- HK_SolarSensorIncrease,
- HK_SolarSensorDecrease,
-};
-
-const char* hk_addons_labels[] =
-{
- "[Boktai] Sunlight + ",
- "[Boktai] Sunlight - ",
-};
-
-const int hk_general[] =
-{
- HK_Pause,
- HK_Reset,
- HK_FrameStep,
- HK_FastForward,
- HK_FastForwardToggle,
- HK_FullscreenToggle,
- HK_Lid,
- HK_Mic,
- HK_SwapScreens,
- HK_SwapScreenEmphasis
-};
-
-const char* hk_general_labels[] =
-{
- "Pause/resume",
- "Reset",
- "Frame step",
- "Fast forward",
- "Toggle FPS limit",
- "Toggle fullscreen",
- "Close/open lid",
- "Microphone",
- "Swap screens",
- "Swap screen emphasis"
-};
-
-const int keypad_num = 12;
-const int hk_addons_num = 2;
-const int hk_general_num = 10;
-
-
InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InputConfigDialog)
{
ui->setupUi(this);
@@ -94,20 +48,24 @@ InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new
keypadJoyMap[i] = Config::JoyMapping[dskeyorder[i]];
}
- for (int i = 0; i < hk_addons_num; i++)
+ int i = 0;
+ for (int hotkey : hk_addons)
{
- addonsKeyMap[i] = Config::HKKeyMapping[hk_addons[i]];
- addonsJoyMap[i] = Config::HKJoyMapping[hk_addons[i]];
+ addonsKeyMap[i] = Config::HKKeyMapping[hotkey];
+ addonsJoyMap[i] = Config::HKJoyMapping[hotkey];
+ i++;
}
- for (int i = 0; i < hk_general_num; i++)
+ i = 0;
+ for (int hotkey : hk_general)
{
- hkGeneralKeyMap[i] = Config::HKKeyMapping[hk_general[i]];
- hkGeneralJoyMap[i] = Config::HKJoyMapping[hk_general[i]];
+ hkGeneralKeyMap[i] = Config::HKKeyMapping[hotkey];
+ hkGeneralJoyMap[i] = Config::HKJoyMapping[hotkey];
+ i++;
}
- populatePage(ui->tabAddons, hk_addons_num, hk_addons_labels, addonsKeyMap, addonsJoyMap);
- populatePage(ui->tabHotkeysGeneral, hk_general_num, hk_general_labels, hkGeneralKeyMap, hkGeneralJoyMap);
+ populatePage(ui->tabAddons, hk_addons_labels, addonsKeyMap, addonsJoyMap);
+ populatePage(ui->tabHotkeysGeneral, hk_general_labels, hkGeneralKeyMap, hkGeneralJoyMap);
int njoy = SDL_NumJoysticks();
if (njoy > 0)
@@ -162,7 +120,9 @@ void InputConfigDialog::setupKeypadPage()
}
}
-void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap)
+void InputConfigDialog::populatePage(QWidget* page,
+ const std::initializer_list<const char*>& labels,
+ int* keymap, int* joymap)
{
// kind of a hack
bool ishotkey = (page != ui->tabInput);
@@ -176,15 +136,17 @@ void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels
main_layout->addWidget(group);
group_layout = new QGridLayout();
group_layout->setSpacing(1);
- for (int i = 0; i < num; i++)
+ int i = 0;
+ for (const char* labelStr : labels)
{
- QLabel* label = new QLabel(QString(labels[i])+":");
+ QLabel* label = new QLabel(QString(labelStr)+":");
KeyMapButton* btn = new KeyMapButton(&keymap[i], ishotkey);
group_layout->addWidget(label, i, 0);
group_layout->addWidget(btn, i, 1);
+ i++;
}
- group_layout->setRowStretch(num, 1);
+ group_layout->setRowStretch(labels.size(), 1);
group->setLayout(group_layout);
group->setMinimumWidth(275);
@@ -192,15 +154,17 @@ void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels
main_layout->addWidget(group);
group_layout = new QGridLayout();
group_layout->setSpacing(1);
- for (int i = 0; i < num; i++)
+ i = 0;
+ for (const char* labelStr : labels)
{
- QLabel* label = new QLabel(QString(labels[i])+":");
+ QLabel* label = new QLabel(QString(labelStr)+":");
JoyMapButton* btn = new JoyMapButton(&joymap[i], ishotkey);
group_layout->addWidget(label, i, 0);
group_layout->addWidget(btn, i, 1);
+ i++;
}
- group_layout->setRowStretch(num, 1);
+ group_layout->setRowStretch(labels.size(), 1);
group->setLayout(group_layout);
group->setMinimumWidth(275);
@@ -215,16 +179,20 @@ void InputConfigDialog::on_InputConfigDialog_accepted()
Config::JoyMapping[dskeyorder[i]] = keypadJoyMap[i];
}
- for (int i = 0; i < hk_addons_num; i++)
+ int i = 0;
+ for (int hotkey : hk_addons)
{
- Config::HKKeyMapping[hk_addons[i]] = addonsKeyMap[i];
- Config::HKJoyMapping[hk_addons[i]] = addonsJoyMap[i];
+ Config::HKKeyMapping[hotkey] = addonsKeyMap[i];
+ Config::HKJoyMapping[hotkey] = addonsJoyMap[i];
+ i++;
}
- for (int i = 0; i < hk_general_num; i++)
+ i = 0;
+ for (int hotkey : hk_general)
{
- Config::HKKeyMapping[hk_general[i]] = hkGeneralKeyMap[i];
- Config::HKJoyMapping[hk_general[i]] = hkGeneralJoyMap[i];
+ Config::HKKeyMapping[hotkey] = hkGeneralKeyMap[i];
+ Config::HKJoyMapping[hotkey] = hkGeneralJoyMap[i];
+ i++;
}
Config::JoystickID = Input::JoystickID;
diff --git a/src/frontend/qt_sdl/InputConfig/InputConfigDialog.h b/src/frontend/qt_sdl/InputConfig/InputConfigDialog.h
index f1ea059..76112e8 100644
--- a/src/frontend/qt_sdl/InputConfig/InputConfigDialog.h
+++ b/src/frontend/qt_sdl/InputConfig/InputConfigDialog.h
@@ -21,6 +21,56 @@
#include <QDialog>
#include <QPushButton>
+#include <initializer_list>
+
+#include "Config.h"
+
+static constexpr int keypad_num = 12;
+
+static constexpr std::initializer_list<int> hk_addons =
+{
+ HK_SolarSensorIncrease,
+ HK_SolarSensorDecrease,
+};
+
+static constexpr std::initializer_list<const char*> hk_addons_labels =
+{
+ "[Boktai] Sunlight + ",
+ "[Boktai] Sunlight - ",
+};
+
+static_assert(hk_addons.size() == hk_addons_labels.size());
+
+static constexpr std::initializer_list<int> hk_general =
+{
+ HK_Pause,
+ HK_Reset,
+ HK_FrameStep,
+ HK_FastForward,
+ HK_FastForwardToggle,
+ HK_FullscreenToggle,
+ HK_Lid,
+ HK_Mic,
+ HK_SwapScreens,
+ HK_SwapScreenEmphasis
+};
+
+static constexpr std::initializer_list<const char*> hk_general_labels =
+{
+ "Pause/resume",
+ "Reset",
+ "Frame step",
+ "Fast forward",
+ "Toggle FPS limit",
+ "Toggle fullscreen",
+ "Close/open lid",
+ "Microphone",
+ "Swap screens",
+ "Swap screen emphasis"
+};
+
+static_assert(hk_general.size() == hk_general_labels.size());
+
namespace Ui { class InputConfigDialog; }
class InputConfigDialog;
@@ -60,14 +110,16 @@ private slots:
void on_cbxJoystick_currentIndexChanged(int id);
private:
- void populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap);
+ void populatePage(QWidget* page,
+ const std::initializer_list<const char*>& labels,
+ int* keymap, int* joymap);
void setupKeypadPage();
Ui::InputConfigDialog* ui;
- int keypadKeyMap[12], keypadJoyMap[12];
- int addonsKeyMap[2], addonsJoyMap[2];
- int hkGeneralKeyMap[9], hkGeneralJoyMap[9];
+ int keypadKeyMap[12], keypadJoyMap[12];
+ int addonsKeyMap[hk_addons.size()], addonsJoyMap[hk_addons.size()];
+ int hkGeneralKeyMap[hk_general.size()], hkGeneralJoyMap[hk_general.size()];
};