How to snap to the centre


#1

HI,

Presently i am able to snap to topleft topright…etc…But i am not able to snap it to the centre of the grid, though i found “JGoObject.centre” it is snapping on the intersection point.

Thanks
john


#2

That isn’t a standard option–everything is oriented around the grid points, not any other locations such as midway between the grid points.
There might be a way for you to implement this by overriding JGoView.moveSelection and findNearestGridPoint:
public void moveSelection(JGoSelection sel, int modifiers, int offsetx, int offsety, int event) {
myGridMoveHack = true;
super.moveSelection(sel, modifiers, offsetx, offsety, event);
myGridMoveHack = false;
}
private boolean myGridMoveHack = false;
public Point findNearestGridPoint(int x, int y, Point result) {
result = super.findNearestGridPoint(x, y, result);
if (myGridMoveHack) {
result.x += getGridWidth()/2;
result.y += getGridHeight()/2;
}
return result;
}
I haven’t tried this–there might be some problem with always returning the midpoint that is greater (in X and Y) that the nearest grid point, rather than whichever midpoint would be closest.