implement resize feature
This commit is contained in:
@@ -8,7 +8,7 @@ import java.awt.*;
|
||||
|
||||
public class SCircle extends AbstractShape {
|
||||
|
||||
private final int radius;
|
||||
private int radius;
|
||||
|
||||
private SCircle(int x, int y, int radius) {
|
||||
super(new Rectangle(x, y, radius * 2, radius * 2));
|
||||
@@ -20,6 +20,32 @@ public class SCircle extends AbstractShape {
|
||||
visitor.visitCircle(this);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shape clone() {
|
||||
var color = (ColorAttributes) getAttributes(ColorAttributes.ID);
|
||||
|
||||
Reference in New Issue
Block a user