From c2fea6bd96de92b0196b1a655e95b9f7d7d8d634 Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Mon, 13 Jun 2022 23:40:26 -0400 Subject: [PATCH] ui: default image slice selection to center --- src/gui/image_slice_window.cpp | 12 ++++++++++++ src/gui/image_slice_window.hpp | 2 ++ 2 files changed, 14 insertions(+) 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;