Changeset 2688 in osm


Ignore:
Timestamp:
2007-04-30T11:48:22+02:00 (17 years ago)
Author:
damians
Message:

Added support for the shown tag.
Changed the isVisible code so that position for visible points is not computed twice.
Added README file.
Added styles folder and an elemstyles.xml file

Location:
applications/editors/josm/plugins/mappaint
Files:
3 added
1 edited

Legend:

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

    r2685 r2688  
    3535        // Altered from SimplePaintVisitor
    3636        @Override public void visit(Node n) {
    37                 if (isNodeVisible(n)) {
     37                if (!n.shown) {
    3838                        ElemStyle nodeStyle = MapPaintPlugin.elemStyles.getStyle(n);
    3939                        if(nodeStyle!=null && Main.map.mapView.zoom()>=nodeStyle.getMinZoom()){
     
    5757         */
    5858        @Override public void visit(Segment ls) {
    59                 if (isSegmentVisible(ls))
    6059                        drawSegment(ls, getPreferencesColor("untagged",Color.GRAY),Main.pref.getBoolean("draw.segment.direction"));
    6160        }
     
    9291                {
    9392                        orderNumber++;
    94                         if (isSegmentVisible(ls))
    95                         {
    9693                                if (area && fillAreas)
    9794                                        //Draw segments in a different colour so direction arrows show against the fill
    98                                         drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.YELLOW) : getPreferencesColor("untagged",Color.GRAY), width);
     95                                        drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.YELLOW) : getPreferencesColor("untagged",Color.GRAY),Main.pref.getBoolean("draw.segment.direction"), width);
    9996                                else
    100                                         drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.YELLOW) : colour, width);
     97                                        drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.YELLOW) : colour,Main.pref.getBoolean("draw.segment.direction"), width);
    10198                                if (!ls.incomplete && Main.pref.getBoolean("draw.segment.order_number"))
    10299                                {
     
    108105                                        catch (IllegalAccessError e) {} //SimplePaintVisitor::drawOrderNumber was private prior to rev #211
    109106                                }
    110                         }
    111107                }
    112108        }
     
    137133        }
    138134
    139         /**
    140          * Checks if the given node is in the visible area.
    141          */
    142         protected boolean isNodeVisible(Node n) {
    143                 Point p = nc.getPoint(n.eastNorth);
    144                 return !((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight()));
    145         }
    146 
    147         /**
    148          * Checks if the given segment is in the visible area.
    149          * NOTE: This will return true for a small number of non-visible
    150          *       segments.
    151          */
    152         protected boolean isSegmentVisible(Segment ls) {
    153                 if (ls.incomplete) return false;
    154                 Point p1 = nc.getPoint(ls.from.eastNorth);
    155                 Point p2 = nc.getPoint(ls.to.eastNorth);
    156                 if ((p1.x < 0) && (p2.x < 0)) return false;
    157                 if ((p1.y < 0) && (p2.y < 0)) return false;
    158                 if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;
    159                 if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;
    160                 return true;
    161         }
    162 
    163135        // NEW
    164136        protected void drawNode(Node n, ImageIcon icon) {
     137                if (n.shown) return;
     138                n.shown=true;
    165139                Point p = nc.getPoint(n.eastNorth);
     140                if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
    166141                int w = icon.getIconWidth(), h=icon.getIconHeight();
    167142                icon.paintIcon ( Main.map.mapView, g, p.x-w/2, p.y-h/2 );
     
    187162        // Altered - now specify width
    188163        @Override protected void drawSegment(Segment ls, Color col,boolean showDirection) {
    189                         drawSegment(ls,col,1);
    190         }
     164                        drawSegment(ls,col,showDirection,1);
     165        }
     166
    191167
    192168        // Altered - now specify width
    193         private void drawSegment (Segment ls, Color col, int width) {
     169        private void drawSegment (Segment ls, Color col,boolean showDirection, int width) {
     170                //do not draw already visible segments
     171                if (ls.shown) return;
     172                ls.shown=true;
    194173                Graphics2D g2d = (Graphics2D)g;
    195174                if (ls.incomplete)
     
    202181                Point p1 = nc.getPoint(ls.from.eastNorth);
    203182                Point p2 = nc.getPoint(ls.to.eastNorth);
     183                // checking if this Point is visible
     184                if ((p1.x < 0) && (p2.x < 0)) return ;
     185                if ((p1.y < 0) && (p2.y < 0)) return ;
     186                if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return ;
     187                if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return ;
     188
    204189                g.drawLine(p1.x, p1.y, p2.x, p2.y);
    205190
    206                 if (Main.pref.getBoolean("draw.segment.direction")) {
     191                if (showDirection) {
    207192                        double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
    208                 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
    209                 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
    210                 }
     193            g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
     194            g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
     195                }
     196               
    211197        }
    212198
     
    220206        @Override public void drawNode(Node n, Color color) {
    221207                Point p = nc.getPoint(n.eastNorth);
     208                if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
    222209                g.setColor(color);
    223210                g.drawRect(p.x-1, p.y-1, 2, 2);
     
    229216
    230217                Collection<Way> noAreaWays = new LinkedList<Way>();
     218
    231219                for (final OsmPrimitive osm : data.segments)
    232220                        if (!osm.deleted)
    233                                 osm.visit(this);
     221                                osm.shown=false;
     222
     223                for (final OsmPrimitive osm : data.nodes)
     224                        if (!osm.deleted)
     225                                osm.shown=false;
    234226                               
    235227                for (final OsmPrimitive osm : data.ways)
     
    242234                        osm.visit(this);
    243235
     236                for (final OsmPrimitive osm : data.segments)
     237                        if (!osm.deleted)
     238                                osm.visit(this);
     239
    244240                for (final OsmPrimitive osm : data.nodes)
    245241                        if (!osm.deleted)
     
    247243
    248244                for (final OsmPrimitive osm : data.getSelected())
    249                         if (!osm.deleted)
    250                                 osm.visit(this);
     245                        if (!osm.deleted){
     246                                osm.shown=false; //to be sure it will be drawn
     247                                osm.visit(this);
     248                        }
    251249        }
    252250}
Note: See TracChangeset for help on using the changeset viewer.