Java Code Examples for javafx.scene.canvas.GraphicsContext#strokeLine()

The following examples show how to use javafx.scene.canvas.GraphicsContext#strokeLine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FXPaintUtils.java    From gef with Eclipse Public License 2.0 7 votes vote down vote up
/**
 * Creates a rectangular {@link Image} to visualize the given {@link Paint}.
 *
 * @param width
 *            The width of the resulting {@link Image}.
 * @param height
 *            The height of the resulting {@link Image}.
 * @param paint
 *            The {@link Paint} to use for filling the {@link Image}.
 * @return The resulting (filled) {@link Image}.
 */
public static ImageData getPaintImageData(int width, int height, Paint paint) {
	// use JavaFX canvas to render a rectangle with the given paint
	Canvas canvas = new Canvas(width, height);
	GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
	graphicsContext.setFill(paint);
	graphicsContext.fillRect(0, 0, width, height);
	graphicsContext.setStroke(Color.BLACK);
	graphicsContext.strokeRect(0, 0, width, height);
	// handle transparent color separately (we want to differentiate it from
	// transparent fill)
	if (paint instanceof Color && ((Color) paint).getOpacity() == 0) {
		// draw a red line from bottom-left to top-right to indicate a
		// transparent fill color
		graphicsContext.setStroke(Color.RED);
		graphicsContext.strokeLine(0, height - 1, width, 1);
	}
	WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), null);
	return SWTFXUtils.fromFXImage(snapshot, null);
}
 
Example 2
Source File: SubcircuitPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFill(Color.WHITE);
	GuiUtils.drawShape(graphics::fillRect, this);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	if(mouseEntered) {
		double width = getScreenWidth();
		double height = getScreenHeight();
		
		graphics.setLineWidth(1.5);
		graphics.strokeOval(getScreenX() + (width - 13) / 2,
		                    getScreenY() + (height - 13) / 2,
		                    13,
		                    13);
		
		graphics.setLineWidth(2.5);
		graphics.strokeLine(getScreenX() + width / 2 + 4.6,
		                    getScreenY() + height / 2 + 4.6,
		                    getScreenX() + width / 2 + 10,
		                    getScreenY() + height / 2 + 10);
	}
}
 
Example 3
Source File: TileMap.java    From mcaselector with MIT License 6 votes vote down vote up
private void drawChunkGrid(GraphicsContext ctx) {
	ctx.setLineWidth(Tile.GRID_LINE_WIDTH);
	ctx.setStroke(Tile.CHUNK_GRID_COLOR.makeJavaFXColor());

	Point2f p = getChunkGridMin(offset, scale);
	Point2f pReg = getRegionGridMin(offset, scale);

	for (float x = p.getX() + Tile.CHUNK_SIZE / scale; x <= getWidth(); x += Tile.CHUNK_SIZE / scale) {
		if (showRegionGrid && (int) (pReg.getX() + Tile.SIZE / scale) == (int) x) {
			pReg.setX(pReg.getX() + Tile.SIZE / scale);
			continue;
		}

		ctx.strokeLine(x, 0, x, getHeight());
	}

	for (float y = p.getY() + Tile.CHUNK_SIZE / scale; y <= getHeight(); y += Tile.CHUNK_SIZE / scale) {
		if (showRegionGrid && (int) (pReg.getY() + Tile.SIZE / scale) == (int) y) {
			pReg.setY(pReg.getY() + Tile.SIZE / scale);
			continue;
		}
		ctx.strokeLine(0, y, getWidth(), y);
	}
}
 
Example 4
Source File: RadialBargraphSkin.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    double  sinValue;
    double  cosValue;
    double  startAngle = getSkinnable().getStartAngle();
    Point2D center     = new Point2D(size * 0.5, size * 0.5);
    for (double angle = 0, counter = getSkinnable().getMinValue() ; Double.compare(counter, getSkinnable().getMaxValue()) <= 0 ; angle -= angleStep, counter++) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerPoint = new Point2D(center.getX() + size * 0.388 * sinValue, center.getY() + size * 0.388 * cosValue);
        Point2D outerPoint = new Point2D(center.getX() + size * 0.485 * sinValue, center.getY() + size * 0.485 * cosValue);

        CTX.setStroke(getSkinnable().getTickMarkFill());
        if (counter % getSkinnable().getMinorTickSpace() == 0) {
            CTX.setLineWidth(size * 0.0035);
            CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY());
        }
    }
}
 
