lastMouseY = my;
boolean shiftDown = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
boolean ctrlDown = (mods & MouseEvent.CTRL_DOWN_MASK) != 0;
boolean altDown = (mods & MouseEvent.ALT_DOWN_MASK) != 0;
Curve ret = null;
switch (state) {
case ENDPOINT_DRAG:
if (mouseDown) {
if (shiftDown) {
Location p = LineUtil.snapTo8Cardinals(end0, mx, my);
mx = p.getX();
my = p.getY();
}
if (ctrlDown) {
mx = canvas.snapX(mx);
my = canvas.snapY(my);
}
end1 = Location.create(mx, my);
}
break;
case CONTROL_DRAG:
if (mouseDown) {
int cx = mx;
int cy = my;
if (ctrlDown) {
cx = canvas.snapX(cx);
cy = canvas.snapY(cy);
}
if (shiftDown) {
double x0 = end0.getX();
double y0 = end0.getY();
double x1 = end1.getX();
double y1 = end1.getY();
double midx = (x0 + x1) / 2;
double midy = (y0 + y1) / 2;
double dx = x1 - x0;
double dy = y1 - y0;
double[] p = LineUtil.nearestPointInfinite(cx, cy,
midx, midy, midx - dy, midy + dx);
cx = (int) Math.round(p[0]);
cy = (int) Math.round(p[1]);
}
if (altDown) {
double[] e0 = { end0.getX(), end0.getY() };
double[] e1 = { end1.getX(), end1.getY() };
double[] mid = { cx, cy };
double[] ct = CurveUtil.interpolate(e0, e1, mid);
cx = (int) Math.round(ct[0]);
cy = (int) Math.round(ct[1]);
}
ret = new Curve(end0, end1, Location.create(cx, cy));
curCurve = ret;
}
break;
}
return ret;