Changeset 10806 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2016-08-15T14:57:06+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13303 - Fixes for hatched texture (modified patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r10680 r10806  
    88import java.text.MessageFormat;
    99import java.util.Objects;
     10import java.util.function.Consumer;
    1011
    1112import org.openstreetmap.josm.data.coor.LatLon;
    1213import org.openstreetmap.josm.data.osm.BBox;
     14import org.openstreetmap.josm.data.projection.Projection;
    1315import org.openstreetmap.josm.tools.CheckParameterUtil;
    1416
     
    399401     */
    400402    public Rectangle2D.Double asRect() {
    401         double w = maxLon-minLon + (crosses180thMeridian() ? 360.0 : 0.0);
     403        double w = getWidth();
    402404        return new Rectangle2D.Double(minLon, minLat, w, maxLat-minLat);
    403405    }
    404406
     407    private double getWidth() {
     408        return maxLon-minLon + (crosses180thMeridian() ? 360.0 : 0.0);
     409    }
     410
    405411    public double getArea() {
    406         double w = maxLon-minLon + (crosses180thMeridian() ? 360.0 : 0.0);
     412        double w = getWidth();
    407413        return w * (maxLat - minLat);
    408414    }
     
    440446        minLon = LatLon.toIntervalLon(minLon);
    441447        maxLon = LatLon.toIntervalLon(maxLon);
     448    }
     449
     450    /**
     451     * Visit points along the edge of this bounds instance.
     452     * @param projection The projection that should be used to determine how often the edge should be split along a given corner.
     453     * @param visitor A function to call for the points on the edge.
     454     * @since 10806
     455     */
     456    public void visitEdge(Projection projection, Consumer<LatLon> visitor) {
     457        double width = getWidth();
     458        double height = maxLat - minLat;
     459        //TODO: Use projection to see if there is any need for doing this along each axis.
     460        int splitX = Math.max((int) width / 10, 10);
     461        int splitY = Math.max((int) height / 10, 10);
     462
     463        for (int step = 0; step < splitX; step++) {
     464            visitor.accept(new LatLon(minLat, minLon + width * step / splitX));
     465        }
     466        for (int step = 0; step < splitY; step++) {
     467            visitor.accept(new LatLon(minLat + height * step / splitY, maxLon));
     468        }
     469        for (int step = 0; step < splitX; step++) {
     470            visitor.accept(new LatLon(maxLat, maxLon - width * step / splitX));
     471        }
     472        for (int step = 0; step < splitY; step++) {
     473            visitor.accept(new LatLon(maxLat - height * step / splitY, minLon));
     474        }
    442475    }
    443476
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r9665 r10806  
    5454    public void visit(Bounds b) {
    5555        if (b != null) {
    56             visit(b.getMin());
    57             visit(b.getMax());
     56            b.visitEdge(Main.getProjection(), this::visit);
    5857        }
    5958    }
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r10755 r10806  
    1818import java.awt.event.MouseMotionListener;
    1919import java.awt.geom.Area;
    20 import java.awt.geom.GeneralPath;
    2120import java.awt.image.BufferedImage;
    2221import java.beans.PropertyChangeEvent;
     
    4645import org.openstreetmap.josm.data.ViewportData;
    4746import org.openstreetmap.josm.data.coor.EastNorth;
    48 import org.openstreetmap.josm.data.coor.LatLon;
    4947import org.openstreetmap.josm.data.imagery.ImageryInfo;
    5048import org.openstreetmap.josm.data.osm.DataSet;
     
    974972        tempG.setColor(Color.WHITE);
    975973        Bounds b = getProjection().getWorldBoundsLatLon();
    976         double lat = b.getMinLat();
    977         double lon = b.getMinLon();
    978 
    979         Point p = getPoint(b.getMin());
    980 
    981         GeneralPath path = new GeneralPath();
    982 
    983         double d = 1.0;
    984         path.moveTo(p.x, p.y);
    985         double max = b.getMax().lat();
    986         for (; lat <= max; lat += d) {
    987             p = getPoint(new LatLon(lat >= max ? max : lat, lon));
    988             path.lineTo(p.x, p.y);
    989         }
    990         lat = max; max = b.getMax().lon();
    991         for (; lon <= max; lon += d) {
    992             p = getPoint(new LatLon(lat, lon >= max ? max : lon));
    993             path.lineTo(p.x, p.y);
    994         }
    995         lon = max; max = b.getMinLat();
    996         for (; lat >= max; lat -= d) {
    997             p = getPoint(new LatLon(lat <= max ? max : lat, lon));
    998             path.lineTo(p.x, p.y);
    999         }
    1000         lat = max; max = b.getMinLon();
    1001         for (; lon >= max; lon -= d) {
    1002             p = getPoint(new LatLon(lat, lon <= max ? max : lon));
    1003             path.lineTo(p.x, p.y);
    1004         }
    1005974
    1006975        int w = getWidth();
     
    1008977
    1009978        // Work around OpenJDK having problems when drawing out of bounds
    1010         final Area border = new Area(path);
     979        final Area border = getState().getArea(b);
    1011980        // Make the viewport 1px larger in every direction to prevent an
    1012981        // additional 1px border when zooming in
  • trunk/src/org/openstreetmap/josm/gui/MapViewState.java

    r10805 r10806  
    66import java.awt.Rectangle;
    77import java.awt.geom.AffineTransform;
     8import java.awt.geom.Area;
     9import java.awt.geom.Path2D;
    810import java.awt.geom.Point2D;
    911import java.awt.geom.Point2D.Double;
     
    215217    }
    216218
     219    public Area getArea(Bounds bounds) {
     220        Path2D area = new Path2D.Double();
     221        bounds.visitEdge(getProjection(), latlon -> {
     222            MapViewPoint point = getPointFor(latlon);
     223            if (area.getCurrentPoint() == null) {
     224                area.moveTo(point.getInViewX(), point.getInViewY());
     225            } else {
     226                area.lineTo(point.getInViewX(), point.getInViewY());
     227            }
     228        });
     229        area.closePath();
     230        return new Area(area);
     231    }
     232
    217233    /**
    218234     * Creates a new state that is the same as the current state except for that it is using a new center.
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r10788 r10806  
    1313import java.awt.GraphicsEnvironment;
    1414import java.awt.GridBagLayout;
    15 import java.awt.Point;
    1615import java.awt.Rectangle;
    1716import java.awt.TexturePaint;
    1817import java.awt.event.ActionEvent;
    1918import java.awt.geom.Area;
     19import java.awt.geom.Rectangle2D;
    2020import java.awt.image.BufferedImage;
    2121import java.io.File;
     
    5252import org.openstreetmap.josm.data.conflict.Conflict;
    5353import org.openstreetmap.josm.data.conflict.ConflictCollection;
     54import org.openstreetmap.josm.data.coor.EastNorth;
    5455import org.openstreetmap.josm.data.coor.LatLon;
    5556import org.openstreetmap.josm.data.gpx.GpxConstants;
     
    8283import org.openstreetmap.josm.gui.ExtendedDialog;
    8384import org.openstreetmap.josm.gui.MapView;
     85import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
    8486import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    8587import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     
    111113 */
    112114public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener {
     115    private static final int HATCHED_SIZE = 15;
    113116    /** Property used to know if this layer has to be saved on disk */
    114117    public static final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk";
     
    304307
    305308    /**
    306      * a paint texture for non-downloaded area
    307      */
    308     private static volatile TexturePaint hatched;
     309     * a texture for non-downloaded area
     310     */
     311    private static volatile BufferedImage hatched;
    309312
    310313    static {
     
    332335     */
    333336    public static void createHatchTexture() {
    334         BufferedImage bi = new BufferedImage(15, 15, BufferedImage.TYPE_INT_ARGB);
     337        BufferedImage bi = new BufferedImage(HATCHED_SIZE, HATCHED_SIZE, BufferedImage.TYPE_INT_ARGB);
    335338        Graphics2D big = bi.createGraphics();
    336339        big.setColor(getBackgroundColor());
    337340        Composite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
    338341        big.setComposite(comp);
    339         big.fillRect(0, 0, 15, 15);
     342        big.fillRect(0, 0, HATCHED_SIZE, HATCHED_SIZE);
    340343        big.setColor(getOutsideColor());
    341344        big.drawLine(-1, 6, 6, -1);
    342345        big.drawLine(4, 16, 16, 4);
    343         Rectangle r = new Rectangle(0, 0, 15, 15);
    344         hatched = new TexturePaint(bi, r);
     346        hatched = bi;
    345347    }
    346348
     
    408410                    continue;
    409411                }
    410                 Point p1 = mv.getPoint(bounds.getMin());
    411                 Point p2 = mv.getPoint(bounds.getMax());
    412                 Rectangle r = new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p2.x-p1.x), Math.abs(p2.y-p1.y));
    413                 a.subtract(new Area(r));
     412                a.subtract(mv.getState().getArea(bounds));
    414413            }
    415414
    416415            // paint remainder
    417             g.setPaint(hatched);
     416            MapViewPoint anchor = mv.getState().getPointFor(new EastNorth(0, 0));
     417            Rectangle2D anchorRect = new Rectangle2D.Double(anchor.getInView().getX() % HATCHED_SIZE,
     418                    anchor.getInView().getY() % HATCHED_SIZE, HATCHED_SIZE, HATCHED_SIZE);
     419            g.setPaint(new TexturePaint(hatched, anchorRect));
    418420            g.fill(a);
    419421        }
Note: See TracChangeset for help on using the changeset viewer.