Example 5
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawTransform(Transform xf) {
  GraphicsContext g = getGraphics();
  getWorldToScreenToOut(xf.p, temp);
  temp2.setZero();
  float k_axisScale = 0.4f;

  Color c = cpool.getColor(1, 0, 0);
  g.setStroke(c);

  temp2.x = xf.p.x + k_axisScale * xf.q.c;
  temp2.y = xf.p.y + k_axisScale * xf.q.s;
  getWorldToScreenToOut(temp2, temp2);
  g.strokeLine(temp.x, temp.y, temp2.x, temp2.y);

  c = cpool.getColor(0, 1, 0);
  g.setStroke(c);
  temp2.x = xf.p.x + -k_axisScale * xf.q.s;
  temp2.y = xf.p.y + k_axisScale * xf.q.c;
  getWorldToScreenToOut(temp2, temp2);
  g.strokeLine(temp.x, temp.y, temp2.x, temp2.y);
}
 
Example 6
Source File: GuiUtils.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Draws a clock input (triangle symbol) facing the southern border
 */
public static void drawClockInput(GraphicsContext graphics, Connection connection, Direction direction) {
	double x = connection.getScreenX() + connection.getScreenWidth() * 0.5;
	double y = connection.getScreenY() + connection.getScreenWidth() * 0.5;
	
	switch(direction) {
		case NORTH:
			graphics.strokeLine(x - 5, y, x, y + 6);
			graphics.strokeLine(x, y + 6, x + 5, y);
			break;
		case SOUTH:
			graphics.strokeLine(x - 5, y, x, y - 6);
			graphics.strokeLine(x, y - 6, x + 5, y);
			break;
		case EAST:
			graphics.strokeLine(x, y - 5, x - 6, y);
			graphics.strokeLine(x - 6, y, x, y + 5);
			break;
		case WEST:
			graphics.strokeLine(x, y - 5, x + 6, y);
			graphics.strokeLine(x + 6, y, x, y + 5);
			break;
	}
}
 
Example 7
Source File: Text.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState state) {
	graphics.setFill(Color.BLACK);
	graphics.setStroke(Color.BLACK);
	
	graphics.setLineWidth(2);
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	if(text.isEmpty()) {
		graphics.drawImage(textImage, x, y, width, height);
	} else {
		graphics.setFont(GuiUtils.getFont(13));
		for(int i = 0; i < lines.size(); i++) {
			String line = lines.get(i);
			Bounds bounds = GuiUtils.getBounds(graphics.getFont(), line, false);
			
			graphics.fillText(line,
			                  x + (width - bounds.getWidth()) * 0.5,
			                  y + 15 * (i + 1));
			
			if(entered && i == lines.size() - 1) {
				double lx = x + (width + bounds.getWidth()) * 0.5 + 3;
				double ly = y + 15 * (i + 1);
				graphics.strokeLine(lx, ly - 10, lx, ly);
			}
		}
	}
}
 
Example 8
Source File: Region.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
/** Draw the crisp border of a rectangle without filling it */
static void strokeRectangle(GraphicsContext gc, int x1, int y1, int x2, int y2) {
	final double antiAlias = gc.getLineWidth() % 2 != 0 ? 0.5 : 0;
	double x1a = x1 + antiAlias;
	double y1a = y1 + antiAlias;
	double x2a = x2 - antiAlias;
	double y2a = y2 - antiAlias;

	gc.strokeLine(x1a, y1a, x2a, y1a); //top left to top right
	gc.strokeLine(x2a, y1a, x2a, y2a); //top right to bottom right
	gc.strokeLine(x2a, y2a, x1a, y2a); //bottom right to bottom left
	gc.strokeLine(x1a, y2a, x1a, y1a); //bottom left to top left
}
 
