@Override
public void draw(Canvas canvas, Graphics g) {
Selection selection = canvas.getSelection();
int action = curAction;
Location start = dragStart;
Location end = dragEnd;
HandleGesture gesture = null;
boolean drawHandles;
switch (action) {
case MOVE_ALL:
drawHandles = !dragEffective;
break;
case MOVE_HANDLE:
drawHandles = !dragEffective;
if (dragEffective) gesture = curGesture;
break;
default:
drawHandles = true;
}
CanvasObject moveHandleObj = null;
if (gesture != null) moveHandleObj = gesture.getHandle().getObject();
if (drawHandles) {
// unscale the coordinate system so that the stroke width isn't scaled
double zoom = 1.0;
Graphics gCopy = g.create();
if (gCopy instanceof Graphics2D) {
zoom = canvas.getZoomFactor();
if (zoom != 1.0) {
((Graphics2D) gCopy).scale(1.0 / zoom, 1.0 / zoom);
}
}
GraphicsUtil.switchToWidth(gCopy, 1);
int size = (int) Math.ceil(HANDLE_SIZE * Math.sqrt(zoom));
int offs = size / 2;
for (CanvasObject obj : selection.getSelected()) {
List<Handle> handles;
if (action == MOVE_HANDLE && obj == moveHandleObj) {
handles = obj.getHandles(gesture);
} else {
handles = obj.getHandles(null);
}
for (Handle han : handles) {
int x = han.getX();
int y = han.getY();
if (action == MOVE_ALL && dragEffective) {
Location delta = selection.getMovingDelta();
x += delta.getX();
y += delta.getY();
}
x = (int) Math.round(zoom * x);
y = (int) Math.round(zoom * y);
gCopy.clearRect(x - offs, y - offs, size, size);
gCopy.drawRect(x - offs, y - offs, size, size);
}
}
Handle selHandle = selection.getSelectedHandle();
if (selHandle != null) {
int x = selHandle.getX();
int y = selHandle.getY();
if (action == MOVE_ALL && dragEffective) {
Location delta = selection.getMovingDelta();
x += delta.getX();
y += delta.getY();
}
x = (int) Math.round(zoom * x);
y = (int) Math.round(zoom * y);
int[] xs = { x - offs, x, x + offs, x };
int[] ys = { y, y - offs, y, y + offs };