From fabb6cc3f13562d4c2b5ace34d6b1a2aa43ffd93 Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Fri, 15 Jul 2022 08:31:44 -0400 Subject: [PATCH] fix: correct computed sizes on slice window to properly display margins The display size of the Output image was being computed using the available element size, which included margins and was leading to the bottom couple pixels being clipped. Correcting that to properly account for the actual image size. --- src/gui/image_slice_window.cpp | 17 +++++++++++------ src/gui/image_slice_window.hpp | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/gui/image_slice_window.cpp b/src/gui/image_slice_window.cpp index 1d4e4353..2b3bb166 100644 --- a/src/gui/image_slice_window.cpp +++ b/src/gui/image_slice_window.cpp @@ -421,12 +421,9 @@ ImageSlicePreview::ImageSlicePreview(Window* parent, int id, ImageSlice& slice, void ImageSlicePreview::update() { bitmap = wxNullBitmap; Refresh(false); -} - -wxSize ImageSlicePreview::DoGetBestSize() const { - // We know the client size we want, calculate the size that goes with that - wxSize ws = GetSize(), cs = GetClientSize(); +} +wxSize ImageSlicePreview::getBestSliceSize() const { float target_ratio = ((float)slice.target_size.GetWidth()) / ((float)slice.target_size.GetHeight()); if (target_ratio > 1.0) { return wxSize(500, 500 / target_ratio); @@ -435,6 +432,14 @@ wxSize ImageSlicePreview::DoGetBestSize() const { } } +wxSize ImageSlicePreview::DoGetBestSize() const { + // We know the client size we want, calculate the size that goes with that + // This helps with applying margins and other spacing necessities. + wxSize ws = GetSize(), cs = GetClientSize(); + + return getBestSliceSize() + ws - cs; +} + void ImageSlicePreview::onPaint(wxPaintEvent&) { wxPaintDC dc(this); draw(dc); @@ -459,7 +464,7 @@ void ImageSlicePreview::draw(DC& dc) { } // Rescale the bitmap based on the available size. - auto available_size = DoGetBestSize(); + auto available_size = getBestSliceSize(); bitmap = wxBitmap(bitmap.ConvertToImage().Scale(available_size.GetWidth(), available_size.GetHeight())); } if (bitmap.Ok()) { diff --git a/src/gui/image_slice_window.hpp b/src/gui/image_slice_window.hpp index 2a8dcf1b..4b26fb28 100644 --- a/src/gui/image_slice_window.hpp +++ b/src/gui/image_slice_window.hpp @@ -137,7 +137,8 @@ private: // --------------------------------------------------- : Events DECLARE_EVENT_TABLE(); - + + wxSize getBestSliceSize() const; wxSize DoGetBestSize() const override; void onLeftDown(wxMouseEvent&);