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

The following examples show how to use javafx.scene.canvas.GraphicsContext#setFill() . 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: DiagramCanvas.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints the panel and all the graph elements in aDiagramView.
 * Called after the panel is resized.
 */
public void paintPanel()
{
	GraphicsContext context = getGraphicsContext2D();
	context.setFill(Color.WHITE); 
	context.fillRect(0, 0, getWidth(), getHeight());
	if(UserPreferences.instance().getBoolean(BooleanPreference.showGrid)) 
	{
		Grid.draw(context, new Rectangle(0, 0, (int) getWidth(), (int) getHeight()));
	}
	DiagramType.viewerFor(aDiagram).draw(aDiagram, context);
	aController.synchronizeSelectionModel();
	aController.getSelectionModel().forEach( selected -> ViewerUtilities.drawSelectionHandles(selected, context));
	aController.getSelectionModel().getRubberband().ifPresent( rubberband -> ToolGraphics.drawRubberband(context, rubberband));
	aController.getSelectionModel().getLasso().ifPresent( lasso -> ToolGraphics.drawLasso(context, lasso));
}
 
Example 2
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Strokes and fills a path, by converting the elements to integer coordinates and then
 * aligning them to the center of the pixels, so that it aligns precisely
 * with the JavaFX coordinate system. See the documentation for 
 * javafx.scene.shape.Shape for details.
 * 
 * @param pGraphics The graphics context.
 * @param pPath The path to stroke
 * @param pFill The fill color for the path.
 * @param pShadow True to include a drop shadow.
 */
public static void strokeAndFillSharpPath(GraphicsContext pGraphics, Path pPath, Paint pFill, boolean pShadow)
{
	double width = pGraphics.getLineWidth();
	Paint fill = pGraphics.getFill();
	pGraphics.setLineWidth(LINE_WIDTH);
	pGraphics.setFill(pFill);
	applyPath(pGraphics, pPath);
	
	if( pShadow )
	{
		pGraphics.setEffect(DROP_SHADOW);
	}
	pGraphics.fill();
	pGraphics.stroke();
	pGraphics.setLineWidth(width);
	pGraphics.setFill(fill);
	pGraphics.setEffect(null);
}
 
Example 3
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
  Color f = cpool.getColor(color.x, color.y, color.z, .4f);
  Color s = cpool.getColor(color.x, color.y, color.z, 1f);
  GraphicsContext g = getGraphics();
  saveState(g);
  double[] xs = xDoublePool.get(vertexCount);
  double[] ys = yDoublePool.get(vertexCount);
  for (int i = 0; i < vertexCount; i++) {
    getWorldToScreenToOut(vertices[i], temp);
    xs[i] = temp.x;
    ys[i] = temp.y;
  }
  g.setLineWidth(stroke);
  g.setFill(f);
  g.fillPolygon(xs, ys, vertexCount);
  g.setStroke(s);
  g.strokePolygon(xs, ys, vertexCount);
  restoreState(g);
}
 
Example 4
Source File: DefaultControlTreeItemGraphic.java    From arma-dialog-creator with MIT License 6 votes vote down vote up
private void fillBox(Color color) {
	GraphicsContext gc = box.getGraphicsContext2D();
	gc.save();
	gc.clearRect(0, 0, box.getWidth(), box.getHeight());
	gc.setFill(color);
	gc.fillRect(0, 0, box.getWidth(), box.getHeight());
	gc.restore();

	//generate hex string and bind it to tooltip
	final double f = 255.0;
	int r = (int) (color.getRed() * f);
	int g = (int) (color.getGreen() * f);
	int b = (int) (color.getBlue() * f);
	String opacity = DecimalFormat.getNumberInstance().format(color.getOpacity() * 100);

	Tooltip.install(box, new Tooltip(String.format(
			"red:%d, green:%d, blue:%d, opacity:%s%%", r, g, b, opacity))
	);
}
 
