implement resize feature
This commit is contained in:
@@ -16,6 +16,54 @@ public class STriangle extends AbstractShape {
|
||||
visitor.visitTriangle(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(ResizeHandle handle, int dx, int dy) {
|
||||
Rectangle bounds = getBounds();
|
||||
int delta = Math.max(Math.abs(dx), Math.abs(dy));
|
||||
|
||||
boolean shrink = switch (handle) {
|
||||
case SE -> (dx < 0 || dy < 0);
|
||||
case NW -> (dx > 0 || dy > 0);
|
||||
case NE -> (dx < 0);
|
||||
case SW -> (dx > 0);
|
||||
case E, W -> (dx < 0);
|
||||
case N, S -> (dy < 0);
|
||||
default -> false;
|
||||
};
|
||||
|
||||
int sizeChange = shrink ? -delta : delta;
|
||||
|
||||
switch (handle) {
|
||||
case SE, E, W -> {
|
||||
bounds.width += sizeChange;
|
||||
bounds.height += sizeChange;
|
||||
}
|
||||
case NW -> {
|
||||
bounds.x -= sizeChange;
|
||||
bounds.width += sizeChange;
|
||||
bounds.y -= sizeChange;
|
||||
bounds.height += sizeChange;
|
||||
}
|
||||
case NE -> {
|
||||
bounds.y -= sizeChange;
|
||||
bounds.width += sizeChange;
|
||||
bounds.height += sizeChange;
|
||||
}
|
||||
case SW -> {
|
||||
bounds.x -= sizeChange;
|
||||
bounds.width += sizeChange;
|
||||
bounds.height += sizeChange;
|
||||
}
|
||||
case N, S -> {
|
||||
bounds.width += sizeChange;
|
||||
bounds.height += sizeChange;
|
||||
}
|
||||
}
|
||||
|
||||
if (bounds.width < 1) bounds.width = 1;
|
||||
if (bounds.height < 1) bounds.height = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shape clone() {
|
||||
var color = (ColorAttributes) getAttributes(ColorAttributes.ID);
|
||||
|
||||
Reference in New Issue
Block a user