Example 9
Source File: GridComponent.java    From FXGLGames with MIT License 5 votes vote down vote up
void update(GraphicsContext g) {
    position1.x = end11.getPosition().x + (end12.getPosition().x - end11.getPosition().x) / 2;
    position1.y = end11.getPosition().y + (end12.getPosition().y - end11.getPosition().y) / 2;

    position2.x = end21.getPosition().x + (end22.getPosition().x - end21.getPosition().x) / 2;
    position2.y = end21.getPosition().y + (end22.getPosition().y - end21.getPosition().y) / 2;

    g.strokeLine(position1.x, position1.y, position2.x, position2.y);
}
 
Example 10
Source File: Hexagon.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public void drawHexagon(final GraphicsContext gc, Direction... directions) {
    final ObservableList<Double> points = getPoints();
    final int nPoints = points.size() / 2;
    final double[] xPoints = new double[nPoints];
    final double[] yPoints = new double[nPoints];
    for (int i = 0; i < nPoints; i++) {
        xPoints[i] = 0.5 + Math.round(points.get(2 * i));
        yPoints[i] = 0.5 + Math.round(points.get(2 * i + 1));
    }
    gc.fillPolygon(xPoints, yPoints, nPoints);

    for (final Direction side : directions) {
        switch (side) {
        case EAST:
            gc.strokeLine(xPoints[0], yPoints[0], xPoints[1], yPoints[1]);
            break;
        case NORTHEAST:
            gc.strokeLine(xPoints[1], yPoints[1], xPoints[2], yPoints[2]);
            break;
        case NORTHWEST:
            gc.strokeLine(xPoints[2], yPoints[2], xPoints[3], yPoints[3]);
            break;
        case WEST:
            gc.strokeLine(xPoints[3], yPoints[3], xPoints[4], yPoints[4]);
            break;
        case SOUTHWEST:
            gc.strokeLine(xPoints[4], yPoints[4], xPoints[5], yPoints[5]);
            break;
        case SOUTHEAST:
            gc.strokeLine(xPoints[5], yPoints[5], xPoints[0], yPoints[0]);
            break;
        default:
            break;
        }
    }
    // gc.strokePolygon(xPoints, yPoints, nPoints);
}
 
Example 11
Source File: Button.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState state) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));

	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	int offset = 3;
	
	graphics.setStroke(Color.BLACK);
	
	if(isPressed) {
		graphics.setFill(Color.WHITE);
	} else {
		graphics.setFill(Color.DARKGRAY);
	}
	
	graphics.fillRect(x + offset, y + offset, width - offset, height - offset);
	graphics.strokeRect(x + offset, y + offset, width - offset, height - offset);
	
	if(!isPressed) {
		graphics.setFill(Color.WHITE);
		
		graphics.fillRect(x, y, width - offset, height - offset);
		graphics.strokeRect(x, y, width - offset, height - offset);
		
		graphics.strokeLine(x, y + height - offset, x + offset, y + height);
		graphics.strokeLine(x + width - offset, y, x + width, y + offset);
		graphics.strokeLine(x + width - offset, y + height - offset, x + width, y + height);
	}
}
 
