implement resize feature
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user