fix: fix resize and dragging

- AbstractShape: make bounds protected for subclass access
- STriangle: refactor resize logic
- SCircle: refactor resize logic (preserves equal dimensions)
- SText: add reasonable default bounds for hit testing
This commit is contained in:
2026-03-26 23:54:31 +01:00
parent fbe3714182
commit 3a6f98455a
4 changed files with 47 additions and 50 deletions

View File

@@ -22,28 +22,24 @@ public class SCircle extends AbstractShape {
@Override
public void resize(ResizeHandle handle, int dx, int dy) {
Rectangle bounds = getBounds();
int newWidth = bounds.width;
int newHeight = bounds.height;
switch (handle) {
case E, W -> newWidth += dx;
case N, S -> newHeight += dy;
case SE, NW -> {
newWidth += dx;
newHeight += dy;
}
case NE, SW -> {
newWidth += dx;
newHeight += dy;
}
}
int delta = Math.max(Math.abs(dx), Math.abs(dy));
boolean shrink = switch (handle) {
case E, SE, NE -> dx < 0;
case W, SW, NW -> dx > 0;
case N, S -> dy < 0;
default -> false;
};
int sizeChange = shrink ? -delta : delta;
int newWidth = bounds.width + sizeChange;
int newHeight = bounds.height + sizeChange;
if (newWidth < 2) newWidth = 2;
if (newHeight < 2) newHeight = 2;
this.radius = Math.max(newWidth, newHeight) / 2;
bounds.setSize(this.radius * 2, this.radius * 2);
bounds.setSize(newWidth, newHeight);
this.radius = Math.max(bounds.width, bounds.height) / 2;
}
@Override