Example 12
Source File: GaugeSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    if (getSkinnable().isHistogramEnabled()) {
        double xy;
        double wh;
        double step         = 0;
        double OFFSET       = 90 - getSkinnable().getStartAngle();
        double ANGLE_EXTEND = (getSkinnable().getMaxValue()) * angleStep;
        CTX.setStroke(Color.rgb(200, 200, 200));
        CTX.setLineWidth(size * 0.001);
        CTX.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0 ; i < 5 ; i++) {
            xy = (size - (0.435 + step) * size) / 2;
            wh = size * (0.435 + step);
            CTX.strokeArc(xy, xy, wh, wh, -OFFSET, -ANGLE_EXTEND, ArcType.OPEN);
            step += 0.075;
        }
    }

    double  sinValue;
    double  cosValue;
    double  startAngle = getSkinnable().getStartAngle();
    double  orthText   = Gauge.TickLabelOrientation.ORTHOGONAL == getSkinnable().getTickLabelOrientation() ? 0.33 : 0.31;
    Point2D center     = new Point2D(size * 0.5, size * 0.5);
    for (double angle = 0, counter = getSkinnable().getMinValue() ; Double.compare(counter, getSkinnable().getMaxValue()) <= 0 ; angle -= angleStep, counter++) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerMainPoint   = new Point2D(center.getX() + size * 0.368 * sinValue, center.getY() + size * 0.368 * cosValue);
        Point2D innerMediumPoint = new Point2D(center.getX() + size * 0.388 * sinValue, center.getY() + size * 0.388 * cosValue);
        Point2D innerMinorPoint  = new Point2D(center.getX() + size * 0.3975 * sinValue, center.getY() + size * 0.3975 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + size * 0.432 * sinValue, center.getY() + size * 0.432 * cosValue);
        Point2D textPoint        = new Point2D(center.getX() + size * orthText * sinValue, center.getY() + size * orthText * cosValue);

        CTX.setStroke(getSkinnable().getTickMarkFill());
        if (counter % getSkinnable().getMajorTickSpace() == 0) {
            // Draw major tickmark
            CTX.setLineWidth(size * 0.0055);
            CTX.strokeLine(innerMainPoint.getX(), innerMainPoint.getY(), outerPoint.getX(), outerPoint.getY());

            // Draw text
            CTX.save();
            CTX.translate(textPoint.getX(), textPoint.getY());
            switch(getSkinnable().getTickLabelOrientation()) {
                case ORTHOGONAL:
                    if ((360 - startAngle - angle) % 360 > 90 && (360 - startAngle - angle) % 360 < 270) {
                        CTX.rotate((180 - startAngle - angle) % 360);
                    } else {
                        CTX.rotate((360 - startAngle - angle) % 360);
                    }
                    break;
                case TANGENT:
                    if ((360 - startAngle - angle - 90) % 360 > 90 && (360 - startAngle - angle - 90) % 360 < 270) {
                        CTX.rotate((90 - startAngle - angle) % 360);
                    } else {
                        CTX.rotate((270 - startAngle - angle) % 360);
                    }
                    break;
                case HORIZONTAL:
                default:
                    break;
            }
            CTX.setFont(Font.font("Verdana", FontWeight.NORMAL, 0.045 * size));
            CTX.setTextAlign(TextAlignment.CENTER);
            CTX.setTextBaseline(VPos.CENTER);
            CTX.setFill(getSkinnable().getTickLabelFill());
            CTX.fillText(Integer.toString((int) counter), 0, 0);
            CTX.restore();
        } else if (getSkinnable().getMinorTickSpace() % 2 != 0 && counter % 5 == 0) {
            CTX.setLineWidth(size * 0.0035);
            CTX.strokeLine(innerMediumPoint.getX(), innerMediumPoint.getY(), outerPoint.getX(), outerPoint.getY());
        } else if (counter % getSkinnable().getMinorTickSpace() == 0) {
            CTX.setLineWidth(size * 0.00225);
            CTX.strokeLine(innerMinorPoint.getX(), innerMinorPoint.getY(), outerPoint.getX(), outerPoint.getY());
        }
    }
}
 
