Changeset 3968 in josm for trunk


Ignore:
Timestamp:
2011-03-09T16:22:48+01:00 (13 years ago)
Author:
bastiK
Message:

applied #6035 (patch by jcollie) - Add extra polygon shapes to MapCSS painter

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

    r3964 r3968  
    361361    }
    362362
     363    private Polygon buildPolygon(Point center, int radius, int sides, double rotation) {
     364        Polygon polygon = new Polygon();
     365        for (int i = 0; i < sides; i++) {
     366            double angle = ((2 * Math.PI / sides) * i) - rotation;
     367            int x = (int) Math.round(center.x + radius * Math.cos(angle));
     368            int y = (int) Math.round(center.y + radius * Math.sin(angle));
     369            polygon.addPoint(x, y);
     370        }
     371        return polygon;
     372    }
     373
     374    private Polygon buildPolygon(Point center, int radius, int sides) {
     375        return buildPolygon(center, radius, sides, 0.0);
     376    }
     377
    363378    public void drawNodeSymbol(Node n, Symbol s, Color fillColor, Color strokeColor, NodeTextElement text) {
    364379        Point p = nc.getPoint(n);
     
    369384            g.setColor(fillColor);
    370385            switch (s.symbol) {
    371                 case SQUARE:
    372                     g.fillRect(p.x - radius, p.y - radius, s.size, s.size);
    373                     break;
    374                 case CIRCLE:
    375                     g.fillOval(p.x - radius, p.y - radius, s.size, s.size);
    376                     break;
    377                 default:
    378                     throw new AssertionError();
     386            case SQUARE:
     387                g.fillRect(p.x - radius, p.y - radius, s.size, s.size);
     388                break;
     389            case CIRCLE:
     390                g.fillOval(p.x - radius, p.y - radius, s.size, s.size);
     391                break;
     392            case TRIANGLE:
     393                g.fillPolygon(buildPolygon(p, radius, 3, Math.PI / 2));
     394                break;
     395            case PENTAGON:
     396                g.fillPolygon(buildPolygon(p, radius, 5, Math.PI / 2));
     397                break;
     398            case HEXAGON:
     399                g.fillPolygon(buildPolygon(p, radius, 6));
     400                break;
     401            case HEPTAGON:
     402                g.fillPolygon(buildPolygon(p, radius, 7, Math.PI / 2));
     403                break;
     404            case OCTAGON:
     405                g.fillPolygon(buildPolygon(p, radius, 8, Math.PI / 8));
     406                break;
     407            case NONAGON:
     408                g.fillPolygon(buildPolygon(p, radius, 9, Math.PI / 2));
     409                break;
     410            case DECAGON:
     411                g.fillPolygon(buildPolygon(p, radius, 10));
     412                break;
     413            default:
     414                throw new AssertionError();
    379415            }
    380416        }
     
    383419            g.setColor(strokeColor);
    384420            switch (s.symbol) {
    385                 case SQUARE:
    386                     g.drawRect(p.x - radius, p.y - radius, s.size - 1, s.size - 1);
    387                     break;
    388                 case CIRCLE:
    389                     g.drawOval(p.x - radius, p.y - radius, s.size - 1, s.size - 1);
    390                     break;
    391                 default:
    392                     throw new AssertionError();
     421            case SQUARE:
     422                g.drawRect(p.x - radius, p.y - radius, s.size - 1, s.size - 1);
     423                break;
     424            case CIRCLE:
     425                g.drawOval(p.x - radius, p.y - radius, s.size - 1, s.size - 1);
     426                break;
     427            case TRIANGLE:
     428                g.drawPolygon(buildPolygon(p, radius, 3, Math.PI / 2));
     429                break;
     430            case PENTAGON:
     431                g.drawPolygon(buildPolygon(p, radius, 5, Math.PI / 2));
     432                break;
     433            case HEXAGON:
     434                g.drawPolygon(buildPolygon(p, radius, 6));
     435                break;
     436            case HEPTAGON:
     437                g.drawPolygon(buildPolygon(p, radius, 7, Math.PI / 2));
     438                break;
     439            case OCTAGON:
     440                g.drawPolygon(buildPolygon(p, radius, 8, Math.PI / 8));
     441                break;
     442            case NONAGON:
     443                g.drawPolygon(buildPolygon(p, radius, 9, Math.PI / 2));
     444                break;
     445            case DECAGON:
     446                g.drawPolygon(buildPolygon(p, radius, 10));
     447                break;
     448            default:
     449                throw new AssertionError();
    393450            }
    394451            g.setStroke(new BasicStroke());
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r3967 r3968  
    3535    private ImageIcon disabledIcon;
    3636
    37     public enum SymbolShape { SQUARE, CIRCLE }
     37    public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON }
    3838    public enum HorizontalTextAlignment { LEFT, CENTER, RIGHT }
    3939    public enum VerticalTextAlignment { ABOVE, TOP, CENTER, BOTTOM, BELOW }
     
    206206        if (shapeKW == null)
    207207            return null;
    208         if (equal(shapeKW, "square")) {
     208        if (equal(shapeKW.val, "square")) {
    209209            shape = SymbolShape.SQUARE;
    210         } else if (equal(shapeKW, "circle")) {
     210        } else if (equal(shapeKW.val, "circle")) {
    211211            shape = SymbolShape.CIRCLE;
     212        } else if (equal(shapeKW.val, "triangle")) {
     213            shape = SymbolShape.TRIANGLE;
     214        } else if (equal(shapeKW.val, "pentagon")) {
     215            shape = SymbolShape.PENTAGON;
     216        } else if (equal(shapeKW.val, "hexagon")) {
     217            shape = SymbolShape.HEXAGON;
     218        } else if (equal(shapeKW.val, "heptagon")) {
     219            shape = SymbolShape.HEPTAGON;
     220        } else if (equal(shapeKW.val, "octagon")) {
     221            shape = SymbolShape.OCTAGON;
     222        } else if (equal(shapeKW.val, "nonagon")) {
     223            shape = SymbolShape.NONAGON;
     224        } else if (equal(shapeKW.val, "decagon")) {
     225            shape = SymbolShape.DECAGON;
    212226        } else
    213227            return null;
Note: See TracChangeset for help on using the changeset viewer.