Bug in SnapToGrid [message #230375] |
Fri, 09 February 2007 16:55 |
Calman Steynberg Messages: 10 Registered: July 2009 |
Junior Member |
|
|
SnapToGrid has an issue where it only works for snapping to the top
right (NORTH | WEST) corner of a figure.
The issue is that in the code for handling SOUTH and EAST, it sets
preciseHeight and preciseWidth instead of preciseX and preciseY. Since
preciseX and preciseY is used to determine snapping, but is always 0,
snapping then turns off completely.
The code for snapRectangle below fixes this and lets the figure snap to
any side.
I'll file a bugzilla issue with a patch file as soon as I get the chance
today.
Calman
public int snapRectangle(Request request, int snapLocations,
PrecisionRectangle rect, PrecisionRectangle result) {
rect = rect.getPreciseCopy();
makeRelative(container.getContentPane(), rect);
PrecisionRectangle correction = new PrecisionRectangle();
makeRelative(container.getContentPane(), correction);
if (gridX > 0 && (snapLocations & EAST) != 0) {
double rightCorrection = Math.IEEEremainder(rect.preciseRight()
- origin.x - 1, gridX);
correction.preciseX -= rightCorrection;
snapLocations &= ~EAST;
}
if ((snapLocations & (WEST | HORIZONTAL)) != 0 && gridX > 0) {
double leftCorrection = Math.IEEEremainder(rect.preciseX -
origin.x,
gridX);
correction.preciseX -= leftCorrection;
if ((snapLocations & HORIZONTAL) == 0)
correction.preciseWidth += leftCorrection;
snapLocations &= ~(WEST | HORIZONTAL);
}
if ((snapLocations & SOUTH) != 0 && gridY > 0) {
double bottomCorrection = Math.IEEEremainder(rect.preciseBottom()
- origin.y - 1, gridY);
correction.preciseY -= bottomCorrection;
snapLocations &= ~SOUTH;
}
if ((snapLocations & (NORTH | VERTICAL)) != 0 && gridY > 0) {
double topCorrection = Math.IEEEremainder(
rect.preciseY - origin.y, gridY);
correction.preciseY -= topCorrection;
if ((snapLocations & VERTICAL) == 0)
correction.preciseHeight += topCorrection;
snapLocations &= ~(NORTH | VERTICAL);
}
correction.updateInts();
makeAbsolute(container.getContentPane(), correction);
result.preciseX += correction.preciseX;
result.preciseY += correction.preciseY;
result.preciseWidth += correction.preciseWidth;
result.preciseHeight += correction.preciseHeight;
result.updateInts();
return snapLocations;
}
|
|
|
Powered by
FUDForum. Page generated in 0.03580 seconds