Example 5
Source File: DefaultRenderColorScheme.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public static void setFillScheme(final GraphicsContext gc, final String defaultStyle, final int dsIndex) {
    AssertUtils.gtEqThanZero("setFillScheme dsIndex", dsIndex);
    final Map<String, List<String>> map = splitQuery(defaultStyle);

    final Color fillColor = StyleParser.getColorPropertyValue(defaultStyle, XYChartCss.FILL_COLOR);
    if (fillColor != null) {
        final Color rawColor = fillColor;

        final Color color = getColorModifier(map, rawColor);
        if (color == null) {
            return;
        }

        final ImagePattern hatch = FillPatternStyleHelper.getDefaultHatch(color.brighter(),
                dsIndex * hatchShiftByIndexProperty().get());

        gc.setFill(hatch);
    } else {
        final int size = fillStylesProperty().size();
        gc.setFill(fillStylesProperty().get(dsIndex % size));
    }
}
 
Example 6
Source File: ControlledBufferPeer.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));
	GuiUtils.rotateGraphics(this, graphics, getProperties().getValue(Properties.DIRECTION));
	
	graphics.beginPath();
	graphics.moveTo(getScreenX(), getScreenY());
	graphics.lineTo(getScreenX() + getScreenWidth(), getScreenY() + getScreenHeight() * 0.5);
	graphics.lineTo(getScreenX(), getScreenY() + getScreenHeight());
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.fill();
	graphics.setStroke(Color.BLACK);
	graphics.stroke();
}
 
Example 7
Source File: MultiplierPeer.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);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(16, true));
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), "×");
	graphics.setFill(Color.BLACK);
	graphics.fillText("×",
	                  getScreenX() + (getScreenWidth() - bounds.getWidth()) * 0.5,
	                  getScreenY() + (getScreenHeight() + bounds.getHeight()) * 0.45);
}
 
Example 8
Source File: TileMap.java    From mcaselector with MIT License 5 votes vote down vote up
private void draw(GraphicsContext ctx) {
	ctx.setFill(Tile.EMPTY_CHUNK_BACKGROUND_COLOR.makeJavaFXColor());
	ctx.fillRect(0, 0, getWidth(), getHeight());
	runOnVisibleRegions(region -> {
		if (!tiles.containsKey(region)) {
			tiles.put(region, new Tile(region));
		}
		Tile tile = tiles.get(region);
		visibleTiles.add(tile);

		Point2i regionOffset = region.regionToBlock().sub((int) offset.getX(), (int) offset.getY());

		if (!tile.isLoaded() && !tile.isLoading()) {
			imgPool.requestImage(tile, getZoomLevel());
		}
		Point2f p = new Point2f(regionOffset.getX() / scale, regionOffset.getY() / scale);

		TileImage.draw(tile, ctx, scale, p);
	});

	if (showRegionGrid) {
		drawRegionGrid(ctx);
	}

	if (showChunkGrid && scale <= CHUNK_GRID_SCALE) {
		drawChunkGrid(ctx);
	}
}
 
Example 9
Source File: Hexagon.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public void draw(GraphicsContext gc) {
    gc.save();
    gc.setStroke(getStroke());
    gc.setLineWidth(getStrokeWidth());
    gc.setFill(getFill());
    drawHexagon(gc);
    gc.restore();
}
 
Example 10
Source File: StructuredTextRenderer.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
/** Note (July 29, 2017) this is the implementation for painting structured text. Notice it isn't done yet */
@Deprecated
private void paintStructuredText(@NotNull GraphicsContext gc) {
	final int controlWidth = getWidth();
	gc.beginPath();
	gc.rect(x1, y1, controlWidth, getHeight());
	gc.closePath();
	gc.clip(); //prevent text going out of bounds


	int rowWidth = 0;
	int rowY = y1;

	for (GraphicTextSection section : sections) {
		gc.setFont(section.font);
		if (section.textColor == null) {
			gc.setFill(defaultSectionData.textColor);
		} else {
			gc.setFill(section.textColor);
		}

		boolean outOfBounds = section.textWidth + rowWidth > controlWidth;
		if (outOfBounds) {
			FontMetrics fontMetrics = new FontMetrics(section.font);
			StringBuilder sb = new StringBuilder(section.text);
			//break the text into multiple lines
			while (section.textWidth + rowWidth > controlWidth) {

			}
		} else {

		}
	}
}
 
