From 0ca5184dda5c3b582cbce7d01d1dfbfce2adb044 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Sat, 22 Oct 2022 19:47:43 -0700 Subject: [PATCH] [option] Convert all uses of geometry options to use config::Option Moving and resizing the window no longer updates the entire option set, reducing jank on move and resize. --- src/common/ConfigManager.cpp | 4 +- src/common/ConfigManager.h | 4 +- src/wx/cmdevents.cpp | 61 ++++++++++++--------- src/wx/config/option.cpp | 2 +- src/wx/dialogs/display-config.cpp | 2 - src/wx/panel.cpp | 3 +- src/wx/wxvbam.cpp | 91 ++++++++++++++----------------- src/wx/wxvbam.h | 7 +-- 8 files changed, 86 insertions(+), 88 deletions(-) diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index bb541a71..4b6c7b26 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -247,8 +247,8 @@ int vsync; int wasPaused = 0; uint32_t windowHeight; int windowMaximized; -int windowPositionX, bkpPosX = 0; -int windowPositionY, bkpPosY = 0; +int windowPositionX = 0; +int windowPositionY = 0; uint32_t windowWidth; int winGbBorderOn; int winGbPrinterEnabled; diff --git a/src/common/ConfigManager.h b/src/common/ConfigManager.h index 16772d3e..54ee25b5 100644 --- a/src/common/ConfigManager.h +++ b/src/common/ConfigManager.h @@ -137,8 +137,8 @@ extern int vsync; extern int wasPaused; extern uint32_t windowHeight; extern int windowMaximized; -extern int windowPositionX, bkpPosX; -extern int windowPositionY, bkpPosY; +extern int windowPositionX; +extern int windowPositionY; extern uint32_t windowWidth; extern int winGbBorderOn; extern int winGbPrinterEnabled; diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index c0ceac7e..5211683e 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -46,6 +46,32 @@ void MainFrame::GetMenuOptionBool(const wxString& menuName, bool* field) } } +void MainFrame::GetMenuOptionConfig(const wxString& menu_name, + const config::OptionID& option_id) { + config::Option* option = config::Option::ByID(option_id); + assert(option); + + int id = wxXmlResource::GetXRCID(menu_name); + for (size_t i = 0; i < checkable_mi.size(); i++) { + if (checkable_mi[i].cmd != id) + continue; + + const bool is_checked = checkable_mi[i].mi->IsChecked(); + switch (option->type()) { + case config::Option::Type::kBool: + option->SetBool(is_checked); + break; + case config::Option::Type::kInt: + option->SetInt(is_checked); + break; + default: + assert(false); + return; + } + break; + } +} + void MainFrame::GetMenuOptionInt(const wxString& menuName, int* field, int mask) { assert(field); @@ -2714,36 +2740,22 @@ EVT_HANDLER(GameBoyAdvanceConfigure, "Game Boy Advance options...") EVT_HANDLER_MASK(DisplayConfigure, "Display options...", CMDEN_NREC_ANY) { - bool fs = fullScreen; - wxVideoMode dm = gopts.fs_mode; - if (gopts.max_threads != 1) { gopts.max_threads = wxThread::GetCPUCount(); } - //Just in case GetCPUCount() returns 0 - if (!gopts.max_threads) + // Just in case GetCPUCount() returns 0 or -1 + if (gopts.max_threads < 0) { gopts.max_threads = 1; - - wxDialog* dlg = GetXRCDialog("DisplayConfig"); - - if (ShowModal(dlg) != wxID_OK) - return; - - if (frameSkip >= 0) - systemFrameSkip = frameSkip; - - if (fs != fullScreen) { - panel->ShowFullScreen(fullScreen); - } else if (panel->IsFullScreen() && dm != gopts.fs_mode) { - // maybe not the best way to do this.. - panel->ShowFullScreen(false); - panel->ShowFullScreen(true); } - if (panel->panel) { - panel->panel->Destroy(); - panel->panel = nullptr; + wxDialog* dlg = GetXRCDialog("DisplayConfig"); + if (ShowModal(dlg) != wxID_OK) { + return; + } + + if (frameSkip >= 0) { + systemFrameSkip = frameSkip; } update_opts(); @@ -3125,8 +3137,7 @@ EVT_HANDLER(FrameSkipAuto, "Auto Skip frames.") EVT_HANDLER(Fullscreen, "Enter fullscreen mode at startup") { - GetMenuOptionInt("Fullscreen", &fullScreen, 1); - update_opts(); + GetMenuOptionConfig("Fullscreen", config::OptionID::kgeometryfullScreen); } EVT_HANDLER(PauseWhenInactive, "Pause game when main window loses focus") diff --git a/src/wx/config/option.cpp b/src/wx/config/option.cpp index 5e29e803..9ddef459 100644 --- a/src/wx/config/option.cpp +++ b/src/wx/config/option.cpp @@ -359,7 +359,7 @@ bool Option::SetInt(int32_t value) { bool Option::SetUnsigned(uint32_t value) { assert(is_unsigned()); - uint32_t old_value = value; + uint32_t old_value = GetUnsigned(); if (value < nonstd::get(min_) || value > nonstd::get(max_)) { wxLogWarning( diff --git a/src/wx/dialogs/display-config.cpp b/src/wx/dialogs/display-config.cpp index c3723c7f..f63bf14b 100644 --- a/src/wx/dialogs/display-config.cpp +++ b/src/wx/dialogs/display-config.cpp @@ -13,8 +13,6 @@ #include #include -#include "../../System.h" -#include "../../common/ConfigManager.h" #include "config/option.h" #include "rpi.h" #include "wayland.h" diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index 73551e5a..727f21be 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -391,8 +391,9 @@ void GameArea::LoadGame(const wxString& name) emusys = &GBASystem; } - if (fullScreen) + if (config::Option::ByID(config::OptionID::kgeometryfullScreen)->GetInt()) { GameArea::ShowFullScreen(true); + } loaded = t; SetFrameTitle(); diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 947da6de..fd1631ee 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -471,13 +471,17 @@ bool wxvbamApp::OnInit() { config::GameControlState::Instance().OnGameBindingsChanged(); // create the main window - int x = windowPositionX; - int y = windowPositionY; - int width = windowWidth; - int height = windowHeight; - int isFullscreen = fullScreen; - int isMaximized = windowMaximized; - frame = wxDynamicCast(xr->LoadFrame(NULL, wxT("MainFrame")), MainFrame); + int x = config::Option::ByID(config::OptionID::kgeometrywindowX)->GetInt(); + int y = config::Option::ByID(config::OptionID::kgeometrywindowY)->GetInt(); + int width = config::Option::ByID(config::OptionID::kgeometrywindowWidth) + ->GetUnsigned(); + int height = config::Option::ByID(config::OptionID::kgeometrywindowHeight) + ->GetUnsigned(); + bool isFullscreen = + config::Option::ByID(config::OptionID::kgeometryfullScreen)->GetInt(); + bool isMaximized = + config::Option::ByID(config::OptionID::kgeometryisMaximized)->GetInt(); + frame = wxDynamicCast(xr->LoadFrame(nullptr, "MainFrame"), MainFrame); if (!frame) { wxLogError(_("Could not create main window")); @@ -835,59 +839,46 @@ void MainFrame::OnMenu(wxContextMenuEvent& event) } } -void MainFrame::OnMove(wxMoveEvent& event) -{ - (void)event; // unused params - wxPoint pos = GetScreenPosition(); - int x = pos.x, y = pos.y; - if (!IsFullScreen() && !IsMaximized()) - { - if (x >= 0 && y >= 0) - { - bkpPosX = windowPositionX; - bkpPosY = windowPositionY; - windowPositionX = x; - windowPositionY = y; +void MainFrame::OnMove(wxMoveEvent&) { + wxPoint window_pos = GetScreenPosition(); + + if (!IsFullScreen() && !IsMaximized()) { + if (window_pos.x >= 0 && window_pos.y >= 0) { + config::Option::ByID(config::OptionID::kgeometrywindowX) + ->SetInt(window_pos.x); + config::Option::ByID(config::OptionID::kgeometrywindowY) + ->SetInt(window_pos.y); } } - else - { - windowPositionX = bkpPosX; - windowPositionY = bkpPosY; - } - update_opts(); } void MainFrame::OnSize(wxSizeEvent& event) { wxFrame::OnSize(event); - wxRect pos = GetRect(); - wxPoint windowPos = GetScreenPosition(); - int height = pos.GetHeight(), width = pos.GetWidth(); - int x = windowPos.x, y = windowPos.y; - bool isFullscreen = IsFullScreen(); - bool isMaximized = IsMaximized(); - if (!isFullscreen && !isMaximized) - { - if (height > 0 && width > 0) - { - windowHeight = height; - windowWidth = width; + wxRect window_rect = GetRect(); + wxPoint window_pos = GetScreenPosition(); + config::Option* window_x = + config::Option::ByID(config::OptionID::kgeometrywindowX); + config::Option* window_y = + config::Option::ByID(config::OptionID::kgeometrywindowY); + + if (!IsFullScreen() && !IsMaximized()) { + if (window_rect.GetHeight() > 0 && window_rect.GetWidth() > 0) { + config::Option::ByID(config::OptionID::kgeometrywindowHeight) + ->SetUnsigned(window_rect.GetHeight()); + config::Option::ByID(config::OptionID::kgeometrywindowWidth) + ->SetUnsigned(window_rect.GetWidth()); } - if (x >= 0 && y >= 0) - { - windowPositionX = x; - windowPositionY = y; + if (window_pos.x >= 0 && window_pos.y >= 0) { + window_x->SetInt(window_pos.x); + window_y->SetInt(window_pos.y); } } - else - { - windowPositionX = bkpPosX; - windowPositionY = bkpPosY; - } - windowMaximized = isMaximized; - fullScreen = isFullscreen; - update_opts(); + + config::Option::ByID(config::OptionID::kgeometryisMaximized) + ->SetInt(IsMaximized()); + config::Option::ByID(config::OptionID::kgeometryfullScreen) + ->SetInt(IsFullScreen()); } int MainFrame::FilterEvent(wxEvent& event) diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index 70c0a5d1..77318fb2 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -19,11 +19,6 @@ #include "wx/wxmisc.h" #include "wxhead.h" -/* yeah, they aren't needed globally, but I'm too lazy to limit where needed */ -#include "../common/ConfigManager.h" - -#include "../System.h" -#include "../Util.h" #include "../gb/gb.h" #include "../gb/gbCheats.h" #include "../gb/gbGlobals.h" @@ -223,6 +218,8 @@ public: void MenuOptionIntMask(const wxString& menuName, int field, int mask); void MenuOptionIntRadioValue(const wxString& menuName, int field, int mask); void MenuOptionBool(const wxString& menuName, bool field); + void GetMenuOptionConfig(const wxString& menu_name, + const config::OptionID& option_id); void GetMenuOptionInt(const wxString& menuName, int* field, int mask); void GetMenuOptionBool(const wxString& menuName, bool* field); void SetMenuOption(const wxString& menuName, int value);