Skip to content

Commit

Permalink
fit mode & desktop percent cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnovak committed Nov 17, 2023
1 parent 71c64ae commit 02d133e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
12 changes: 6 additions & 6 deletions include/sdlmain.h
Expand Up @@ -96,15 +96,15 @@ struct ViewportSettings {
// Either parameter can be set in Fit mode (but not both at the
// same time), or none
struct {
std::optional<DosBox::Rect> limit_rectangle = {};
std::optional<float> desktop_percent = {};
std::optional<DosBox::Rect> limit_size = {};
std::optional<float> desktop_scale = {};
} fit = {};

// At least 'height_percent' must be set in Overflow mode, or
// both 'width_percent' and 'height_percent'
// At least 'height_scale' must be set in Overflow mode, or
// both 'width_scale' and 'height_scale'
struct {
float height_percent = {};
std::optional<float> width_percent = {};
float height_scale = {};
std::optional<float> width_scale = {};
} overflow = {};
};

Expand Down
25 changes: 16 additions & 9 deletions src/gui/sdlmain.cpp
Expand Up @@ -1466,16 +1466,20 @@ static DosBox::Rect calc_restricted_viewport_size_in_pixels(const DosBox::Rect&
switch (sdl.viewport.mode) {
case ViewportMode::Fit: {
auto viewport_px = [&] {
if (sdl.viewport.fit.limit_rectangle) {
return sdl.viewport.fit.limit_rectangle->Copy().ScaleSize(
if (sdl.viewport.fit.limit_size) {
return sdl.viewport.fit.limit_size->Copy().ScaleSize(
sdl.desktop.dpi_scale);

} else if (sdl.viewport.fit.desktop_percent) {
} else if (sdl.viewport.fit.desktop_scale) {
auto desktop_px = to_rect(get_desktop_size())
.ScaleSize(sdl.desktop.dpi_scale);

LOG_TRACE("desktop_px: %fx%f",
desktop_px.w,
desktop_px.h);

return desktop_px.ScaleSize(
*sdl.viewport.fit.desktop_percent);
*sdl.viewport.fit.desktop_scale);

} else {
// The viewport equals the canvas size in
Expand All @@ -1484,6 +1488,9 @@ static DosBox::Rect calc_restricted_viewport_size_in_pixels(const DosBox::Rect&
}
}();

LOG_TRACE("viewport_px: %fx%f", viewport_px.w, viewport_px.h);
LOG_TRACE("canvas_px: %fx%f", canvas_px.w, canvas_px.h);

if (canvas_px.Contains(viewport_px)) {
return viewport_px;
} else {
Expand Down Expand Up @@ -3019,20 +3026,20 @@ static ViewportSettings parse_viewport_settings(const std::string& viewport_reso
}

if (p > 0.0f) {
viewport.fit.desktop_percent = p;
viewport.fit.desktop_scale = p / 100.0f;

const auto limit_w = iround(desktop.w * static_cast<double>(p) / 100.0);
const auto limit_h = iround(desktop.h * static_cast<double>(p) / 100.0);
const auto limit_w = iround(desktop.w * *viewport.fit.desktop_scale);
const auto limit_h = iround(desktop.h * *viewport.fit.desktop_scale);

LOG_MSG("DISPLAY: Limiting viewport resolution to %2.4g%% (%dx%d) of the desktop",
LOG_MSG("DISPLAY: Limiting viewport resolution to %2.4g%% of the desktop (%dx%d)",
static_cast<double>(p),
limit_w,
limit_h);

return viewport;

} else {
viewport.fit.limit_rectangle = {w, h};
viewport.fit.limit_size = {w, h};

LOG_MSG("DISPLAY: Limiting viewport resolution to %dx%d", w, h);

Expand Down

0 comments on commit 02d133e

Please sign in to comment.