Example 11
Source File: BulletChartSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void drawSections(final GraphicsContext CTX) {
    sectionsCanvas.setCache(false);
    CTX.clearRect(0, 0, sectionsCanvas.getWidth(), sectionsCanvas.getHeight());
    CTX.setFill(gauge.getBackgroundPaint());
    if (Orientation.VERTICAL == orientation) {
        CTX.fillRect(0, 0, 0.5 * width, 0.9 * height);
    } else {
        CTX.fillRect(0, 0, 0.79699248 * width, 0.5 * height);
    }

    double tmpStepSize = stepSize * 1.11111111;
    double minValue = gauge.getMinValue();
    double maxValue = gauge.getMaxValue();

    int listSize = gauge.getSections().size();
    for (int i = 0 ; i < listSize ; i++) {
        final Section SECTION = gauge.getSections().get(i);
        final double SECTION_START;

        final double SECTION_SIZE = SECTION.getRange() * tmpStepSize;
        if (Double.compare(SECTION.getStart(), maxValue) <= 0 && Double.compare(SECTION.getStop(), minValue) >= 0) {
            if (Double.compare(SECTION.getStart(), minValue) < 0 && Double.compare(SECTION.getStop(), maxValue) < 0) {
                SECTION_START = minValue * tmpStepSize;
            } else {
                SECTION_START = height - (SECTION.getStart() * tmpStepSize) - SECTION_SIZE;
            }
            CTX.save();
            CTX.setFill(SECTION.getColor());
            if (Orientation.VERTICAL == orientation) {
                CTX.fillRect(0.0, SECTION_START, 0.5 * width, SECTION_SIZE);
            } else {
                CTX.fillRect(SECTION_START, 0.0, SECTION_SIZE, 0.5 * height);
            }
            CTX.restore();
        }
    }
    sectionsCanvas.setCache(true);
    sectionsCanvas.setCacheHint(CacheHint.QUALITY);
}
 
Example 12
Source File: MoleculeViewSkin.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void drawBackground(GraphicsContext ctx, double w, double h)
    {
        ctx.save();
        ctx.clearRect(0, 0, w, h);
        if (!control.isTransparent()) {
            ctx.setFill(getBackgroundColor());
            ctx.fillRect(0, 0, w, h);
        } else {
//            System.out.println("Controle is Transparent");
        }
        ctx.restore();
    }
 
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: MnistTestFXApp.java    From java-ml-projects with Apache License 2.0 4 votes vote down vote up
private void clear(GraphicsContext ctx) {
	ctx.setFill(Color.BLACK);
	ctx.fillRect(0, 0, 300, 300);
}
 
Example 15
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
/**
 * @param gc the graphics context from the Canvas parent
 * @param localCachedPoints reference to local cached data point object
 */
