Changeset 33420 in osm for applications/editors


Ignore:
Timestamp:
2017-06-30T09:17:07+02:00 (7 years ago)
Author:
glebius
Message:

Fix LiveGps plugin cursor drawing after changes to GpxLayer class.
The commit that is supposed to cause regreesion is r12157, or
somewhere around.

Location:
applications/editors/josm/plugins/livegps/src/livegps
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java

    r33138 r33420  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.Color;
    7 import java.awt.Graphics2D;
    8 import java.awt.Point;
    96import java.awt.Rectangle;
    107import java.awt.geom.Point2D;
     
    2219import org.openstreetmap.josm.data.gpx.GpxTrack;
    2320import org.openstreetmap.josm.data.gpx.WayPoint;
    24 import org.openstreetmap.josm.data.preferences.CachingProperty;
    25 import org.openstreetmap.josm.data.preferences.ColorProperty;
    26 import org.openstreetmap.josm.gui.MapView;
    2721import org.openstreetmap.josm.gui.layer.GpxLayer;
    2822
    2923public class LiveGpsLayer extends GpxLayer implements PropertyChangeListener {
    3024    public static final String LAYER_NAME = tr("LiveGPS layer");
    31     public static final String C_LIVEGPS_COLOR_POSITION = "color.livegps.position";
    32     public static final String C_LIVEGPS_COLOR_POSITION_ESTIMATE = "color.livegps.position_estimate";
    33 
    34     private static final CachingProperty<Color> COLOR_POSITION =
    35             new ColorProperty(C_LIVEGPS_COLOR_POSITION, Color.RED).cached();
    36     private static final CachingProperty<Color> COLOR_POSITION_ESTIMATE =
    37             new ColorProperty(C_LIVEGPS_COLOR_POSITION_ESTIMATE, Color.CYAN).cached();
    3825
    3926    private static final int DEFAULT_REFRESH_INTERVAL = 250;
     
    4431    private static final String C_CENTER_INTERVAL = "livegps.center_interval_msec";  /* in msec */
    4532    private static final String C_CENTER_FACTOR = "livegps.center_factor" /* in percent */;
    46     private static final String C_CURSOR_H = "livegps.cursor_height"; /* in pixels */
    47     private static final String C_CURSOR_W = "livegps.cursor_width"; /* in pixels */
    48     private static final String C_CURSOR_T = "livegps.cursor_thickness"; /* in pixels */
    4933    private int refreshInterval;
    5034    private int centerInterval;
     
    7155
    7256        initIntervals();
     57    }
     58
     59    @Override
     60    protected LayerPainter createMapViewPainter(MapViewEvent event) {
     61        return new LiveGpsDrawHelper(this);
    7362    }
    7463
     
    11099    public void setAutoCenter(boolean ac) {
    111100        autocenter = ac;
    112     }
    113 
    114     @Override
    115     public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    116         super.paint(g, mv, bounds);
    117 
    118         if (lastPoint == null)
    119             return;
    120 
    121         Point screen = mv.getPoint(lastPoint.getCoor());
    122 
    123         int TriaHeight = Main.pref.getInteger(C_CURSOR_H, 20);
    124         int TriaWidth = Main.pref.getInteger(C_CURSOR_W, 10);
    125         int TriaThick = Main.pref.getInteger(C_CURSOR_T, 4);
    126 
    127         /*
    128          * Draw a bold triangle.
    129          * In case of deep zoom draw also a thin DOP oval.
    130          */
    131 
    132         g.setColor(COLOR_POSITION_ESTIMATE.get());
    133         int w, h;
    134         double ppm = 100 / mv.getDist100Pixel();    /* pixels per metre */
    135 
    136         w = (int) Math.round(lastData.getEpx() * ppm);
    137         h = (int) Math.round(lastData.getEpy() * ppm);
    138 
    139         if (w > TriaWidth || h > TriaWidth) {
    140             int xo, yo;
    141 
    142             yo = screen.y - Math.round(h/2);
    143             xo = screen.x - Math.round(w/2);
    144 
    145             g.drawOval(xo, yo, w, h);
    146         }
    147 
    148         int[] x = new int[4];
    149         int[] y = new int[4];
    150         float course = lastData.getCourse();
    151         float csin = (float) Math.sin(Math.toRadians(course));
    152         float ccos = (float) Math.cos(Math.toRadians(course));
    153         float csin120 = (float) Math.sin(Math.toRadians(course + 120));
    154         float ccos120 = (float) Math.cos(Math.toRadians(course + 120));
    155         float csin240 = (float) Math.sin(Math.toRadians(course + 240));
    156         float ccos240 = (float) Math.cos(Math.toRadians(course + 240));
    157 
    158         g.setColor(COLOR_POSITION.get());
    159 
    160         for (int i = 0; i < TriaThick; i++, TriaHeight--, TriaWidth--) {
    161 
    162             x[0] = screen.x + Math.round(TriaHeight * csin);
    163             y[0] = screen.y - Math.round(TriaHeight * ccos);
    164             x[1] = screen.x + Math.round(TriaWidth * csin120);
    165             y[1] = screen.y - Math.round(TriaWidth * ccos120);
    166             x[2] = screen.x;
    167             y[2] = screen.y;
    168             x[3] = screen.x + Math.round(TriaWidth * csin240);
    169             y[3] = screen.y - Math.round(TriaWidth * ccos240);
    170 
    171             g.drawPolygon(x, y, 4);
    172         }
    173 
    174101    }
    175102
Note: See TracChangeset for help on using the changeset viewer.