feat: initial arbitrary constrain of slice window images to 500x500

This commit is contained in:
Brendan Hagan
2022-07-03 23:48:02 -04:00
parent 2db0ad9ad4
commit 5c983275af
2 changed files with 19 additions and 10 deletions
+2 -2
View File
@@ -521,8 +521,8 @@ label:
html export options:Export options html export options:Export options
# Image slicer # Image slicer
original: Original: original: Original (%s x %s):
result: Result: result: Result (%s x %s):
size: Size size: Size
original size: &Original Size original size: &Original Size
size to fit: Size to &Fit size to fit: Size to &Fit
+17 -8
View File
@@ -13,7 +13,7 @@
#include <util/rotation.hpp> #include <util/rotation.hpp>
#include <gfx/gfx.hpp> #include <gfx/gfx.hpp>
#include <wx/spinctrl.h> #include <wx/spinctrl.h>
#include <wx/dcbuffer.h> #include <wx/dcbuffer.h>
// ----------------------------------------------------------------------------- : ImageSlice // ----------------------------------------------------------------------------- : ImageSlice
@@ -133,11 +133,11 @@ ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wx
// top row: image editors // top row: image editors
wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL); wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
wxSizer* s3 = new wxBoxSizer(wxVERTICAL); 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); s3->Add(selector, 1, wxEXPAND | wxTOP, 4);
s2->Add(s3, 1, wxEXPAND | wxALL, 4); s2->Add(s3, 1, wxEXPAND | wxALL, 4);
wxSizer* s4 = new wxBoxSizer(wxVERTICAL); 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); s4->Add(preview, 0, wxTOP, 4);
s2->Add(s4, 0, wxALL, 4); s2->Add(s4, 0, wxALL, 4);
s->Add(s2, 1, wxEXPAND); 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 // We know the client size we want, calculate the size that goes with that
wxSize ws = GetSize(), cs = GetClientSize(); wxSize ws = GetSize(), cs = GetClientSize();
// This just gets it back to 100% scale. Doesn't solve the sizing issue of the overall window. float target_ratio = ((float)slice.target_size.GetWidth()) / ((float)slice.target_size.GetHeight());
// All the above are doing appears to be finding margins/borders and accounting for them on a fixed scale. if (target_ratio > 1.0) {
return slice.target_size / 2 + ws - cs; return wxSize(500, 500 / target_ratio);
} else {
return wxSize(500 * target_ratio, 500);
}
} }
void ImageSlicePreview::onPaint(wxPaintEvent&) { void ImageSlicePreview::onPaint(wxPaintEvent&) {
@@ -474,8 +477,14 @@ ImageSliceSelector::ImageSliceSelector(Window* parent, int id, ImageSlice& slice
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_THEME) : wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_THEME)
, slice(slice) , slice(slice)
, mouse_down(false) , 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); SetBackgroundStyle(wxBG_STYLE_PAINT);
} }