protected void drawBars(final GraphicsContext gc, final CachedDataPoints localCachedPoints) {
    if (!isDrawBars()) {
        return;
    }

    final int xOffset = localCachedPoints.dataSetIndex >= 0 ? localCachedPoints.dataSetIndex : 0;
    final int minRequiredWidth = Math.max(getDashSize(), localCachedPoints.minDistanceX);

    final double barWPercentage = getBarWidthPercentage();
    final double dynBarWidth = minRequiredWidth * barWPercentage / 100;
    final double constBarWidth = getBarWidth();
    final double localBarWidth = isDynamicBarWidth() ? dynBarWidth : constBarWidth;
    final double barWidthHalf = localBarWidth / 2 - (isShiftBar() ? xOffset * getShiftBarOffset() : 0);

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

    if (localCachedPoints.polarPlot) {
        for (int i = 0; i < localCachedPoints.actualDataCount; i++) {
            if (localCachedPoints.styles[i] == null) {
                gc.strokeLine(localCachedPoints.xZero, localCachedPoints.yZero, localCachedPoints.xValues[i],
                        localCachedPoints.yValues[i]);
            } else {
                // work-around: bar colour controlled by the marker color
                gc.save();
                gc.setFill(StyleParser.getColorPropertyValue(localCachedPoints.styles[i], XYChartCss.FILL_COLOR));
                gc.setLineWidth(barWidthHalf);
                gc.strokeLine(localCachedPoints.xZero, localCachedPoints.yZero, localCachedPoints.xValues[i],
                        localCachedPoints.yValues[i]);
                gc.restore();
            }
        }
    } else {
        for (int i = 0; i < localCachedPoints.actualDataCount; i++) {
            double yDiff = localCachedPoints.yValues[i] - localCachedPoints.yZero;
            final double yMin;
            if (yDiff > 0) {
                yMin = localCachedPoints.yZero;
            } else {
                yMin = localCachedPoints.yValues[i];
                yDiff = Math.abs(yDiff);
            }

            if (localCachedPoints.styles[i] == null) {
                gc.fillRect(localCachedPoints.xValues[i] - barWidthHalf, yMin, localBarWidth, yDiff);

            } else {
                gc.save();
                gc.setFill(StyleParser.getColorPropertyValue(localCachedPoints.styles[i], XYChartCss.FILL_COLOR));
                gc.fillRect(localCachedPoints.xValues[i] - barWidthHalf, yMin, localBarWidth, yDiff);
                gc.restore();
            }
        }
    }

    gc.restore();
}
 
Example 16
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 17
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
protected static void drawPolyLineHistogramBezier(final GraphicsContext gc,
        final CachedDataPoints localCachedPoints) {
    final int n = localCachedPoints.actualDataCount;
    if (n < 2) {
        drawPolyLineLine(gc, localCachedPoints);
        return;
    }

    // need to allocate new array :-(
    final double[] xCp1 = DoubleArrayCache.getInstance().getArrayExact(n);
    final double[] yCp1 = DoubleArrayCache.getInstance().getArrayExact(n);
    final double[] xCp2 = DoubleArrayCache.getInstance().getArrayExact(n);
    final double[] yCp2 = DoubleArrayCache.getInstance().getArrayExact(n);

    BezierCurve.calcCurveControlPoints(localCachedPoints.xValues, localCachedPoints.yValues, xCp1, yCp1, xCp2, yCp2,
            localCachedPoints.actualDataCount);

    gc.save();
    DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);
    DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle);
    // use stroke as fill colour
    gc.setFill(gc.getStroke());
    gc.beginPath();
    for (int i = 0; i < n - 1; i++) {
        final double x0 = localCachedPoints.xValues[i];
        final double x1 = localCachedPoints.xValues[i + 1];
        final double y0 = localCachedPoints.yValues[i];
        final double y1 = localCachedPoints.yValues[i + 1];

        // coordinates of first Bezier control point.
        final double xc0 = xCp1[i];
        final double yc0 = yCp1[i];
        // coordinates of the second Bezier control point.
        final double xc1 = xCp2[i];
        final double yc1 = yCp2[i];

        gc.moveTo(x0, y0);
        gc.bezierCurveTo(xc0, yc0, xc1, yc1, x1, y1);
    }
    gc.moveTo(localCachedPoints.xValues[n - 1], localCachedPoints.yValues[n - 1]);
    gc.closePath();
    gc.stroke();
    gc.restore();

    // release arrays to Cache
    DoubleArrayCache.getInstance().add(xCp1);
    DoubleArrayCache.getInstance().add(yCp1);
    DoubleArrayCache.getInstance().add(xCp2);
    DoubleArrayCache.getInstance().add(yCp2);
}
 