Example 13
Source File: ModernSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    double               sinValue;
    double               cosValue;
    double               centerX                = size * 0.5;
    double               centerY                = size * 0.5;
    double               minorTickSpace         = gauge.getMinorTickSpace();
    double               minValue               = gauge.getMinValue();
    double               maxValue               = gauge.getMaxValue();
    double               tmpAngleStep           = angleStep * minorTickSpace;
    int                  decimals               = gauge.getTickLabelDecimals();
    BigDecimal           minorTickSpaceBD       = BigDecimal.valueOf(minorTickSpace);
    BigDecimal           majorTickSpaceBD       = BigDecimal.valueOf(gauge.getMajorTickSpace());
    BigDecimal           mediumCheck2           = BigDecimal.valueOf(2 * minorTickSpace);
    BigDecimal           mediumCheck5           = BigDecimal.valueOf(5 * minorTickSpace);
    BigDecimal           counterBD              = BigDecimal.valueOf(minValue);
    double               counter                = minValue;
    boolean              majorTickMarksVisible  = gauge.getMajorTickMarksVisible();
    boolean              mediumTickMarksVisible = gauge.getMediumTickMarksVisible();
    boolean              tickLabelsVisible      = gauge.getTickLabelsVisible();
    TickLabelOrientation tickLabelOrientation   = gauge.getTickLabelOrientation();
    Color                tickMarkColor          = gauge.getTickMarkColor();
    Color                majorTickMarkColor     = tickMarkColor;
    Color                mediumTickMarkColor    = tickMarkColor;
    Color                tickLabelColor         = gauge.getTickLabelColor();

    double innerPointX;
    double innerPointY;
    double outerPointX;
    double outerPointY;
    double innerMediumPointX;
    double innerMediumPointY;
    double outerMediumPointX;
    double outerMediumPointY;
    double textPointX;
    double textPointY;

    double orthTextFactor = 0.46; //TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.46 : 0.46;

    Font tickLabelFont = Fonts.robotoCondensedLight((decimals == 0 ? 0.047 : 0.040) * size);
    CTX.setFont(tickLabelFont);
    CTX.setTextAlign(TextAlignment.CENTER);
    CTX.setTextBaseline(VPos.CENTER);

    CTX.setLineCap(StrokeLineCap.BUTT);
    CTX.setLineWidth(size * 0.0035);
    for (double angle = 0 ; Double.compare(-ANGLE_RANGE - tmpAngleStep, angle) < 0 ; angle -= tmpAngleStep) {
        sinValue = Math.sin(Math.toRadians(angle + START_ANGLE));
        cosValue = Math.cos(Math.toRadians(angle + START_ANGLE));

        innerPointX       = centerX + size * 0.375 * sinValue;
        innerPointY       = centerY + size * 0.375 * cosValue;
        outerPointX       = centerX + size * 0.425 * sinValue;
        outerPointY       = centerY + size * 0.425 * cosValue;
        innerMediumPointX = centerX + size * 0.35 * sinValue;
        innerMediumPointY = centerY + size * 0.35 * cosValue;
        outerMediumPointX = centerX + size * 0.4 * sinValue;
        outerMediumPointY = centerY + size * 0.4 * cosValue;
        textPointX        = centerX + size * orthTextFactor * sinValue;
        textPointY        = centerY + size * orthTextFactor * cosValue;

        // Set the general tickmark color
        CTX.setStroke(tickMarkColor);

        if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) {
            // Draw major tick mark
            if (majorTickMarksVisible) {
                CTX.setFill(majorTickMarkColor);
                CTX.setStroke(majorTickMarkColor);
                CTX.strokeLine(innerPointX, innerPointY, outerPointX, outerPointY);
            }
            // Draw tick label text
            if (tickLabelsVisible) {
                CTX.save();
                CTX.translate(textPointX, textPointY);

                Helper.rotateContextForText(CTX, START_ANGLE, angle, tickLabelOrientation);

                CTX.setFill(tickLabelColor);
                if (TickLabelOrientation.HORIZONTAL == tickLabelOrientation &&
                    (Double.compare(counter, minValue) == 0 ||
                    Double.compare(counter, maxValue) == 0)) {
                        CTX.setFill(Color.TRANSPARENT);
                }
                CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0);
                CTX.restore();
            }
        } else if (mediumTickMarksVisible &&
                   Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 &&
                   Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) {
            // Draw medium tick mark
            CTX.setFill(mediumTickMarkColor);
            CTX.setStroke(mediumTickMarkColor);
            CTX.strokeLine(innerMediumPointX, innerMediumPointY, outerMediumPointX, outerMediumPointY);
        }
        counterBD = counterBD.add(minorTickSpaceBD);
        counter   = counterBD.doubleValue();
    }
}
 
