From bf2452aab916c034bc80fc76d6836b0163a67a52 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Tue, 24 Oct 2023 12:49:34 -0700 Subject: [PATCH] Resize GameArea after MainFrame initialization The GameArea was setting incorrect minimum size during initialization due to the MainFrame not being entirely loaded, this caused the MainFrame to not be resized properly on initialization. Resetting the MainFrame minimum size after everything has been loaded fixes the issue. This also changes MainFrame to ignore events sent before initialization is complete, which should speed up startup a bit. Fixes #1186 --- src/wx/guiinit.cpp | 7 +++++++ src/wx/wxvbam.cpp | 6 ++++++ src/wx/wxvbam.h | 3 +++ 3 files changed, 16 insertions(+) diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index 8667b197..80efaa42 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -2813,5 +2813,12 @@ bool MainFrame::BindControls() panel->SetFrameTitle(); // All OK; activate idle loop panel->SetExtraStyle(panel->GetExtraStyle() | wxWS_EX_PROCESS_IDLE); + + // Re-adjust size now to nudge some sense into Widgets. + panel->AdjustSize(false); + + // Frame initialization is complete. + init_complete_ = true; + return true; } diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 59a3b801..08ca7c3e 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -930,6 +930,9 @@ void MainFrame::OnMenu(wxContextMenuEvent& event) } void MainFrame::OnMove(wxMoveEvent&) { + if (!init_complete_) { + return; + } if (!IsFullScreen() && !IsMaximized()) { const wxPoint window_pos = GetScreenPosition(); OPTION(kGeomWindowX) = window_pos.x; @@ -954,6 +957,9 @@ void MainFrame::OnMoveEnd(wxMoveEvent&) { void MainFrame::OnSize(wxSizeEvent& event) { wxFrame::OnSize(event); + if (!init_complete_) { + return; + } const wxRect window_rect = GetRect(); const wxPoint window_pos = GetScreenPosition(); diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index 85ec2a05..0bf30d47 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -356,6 +356,9 @@ private: JoystickPoller* jpoll = nullptr; // quicker & more accurate than FindFocus() != NULL bool focused; + // One-time toggle to indicate that this object is fully initialized. This + // used to filter events that are sent during initialization. + bool init_complete_ = false; #ifndef NO_LINK const config::OptionsObserver gba_link_observer_; #endif