small QoL

This commit is contained in:
irisz64
2025-07-01 21:21:14 +02:00
parent 4f618d35e0
commit d72cad61b1
4 changed files with 45 additions and 25 deletions

View File

@@ -34,6 +34,23 @@ void KaizenGui::QueryDevices(SDL_Event event) {
}
}
void KaizenGui::FileDialog() {
NFD::Guard guard;
NFD::UniquePath path;
static const std::vector<nfdfilteritem_t> filterItems = {
{"Nintendo 64 rom archive", "rar,RAR,tar,TAR,zip,ZIP,7z,7Z"},
{"Nintendo 64 rom", "n64,z64,v64,N64,Z64,V64"}
};
auto result = NFD::OpenDialog(path, filterItems.data(), filterItems.size());
if(result == NFD_ERROR)
Util::panic("Error: {}", NFD::GetError());
if(result != NFD_CANCEL) {
LoadROM(path.get());
}
}
void KaizenGui::HandleInput(SDL_Event event) {
n64::PIF &pif = core->cpu->GetMem().mmio.si.pif;
switch(event.type) {
@@ -90,6 +107,24 @@ void KaizenGui::HandleInput(SDL_Event event) {
break;
{
auto keys = SDL_GetKeyboardState(nullptr);
if((keys[SDL_SCANCODE_LCTRL] || keys[SDL_SCANCODE_RCTRL]) && keys[SDL_SCANCODE_O]) {
FileDialog();
}
if(core->romLoaded) {
if(keys[SDL_SCANCODE_P]) {
emuThread.TogglePause();
}
if(keys[SDL_SCANCODE_R]) {
emuThread.Reset();
}
if(keys[SDL_SCANCODE_Q]) {
emuThread.Stop();
}
}
pif.UpdateButton(0, n64::Controller::Key::Z, keys[SDL_SCANCODE_Z]);
pif.UpdateButton(0, n64::Controller::Key::CUp, keys[SDL_SCANCODE_HOME]);
pif.UpdateButton(0, n64::Controller::Key::CDown, keys[SDL_SCANCODE_END]);
@@ -115,26 +150,10 @@ void KaizenGui::HandleInput(SDL_Event event) {
void KaizenGui::RenderUI() {
gui::StartFrame();
static bool actionsEnabled = false;
if(ImGui::BeginMainMenuBar()) {
if(ImGui::BeginMenu("File")) {
if(ImGui::MenuItem("Open")) {
NFD::Guard guard;
NFD::UniquePath path;
static const std::vector<nfdfilteritem_t> filterItems = {
{"Nintendo 64 rom archive", "rar,RAR,tar,TAR,zip,ZIP,7z,7Z"},
{"Nintendo 64 rom", "n64,z64,v64,N64,Z64,V64"}
};
auto result = NFD::OpenDialog(path, filterItems.data(), filterItems.size());
if(result == NFD_ERROR)
Util::panic("Error: {}", NFD::GetError());
if(result != NFD_CANCEL) {
LoadROM(path.get());
actionsEnabled = true;
}
if(ImGui::MenuItem("Open", "Ctrl-O")) {
FileDialog();
}
if(ImGui::MenuItem("Exit")) {
quit = true;
@@ -143,19 +162,19 @@ void KaizenGui::RenderUI() {
ImGui::EndMenu();
}
if(ImGui::BeginMenu("Emulation")) {
ImGui::BeginDisabled(!actionsEnabled);
ImGui::BeginDisabled(!core->romLoaded);
if(ImGui::MenuItem(core->pause ? "Resume" : "Pause")) {
if(ImGui::MenuItem(core->pause ? "Resume" : "Pause", "P")) {
emuThread.TogglePause();
}
if(ImGui::MenuItem("Reset")) {
if(ImGui::MenuItem("Reset", "R")) {
emuThread.Reset();
}
if(ImGui::MenuItem("Stop")) {
if(ImGui::MenuItem("Stop", "Q")) {
emuThread.Stop();
actionsEnabled = false;
core->romLoaded = false;
}
ImGui::EndDisabled();
@@ -199,7 +218,7 @@ void KaizenGui::RenderUI() {
ImGui::RenderPlatformWindowsDefault();
}
if(!core->pause && core->romLoaded) {
if(core->romLoaded) {
core->parallel.UpdateScreen(*core.get());
return;
}

View File

@@ -27,6 +27,7 @@ public:
private:
bool quit = false;
std::function<void()> emuExitFunc;
void FileDialog();
void RenderUI();
void HandleInput(SDL_Event event);
void QueryDevices(SDL_Event event);

View File

@@ -8,7 +8,6 @@
std::string savePath;
bool SettingsWindow::render() {
static bool applyEnabled = false;
ImGui::OpenPopup("Settings", ImGuiPopupFlags_None);
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));

View File

@@ -8,6 +8,7 @@ class SettingsWindow final {
CPUSettings cpuSettings;
AudioSettings audioSettings;
std::string savesPath;
bool applyEnabled = false;
public:
bool render();
SettingsWindow() = default;