Example 14
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
protected static void drawPolyLineHistogram(final GraphicsContext gc, final CachedDataPoints localCachedPoints) {
    final int n = localCachedPoints.actualDataCount;
    if (n == 0) {
        return;
    }

    // need to allocate new array :-(
    final double[] newX = DoubleArrayCache.getInstance().getArrayExact(2 * (n + 1));
    final double[] newY = DoubleArrayCache.getInstance().getArrayExact(2 * (n + 1));

    final double xRange = localCachedPoints.xMax - localCachedPoints.xMin;
    double diffLeft;
    double diffRight = n > 0 ? 0.5 * (localCachedPoints.xValues[1] - localCachedPoints.xValues[0]) : 0.5 * xRange;
    newX[0] = localCachedPoints.xValues[0] - diffRight;
    newY[0] = localCachedPoints.yZero;
    for (int i = 0; i < n; i++) {
        diffLeft = localCachedPoints.xValues[i] - newX[2 * i];
        diffRight = i + 1 < n ? 0.5 * (localCachedPoints.xValues[i + 1] - localCachedPoints.xValues[i]) : diffLeft;
        if (i == 0) {
            diffLeft = diffRight;
        }

        newX[2 * i + 1] = localCachedPoints.xValues[i] - diffLeft;
        newY[2 * i + 1] = localCachedPoints.yValues[i];
        newX[2 * i + 2] = localCachedPoints.xValues[i] + diffRight;
        newY[2 * i + 2] = localCachedPoints.yValues[i];
    }
    // last point
    newX[2 * (n + 1) - 1] = localCachedPoints.xValues[n - 1] + diffRight;
    newY[2 * (n + 1) - 1] = localCachedPoints.yZero;

    gc.save();
    DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);
    DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle);

    for (int i = 0; i < 2 * (n + 1) - 1; i++) {
        final double x1 = newX[i];
        final double x2 = newX[i + 1];
        final double y1 = newY[i];
        final double y2 = newY[i + 1];
        gc.strokeLine(x1, y1, x2, y2);
    }

    gc.restore();

    // release arrays to cache
    DoubleArrayCache.getInstance().add(newX);
    DoubleArrayCache.getInstance().add(newY);
}
 
Example 15
Source File: GridComponent.java    From FXGLGames with MIT License 4 votes vote down vote up
void update(GraphicsContext g) {
    g.strokeLine(end1.getPosition().x, end1.getPosition().y, end2.getPosition().x, end2.getPosition().y);
}
 
Example 16
Source File: ClockPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	Port port = getComponent().getPort(Clock.PORT);
	if(circuitState.isShortCircuited(port.getLink())) {
		graphics.setFill(Color.RED);
	} else {
		GuiUtils.setBitColor(graphics, circuitState.getLastPushed(port).getBit(0));
	}
	GuiUtils.drawShape(graphics::fillRect, this);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setStroke(Color.WHITE);
	graphics.setLineWidth(1.5);
	double offset1 = Clock.getTickState(getComponent().getCircuit().getSimulator()) ? 0.3 : 0;
	double offset2 = Clock.getTickState(getComponent().getCircuit().getSimulator()) ? 0.6 : 0;
	
	// lower line
	graphics.strokeLine(getScreenX() + getScreenWidth() * (0.2 + offset1),
	                    getScreenY() + getScreenHeight() * 0.7,
	                    getScreenX() + getScreenWidth() * (0.5 + offset1),
	                    getScreenY() + getScreenHeight() * 0.7);
	
	// upper line
	graphics.strokeLine(getScreenX() + getScreenWidth() * (0.5 - offset1),
	                    getScreenY() + getScreenHeight() * 0.3,
	                    getScreenX() + getScreenWidth() * (0.8 - offset1),
	                    getScreenY() + getScreenHeight() * 0.3);
	
	// lower vertical line
	graphics.strokeLine(getScreenX() + getScreenWidth() * (0.2 + offset2),
	                    getScreenY() + getScreenHeight() * 0.5,
	                    getScreenX() + getScreenWidth() * (0.2 + offset2),
	                    getScreenY() + getScreenHeight() * 0.7);
	
	// upper vetical line line
	graphics.strokeLine(getScreenX() + getScreenWidth() * (0.8 - offset2),
	                    getScreenY() + getScreenHeight() * 0.3,
	                    getScreenX() + getScreenWidth() * (0.8 - offset2),
	                    getScreenY() + getScreenHeight() * 0.5);
	
	// middle vertical line
	graphics.strokeLine(getScreenX() + getScreenWidth() * 0.5,
	                    getScreenY() + getScreenHeight() * 0.3,
	                    getScreenX() + getScreenWidth() * 0.5,
	                    getScreenY() + getScreenHeight() * 0.7);
}
 
