From b31925517881aaaf585af48379fddf8dde7d1e52 Mon Sep 17 00:00:00 2001 From: SimoZ64 Date: Mon, 28 Apr 2025 23:51:34 +0200 Subject: [PATCH] more work towards a clean code --- src/frontend/CMakeLists.txt | 4 +- src/frontend/EmuThread.hpp | 2 +- src/frontend/ImGuiImpl/Combobox.hpp | 11 +- src/frontend/ImGuiImpl/PushButton.hpp | 34 ++++ src/frontend/ImGuiImpl/Slider.hpp | 2 +- src/frontend/InputSettings.cpp | 166 ++++--------------- src/frontend/InputSettings.hpp | 27 ++- src/frontend/{KaizenQt.cpp => KaizenGui.cpp} | 32 ++-- src/frontend/{KaizenQt.hpp => KaizenGui.hpp} | 11 +- src/frontend/MainWindow.cpp | 19 ++- src/frontend/MainWindow.hpp | 12 +- src/frontend/RenderWidget.cpp | 26 +-- src/frontend/SettingsWindow.cpp | 6 +- src/frontend/SettingsWindow.hpp | 14 +- src/frontend/main.cpp | 10 +- 15 files changed, 163 insertions(+), 213 deletions(-) create mode 100644 src/frontend/ImGuiImpl/PushButton.hpp rename src/frontend/{KaizenQt.cpp => KaizenGui.cpp} (79%) rename src/frontend/{KaizenQt.hpp => KaizenGui.hpp} (72%) diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index 6a4bb1ac..3c5e3784 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -107,8 +107,8 @@ add_subdirectory(../../external/capstone capstone) add_executable(kaizen main.cpp - KaizenQt.hpp - KaizenQt.cpp + KaizenGui.hpp + KaizenGui.cpp RenderWidget.cpp RenderWidget.hpp EmuThread.hpp diff --git a/src/frontend/EmuThread.hpp b/src/frontend/EmuThread.hpp index dfa7b496..510869b3 100644 --- a/src/frontend/EmuThread.hpp +++ b/src/frontend/EmuThread.hpp @@ -24,6 +24,6 @@ public: bool interruptionRequested = false, isRunning = false; std::shared_ptr core; SettingsWindow &settings; - std::string fps; + std::string& fps; std::thread thread; }; diff --git a/src/frontend/ImGuiImpl/Combobox.hpp b/src/frontend/ImGuiImpl/Combobox.hpp index d12d8087..71866114 100644 --- a/src/frontend/ImGuiImpl/Combobox.hpp +++ b/src/frontend/ImGuiImpl/Combobox.hpp @@ -5,7 +5,9 @@ namespace gui { struct Combobox { - Combobox(std::string label, const std::vector& items, std::string preview = "") : label(label), items(items), preview(preview) {} + Combobox(std::string label, std::vector items, std::string preview = "", bool enabled = true) : label(label), items(items), preview(preview), enabled(enabled) {} + + void addItem(const std::string& text) { items.push_back(text); } bool render() { const char* _preview = ""; @@ -18,6 +20,7 @@ struct Combobox { bool changed = false; + ImGui::BeginDisabled(!enabled); if (ImGui::BeginCombo(label.c_str(), _preview)) { for (int n = 0; n < items.size(); n++) { const bool is_selected = ((current_index) == n); @@ -32,14 +35,18 @@ struct Combobox { } ImGui::EndCombo(); } + ImGui::EndDisabled(); return changed; } + void setEnabled(bool v) { enabled = v; } + void setCurrentIndex(int v) { current_index = v; } int getCurrentIndex() { return current_index; } private: - const std::vector& items; + bool enabled = true; + std::vector& items; std::string label, preview; int current_index = 0; }; diff --git a/src/frontend/ImGuiImpl/PushButton.hpp b/src/frontend/ImGuiImpl/PushButton.hpp new file mode 100644 index 00000000..db47a5e3 --- /dev/null +++ b/src/frontend/ImGuiImpl/PushButton.hpp @@ -0,0 +1,34 @@ +#pragma once +#include +#include + +namespace gui { +struct PushButton { + PushButton(const std::string& label, const std::string& name = "", bool enabled = true) : label(label), name(name), enabled(enabled) {} + + bool render() { + if(name != "") { + ImGui::Text(name.c_str()); + ImGui::SameLine(); + } + + ImGui::BeginDisabled(!enabled); + bool ret = ImGui::Button(label.c_str()); + ImGui::EndDisabled(); + return ret; + } + + void setEnabled(bool v) { enabled = v; } + bool getEnabled() { return enabled; } + + std::string& getName() const { return name; } + void setName(const std::string& v) { name = v; } + + std::string& getLabel() const { return label; } + void setLabel(const std::string& v) { label = v; } +private: + bool enabled = true; + std::string name; + std::string label; +}; +} \ No newline at end of file diff --git a/src/frontend/ImGuiImpl/Slider.hpp b/src/frontend/ImGuiImpl/Slider.hpp index ac6c49bd..a870c633 100644 --- a/src/frontend/ImGuiImpl/Slider.hpp +++ b/src/frontend/ImGuiImpl/Slider.hpp @@ -12,7 +12,7 @@ struct Slider { bool render() { return ImGui::SliderScalarN(label.c_str(), type_to_imgui(), (void*)&val, 1, (void*)&min, (void*)&max); } - T getValue() { return val; } + T getValue() const { return val; } private: constexpr ImGuiDataType_ type_to_imgui() { if constexpr(std::is_same_v) { diff --git a/src/frontend/InputSettings.cpp b/src/frontend/InputSettings.cpp index 948b1331..589bc774 100644 --- a/src/frontend/InputSettings.cpp +++ b/src/frontend/InputSettings.cpp @@ -3,81 +3,14 @@ #include #include -InputSettings::InputSettings(nlohmann::json &settings) : QWidget(nullptr), settings(settings) { - buttonLabels[0] = std::make_unique("A"); - buttonLabels[1] = std::make_unique("B"); - buttonLabels[2] = std::make_unique("Z"); - buttonLabels[3] = std::make_unique("Start"); - buttonLabels[4] = std::make_unique("L"); - buttonLabels[5] = std::make_unique("R"); - buttonLabels[6] = std::make_unique("Dpad Up"); - buttonLabels[7] = std::make_unique("Dpad Down"); - buttonLabels[8] = std::make_unique("Dpad Left"); - buttonLabels[9] = std::make_unique("Dpad Right"); - buttonLabels[10] = std::make_unique("C Up"); - buttonLabels[11] = std::make_unique("C Down"); - buttonLabels[12] = std::make_unique("C Left"); - buttonLabels[13] = std::make_unique("C Right"); - buttonLabels[14] = std::make_unique("Analog Up"); - buttonLabels[15] = std::make_unique("Analog Down"); - buttonLabels[16] = std::make_unique("Analog Left"); - buttonLabels[17] = std::make_unique("Analog Right"); - - auto str = JSONGetField(settings, "input", "A"); - kbButtons[0] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "B"); - kbButtons[1] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Z"); - kbButtons[2] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Start"); - kbButtons[3] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "L"); - kbButtons[4] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "R"); - kbButtons[5] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Dpad Up"); - kbButtons[6] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Dpad Down"); - kbButtons[7] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Dpad Left"); - kbButtons[8] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Dpad Right"); - kbButtons[9] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "C Up"); - kbButtons[10] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "C Down"); - kbButtons[11] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "C Left"); - kbButtons[12] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "C Right"); - kbButtons[13] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Analog Up"); - kbButtons[14] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Analog Down"); - kbButtons[15] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Analog Left"); - kbButtons[16] = std::make_unique(str.c_str()); - str = JSONGetField(settings, "input", "Analog Right"); - kbButtons[17] = std::make_unique(str.c_str()); - - for (int i = 0; i < 18; i++) { - connect(kbButtons[i].get(), &QPushButton::pressed, this, [&, i] { - devices->setEnabled(false); - for (const auto &kbButton : kbButtons) { - kbButton->setEnabled(false); - } - - grabbing = true; - whichGrabbing = i; - - if (devices->currentText() == "Keyboard/Mouse") { - grabKeyboard(); - } else { - selectedDeviceIsNotKeyboard = true; - } - }); +InputSettings::InputSettings(nlohmann::json &settings) : settings(settings) { + for(auto& kb : kbButtons) { + kb.setLabel(JSONGetField(settings, "input", kb.getName())); } + devices.addItem("Keyboard/Mouse"); + + /* TODO: GAMEPAD STUFF IDK HOW TO HANDLE YET connect(devices.get(), &QComboBox::currentTextChanged, this, [&](const QString &text) { JSONSetField(settings, "input", "Device", text.toStdString()); emit modified(); @@ -90,62 +23,30 @@ InputSettings::InputSettings(nlohmann::json &settings) : QWidget(nullptr), setti connect(&pollGamepad, &QTimer::timeout, this, &InputSettings::PollGamepad); pollGamepad.start(16); - - devices->addItem("Keyboard/Mouse"); - deviceComboBoxLayout->addWidget(devicesLabel.get()); - deviceComboBoxLayout->addWidget(devices.get()); - mainLayout->addLayout(deviceComboBoxLayout.get()); - - AB->addWidget(buttonLabels[0].get()); - AB->addWidget(kbButtons[0].get()); - AB->addWidget(buttonLabels[1].get()); - AB->addWidget(kbButtons[1].get()); - mainLayout->addLayout(AB.get()); - ZStart->addWidget(buttonLabels[2].get()); - ZStart->addWidget(kbButtons[2].get()); - ZStart->addWidget(buttonLabels[3].get()); - ZStart->addWidget(kbButtons[3].get()); - mainLayout->addLayout(ZStart.get()); - LR->addWidget(buttonLabels[4].get()); - LR->addWidget(kbButtons[4].get()); - LR->addWidget(buttonLabels[5].get()); - LR->addWidget(kbButtons[5].get()); - mainLayout->addLayout(LR.get()); - DupDdown->addWidget(buttonLabels[6].get()); - DupDdown->addWidget(kbButtons[6].get()); - DupDdown->addWidget(buttonLabels[7].get()); - DupDdown->addWidget(kbButtons[7].get()); - mainLayout->addLayout(DupDdown.get()); - DleftDright->addWidget(buttonLabels[8].get()); - DleftDright->addWidget(kbButtons[8].get()); - DleftDright->addWidget(buttonLabels[9].get()); - DleftDright->addWidget(kbButtons[9].get()); - mainLayout->addLayout(DleftDright.get()); - CupCdown->addWidget(buttonLabels[10].get()); - CupCdown->addWidget(kbButtons[10].get()); - CupCdown->addWidget(buttonLabels[11].get()); - CupCdown->addWidget(kbButtons[11].get()); - mainLayout->addLayout(CupCdown.get()); - CleftCright->addWidget(buttonLabels[12].get()); - CleftCright->addWidget(kbButtons[12].get()); - CleftCright->addWidget(buttonLabels[13].get()); - CleftCright->addWidget(kbButtons[13].get()); - mainLayout->addLayout(CleftCright.get()); - AupAdown->addWidget(buttonLabels[14].get()); - AupAdown->addWidget(kbButtons[14].get()); - AupAdown->addWidget(buttonLabels[15].get()); - AupAdown->addWidget(kbButtons[15].get()); - mainLayout->addLayout(AupAdown.get()); - AleftAright->addWidget(buttonLabels[16].get()); - AleftAright->addWidget(kbButtons[16].get()); - AleftAright->addWidget(buttonLabels[17].get()); - AleftAright->addWidget(kbButtons[17].get()); - mainLayout->addLayout(AleftAright.get()); - mainLayout->addStretch(); - setLayout(mainLayout.get()); + */ } +bool InputSettings::render() { + int i = 0; + for(auto& kb : kbButtons) { + if(kb.render()) { + devices.setEnabled(false); + for (auto &otherKb : kbButtons) { + otherKb.setEnabled(false); + } + } + // TODO: ACTUALLY GRAB THE PRESSED INPUT + // ... + + if(i % 2 != 0) // only go down every 2 buttons... just... i like it this way + ImGui::SameLine(); + + i++; + } +} + +/* TODO: RECREATE THIS IN SDL void InputSettings::keyPressEvent(QKeyEvent *e) { if (grabbing) { const auto k = QKeySequence(e->key()).toString().toStdString(); @@ -165,17 +66,21 @@ void InputSettings::keyPressEvent(QKeyEvent *e) { } } } +*/ -std::array InputSettings::GetMappedKeys() const { - std::array ret{}; +std::array InputSettings::GetMappedKeys() { + std::array ret{}; + + int i = 0; - for (int i = 0; i < 18; i++) { - ret[i] = QKeySequence(kbButtons[i]->text().toUpper())[0].key(); + for (const auto& kb : kbButtons) { + ret[i++] = SDL_GetKeyFromName(kb.getLabel().c_str()); } return ret; } +/*TODO: RECREATE THIS IN SDL void InputSettings::QueryDevices() noexcept { if (!devices->isEnabled()) return; @@ -253,3 +158,4 @@ void InputSettings::PollGamepad() noexcept { } } } +*/ diff --git a/src/frontend/InputSettings.hpp b/src/frontend/InputSettings.hpp index e5d1aad4..b4c4e0ba 100644 --- a/src/frontend/InputSettings.hpp +++ b/src/frontend/InputSettings.hpp @@ -1,6 +1,8 @@ #pragma once #include #include +#include +#include class InputSettings final { bool grabbing = false; @@ -10,6 +12,28 @@ class InputSettings final { void PollGamepad() noexcept; std::unordered_map gamepadIndexes{}; + std::array kbButtons = { + gui::PushButton{"", "A"}, + gui::PushButton{"", "B"}, + gui::PushButton{"", "Z"}, + gui::PushButton{"", "Start"}, + gui::PushButton{"", "L"}, + gui::PushButton{"", "R"}, + gui::PushButton{"", "Dpad Up"}, + gui::PushButton{"", "Dpad Down"}, + gui::PushButton{"", "Dpad Left"}, + gui::PushButton{"", "Dpad Right"}, + gui::PushButton{"", "C Up"}, + gui::PushButton{"", "C Down"}, + gui::PushButton{"", "C Left"}, + gui::PushButton{"", "C Right"}, + gui::PushButton{"", "Analog Up"}, + gui::PushButton{"", "Analog Down"}, + gui::PushButton{"", "Analog Left"}, + gui::PushButton{"", "Analog Right"}, + }; + + gui::Combobox devices{"Device:", {}}; //std::unique_ptr AB = std::make_unique(); //std::unique_ptr ZStart = std::make_unique(); @@ -29,8 +53,9 @@ class InputSettings final { //std::unique_ptr devices = std::make_unique(); //Q_OBJECT public: + bool render(); bool selectedDeviceIsNotKeyboard = false; explicit InputSettings(nlohmann::json &); nlohmann::json &settings; - //std::array GetMappedKeys() const; + std::array GetMappedKeys(); }; diff --git a/src/frontend/KaizenQt.cpp b/src/frontend/KaizenGui.cpp similarity index 79% rename from src/frontend/KaizenQt.cpp rename to src/frontend/KaizenGui.cpp index cabafde7..1ca65315 100644 --- a/src/frontend/KaizenQt.cpp +++ b/src/frontend/KaizenGui.cpp @@ -1,28 +1,16 @@ #include -#include +#include namespace fs = std::filesystem; -KaizenQt::KaizenQt() noexcept : QWidget(nullptr) { - core = std::make_shared(); - mainWindow = std::make_unique(core); - settingsWindow = std::make_unique(); - emuThread = std::make_unique(core, *mainWindow->fpsCounter, *mainWindow->vulkanWidget, *settingsWindow); +KaizenGui::KaizenGui() noexcept : mainWindow(core), emuThread(core, mainWindow.fpsCounter, mainWindow.vulkanWidget, settingsWindow) { // debugger = std::make_unique(); ConnectMainWindowSignalsToSlots(); Util::RPC::GetInstance().Update(Util::RPC::Idling); - - setAcceptDrops(true); - setFocusPolicy(Qt::StrongFocus); - setFocus(); - grabKeyboard(); - mainWindow->show(); - // debugger->hide(); - settingsWindow->hide(); } -void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept { +void KaizenGui::ConnectMainWindowSignalsToSlots() noexcept { connect(settingsWindow.get(), &SettingsWindow::regrabKeyboard, this, [&] { grabKeyboard(); }); connect(settingsWindow.get(), &SettingsWindow::gotClosed, this, @@ -33,14 +21,14 @@ void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept { connect(mainWindow.get(), &MainWindow::OpenSettings, this, [this] { settingsWindow->show(); }); // connect(mainWindow.get(), &MainWindow::OpenDebugger, this, [this] { debugger->show(); }); - connect(mainWindow.get(), &MainWindow::OpenROM, this, &KaizenQt::LoadROM); - connect(mainWindow.get(), &MainWindow::Exit, this, &KaizenQt::Quit); + connect(mainWindow.get(), &MainWindow::OpenROM, this, &KaizenGui::LoadROM); + connect(mainWindow.get(), &MainWindow::Exit, this, &KaizenGui::Quit); connect(mainWindow.get(), &MainWindow::Reset, emuThread.get(), &EmuThread::Reset); connect(mainWindow.get(), &MainWindow::Stop, this, [this] { emuThread->requestInterruption(); }); connect(mainWindow.get(), &MainWindow::Pause, emuThread.get(), &EmuThread::TogglePause); } -void KaizenQt::LoadROM(const QString &path) const noexcept { +void KaizenGui::LoadROM(const QString &path) const noexcept { mainWindow->actionPause->setEnabled(true); mainWindow->actionReset->setEnabled(true); mainWindow->actionStop->setEnabled(true); @@ -51,7 +39,7 @@ void KaizenQt::LoadROM(const QString &path) const noexcept { Util::RPC::GetInstance().Update(Util::RPC::Playing, gameNameDB); } -void KaizenQt::Quit() const noexcept { +void KaizenGui::Quit() const noexcept { if (emuThread) { emuThread->requestInterruption(); while (emuThread->isRunning) {} @@ -59,7 +47,7 @@ void KaizenQt::Quit() const noexcept { QApplication::quit(); } -void KaizenQt::LoadTAS(const QString &path) const noexcept { +void KaizenGui::LoadTAS(const QString &path) const noexcept { if (emuThread->core->LoadTAS(fs::path(path.toStdString()))) { const auto gameNameDB = emuThread->core->cpu->GetMem().rom.gameNameDB; const auto movieName = fs::path(path.toStdString()).stem().string(); @@ -70,7 +58,7 @@ void KaizenQt::LoadTAS(const QString &path) const noexcept { Util::panic("Could not load TAS movie {}!", path.toStdString()); } -void KaizenQt::keyPressEvent(QKeyEvent *e) { +void KaizenGui::keyPressEvent(QKeyEvent *e) { if (settingsWindow->inputSettings->selectedDeviceIsNotKeyboard) return; @@ -97,7 +85,7 @@ void KaizenQt::keyPressEvent(QKeyEvent *e) { QWidget::keyPressEvent(e); } -void KaizenQt::keyReleaseEvent(QKeyEvent *e) { +void KaizenGui::keyReleaseEvent(QKeyEvent *e) { if (settingsWindow->inputSettings->selectedDeviceIsNotKeyboard) return; diff --git a/src/frontend/KaizenQt.hpp b/src/frontend/KaizenGui.hpp similarity index 72% rename from src/frontend/KaizenQt.hpp rename to src/frontend/KaizenGui.hpp index 33ec8abc..5111879b 100644 --- a/src/frontend/KaizenQt.hpp +++ b/src/frontend/KaizenGui.hpp @@ -6,18 +6,19 @@ #include #include -class KaizenQt { +class KaizenGui { public: - KaizenQt() noexcept; + KaizenGui() noexcept; void LoadTAS(const std::string &path) const noexcept; void LoadROM(const std::string &path) const noexcept; + int run(); private: void Quit() const noexcept; void ConnectMainWindowSignalsToSlots() noexcept; - std::unique_ptr mainWindow; - std::unique_ptr settingsWindow; - std::unique_ptr emuThread; + MainWindow mainWindow; + SettingsWindow settingsWindow; + EmuThread emuThread; // std::unique_ptr debugger; std::shared_ptr core; }; diff --git a/src/frontend/MainWindow.cpp b/src/frontend/MainWindow.cpp index 84dbd232..c9d8579c 100644 --- a/src/frontend/MainWindow.cpp +++ b/src/frontend/MainWindow.cpp @@ -1,8 +1,7 @@ #include -#include -MainWindow::MainWindow(const std::shared_ptr &core) noexcept { - if (objectName().isEmpty()) +MainWindow::MainWindow(const std::shared_ptr &core) noexcept : vulkanWidget(core) { + /* if (objectName().isEmpty()) setObjectName("MainWindow"); resize(800, 646); actionOpenDebuggerWindow = std::make_unique(this); @@ -27,8 +26,6 @@ MainWindow::MainWindow(const std::shared_ptr &core) noexcept { verticalLayout->setSpacing(0); verticalLayout->setObjectName("verticalLayout"); verticalLayout->setContentsMargins(0, 0, 0, 0); - vulkanWidget = std::make_unique(core); - vulkanWidget->setObjectName("vulkanWidget"); verticalLayout->addWidget(vulkanWidget.get()); @@ -73,11 +70,11 @@ MainWindow::MainWindow(const std::shared_ptr &core) noexcept { actionReset->setDisabled(true); actionStop->setDisabled(true); vulkanWidget->hide(); - ConnectSignalsToSlots(); + ConnectSignalsToSlots();*/ } void MainWindow::Retranslate() { - setWindowTitle(QCoreApplication::translate("MainWindow", "Kaizen", nullptr)); + /*setWindowTitle(QCoreApplication::translate("MainWindow", "Kaizen", nullptr)); actionOpenDebuggerWindow->setText(QCoreApplication::translate("MainWindow", "CPU Debugger", nullptr)); actionOpenDebuggerWindow->setStatusTip(QCoreApplication::translate( "MainWindow", "Open the CPU debugger window which allows you see registers, memory and disassembled code", @@ -102,10 +99,11 @@ void MainWindow::Retranslate() { menuEmulation->setTitle(QCoreApplication::translate("MainWindow", "Emulation", nullptr)); menuTools->setTitle(QCoreApplication::translate("MainWindow", "Tools", nullptr)); menuAbout->setTitle(QCoreApplication::translate("MainWindow", "Help", nullptr)); + */ } // retranslateUi void MainWindow::ConnectSignalsToSlots() noexcept { - connect(actionOpen.get(), &QAction::triggered, this, [this]() { + /* connect(actionOpen.get(), &QAction::triggered, this, [this]() { const QString file_name = QFileDialog::getOpenFileName( this, "Nintendo 64 executable", QString(), "All supported types (*.zip *.ZIP *.7z *.7Z *.rar *.RAR *.tar *.TAR *.n64 *.N64 *.v64 *.V64 *.z64 *.Z64)"); @@ -147,4 +145,9 @@ void MainWindow::ConnectSignalsToSlots() noexcept { connect(actionSettings.get(), &QAction::triggered, this, [this]() { emit OpenSettings(); }); connect(actionOpenDebuggerWindow.get(), &QAction::triggered, this, [this]() { emit OpenDebugger(); }); + */ } + +bool MainWindow::render() { + +} \ No newline at end of file diff --git a/src/frontend/MainWindow.hpp b/src/frontend/MainWindow.hpp index 7704e6f4..162e326f 100644 --- a/src/frontend/MainWindow.hpp +++ b/src/frontend/MainWindow.hpp @@ -5,6 +5,10 @@ class MainWindow final { public: explicit MainWindow(const std::shared_ptr &) noexcept; + std::string fpsCounter; + RenderWidget vulkanWidget; + + bool render(); //std::unique_ptr actionOpenDebuggerWindow{}; //std::unique_ptr actionAbout{}; @@ -30,12 +34,4 @@ private: void ConnectSignalsToSlots() noexcept; bool textPauseToggle = false; - - void OpenDebugger(); - void OpenSettings(); - void OpenROM(const std::string &rom_file); - void Exit(); - void Reset(); - void Stop(); - void Pause(); }; diff --git a/src/frontend/RenderWidget.cpp b/src/frontend/RenderWidget.cpp index b73e2f81..60c05e72 100644 --- a/src/frontend/RenderWidget.cpp +++ b/src/frontend/RenderWidget.cpp @@ -1,34 +1,22 @@ #include -#include +#include #include #include -RenderWidget::RenderWidget(const std::shared_ptr &core) : QWidget(nullptr) { - setAttribute(Qt::WA_NativeWindow); - setAttribute(Qt::WA_PaintOnScreen); - if (GetOSCompositorCategory() == CompositorCategory::Wayland) { - setAttribute(Qt::WA_DontCreateNativeAncestors); - } - - if (GetOSCompositorCategory() == CompositorCategory::MacOS) { - windowHandle()->setSurfaceType(QWindow::MetalSurface); - } else { - windowHandle()->setSurfaceType(QWindow::VulkanSurface); - } - +RenderWidget::RenderWidget(const std::shared_ptr &core) { if (!Vulkan::Context::init_loader(nullptr)) { Util::panic("Could not initialize Vulkan ICD"); } - qtVkInstanceFactory = std::make_shared(); - windowHandle()->setVulkanInstance(&qtVkInstanceFactory->handle); + imGuiVkInstanceFactory = std::make_shared(); + windowHandle()->setVulkanInstance(&imGuiVkInstanceFactory->handle); windowHandle()->create(); - wsiPlatform = std::make_shared(core, windowHandle()); - windowInfo = std::make_shared(windowHandle()); + wsiPlatform = std::make_shared(core, windowHandle()); + windowInfo = std::make_shared(windowHandle()); } -void QtWSIPlatform::poll_input() { +void ImGuiWSIPlatform::poll_input() { if (!canPollEvents) return; diff --git a/src/frontend/SettingsWindow.cpp b/src/frontend/SettingsWindow.cpp index 36c6ce56..e91d5000 100644 --- a/src/frontend/SettingsWindow.cpp +++ b/src/frontend/SettingsWindow.cpp @@ -3,7 +3,7 @@ std::string savePath; -SettingsWindow::SettingsWindow() : QWidget(nullptr) { +SettingsWindow::SettingsWindow() { settings = JSONOpenOrCreate("resources/settings.json"); savePath = JSONGetField(settings, "general", "savePath"); @@ -18,9 +18,9 @@ SettingsWindow::SettingsWindow() : QWidget(nullptr) { audioSettings = std::make_unique(settings); inputSettings = std::make_unique(settings); generalSettings = std::make_unique(); - keyMap = inputSettings->GetMappedKeys(); + keyMap = inputSettings.GetMappedKeys(); - folderLabel = std::make_unique(fmt::format("{}", savePath).c_str()); + savesFolder.setName(fmt::format(savesFolder.getName(), savePath)); connect(folderBtn.get(), &QPushButton::pressed, this, [&]() { savePath = QFileDialog::getExistingDirectory(this, tr("Select directory")).toStdString(); diff --git a/src/frontend/SettingsWindow.hpp b/src/frontend/SettingsWindow.hpp index 69b87152..01a0d166 100644 --- a/src/frontend/SettingsWindow.hpp +++ b/src/frontend/SettingsWindow.hpp @@ -5,6 +5,7 @@ #include class SettingsWindow final { + gui::PushButton cancel{"Cancel"}, apply{"Apply", "", false}, savesFolder{"Open", "Save path: {}"}; //std::unique_ptr cancel = std::make_unique("Cancel"); //std::unique_ptr apply = std::make_unique("Apply"); //std::unique_ptr iconProv = std::make_unique(); @@ -17,14 +18,15 @@ class SettingsWindow final { //std::unique_ptr mainLayout = std::make_unique(); //std::unique_ptr buttonsLayout = std::make_unique(); public: + bool render() {} // TODO SettingsWindow(); - [[nodiscard]] float getVolumeL() const { return static_cast(audioSettings->volumeL->value()) / 100.f; } - [[nodiscard]] float getVolumeR() const { return static_cast(audioSettings->volumeR->value()) / 100.f; } + [[nodiscard]] float getVolumeL() const { return audioSettings.volumeL.getValue() / 100.f; } + [[nodiscard]] float getVolumeR() const { return audioSettings.volumeR.getValue() / 100.f; } - //std::array keyMap{}; + std::array keyMap{}; nlohmann::json settings; - std::unique_ptr cpuSettings{}; - std::unique_ptr audioSettings{}; - std::unique_ptr inputSettings{}; + CPUSettings cpuSettings{settings}; + AudioSettings audioSettings{settings}; + InputSettings inputSettings{settings}; //std::unique_ptr generalSettings{}; }; diff --git a/src/frontend/main.cpp b/src/frontend/main.cpp index f2c433c3..2e5f6f49 100644 --- a/src/frontend/main.cpp +++ b/src/frontend/main.cpp @@ -1,17 +1,17 @@ -#include +#include #include int main(int argc, char **argv) { - const KaizenQt kaizenQt; + KaizenGui kaizenGui; cflags::cflags flags; std::string romPath; std::string moviePath; - flags.add_string_callback('\0', "rom", [&kaizenQt](std::string v) { kaizenQt.LoadROM(v); }, "Rom to launch from command-line"); - flags.add_string_callback('\0', "movie", [&kaizenQt](std::string v) { kaizenQt.LoadTAS(v); }, "Mupen Movie to replay"); + flags.add_string_callback('\0', "rom", [&kaizenGui](std::string v) { kaizenGui.LoadROM(v); }, "Rom to launch from command-line"); + flags.add_string_callback('\0', "movie", [&kaizenGui](std::string v) { kaizenGui.LoadTAS(v); }, "Mupen Movie to replay"); if(!flags.parse(argc, argv)) { return -1; } - return 0; + return kaizenGui.run(); }