From 37198f1b99a1e876824bb02b661af93262c549bb Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Mon, 22 Nov 2021 09:32:17 +0300 Subject: [PATCH] Added integer scaling option. Useful for getting exact upscale in combination with nearest neighbor. Ref issue #97. --- SpaceCadetPinball/fullscrn.cpp | 16 +++++++++++++--- SpaceCadetPinball/options.cpp | 6 ++++++ SpaceCadetPinball/options.h | 2 ++ SpaceCadetPinball/winmain.cpp | 4 ++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/SpaceCadetPinball/fullscrn.cpp b/SpaceCadetPinball/fullscrn.cpp index 2868776..4db62bf 100644 --- a/SpaceCadetPinball/fullscrn.cpp +++ b/SpaceCadetPinball/fullscrn.cpp @@ -116,17 +116,27 @@ void fullscrn::window_size_changed() ScaleX = static_cast(width) / res->TableWidth; ScaleY = static_cast(height) / res->TableHeight; OffsetX = OffsetY = 0; + auto offset2X = 0, offset2Y = 0; + + if (options::Options.IntegerScaling) + { + ScaleX = ScaleX < 1 ? ScaleX : std::floor(ScaleX); + ScaleY = ScaleY < 1 ? ScaleY : std::floor(ScaleY); + } if (options::Options.UniformScaling) { ScaleY = ScaleX = std::min(ScaleX, ScaleY); - OffsetX = static_cast(floor((width - res->TableWidth * ScaleX) / 2)); - OffsetY = static_cast(floor((height - res->TableHeight * ScaleY) / 2)); } + offset2X = static_cast(floor(width - res->TableWidth * ScaleX)); + offset2Y = static_cast(floor(height - res->TableHeight * ScaleY)); + OffsetX = offset2X / 2; + OffsetY = offset2Y / 2; + render::DestinationRect = SDL_Rect { OffsetX, OffsetY + menuHeight, - width - OffsetX * 2, height - OffsetY * 2 + width - offset2X, height - offset2Y }; } diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index 636d0e8..e444f49 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -101,6 +101,7 @@ void options::InitPrimary() Options.SoundChannels = std::min(MaxSoundChannels, std::max(MinSoundChannels, Options.SoundChannels)); Options.HybridSleep = get_int("HybridSleep", false); Options.Prefer3DPBGameData = get_int("Prefer 3DPB Game Data", false); + Options.IntegerScaling = get_int("Integer Scaling", false); } void options::InitSecondary() @@ -137,6 +138,7 @@ void options::uninit() set_int("Sound Channels", Options.SoundChannels); set_int("HybridSleep", Options.HybridSleep); set_int("Prefer 3DPB Game Data", Options.Prefer3DPBGameData); + set_int("Integer Scaling", Options.IntegerScaling); } @@ -260,6 +262,10 @@ void options::toggle(Menu1 uIDCheckItem) Options.Prefer3DPBGameData ^= true; winmain::Restart(); break; + case Menu1::WindowIntegerScale: + Options.IntegerScaling ^= true; + fullscrn::window_size_changed(); + break; default: break; } diff --git a/SpaceCadetPinball/options.h b/SpaceCadetPinball/options.h index fff3d15..3bb1383 100644 --- a/SpaceCadetPinball/options.h +++ b/SpaceCadetPinball/options.h @@ -26,6 +26,7 @@ enum class Menu1:int R1024x768 = 503, WindowUniformScale = 600, WindowLinearFilter = 601, + WindowIntegerScale = 602, Prefer3DPBGameData = 700, }; @@ -76,6 +77,7 @@ struct optionsStruct int SoundChannels; bool HybridSleep; bool Prefer3DPBGameData; + bool IntegerScaling; }; struct ControlRef diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index b7c7930..f96bb3c 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -466,6 +466,10 @@ void winmain::RenderUi() { options::toggle(Menu1::WindowLinearFilter); } + if (ImGui::MenuItem("Integer Scaling", nullptr, Options.IntegerScaling)) + { + options::toggle(Menu1::WindowIntegerScale); + } ImGui::DragFloat("UI Scale", &ImIO->FontGlobalScale, 0.005f, 0.8f, 5, "%.2f", ImGuiSliderFlags_AlwaysClamp); ImGui::Separator();