implement resize feature

This commit is contained in:
2026-03-19 22:20:23 +01:00
parent bd9c6c4b7d
commit e742bbd827
9 changed files with 244 additions and 9 deletions

View File

@@ -34,6 +34,45 @@ public abstract class AbstractShape implements Shape {
getBounds().translate(dx, dy);
}
@Override
public void resize(ResizeHandle handle, int dx, int dy) {
Rectangle bounds = getBounds();
switch (handle) {
case E -> bounds.width += dx;
case W -> {
bounds.x += dx;
bounds.width -= dx;
}
case S -> bounds.height += dy;
case N -> {
bounds.y += dy;
bounds.height -= dy;
}
case SE -> {
bounds.width += dx;
bounds.height += dy;
}
case SW -> {
bounds.x += dx;
bounds.width -= dx;
bounds.height += dy;
}
case NE -> {
bounds.width += dx;
bounds.y += dy;
bounds.height -= dy;
}
case NW -> {
bounds.x += dx;
bounds.width -= dx;
bounds.y += dy;
bounds.height -= dy;
}
}
if (bounds.width < 1) bounds.width = 1;
if (bounds.height < 1) bounds.height = 1;
}
@Override
public Rectangle getBounds() {
return this.bounds;