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.
This commit is contained in:
Brendan Hagan
2022-07-15 08:31:44 -04:00
parent 07c7ca464a
commit fabb6cc3f1
2 changed files with 13 additions and 7 deletions
+11 -6
View File
@@ -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()) {
+2 -1
View File
@@ -137,7 +137,8 @@ private:
// --------------------------------------------------- : Events
DECLARE_EVENT_TABLE();
wxSize getBestSliceSize() const;
wxSize DoGetBestSize() const override;
void onLeftDown(wxMouseEvent&);