Add blurry scaling option

This looks slightly nicer on very pixel-dense screens (scale factors 5 and up) than nearest neighbour fractional upscaling does.

Also fix window icon disappearing at times and the window being resized after configuration changes.

We should maybe start preserving window size also at some point, the way we do position now.
This commit is contained in:
Tamás Bálint Misius 2023-10-06 15:04:29 +02:00
parent 814b73a5ed
commit 7541273640
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
10 changed files with 44 additions and 9 deletions

View File

@ -293,6 +293,7 @@ int Main(int argc, char *argv[])
prefs.Get("Fullscreen", false), prefs.Get("Fullscreen", false),
prefs.Get("AltFullscreen", false), prefs.Get("AltFullscreen", false),
prefs.Get("ForceIntegerScaling", true), prefs.Get("ForceIntegerScaling", true),
prefs.Get("BlurryScaling", false),
}; };
auto graveExitsConsole = prefs.Get("GraveExitsConsole", true); auto graveExitsConsole = prefs.Get("GraveExitsConsole", true);
momentumScroll = prefs.Get("MomentumScroll", true); momentumScroll = prefs.Get("MomentumScroll", true);

View File

@ -127,11 +127,6 @@ void SDLOpen()
} }
} }
if constexpr (SET_WINDOW_ICON)
{
WindowIcon(sdl_window);
}
StopTextInput(); StopTextInput();
} }
@ -179,6 +174,7 @@ void SDLSetScreen()
// see https://github.com/jacob1/The-Powder-Toy/issues/24 // see https://github.com/jacob1/The-Powder-Toy/issues/24
newFrameOpsNorm.resizable != currentFrameOpsNorm.resizable || newFrameOpsNorm.resizable != currentFrameOpsNorm.resizable ||
newFrameOpsNorm.changeResolution != currentFrameOpsNorm.changeResolution || newFrameOpsNorm.changeResolution != currentFrameOpsNorm.changeResolution ||
newFrameOpsNorm.blurryScaling != currentFrameOpsNorm.blurryScaling ||
newVsyncHint != vsyncHint; newVsyncHint != vsyncHint;
if (!(recreate || if (!(recreate ||
@ -189,6 +185,10 @@ void SDLSetScreen()
} }
auto size = WINDOW * newFrameOpsNorm.scale; auto size = WINDOW * newFrameOpsNorm.scale;
if (sdl_window && newFrameOpsNorm.resizable)
{
SDL_GetWindowSize(sdl_window, &size.X, &size.Y);
}
if (recreate) if (recreate)
{ {
@ -229,6 +229,12 @@ void SDLSetScreen()
fprintf(stderr, "SDL_CreateWindow failed: %s\n", SDL_GetError()); fprintf(stderr, "SDL_CreateWindow failed: %s\n", SDL_GetError());
Platform::Exit(-1); Platform::Exit(-1);
} }
if constexpr (SET_WINDOW_ICON)
{
WindowIcon(sdl_window);
}
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, newFrameOpsNorm.blurryScaling ? "linear" : "nearest");
sdl_renderer = SDL_CreateRenderer(sdl_window, -1, rendererFlags); sdl_renderer = SDL_CreateRenderer(sdl_window, -1, rendererFlags);
if (!sdl_renderer) if (!sdl_renderer)
{ {
@ -250,10 +256,6 @@ void SDLSetScreen()
Platform::Exit(-1); Platform::Exit(-1);
} }
SDL_RaiseWindow(sdl_window); SDL_RaiseWindow(sdl_window);
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
//Uncomment this to enable resizing
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
//SDL_SetWindowResizable(sdl_window, SDL_TRUE);
} }
SDL_RenderSetIntegerScale(sdl_renderer, newFrameOpsNorm.forceIntegerScaling ? SDL_TRUE : SDL_FALSE); SDL_RenderSetIntegerScale(sdl_renderer, newFrameOpsNorm.forceIntegerScaling ? SDL_TRUE : SDL_FALSE);
if (!(newFrameOpsNorm.resizable && SDL_GetWindowFlags(sdl_window) & SDL_WINDOW_MAXIMIZED)) if (!(newFrameOpsNorm.resizable && SDL_GetWindowFlags(sdl_window) & SDL_WINDOW_MAXIMIZED))

View File

@ -8,6 +8,7 @@ struct WindowFrameOps
bool fullscreen = false; bool fullscreen = false;
bool changeResolution = false; bool changeResolution = false;
bool forceIntegerScaling = false; bool forceIntegerScaling = false;
bool blurryScaling = false;
WindowFrameOps Normalize() const WindowFrameOps Normalize() const
{ {
@ -17,6 +18,7 @@ struct WindowFrameOps
fullscreen , fullscreen ,
fullscreen ? changeResolution : false, fullscreen ? changeResolution : false,
fullscreen ? forceIntegerScaling : false, fullscreen ? forceIntegerScaling : false,
blurryScaling ,
}; };
} }
}; };

View File