Example 17
Source File: LabelledMarkerRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws vertical markers with vertical (default) labels attached to the top
 *
 * @param gc the graphics context from the Canvas parent
 * @param chart instance of the calling chart
 * @param dataSet instance of the data set that is supposed to be drawn
 * @param indexMin minimum index of data set to be drawn
 * @param indexMax maximum index of data set to be drawn
 */
protected void drawVerticalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet,
        final int indexMin, final int indexMax) {
    Axis xAxis = this.getFirstAxis(Orientation.HORIZONTAL);
    if (xAxis == null) {
        xAxis = chart.getFirstAxis(Orientation.HORIZONTAL);
    }
    if (xAxis == null) {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.atWarn().addArgument(LabelledMarkerRenderer.class.getSimpleName()).log("{}::drawVerticalLabelledMarker(...) getFirstAxis(HORIZONTAL) returned null skip plotting");
        }
        return;
    }

    gc.save();
    setGraphicsContextAttributes(gc, dataSet.getStyle());
    gc.setTextAlign(TextAlignment.LEFT);

    final double height = chart.getCanvas().getHeight();
    double lastLabel = -Double.MAX_VALUE;
    double lastFontSize = 0;
    for (int i = indexMin; i < indexMax; i++) {
        final double screenX = (int) xAxis.getDisplayPosition(dataSet.get(DataSet.DIM_X, i));
        final String label = dataSet.getDataLabel(i);
        if (label == null) {
            continue;
        }

        final String pointStyle = dataSet.getStyle(i);

        if (pointStyle != null) {
            gc.save();
            setGraphicsContextAttributes(gc, pointStyle);
        }

        gc.strokeLine(screenX, 0, screenX, height);

        if (Math.abs(screenX - lastLabel) > lastFontSize && !label.isEmpty()) {
            gc.save();
            gc.setLineWidth(0.8);
            gc.setLineDashes(1.0);
            gc.translate(Math.ceil(screenX + 3), Math.ceil(0.01 * height));
            gc.rotate(+90);
            gc.fillText(label, 0.0, 0);
            gc.restore();
            lastLabel = screenX;
            lastFontSize = gc.getFont().getSize();
        }
        if (pointStyle != null) {
            gc.restore();
        }
    }
    gc.restore();
}
 
Example 18
Source File: LabelledMarkerRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws horizontal markers with horizontal (default) labels attached to the top
 *
 * @param gc the graphics context from the Canvas parent
 * @param chart instance of the calling chart
 * @param dataSet instance of the data set that is supposed to be drawn
 * @param indexMin minimum index of data set to be drawn
 * @param indexMax maximum index of data set to be drawn
 */
protected void drawHorizontalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet,
        final int indexMin, final int indexMax) {
    final Axis yAxis = this.getFirstAxis(Orientation.VERTICAL, chart);

    gc.save();
    setGraphicsContextAttributes(gc, dataSet.getStyle());
    gc.setTextAlign(TextAlignment.RIGHT);

    final double width = chart.getCanvas().getWidth();
    double lastLabel = -Double.MAX_VALUE;
    double lastFontSize = 0;
    for (int i = indexMin; i < indexMax; i++) {
        final double screenY = (int) yAxis.getDisplayPosition(dataSet.get(DataSet.DIM_Y, i));
        final String label = dataSet.getDataLabel(i);
        if (label == null) {
            continue;
        }

        final String pointStyle = dataSet.getStyle(i);
        if (pointStyle != null) {
            gc.save();
            setGraphicsContextAttributes(gc, pointStyle);
        }

        gc.strokeLine(0, screenY, width, screenY);

        if (Math.abs(screenY - lastLabel) > lastFontSize && !label.isEmpty()) {
            gc.save();
            gc.setLineWidth(0.8);
            gc.setLineDashes(1.0);
            gc.translate(Math.ceil(screenY + 3), Math.ceil(0.99 * width));
            gc.fillText(label, 0.0, 0);
            gc.restore();
            lastLabel = screenY;
            lastFontSize = gc.getFont().getSize();
        }

        if (pointStyle != null) {
            gc.restore();
        }
    }
    gc.restore();
}
 
