diff --git a/src/gui/image_slice_window.cpp b/src/gui/image_slice_window.cpp index 33def1d1..a3ab465b 100644 --- a/src/gui/image_slice_window.cpp +++ b/src/gui/image_slice_window.cpp @@ -51,6 +51,16 @@ void ImageSlice::constrain(PreferedProperty prefer) { } } +void ImageSlice::centerSelection() { + if (selection.GetWidth() < source.GetWidth()) { + selection.x = ((source.GetWidth() - selection.GetWidth()) / 2); + } + + if (selection.GetHeight() < source.GetHeight()) { + selection.y = ((source.GetHeight() - selection.GetHeight()) / 2); + } +} + Image ImageSlice::getSlice() const { if (selection.width == target_size.GetWidth() && selection.height == target_size.GetHeight() && selection.x == 0 && selection.y == 0) { // exactly the right size @@ -82,6 +92,8 @@ ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wx { // init slice slice.constrain(); + slice.centerSelection(); + // init controls const wxPoint defPos = wxDefaultPosition; const wxSize spinSize(80,-1); diff --git a/src/gui/image_slice_window.hpp b/src/gui/image_slice_window.hpp index 12c278c2..59af5eda 100644 --- a/src/gui/image_slice_window.hpp +++ b/src/gui/image_slice_window.hpp @@ -42,6 +42,8 @@ public: /// Enforce relations between values void constrain(PreferedProperty prefer = PREFER_NONE); + /// Attempt to center the current constraints + void centerSelection(); /// Get the sliced image Image getSlice() const;