Added integer scaling option.

Useful for getting exact upscale in combination with nearest neighbor.
Ref issue #97.
This commit is contained in:
Muzychenko Andrey 2021-11-22 09:32:17 +03:00
parent 64c3f2031b
commit 37198f1b99
4 changed files with 25 additions and 3 deletions

View File

@ -116,17 +116,27 @@ void fullscrn::window_size_changed()
ScaleX = static_cast<float>(width) / res->TableWidth;
ScaleY = static_cast<float>(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<int>(floor((width - res->TableWidth * ScaleX) / 2));
OffsetY = static_cast<int>(floor((height - res->TableHeight * ScaleY) / 2));
}
offset2X = static_cast<int>(floor(width - res->TableWidth * ScaleX));
offset2Y = static_cast<int>(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
};
}

View File

@ -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;
}

View File

@ -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

View File

@ -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();