Example 19
Source File: GanttTaskCell.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * draw all separators in the gantt task cell
 * 
 * @param gc                     graphics context
 * @param startdatedisplaywindow start date (first day) of the display window
 * @param enddatedisplaywindow   end date (last day) of the display window
 * @param ystarthour             start hour of the planning
 * @param ystartday              start day of the planning
 * @param yend                   end of the cell in pixel
 * @param totalwidth             total width in pixel
 * @param businesscalendar       business calendar to use for displaying of
 *                               opening hours
 * @param extraxoffset           extra offset in the display
 */
public static void drawSeparators(
		GraphicsContext gc,
		Date startdatedisplaywindow,
		Date enddatedisplaywindow,
		double ystarthour,
		double ystartday,
		double yend,
		double totalwidth,
		BusinessCalendar businesscalendar,
		float extraxoffset) {
	Date[] separatorstoconsider = DateUtils.getAllStartOfDays(startdatedisplaywindow, enddatedisplaywindow,
			businesscalendar);
	boolean isreduceddisplay = isReducedDisplay(separatorstoconsider);

	for (int i = 0; i < separatorstoconsider.length; i++) {
		if (isreduceddisplay) {
			gc.setLineWidth(0.5);

			gc.setStroke(GanttTaskCell.SCALE_LIGHT_GRAY);
		}
		if (!isreduceddisplay) {
			gc.setLineWidth(1);

			gc.setStroke(GanttTaskCell.SCALE_GRAY);
		}

		gc.setEffect(null);
		Date separatortoprint = separatorstoconsider[i];
		if (isMonday(separatortoprint)) {
			gc.setStroke(GanttTaskCell.SCALE_GRAY);
			if (!isreduceddisplay)
				gc.setLineWidth(2);
			if (isreduceddisplay)
				gc.setLineWidth(1);

		}
		double separatorratio = DateUtils.genericDateToCoordinates(separatortoprint, startdatedisplaywindow,
				enddatedisplaywindow, businesscalendar).getValue();
		gc.strokeLine((long) (separatorratio * totalwidth + extraxoffset), (long) ystartday,
				(long) (separatorratio * totalwidth + extraxoffset), (long) (yend));
		if (!isreduceddisplay)
			if (separatorstoconsider.length < 30) {
				for (int j = businesscalendar.getDaywindowhourstart() + 1; j < businesscalendar
						.getDaywindowhourend(); j++) {
					Date hour = new Date(separatortoprint.getTime()
							+ (j - businesscalendar.getDaywindowhourstart()) * 3600 * 1000);
					double hourratio = DateUtils.genericDateToCoordinates(hour, startdatedisplaywindow,
							enddatedisplaywindow, businesscalendar).getValue();
					gc.setStroke(GanttTaskCell.SCALE_LIGHT_GRAY);
					gc.setLineWidth(0.5);

					gc.setEffect(null);
					gc.strokeLine((long) (hourratio * totalwidth + extraxoffset), (long) (ystarthour),
							(long) (hourratio * totalwidth + extraxoffset), (long) (yend));

				}
			}
	}

}
 
Example 20
Source File: ViewUtils.java    From JetUML with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Draws a line with default attributes and a specified line style.
 * 
 * @param pGraphics The graphics context.
 * @param pX1 The x-coordinate of the first point
 * @param pY1 The y-coordinate of the first point
 * @param pX2 The x-coordinate of the second point
 * @param pY2 The y-coordinate of the second point
 * @param pStyle The line style for the path.
 */
public static void drawLine(GraphicsContext pGraphics, int pX1, int pY1, int pX2, int pY2, LineStyle pStyle)
{
	double[] oldDash = pGraphics.getLineDashes();
	pGraphics.setLineDashes(pStyle.getLineDashes());
	pGraphics.strokeLine(pX1 + 0.5, pY1 + 0.5, pX2 + 0.5, pY2 + 0.5);
	pGraphics.setLineDashes(oldDash);
}