Ignore:
Timestamp:
2014-03-20T15:14:02+01:00 (12 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified applications/editors/josm/plugins/smed2/src/render/Renderer.java ΒΆ

    r30323 r30333  
    529529       
    530530        public static void lightSector(Feature feature, Color col1, Color col2, double radius, double s1, double s2, boolean dir, String str) {
    531 //      private static Point2D.Double radial(Feature feature, Snode centre, double radius, double angle) {
    532 //      Point2D origin = Renderer.context.getPoint(centre);
    533 //      return new Point2D.Double(origin.getX() - (radius * Renderer.context.mile(feature) * Math.sin(angle)), origin.getY() - (radius * Renderer.context.mile(feature) * Math.cos(angle)));
    534 //}
    535 
     531                if ((zoom >= 16) && (radius > 0.2)) {
     532                        radius = 0.2 / (Math.pow(2, zoom-16));
     533                }
     534                double mid = (((s1 + s2)  / 2) + (s1 > s2 ? 180 : 0)) % 360;
     535                g2.setStroke(new BasicStroke((float) (3.0 * sScale), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1, new float[] {20 * (float)sScale, 20 * (float)sScale}, 0));
     536                g2.setPaint(Color.black);
     537                Point2D.Double centre = (Point2D.Double) context.getPoint(feature.geom.centre);
     538                double radial = radius * context.mile(feature);
     539                if (dir) {
     540                        g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(mid)), centre.y + radial * Math.cos(Math.toRadians(mid))));
     541                } else {
     542                        g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(s1)), centre.y + radial * Math.cos(Math.toRadians(s1))));
     543                        g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(s2)), centre.y + radial * Math.cos(Math.toRadians(s2))));
     544                }
     545                double arcWidth =  10.0 * sScale;
     546                g2.setStroke(new BasicStroke((float)arcWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1));
     547                g2.setPaint(col1);
     548                g2.draw(new Arc2D.Double(centre.x - radial, centre.y - radial, 2 * radial, 2 * radial, -(s1 + 90), (s1 - s2 - 360) % 360, Arc2D.OPEN));
     549                if (col2 != null) {
     550                        g2.setPaint(col2);
     551                        g2.draw(new Arc2D.Double(centre.x - radial + arcWidth, centre.y - radial + arcWidth, 2 * (radial - arcWidth), 2 * (radial - arcWidth), -(s1 + 90), (s1 - s2 - 360) % 360, Arc2D.OPEN));
     552                }
     553                if ((str != null) && (!str.isEmpty())) {
     554                        g2.setPaint(Color.black);
     555                        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     556            FontRenderContext frc = g2.getFontRenderContext();
     557            Font font = new Font("Arial", Font.PLAIN, 40);
     558            GeneralPath path = new GeneralPath();
     559            GlyphVector gv = font.deriveFont((float)(font.getSize()*sScale)).createGlyphVector(frc, (" " + str));
     560                        double gwidth = gv.getLogicalBounds().getWidth();
     561                        boolean hand = false;
     562            double offset = 0;
     563            Point2D origin;
     564                        double arc = (s2 - s1 + 360) % 360;
     565                        if (dir) {
     566                                radial += 10 * sScale;
     567                                if (mid < 180) {
     568                                        radial += gwidth;
     569                                        hand = true;
     570                                }
     571                                origin = new Point2D.Double(centre.x - radial * Math.sin(Math.toRadians(mid)), centre.y + radial * Math.cos(Math.toRadians(mid)));
     572                    int length = gv.getNumGlyphs();
     573                    for (int i = 0; i < length; i++) {
     574                                        Shape shape = gv.getGlyphOutline(i);
     575                                        Point2D point = gv.getGlyphPosition(i);
     576                                        AffineTransform at = AffineTransform.getTranslateInstance(origin.getX(), origin.getY());
     577                                        at.rotate(Math.toRadians(mid + (hand ? -90 : 90)));
     578                                        at.translate(-point.getX() + offset, -point.getY() + (15 * sScale));
     579                                        path.append(at.createTransformedShape(shape), false);
     580                                        offset += gv.getGlyphMetrics(i).getAdvance();
     581                                        g2.fill(path);
     582                    }
     583                        } else {
     584                                double awidth = (Math.toRadians(arc) * radial);
     585                                if (gwidth < awidth) {
     586                                        offset = 0;
     587                                        double phi = 0;
     588                                        if ((mid > 270) || (mid < 90)) {
     589                                                hand = true;
     590                                                phi = Math.toRadians(s2) - ((awidth - gwidth) / 2) /radial;
     591                                                radial -= 20 * sScale;
     592                                        } else {
     593                                                phi = Math.toRadians(s1) + (((awidth - gwidth) / 2)) /radial;
     594                                                radial += 20 * sScale;
     595                                        }
     596                                        origin = new Point2D.Double(centre.x - radial * Math.sin(phi), centre.y + radial * Math.cos(phi));
     597                            int length = gv.getNumGlyphs();
     598                            for (int i = 0; i < length; i++) {
     599                                                Shape shape = gv.getGlyphOutline(i);
     600                                                Point2D point = gv.getGlyphPosition(i);
     601                                                AffineTransform at = AffineTransform.getTranslateInstance(origin.getX(), origin.getY());
     602                                                at.rotate(phi + (hand ? 0 : Math.toRadians(180)));
     603                                                at.translate(-point.getX() + offset, -point.getY());
     604                                                path.append(at.createTransformedShape(shape), false);
     605                                                double advance = gv.getGlyphMetrics(i).getAdvance();
     606                                                offset += advance;
     607                                                phi += (hand ? -0.5 : +0.5) * advance / radial;
     608                                                g2.fill(path);
     609                            }
     610                                }
     611                        }
     612                }
    536613        }
    537614}
Note: See TracChangeset for help on using the changeset viewer.