[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.
This commit is contained in:
parent
d2d070b52f
commit
0ca5184dda
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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<uint32_t>(min_) ||
|
||||
value > nonstd::get<uint32_t>(max_)) {
|
||||
wxLogWarning(
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
#include <wx/textctrl.h>
|
||||
#include <wx/xrc/xmlres.h>
|
||||
|
||||
#include "../../System.h"
|
||||
#include "../../common/ConfigManager.h"
|
||||
#include "config/option.h"
|
||||
#include "rpi.h"
|
||||
#include "wayland.h"
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue