diff --git a/data/en.mse-locale/locale b/data/en.mse-locale/locale index dae38dc1..66a4a552 100644 --- a/data/en.mse-locale/locale +++ b/data/en.mse-locale/locale @@ -540,7 +540,10 @@ label: selection top: &Top selection width: &Width selection height: &Height - selection center: Recenter + selection center: Center + selection center vertically: Center Vertically + selection center horizontally: Center Horizontally + selection center both: Center Both #zoom: Zoom fix aspect ratio: Fix aspect ratio (width/height) zoom amount: Zoom diff --git a/resource/shape_align_both.png b/resource/shape_align_both.png new file mode 100644 index 00000000..fe874086 Binary files /dev/null and b/resource/shape_align_both.png differ diff --git a/resource/shape_align_center.png b/resource/shape_align_center.png new file mode 100644 index 00000000..efe9a98e Binary files /dev/null and b/resource/shape_align_center.png differ diff --git a/resource/shape_align_middle.png b/resource/shape_align_middle.png new file mode 100644 index 00000000..d350dd88 Binary files /dev/null and b/resource/shape_align_middle.png differ diff --git a/resource/win32_res.rc b/resource/win32_res.rc index ba78d16c..6b5d2d66 100644 --- a/resource/win32_res.rc +++ b/resource/win32_res.rc @@ -187,6 +187,10 @@ message_information IMAGE "message_information.png" message_warning IMAGE "message_warning.png" message_error IMAGE "message_error.png" +shape_align_middle IMAGE "shape_align_middle.png" +shape_align_center IMAGE "shape_align_center.png" +shape_align_both IMAGE "shape_align_both.png" + // -------------------------------------------------------- : WX //wxBITMAP_STD_COLOURS BITMAP "wx/msw/colours.bmp" diff --git a/src/gui/image_slice_window.cpp b/src/gui/image_slice_window.cpp index ad0df406..1d4e4353 100644 --- a/src/gui/image_slice_window.cpp +++ b/src/gui/image_slice_window.cpp @@ -51,14 +51,21 @@ 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); - } +void ImageSlice::centerSelection() { + centerSelectionHorizontally(); + centerSelectionVertically(); +} + +void ImageSlice::centerSelectionHorizontally() { + if (selection.GetWidth() < source.GetWidth()) { + selection.x = ((source.GetWidth() - selection.GetWidth()) / 2); + } +} + +void ImageSlice::centerSelectionVertically() { + if (selection.GetHeight() < source.GetHeight()) { + selection.y = ((source.GetHeight() - selection.GetHeight()) / 2); + } } Image ImageSlice::getSlice(double scale) const { @@ -157,7 +164,23 @@ ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wx s7->Add(width, 0, wxEXPAND); s7->Add(new wxStaticText(this, wxID_ANY, _LABEL_("selection height")), 0, wxALIGN_CENTER_VERTICAL); s7->Add(height, 0, wxEXPAND); - s7->Add(new wxButton(this, ID_SELECTION_CENTER, _LABEL_("selection center")), 0, wxALIGN_CENTER, 2); + + s7->Add(new wxStaticText(this, wxID_ANY, _LABEL_("selection center")), 0, wxALIGN_CENTER_VERTICAL); + wxBoxSizer* s7A = new wxBoxSizer(wxHORIZONTAL); + wxBitmapButton* center_vertically_button = new wxBitmapButton(this, ID_SELECTION_CENTER_VERTICALLY, wxBitmap(load_resource_image(_("shape_align_middle")))); + center_vertically_button->SetToolTip(_LABEL_("selection center vertically")); + s7A->Add(center_vertically_button); + s7A->AddStretchSpacer(); + + wxBitmapButton* center_horizontally_button = new wxBitmapButton(this, ID_SELECTION_CENTER_HORIZONTALLY, wxBitmap(load_resource_image(_("shape_align_center")))); + center_horizontally_button->SetToolTip(_LABEL_("selection center horizontally")); + s7A->Add(center_horizontally_button); + s7A->AddStretchSpacer(); + + wxBitmapButton* center_button = new wxBitmapButton(this, ID_SELECTION_CENTER, wxBitmap(load_resource_image(_("shape_align_both")))); + center_button->SetToolTip(_LABEL_("selection center both")); + s7A->Add(center_button); + s7->Add(s7A, 1, wxEXPAND, 0); s6->Add(s7, 1, wxEXPAND | wxALL, 4); s5->Add(s6, 0, wxEXPAND | wxALL, 4); s5->AddStretchSpacer(1); @@ -299,11 +322,22 @@ void ImageSliceWindow::onUpdateFromControl(PreferedProperty prefer) { updateControls(); } -void ImageSliceWindow::onSelectionCenter(wxCommandEvent&) { - slice.centerSelection(); - preview->update(); - selector->update(); - updateControls(); +void ImageSliceWindow::onSelectionCenter(wxCommandEvent& ev) { + switch (ev.GetId()) { + case ID_SELECTION_CENTER: + slice.centerSelection(); + break; + case ID_SELECTION_CENTER_HORIZONTALLY: + slice.centerSelectionHorizontally(); + break; + case ID_SELECTION_CENTER_VERTICALLY: + slice.centerSelectionVertically(); + break; + } + + preview->update(); + selector->update(); + updateControls(); } void ImageSliceWindow::updateControls() { @@ -356,7 +390,9 @@ BEGIN_EVENT_TABLE(ImageSliceWindow, wxDialog) EVT_TEXT (ID_TOP, ImageSliceWindow::onChangeTop) EVT_TEXT (ID_WIDTH, ImageSliceWindow::onChangeWidth) EVT_TEXT (ID_HEIGHT, ImageSliceWindow::onChangeHeight) - EVT_BUTTON (ID_SELECTION_CENTER, ImageSliceWindow::onSelectionCenter) + EVT_BUTTON (ID_SELECTION_CENTER, ImageSliceWindow::onSelectionCenter) + EVT_BUTTON(ID_SELECTION_CENTER_HORIZONTALLY, ImageSliceWindow::onSelectionCenter) + EVT_BUTTON(ID_SELECTION_CENTER_VERTICALLY, ImageSliceWindow::onSelectionCenter) EVT_CHECKBOX (ID_FIX_ASPECT, ImageSliceWindow::onChangeFixAspect) EVT_SPINCTRL (ID_ZOOM, ImageSliceWindow::onChangeZoom) EVT_SPINCTRL (ID_ZOOM_X, ImageSliceWindow::onChangeZoomX) diff --git a/src/gui/image_slice_window.hpp b/src/gui/image_slice_window.hpp index de86e16d..2a8dcf1b 100644 --- a/src/gui/image_slice_window.hpp +++ b/src/gui/image_slice_window.hpp @@ -43,7 +43,9 @@ public: /// Enforce relations between values void constrain(PreferedProperty prefer = PREFER_NONE); /// Attempt to center the current constraints - void centerSelection(); + void centerSelection(); + void centerSelectionHorizontally(); + void centerSelectionVertically(); /// Get the sliced image Image getSlice(double scale = 1.0) const; diff --git a/src/util/window_id.hpp b/src/util/window_id.hpp index 568046be..2506828b 100644 --- a/src/util/window_id.hpp +++ b/src/util/window_id.hpp @@ -272,7 +272,9 @@ enum ControlID { ID_TOP, ID_WIDTH, ID_HEIGHT, - ID_SELECTION_CENTER, + ID_SELECTION_CENTER, + ID_SELECTION_CENTER_HORIZONTALLY, + ID_SELECTION_CENTER_VERTICALLY, ID_FIX_ASPECT, ID_ZOOM, ID_ZOOM_X,