Skip to content

Commit

Permalink
Screenshot: Add scaling option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Feb 25, 2025
1 parent 3d295d2 commit 581fc07
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/game_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) {
player.font1_size.FromIni(ini);
player.font2.FromIni(ini);
player.font2_size.FromIni(ini);
player.screenshot_scale.FromIni(ini);
}

void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const {
Expand Down Expand Up @@ -610,6 +611,7 @@ void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const {
player.font1_size.ToIni(os);
player.font2.ToIni(os);
player.font2_size.ToIni(os);
player.screenshot_scale.ToIni(os);

os << "\n";
}
1 change: 1 addition & 0 deletions src/game_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct Game_ConfigPlayer {
RangeConfigParam<int> font1_size { "Font 1 Size", "", "Player", "Font1Size", 12, 6, 16};
PathConfigParam font2 { "Font 2", "The game chooses whether it wants font 1 or 2", "Player", "Font2", "" };
RangeConfigParam<int> font2_size { "Font 2 Size", "", "Player", "Font2Size", 12, 6, 16};
RangeConfigParam<int> screenshot_scale { "Screenshot scaling factor", "Scale screenshots by the given factor", "Player", "ScreenshotScale", 1, 1, 24};

void Hide();
};
Expand Down
10 changes: 9 additions & 1 deletion src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,15 @@ bool Output::TakeScreenshot(StringView file) {
}

bool Output::TakeScreenshot(std::ostream& os) {
return DisplayUi->GetDisplaySurface()->WritePNG(os);
int scale = Player::player_config.screenshot_scale.Get();
if (scale > 1) {
auto& disp = DisplayUi->GetDisplaySurface();
auto scaled_disp = Bitmap::Create(disp->GetWidth() * scale, disp->GetHeight() * scale, false);
scaled_disp->ZoomOpacityBlit(0, 0, 0, 0, *disp, disp->GetRect(), scale, scale, Opacity::Opaque());
return scaled_disp->WritePNG(os);
} else {
return DisplayUi->GetDisplaySurface()->WritePNG(os);
}
}

void Output::ToggleLog() {
Expand Down
4 changes: 4 additions & 0 deletions src/window_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ void Window_Settings::RefreshEngine() {
AddOption(cfg.settings_autosave, [&cfg](){ cfg.settings_autosave.Toggle(); });
AddOption(cfg.settings_in_title, [&cfg](){ cfg.settings_in_title.Toggle(); });
AddOption(cfg.settings_in_menu, [&cfg](){ cfg.settings_in_menu.Toggle(); });
AddOption(cfg.screenshot_scale, [this, &cfg](){ cfg.screenshot_scale.Set(GetCurrentOption().current_value); });

GetFrame().options.back().help2 = fmt::format("Screenshot size: {}x{}",
Player::screen_width * cfg.screenshot_scale.Get(), Player::screen_height * cfg.screenshot_scale.Get());
}

void Window_Settings::RefreshEngineFont(bool mincho) {
Expand Down

0 comments on commit 581fc07

Please sign in to comment.