int x0 = bds.getX();
int y0 = bds.getY();
int x1 = x0 + bds.getWidth();
int y1 = y0 + bds.getHeight();
if (gesture == null) {
return new Handle[] { new Handle(this, x0, y0),
new Handle(this, x1, y0), new Handle(this, x1, y1),
new Handle(this, x0, y1) };
} else {
int hx = gesture.getHandle().getX();
int hy = gesture.getHandle().getY();
int dx = gesture.getDeltaX();
int dy = gesture.getDeltaY();
int newX0 = x0 == hx ? x0 + dx : x0;
int newY0 = y0 == hy ? y0 + dy : y0;
int newX1 = x1 == hx ? x1 + dx : x1;
int newY1 = y1 == hy ? y1 + dy : y1;
if (gesture.isShiftDown()) {
if (gesture.isAltDown()) {
if (x0 == hx) {
newX1 -= dx;
}
if (x1 == hx) {
newX0 -= dx;
}
if (y0 == hy) {
newY1 -= dy;
}
if (y1 == hy) {
newY0 -= dy;
}
int w = Math.abs(newX1 - newX0);
int h = Math.abs(newY1 - newY0);
// reduce width to h
if (w > h) {
int dw = (w - h) / 2;
newX0 -= (newX0 > newX1 ? 1 : -1) * dw;
newX1 -= (newX1 > newX0 ? 1 : -1) * dw;
} else {
int dh = (h - w) / 2;
newY0 -= (newY0 > newY1 ? 1 : -1) * dh;
newY1 -= (newY1 > newY0 ? 1 : -1) * dh;
}
} else {
int w = Math.abs(newX1 - newX0);
int h = Math.abs(newY1 - newY0);
// reduce width to h
if (w > h) {
if (x0 == hx) {
newX0 = newX1 + (newX0 > newX1 ? 1 : -1) * h;
}
if (x1 == hx) {
newX1 = newX0 + (newX1 > newX0 ? 1 : -1) * h;
}
// reduce height to w
} else {
if (y0 == hy) {
newY0 = newY1 + (newY0 > newY1 ? 1 : -1) * w;
}
if (y1 == hy) {
newY1 = newY0 + (newY1 > newY0 ? 1 : -1) * w;
}
}
}
} else {
if (gesture.isAltDown()) {
if (x0 == hx) {
newX1 -= dx;
}
if (x1 == hx) {
newX0 -= dx;
}
if (y0 == hy) {
newY1 -= dy;
}
if (y1 == hy) {
newY0 -= dy;
}
} else {
// already handled
;
}
}
return new Handle[] { new Handle(this, newX0, newY0),
new Handle(this, newX1, newY0), new Handle(this, newX1, newY1),
new Handle(this, newX0, newY1) };
}
}