Example 18
Source File: BrushOverlay.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void drawOverlays(final GraphicsContext g)
{

	if (visible && this.viewer.isMouseInside())
	{

		final double scaledRadius = this.viewerRadius.get();

		if (x + scaledRadius > 0 &&
				x - scaledRadius < width &&
				y + scaledRadius > 0 &&
				y - scaledRadius < height)
		{
			final double depth            = brushDepth.get();
			final double depthScaleFactor = 5;
			if (depth > 1)
			{
				//					g.setStroke( Color.BLACK.deriveColor( 0.0, 1.0, 1.0, 0.5 ) );
				g.setStroke(Color.WHEAT.deriveColor(0.0, 1.0, 1.0, 0.5));
				g.setFill(Color.WHITE.deriveColor(0.0, 1.0, 1.0, 0.5));
				g.setFont(Font.font(g.getFont().getFamily(), 15.0));
				g.setLineWidth(this.strokeWidth);
				g.strokeOval(
						x - scaledRadius,
						y - scaledRadius + depth * depthScaleFactor,
						2 * scaledRadius + 1,
						2 * scaledRadius + 1
				            );
				//					g.fillRect( x - scaledRadius, y, 2 * scaledRadius + 1, depth *
				// depthScaleFactor );
				g.strokeLine(x - scaledRadius, y + depth * depthScaleFactor, x - scaledRadius, y);
				g.strokeLine(x + scaledRadius + 1, y + depth * depthScaleFactor, x + scaledRadius + 1, y);
				g.fillText("depth=" + depth, x + scaledRadius + 1, y + depth * depthScaleFactor + scaledRadius +
						1);
			}

			g.setStroke(Color.WHITE);
			g.setLineWidth(this.strokeWidth);
			g.strokeOval(x - scaledRadius, y - scaledRadius, 2 * scaledRadius + 1, 2 * scaledRadius + 1);

			this.viewer.getScene().setCursor( Cursor.NONE );
			return;
		}
	}
	if (wasVisible)
	{
		this.viewer.getScene().setCursor(Cursor.DEFAULT);
		wasVisible = false;
	}
}
 
