Changeset 2596 in osm for applications/editors


Ignore:
Timestamp:
2007-04-19T19:00:44+02:00 (17 years ago)
Author:
andystreet
Message:

Improve performance by only drawing the visible area rather than the whole layer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mappaint/src/mappaint/MapPaintVisitor.java

    r1863 r2596  
    3232        // Altered from SimplePaintVisitor
    3333        @Override public void visit(Node n) {
    34                 ElemStyle nodeStyle = MapPaintPlugin.elemStyles.getStyle(n);
    35                 if(nodeStyle!=null && Main.map.mapView.zoom()>=nodeStyle.getMinZoom()){
    36                         if(nodeStyle instanceof IconElemStyle) {
    37                                 drawNode(n, ((IconElemStyle)nodeStyle).getIcon());
     34                if (isNodeVisible(n)) {
     35                        ElemStyle nodeStyle = MapPaintPlugin.elemStyles.getStyle(n);
     36                        if(nodeStyle!=null && Main.map.mapView.zoom()>=nodeStyle.getMinZoom()){
     37                                if(nodeStyle instanceof IconElemStyle) {
     38                                        drawNode(n, ((IconElemStyle)nodeStyle).getIcon());
     39                                } else {
     40                                        // throw some sort of exception
     41                                }
    3842                        } else {
    39                                 // throw some sort of exception
    40                         }
    41                 } else {
    42                         drawNode(n, n.selected ? getPreferencesColor("selected",
    43                                                                         Color.YELLOW)
    44                                 : getPreferencesColor("node", Color.RED));
     43                                drawNode(n, n.selected ? getPreferencesColor("selected",
     44                                                                                Color.YELLOW)
     45                                        : getPreferencesColor("node", Color.RED));
     46                        }
    4547                }
    4648        }
     
    5254         */
    5355        @Override public void visit(Segment ls) {
    54                 drawSegment(ls, getPreferencesColor("untagged",Color.GRAY));
     56                if (isSegmentVisible(ls))
     57                        drawSegment(ls, getPreferencesColor("untagged",Color.GRAY));
    5558        }
    5659
     
    8790                        for (Segment ls : w.segments)
    8891                        {
    89                                 if (!ls.selected) // selected already in good color
     92                                if ((!ls.selected) && (isSegmentVisible(ls))) // selected already in good color
    9093                                        drawSegment(ls, w.selected ?
    9194                                                getPreferencesColor("selected", Color.YELLOW) : colour,
     
    126129                        g2d.setStroke(new BasicStroke(1));
    127130                }
     131        }
     132
     133        /**
     134         * Checks if the given node is in the visible area.
     135         */
     136        protected boolean isNodeVisible(Node n) {
     137                Point p = nc.getPoint(n.eastNorth);
     138                return !((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight()));
     139        }
     140
     141        /**
     142         * Checks is the given segment is int the visible area.
     143         * NOTE: This will return true for a small number of non-visible
     144         *       segments.
     145         */
     146        protected boolean isSegmentVisible(Segment ls) {
     147                if (ls.incomplete) return false;
     148                Point p1 = nc.getPoint(ls.from.eastNorth);
     149                Point p2 = nc.getPoint(ls.to.eastNorth);
     150                if ((p1.x < 0) && (p2.x < 0)) return false;
     151                if ((p1.y < 0) && (p2.y < 0)) return false;
     152                if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;
     153                if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;
     154                return true;
    128155        }
    129156
Note: See TracChangeset for help on using the changeset viewer.