feat: more slice window alignment options

This commit is contained in:
Brendan Hagan
2022-07-12 00:17:56 -04:00
parent 9f57081417
commit a43920089d
8 changed files with 65 additions and 18 deletions
+51 -15
View File
@@ -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)
+3 -1
View File
@@ -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;
+3 -1
View File
@@ -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,