/** ************************************************************************** * "Intelligent" map scrolling.
* * If the new position is within the centre'ish of the map then we shift * the cursor there. If it is near the edge then we shift the cursor there * and centre the map on that point. "Centre'ish" is defined as the centre * 80% of the frame.
*
* There is extra intelligence built in to reduce the map redraw overhead by
* only moving the cursor if it's new screen position is different than
* the previous one.
*
* @param p NIPoint giving new position
*/
public void intelligentScroll(NIPoint p) { /////////////////////////////////// intelligentScroll()
//
if (currPos != null) // If have a current position
prevPos = (NIPoint)currPos.clone(); // old current -> previous
else { // Else fake a previous one
prevPos = new NIPoint(); // make a new one
prevPos.forward(currProj); // forward project it
} //
//
currPos = (NIPoint)p.clone(); // New point -> current
currPos.forward(currProj); // Forward project new
if ((currPos.getX() != prevPos.getX()) || // If screen pos has changed
(currPos.getY() != prevPos.getY())) { //
cursorLayer.setCursorPosition(currPos); // position cursor there
int width = mapBean.getWidth(); // get window width
int height = mapBean.getHeight(); // and height
if ((currPos.getX() < (width * edgeBand)) || // if within x% of left edge
(currPos.getX() > (width * (1.0f - edgeBand))) || // or right edge
(currPos.getY() < (height * edgeBand)) || // or top edge
(currPos.getY() > (height * (1.0f - edgeBand)))) { // or bottom edge
mapBean.setCenter(currPos); // then centre map on cursor
} //
} //
//
} //////////////////////////////////////////////////////////////////////// End of intelligentScroll()