processing/processing

Add support for dashed / dotted lines

Fechada

#4.207 aberto em 18 de dez. de 2015

 (1 comentário) (1 reação) (0 responsável)Java (1.540 forks)batch import
help wanted

Métricas do repositório

Stars
 (6.431 estrelas)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

There is currently not an easy way to set a stroke to be a dashed line.

JavaFX has built in support for rendering strokes as dashed lines in the GraphicsContext class which is used by the FX2D rendered: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/canvas/GraphicsContext.html#setLineDashes-double...-

Here is a quick proof of concept code I added to PGraphicsFX2D.java to add APIs to enabled dashed lines:

  public void strokeDash(double width, double offset) {
    double[] dashes = { width };
    context.setLineDashOffset(offset);
    context.setLineDashes(dashes);
  }

  public void noDash() {
    context.setLineDashOffset(0.0);
    context.setLineDashes(null);
  }

It is also possible to add to the default renderer (here is some processing 2 code i wrote to add dashed lines):

import java.awt.BasicStroke;
import java.awt.Graphics2D;
void strokeDash(float width) {

    BasicStroke pen;
    float[] dashes = { 2.0f};
    pen = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 4.0f, dashes, 0.0f);

    Graphics2D g2 = ((PGraphicsJava2D) g).g2;
    g2.setStroke(pen);
}

Is this an API that the team would consider adding to processing?

Guia do colaborador