From a7014b9ee4076976fc1cfa02792f95134a4aa809 Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Sun, 3 Jul 2022 22:06:31 -0400 Subject: [PATCH] fix: de-scale slice preview window This is a workaround, not a good solution. The slice doesn't really handle sizing well and doesn't set great maximum sizes on the elements within it. I _think_ that can be worked around by constraining the preview, but none of that is really properly context aware to the user's screen. --- src/gui/image_slice_window.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/gui/image_slice_window.cpp b/src/gui/image_slice_window.cpp index 9509bf8d..61a26678 100644 --- a/src/gui/image_slice_window.cpp +++ b/src/gui/image_slice_window.cpp @@ -388,8 +388,11 @@ void ImageSlicePreview::update() { wxSize ImageSlicePreview::DoGetBestSize() const { // We know the client size we want, calculate the size that goes with that - wxSize ws = GetSize(), cs = GetClientSize(); - return slice.target_size + ws - cs; + wxSize ws = GetSize(), cs = GetClientSize(); + + // This just gets it back to 100% scale. Doesn't solve the sizing issue of the overall window. + // All the above are doing appears to be finding margins/borders and accounting for them on a fixed scale. + return slice.target_size / 2 + ws - cs; } void ImageSlicePreview::onPaint(wxPaintEvent&) { @@ -413,7 +416,11 @@ void ImageSlicePreview::draw(DC& dc) { mdc.SelectObject(wxNullBitmap); } else { bitmap = Bitmap(image); - } + } + + // Rescale the bitmap based on the available size. + auto available_size = DoGetBestSize(); + bitmap = wxBitmap(bitmap.ConvertToImage().Scale(available_size.GetWidth(), available_size.GetHeight())); } if (bitmap.Ok()) { dc.DrawBitmap(bitmap, 0, 0);