+ /**
+ * Wrap the given pixel value if appropriate and possible
+ * @param inPx Pixel x coordinate
+ * @param inWinWidth window width in pixels
+ * @param inZoom zoom level
+ * @return modified pixel x coordinate
+ */
+ private static int wrapLongitudeValue(int inPx, int inWinWidth, int inZoom)
+ {
+ if (inPx > inWinWidth)
+ {
+ // Pixel is too far right, could we wrap it back onto the screen?
+ int px = inPx;
+ while (px > inWinWidth) {
+ px -= (256 << inZoom);
+ }
+ if (px >= 0) {
+ return px; // successfully wrapped back onto the screen
+ }
+ }
+ else if (inPx < 0)
+ {
+ // Pixel is too far left, could we wrap it back onto the screen?
+ int px = inPx;
+ while (px < 0) {
+ px += (256 << inZoom);
+ }
+ if (px < inWinWidth) {
+ return px; // successfully wrapped back onto the screen
+ }
+ }
+ // Either it's already on the screen or couldn't be wrapped
+ return inPx;
+ }
+
+ /**
+ * Draw the lines while dragging a point
+ * @param inG graphics object
+ * @param inPrevIndex index of point to draw from
+ * @param inNextIndex index of point to draw to
+ */
+ private void drawDragLines(Graphics inG, int inPrevIndex, int inNextIndex)
+ {
+ inG.setColor(Config.getColourScheme().getColour(ColourScheme.IDX_POINT));
+ // line from prev point to cursor
+ if (inPrevIndex > -1 && !_track.getPoint(inPrevIndex+1).getSegmentStart())
+ {
+ final int px = getWidth() / 2 + _mapPosition.getXFromCentre(_track.getX(inPrevIndex));
+ final int py = getHeight() / 2 + _mapPosition.getYFromCentre(_track.getY(inPrevIndex));
+ inG.drawLine(px, py, _dragToX, _dragToY);
+ }
+ if (inNextIndex < _track.getNumPoints() && !_track.getPoint(inNextIndex).getSegmentStart())
+ {
+ final int px = getWidth() / 2 + _mapPosition.getXFromCentre(_track.getX(inNextIndex));
+ final int py = getHeight() / 2 + _mapPosition.getYFromCentre(_track.getY(inNextIndex));
+ inG.drawLine(px, py, _dragToX, _dragToY);
+ }
+ }