From 5c983275af27cd74c4c8ddfb854deffd335d62b5 Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Sun, 3 Jul 2022 23:48:02 -0400 Subject: [PATCH] feat: initial arbitrary constrain of slice window images to 500x500 --- data/en.mse-locale/locale | 4 ++-- src/gui/image_slice_window.cpp | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/data/en.mse-locale/locale b/data/en.mse-locale/locale index cf3f8a41..adb0c127 100644 --- a/data/en.mse-locale/locale +++ b/data/en.mse-locale/locale @@ -521,8 +521,8 @@ label: html export options:Export options # Image slicer - original: Original: - result: Result: + original: Original (%s x %s): + result: Result (%s x %s): size: Size original size: &Original Size size to fit: Size to &Fit diff --git a/src/gui/image_slice_window.cpp b/src/gui/image_slice_window.cpp index 61a26678..8e4e4636 100644 --- a/src/gui/image_slice_window.cpp +++ b/src/gui/image_slice_window.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include // ----------------------------------------------------------------------------- : ImageSlice @@ -133,11 +133,11 @@ ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wx // top row: image editors wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL); wxSizer* s3 = new wxBoxSizer(wxVERTICAL); - s3->Add(new wxStaticText(this, wxID_ANY, _LABEL_("original"))); + s3->Add(new wxStaticText(this, wxID_ANY, _LABEL_2_("original", to_string(slice.source.GetWidth()), to_string(slice.source.GetHeight())))); s3->Add(selector, 1, wxEXPAND | wxTOP, 4); s2->Add(s3, 1, wxEXPAND | wxALL, 4); wxSizer* s4 = new wxBoxSizer(wxVERTICAL); - s4->Add(new wxStaticText(this, wxID_ANY, _LABEL_("result"))); + s4->Add(new wxStaticText(this, wxID_ANY, _LABEL_2_("result", to_string(slice.target_size.GetWidth()), to_string(slice.target_size.GetHeight())))); s4->Add(preview, 0, wxTOP, 4); s2->Add(s4, 0, wxALL, 4); s->Add(s2, 1, wxEXPAND); @@ -390,9 +390,12 @@ wxSize ImageSlicePreview::DoGetBestSize() const { // We know the client size we want, calculate the size that goes with that 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; + float target_ratio = ((float)slice.target_size.GetWidth()) / ((float)slice.target_size.GetHeight()); + if (target_ratio > 1.0) { + return wxSize(500, 500 / target_ratio); + } else { + return wxSize(500 * target_ratio, 500); + } } void ImageSlicePreview::onPaint(wxPaintEvent&) { @@ -474,8 +477,14 @@ ImageSliceSelector::ImageSliceSelector(Window* parent, int id, ImageSlice& slice : wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_THEME) , slice(slice) , mouse_down(false) -{ - SetMinSize(wxSize(400, 300)); +{ + + float target_ratio = ((float) slice.source.GetWidth()) / ((float) slice.source.GetHeight()); + if (target_ratio > 1.0) { + SetMinSize(wxSize(500, 500 / target_ratio)); + } else { + SetMinSize(wxSize(500 * target_ratio, 500)); + } SetBackgroundStyle(wxBG_STYLE_PAINT); }