@ -128,10 +128,12 @@ namespace ui
void SetChangeResolution (bool setChangeResolution ) { windowFrameOps.changeResolution = setChangeResolution; } void SetChangeResolution (bool setChangeResolution ) { windowFrameOps.changeResolution = setChangeResolution; }
void SetForceIntegerScaling(bool newForceIntegerScaling) { windowFrameOps.forceIntegerScaling = newForceIntegerScaling; } void SetForceIntegerScaling(bool newForceIntegerScaling) { windowFrameOps.forceIntegerScaling = newForceIntegerScaling; }
void SetResizable (bool newResizable ) { windowFrameOps.resizable = newResizable; } void SetResizable (bool newResizable ) { windowFrameOps.resizable = newResizable; }
void SetBlurryScaling (bool newBlurryScaling ) { windowFrameOps.blurryScaling = newBlurryScaling; }
int GetScale () const { return windowFrameOps.scale; } int GetScale () const { return windowFrameOps.scale; }
bool GetFullscreen () const { return windowFrameOps.fullscreen; } bool GetFullscreen () const { return windowFrameOps.fullscreen; }
bool GetChangeResolution () const { return windowFrameOps.changeResolution; } bool GetChangeResolution () const { return windowFrameOps.changeResolution; }
bool GetForceIntegerScaling() const { return windowFrameOps.forceIntegerScaling; } bool GetForceIntegerScaling() const { return windowFrameOps.forceIntegerScaling; }
bool GetResizable () const { return windowFrameOps.resizable; } bool GetResizable () const { return windowFrameOps.resizable; }
bool GetBlurryScaling () const { return windowFrameOps.blurryScaling; }
}; };
} }

View File

@ -87,6 +87,11 @@ void OptionsController::SetForceIntegerScaling(bool forceIntegerScaling)
model->SetForceIntegerScaling(forceIntegerScaling); model->SetForceIntegerScaling(forceIntegerScaling);
} }
void OptionsController::SetBlurryScaling(bool newBlurryScaling)
{
model->SetBlurryScaling(newBlurryScaling);
}
void OptionsController::SetShowAvatars(bool showAvatars) void OptionsController::SetShowAvatars(bool showAvatars)
{ {
model->SetShowAvatars(showAvatars); model->SetShowAvatars(showAvatars);

View File

@ -27,6 +27,7 @@ public:
void SetFullscreen(bool fullscreen); void SetFullscreen(bool fullscreen);
void SetChangeResolution(bool newChangeResolution); void SetChangeResolution(bool newChangeResolution);
void SetForceIntegerScaling(bool forceIntegerScaling); void SetForceIntegerScaling(bool forceIntegerScaling);
void SetBlurryScaling(bool newBlurryScaling);
void SetScale(int scale); void SetScale(int scale);
void SetGraveExitsConsole(bool graveExitsConsole); void SetGraveExitsConsole(bool graveExitsConsole);
void SetResizable(bool resizable); void SetResizable(bool resizable);

View File

@ -215,6 +215,18 @@ void OptionsModel::SetForceIntegerScaling(bool forceIntegerScaling)
notifySettingsChanged(); notifySettingsChanged();
} }
bool OptionsModel::GetBlurryScaling()
{
return ui::Engine::Ref().GetBlurryScaling();
}
void OptionsModel::SetBlurryScaling(bool newBlurryScaling)
{
ui::Engine::Ref().SetBlurryScaling(newBlurryScaling);
GlobalPrefs::Ref().Set("BlurryScaling", newBlurryScaling);
notifySettingsChanged();
}
bool OptionsModel::GetFastQuit() bool OptionsModel::GetFastQuit()
{ {
return ui::Engine::Ref().GetFastQuit(); return ui::Engine::Ref().GetFastQuit();

View File

@ -49,6 +49,8 @@ public:
void SetChangeResolution(bool newChangeResolution); void SetChangeResolution(bool newChangeResolution);
bool GetForceIntegerScaling(); bool GetForceIntegerScaling();
void SetForceIntegerScaling(bool forceIntegerScaling); void SetForceIntegerScaling(bool forceIntegerScaling);
bool GetBlurryScaling();
void SetBlurryScaling(bool newBlurryScaling);
bool GetFastQuit(); bool GetFastQuit();
void SetFastQuit(bool fastquit); void SetFastQuit(bool fastquit);
int GetDecoSpace(); int GetDecoSpace();

View File

@ -268,6 +268,9 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
c->SetForceIntegerScaling(forceIntegerScaling->GetChecked()); c->SetForceIntegerScaling(forceIntegerScaling->GetChecked());
}); });
} }
blurryScaling = addCheckbox(0, "Blurry scaling \bg- more blurry, better on very big screens", "", [this] {
c->SetBlurryScaling(blurryScaling->GetChecked());
});
addSeparator(); addSeparator();
if (ALLOW_QUIT) if (ALLOW_QUIT)
{ {
@ -448,6 +451,10 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
{ {
forceIntegerScaling->SetChecked(sender->GetForceIntegerScaling()); forceIntegerScaling->SetChecked(sender->GetForceIntegerScaling());
} }
if (blurryScaling)
{
blurryScaling->SetChecked(sender->GetBlurryScaling());
}
if (fastquit) if (fastquit)
{ {
fastquit->SetChecked(sender->GetFastQuit()); fastquit->SetChecked(sender->GetFastQuit());

View File

@ -31,6 +31,7 @@ class OptionsView: public ui::Window
ui::Checkbox *fullscreen{}; ui::Checkbox *fullscreen{};
ui::Checkbox *changeResolution{}; ui::Checkbox *changeResolution{};
ui::Checkbox *forceIntegerScaling{}; ui::Checkbox *forceIntegerScaling{};
ui::Checkbox *blurryScaling{};
ui::Checkbox *fastquit{}; ui::Checkbox *fastquit{};
ui::DropDown *decoSpace{}; ui::DropDown *decoSpace{};
ui::Checkbox *showAvatars{}; ui::Checkbox *showAvatars{};