From 5789492021958ede4486decddd7f45e5d00c61b7 Mon Sep 17 00:00:00 2001 From: MaikelChan Date: Sun, 24 Oct 2021 17:38:23 +0200 Subject: [PATCH] Adjusted screen coordinates so menu doesn't overlap (#66) * Optimized final blit to the screen render target. When bumping the table, instead of offseting the table pixels by CPU, just memcpy all the pixels to vScreenTex once, and then render two separate quads from that texture: one for the board and the other for the sidebar. Then change the coordinates of the board quad when bumping. * Main menu bar doesn't cover game area * Forgot to also take into account changing UI scale. --- SpaceCadetPinball/fullscrn.cpp | 4 +++- SpaceCadetPinball/options.cpp | 1 + SpaceCadetPinball/winmain.cpp | 9 +++++++++ SpaceCadetPinball/winmain.h | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/SpaceCadetPinball/fullscrn.cpp b/SpaceCadetPinball/fullscrn.cpp index 7b4be33..2868776 100644 --- a/SpaceCadetPinball/fullscrn.cpp +++ b/SpaceCadetPinball/fullscrn.cpp @@ -110,6 +110,8 @@ void fullscrn::window_size_changed() { int width, height; SDL_GetRendererOutputSize(winmain::Renderer, &width, &height); + int menuHeight = options::Options.ShowMenu ? winmain::MainMenuHeight : 0; + height -= menuHeight; auto res = &resolution_array[resolution]; ScaleX = static_cast(width) / res->TableWidth; ScaleY = static_cast(height) / res->TableHeight; @@ -124,7 +126,7 @@ void fullscrn::window_size_changed() render::DestinationRect = SDL_Rect { - OffsetX, OffsetY, + OffsetX, OffsetY + menuHeight, width - OffsetX * 2, height - OffsetY * 2 }; } diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index 00d2ab7..5dd9d5d 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -204,6 +204,7 @@ void options::toggle(Menu1 uIDCheckItem) return; case Menu1::Show_Menu: Options.ShowMenu = Options.ShowMenu == 0; + fullscrn::window_size_changed(); return; case Menu1::Full_Screen: Options.FullScreen ^= true; diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 83dfc66..8c27c7d 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -37,6 +37,7 @@ bool winmain::LaunchBallEnabled = true; bool winmain::HighScoresEnabled = true; bool winmain::DemoActive = false; char* winmain::BasePath; +int winmain::MainMenuHeight = 0; std::string winmain::FpsDetails; double winmain::UpdateToFrameRatio; winmain::DurationMs winmain::TargetFrameTime; @@ -341,6 +342,14 @@ void winmain::RenderUi() if (ImGui::BeginMainMenuBar()) { + int currentMenuHeight = static_cast(ImGui::GetWindowSize().y); + if (MainMenuHeight != currentMenuHeight) + { + // Get the height of the main menu bar and update screen coordinates + MainMenuHeight = currentMenuHeight; + fullscrn::window_size_changed(); + } + if (ImGui::BeginMenu("Game")) { if (ImGui::MenuItem("New Game", "F2")) diff --git a/SpaceCadetPinball/winmain.h b/SpaceCadetPinball/winmain.h index b83369c..eb32410 100644 --- a/SpaceCadetPinball/winmain.h +++ b/SpaceCadetPinball/winmain.h @@ -49,6 +49,7 @@ public: static bool HighScoresEnabled; static bool DemoActive; static char* BasePath; + static int MainMenuHeight; static int WinMain(LPCSTR lpCmdLine); static int event_handler(const SDL_Event* event);