From 5c5828d8264497e013e5a40d1bb0556e1a85eaff Mon Sep 17 00:00:00 2001 From: antonioginer Date: Sat, 22 Jan 2022 03:25:47 +0000 Subject: [PATCH] Correctly adjust window size based on the computed visible area for different stretching cases. (#9140) --- src/osd/sdl/window.cpp | 10 ++++++++++ src/osd/windows/window.cpp | 20 +++++++++++++++++++- src/osd/windows/window.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp index 8c60d1131e8..17e10f575dd 100644 --- a/src/osd/sdl/window.cpp +++ b/src/osd/sdl/window.cpp @@ -967,6 +967,10 @@ osd_rect sdl_window_info::constrain_to_aspect_ratio(const osd_rect &rect, int ad // compute the visible area based on the proposed rectangle target()->compute_visible_area(propwidth, propheight, pixel_aspect, target()->orientation(), viswidth, visheight); + // clamp visable area to the proposed rectangle + viswidth = std::min(viswidth, propwidth); + visheight = std::min(visheight, propheight); + // compute the adjustments we need to make adjwidth = (viswidth + extrawidth) - rect.width(); adjheight = (visheight + extraheight) - rect.height(); @@ -1015,6 +1019,12 @@ osd_dim sdl_window_info::get_min_bounds(int constrain) // get the minimum target size target()->compute_minimum_size(minwidth, minheight); + // check if visible area is bigger + int32_t viswidth, visheight; + target()->compute_visible_area(minwidth, minheight, monitor()->aspect(), target()->orientation(), viswidth, visheight); + minwidth = std::max(viswidth, minwidth); + minheight = std::max(visheight, minheight); + // expand to our minimum dimensions if (minwidth < MIN_WINDOW_DIM) minwidth = MIN_WINDOW_DIM; diff --git a/src/osd/windows/window.cpp b/src/osd/windows/window.cpp index 3153ff545cd..6627be003a8 100644 --- a/src/osd/windows/window.cpp +++ b/src/osd/windows/window.cpp @@ -305,6 +305,7 @@ win_window_info::win_window_info( , m_targetorient(0) , m_targetvismask(0) , m_targetscalemode(0) + , m_targetkeepaspect(machine.options().keep_aspect()) , m_lastclicktime(std::chrono::steady_clock::time_point::min()) , m_lastclickx(0) , m_lastclicky(0) @@ -785,13 +786,16 @@ void win_window_info::update() render_layer_config const targetlayerconfig = target()->layer_config(); u32 const targetvismask = target()->visibility_mask(); int const targetscalemode = target()->scale_mode(); - if (targetview != m_targetview || targetorient != m_targetorient || targetlayerconfig != m_targetlayerconfig || targetvismask != m_targetvismask || targetscalemode != m_targetscalemode) + bool const targetkeepaspect = target()->keepaspect(); + if (targetview != m_targetview || targetorient != m_targetorient || targetlayerconfig != m_targetlayerconfig || targetvismask != m_targetvismask || + targetscalemode != m_targetscalemode || targetkeepaspect != m_targetkeepaspect) { m_targetview = targetview; m_targetorient = targetorient; m_targetlayerconfig = targetlayerconfig; m_targetvismask = targetvismask; m_targetscalemode = targetscalemode; + m_targetkeepaspect = targetkeepaspect; // in window mode, reminimize/maximize if (!fullscreen()) @@ -1483,6 +1487,10 @@ osd_rect win_window_info::constrain_to_aspect_ratio(const osd_rect &rect, int ad // compute the visible area based on the proposed rectangle target()->compute_visible_area(propwidth, propheight, pixel_aspect, target()->orientation(), viswidth, visheight); + // clamp visable area to the proposed rectangle + viswidth = std::min(viswidth, propwidth); + visheight = std::min(visheight, propheight); + // compute the adjustments we need to make adjwidth = (viswidth + extrawidth) - rect.width(); adjheight = (visheight + extraheight) - rect.height(); @@ -1531,6 +1539,12 @@ osd_dim win_window_info::get_min_bounds(int constrain) // get the minimum target size target()->compute_minimum_size(minwidth, minheight); + // check if visible area is bigger + int32_t viswidth, visheight; + target()->compute_visible_area(minwidth, minheight, monitor()->aspect(), target()->orientation(), viswidth, visheight); + minwidth = std::max(viswidth, minwidth); + minheight = std::max(visheight, minheight); + // expand to our minimum dimensions if (minwidth < MIN_WINDOW_DIMX) minwidth = MIN_WINDOW_DIMX; @@ -1634,6 +1648,10 @@ void win_window_info::update_minmax_state() (rect_height(&bounds) == minbounds.height()); m_ismaximized = (rect_width(&bounds) == maxbounds.width()) || (rect_height(&bounds) == maxbounds.height()); + + // We can't be maximized and minimized simultaneously + if (m_ismaximized) + m_isminimized = FALSE; } else { diff --git a/src/osd/windows/window.h b/src/osd/windows/window.h index 9cae7207524..ac7ccf3277d 100644 --- a/src/osd/windows/window.h +++ b/src/osd/windows/window.h @@ -108,6 +108,7 @@ public: render_layer_config m_targetlayerconfig; u32 m_targetvismask; int m_targetscalemode; + bool m_targetkeepaspect; // input info std::chrono::steady_clock::time_point m_lastclicktime;