Commit 2df27d95 authored by twanvl's avatar twanvl

Image slicer spin boxes can now always be changed (within bounds), without being constrained back.

parent 1d8a9e6f
...@@ -23,7 +23,7 @@ ImageSlice::ImageSlice(const Image& source, const wxSize& target_size) ...@@ -23,7 +23,7 @@ ImageSlice::ImageSlice(const Image& source, const wxSize& target_size)
, sharpen(true), sharpen_amount(25) , sharpen(true), sharpen_amount(25)
{} {}
void ImageSlice::constrain() { void ImageSlice::constrain(PreferedProperty prefer) {
sharpen_amount = min(100, max(0, sharpen_amount)); sharpen_amount = min(100, max(0, sharpen_amount));
// minimum size // minimum size
selection.width = max(1, selection.width); selection.width = max(1, selection.width);
...@@ -40,7 +40,7 @@ void ImageSlice::constrain() { ...@@ -40,7 +40,7 @@ void ImageSlice::constrain() {
// fix aspect ratio // fix aspect ratio
if (aspect_fixed) { if (aspect_fixed) {
int diff = selection.width * target_size.GetHeight() - selection.height * target_size.GetWidth(); int diff = selection.width * target_size.GetHeight() - selection.height * target_size.GetWidth();
if (diff > 0) { if ((diff > 0 && prefer != PREFER_WIDTH) || prefer == PREFER_HEIGHT) {
// too wide // too wide
selection.width -= int(diff / target_size.GetHeight()); selection.width -= int(diff / target_size.GetHeight());
} else { } else {
...@@ -217,11 +217,11 @@ void ImageSliceWindow::onChangeTop(wxCommandEvent&) { ...@@ -217,11 +217,11 @@ void ImageSliceWindow::onChangeTop(wxCommandEvent&) {
} }
void ImageSliceWindow::onChangeWidth(wxCommandEvent&) { void ImageSliceWindow::onChangeWidth(wxCommandEvent&) {
slice.selection.width = width->GetValue(); slice.selection.width = width->GetValue();
onUpdateFromControl(); onUpdateFromControl(PREFER_WIDTH);
} }
void ImageSliceWindow::onChangeHeight(wxCommandEvent&) { void ImageSliceWindow::onChangeHeight(wxCommandEvent&) {
slice.selection.height = height->GetValue(); slice.selection.height = height->GetValue();
onUpdateFromControl(); onUpdateFromControl(PREFER_HEIGHT);
} }
void ImageSliceWindow::onChangeFixAspect(wxCommandEvent&) { void ImageSliceWindow::onChangeFixAspect(wxCommandEvent&) {
...@@ -239,7 +239,7 @@ void ImageSliceWindow::onChangeZoomX(wxSpinEvent&) { ...@@ -239,7 +239,7 @@ void ImageSliceWindow::onChangeZoomX(wxSpinEvent&) {
onUpdateFromControl(); onUpdateFromControl();
} }
void ImageSliceWindow::onChangeZoomY(wxSpinEvent&) { void ImageSliceWindow::onChangeZoomY(wxSpinEvent&) {
slice.zoomY(zoom_x->GetValue() / 100.0); slice.zoomY(zoom_y->GetValue() / 100.0);
onUpdateFromControl(); onUpdateFromControl();
} }
...@@ -261,8 +261,8 @@ void ImageSliceWindow::onSliceChange(wxCommandEvent&) { ...@@ -261,8 +261,8 @@ void ImageSliceWindow::onSliceChange(wxCommandEvent&) {
updateControls(); updateControls();
} }
void ImageSliceWindow::onUpdateFromControl() { void ImageSliceWindow::onUpdateFromControl(PreferedProperty prefer) {
slice.constrain(); slice.constrain(prefer);
preview->update(); preview->update();
selector->update(); selector->update();
updateControls(); updateControls();
......
...@@ -19,6 +19,13 @@ DECLARE_POINTER_TYPE(AlphaMask); ...@@ -19,6 +19,13 @@ DECLARE_POINTER_TYPE(AlphaMask);
// ----------------------------------------------------------------------------- : ImageSlice // ----------------------------------------------------------------------------- : ImageSlice
/// Which option is just changed, and therefore more important?
enum PreferedProperty
{ PREFER_NONE
, PREFER_WIDTH
, PREFER_HEIGHT
};
/// A slice of an image, i.e. a selected rectangle /// A slice of an image, i.e. a selected rectangle
class ImageSlice { class ImageSlice {
public: public:
...@@ -35,7 +42,7 @@ class ImageSlice { ...@@ -35,7 +42,7 @@ class ImageSlice {
int sharpen_amount; int sharpen_amount;
/// Enforce relations between values /// Enforce relations between values
void constrain(); void constrain(PreferedProperty prefer = PREFER_NONE);
/// Get the sliced image /// Get the sliced image
Image getSlice() const; Image getSlice() const;
...@@ -97,7 +104,7 @@ class ImageSliceWindow : public wxDialog { ...@@ -97,7 +104,7 @@ class ImageSliceWindow : public wxDialog {
// --------------------------------------------------- : Updating // --------------------------------------------------- : Updating
// The manual controls were changed // The manual controls were changed
void onUpdateFromControl(); void onUpdateFromControl(PreferedProperty prefer = PREFER_NONE);
// Update the values in the controls // Update the values in the controls
void updateControls(); void updateControls();
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment