ui: default image slice selection to center

This commit is contained in:
Brendan Hagan
2022-06-13 23:40:26 -04:00
parent b9fa4c5b66
commit c2fea6bd96
2 changed files with 14 additions and 0 deletions
+12
View File
@@ -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);