Example 19
Source File: ColorGradientAxis.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
@Override
protected void drawAxisLine(final GraphicsContext gc, final double axisLength, final double axisWidth,
        final double axisHeight) {
    // N.B. axis canvas is (by-design) larger by 'padding' w.r.t.
    // required/requested axis length (needed for nicer label placements on
    // border.
    final double paddingX = getSide().isHorizontal() ? getAxisPadding() : 0.0;
    final double paddingY = getSide().isVertical() ? getAxisPadding() : 0.0;
    // for relative positioning of axes drawn on top of the main canvas
    final double axisCentre = getCenterAxisPosition();

    final double gradientWidth = getGradientWidth();

    // save css-styled line parameters
    final Path tickStyle = getMajorTickStyle();
    gc.save();
    gc.setStroke(tickStyle.getStroke());
    gc.setLineWidth(tickStyle.getStrokeWidth());

    if (getSide().isHorizontal()) {
        gc.setFill(new LinearGradient(0, 0, axisLength, 0, false, NO_CYCLE, getColorGradient().getStops()));
    } else {
        gc.setFill(new LinearGradient(0, axisLength, 0, 0, false, NO_CYCLE, getColorGradient().getStops()));
    }

    // N.B. important: translate by padding ie. canvas is +padding larger on
    // all size compared to region
    gc.translate(paddingX, paddingY);

    switch (getSide()) {
    case LEFT:
        // axis line on right side of canvas
        gc.fillRect(snap(axisWidth - gradientWidth), snap(0), snap(axisWidth), snap(axisLength));
        gc.strokeRect(snap(axisWidth - gradientWidth), snap(0), snap(axisWidth), snap(axisLength));
        break;
    case RIGHT:
        // axis line on left side of canvas
        gc.fillRect(snap(0), snap(0), snap(gradientWidth), snap(axisLength));
        gc.strokeRect(snap(0), snap(0), snap(gradientWidth), snap(axisLength));
        break;
    case TOP:
        // line on bottom side of canvas (N.B. (0,0) is top left corner)
        gc.fillRect(snap(0), snap(axisHeight - gradientWidth), snap(axisLength), snap(axisHeight));
        gc.strokeRect(snap(0), snap(axisHeight - gradientWidth), snap(axisLength), snap(axisHeight));
        break;
    case BOTTOM:
        // line on top side of canvas (N.B. (0,0) is top left corner)
        gc.rect(snap(0), snap(0), snap(axisLength), snap(gradientWidth));
        break;
    case CENTER_HOR:
        // axis line at the centre of the canvas
        gc.fillRect(snap(0), axisCentre * axisHeight - 0.5 * gradientWidth, snap(axisLength),
                snap(axisCentre * axisHeight + 0.5 * gradientWidth));
        gc.strokeRect(snap(0), axisCentre * axisHeight - 0.5 * gradientWidth, snap(axisLength),
                snap(axisCentre * axisHeight + 0.5 * gradientWidth));
        break;
    case CENTER_VER:
        // axis line at the centre of the canvas
        gc.fillRect(snap(axisCentre * axisWidth - 0.5 * gradientWidth), snap(0),
                snap(axisCentre * axisWidth + 0.5 * gradientWidth), snap(axisLength));
        gc.strokeRect(snap(axisCentre * axisWidth - 0.5 * gradientWidth), snap(0),
                snap(axisCentre * axisWidth + 0.5 * gradientWidth), snap(axisLength));
        break;
    default:
        break;
    }
    gc.restore();
}
 
Example 20
Source File: GaugeSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawAreasAndSections(final GraphicsContext CTX) {
    if (areas.isEmpty() && sections.isEmpty()) return;
    double value  = gauge.getCurrentValue();
    double offset = 90 - startAngle;
    double xy;
    double wh;
    int    listSize;

    // Draw Areas
    if (areasVisible && !areas.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.0895 * size : 0.025 * size;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.821 : size * 0.95;
        listSize = areas.size();
        for (int i = 0; i < listSize ; i++) {
            Section area = areas.get(i);
            double areaStartAngle;
            if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) {
                if (area.getStart() < minValue && area.getStop() < maxValue) {
                    areaStartAngle = 0;
                } else {
                    areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep;
                }
                double areaAngleExtend;
                if (area.getStop() > maxValue) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep;
                } else if (Double.compare(area.getStart(), minValue) < 0) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep;
                } else {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightAreas) {
                    CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor());
                } else {
                    CTX.setFill(area.getColor());
                }
                CTX.fillArc(xy, xy, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND);
                CTX.restore();
            }
        }
    }

    // Draw Sections
    if (sectionsVisible && !sections.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.115 * size : 0.0515 * size;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.77 : size * 0.897;
        listSize = sections.size();
        CTX.setLineWidth(size * 0.052);
        CTX.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0; i < listSize; i++) {
            Section section = sections.get(i);
            double  sectionStartAngle;
            if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) {
                if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) {
                    sectionStartAngle = 0;
                } else {
                    sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep;
                }
                double sectionAngleExtend;
                if (Double.compare(section.getStop(), maxValue) > 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep;
                } else if (Double.compare(section.getStart(), minValue) < 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep;
                } else {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightSections) {
                    CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor());
                } else {
                    CTX.setStroke(section.getColor());
                }
                CTX.strokeArc(xy, xy, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
                CTX.restore();
            }
        }
    }
}