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

The following examples show how to use javafx.scene.canvas.GraphicsContext#quadraticCurveTo() . 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: Helper.java    From OEE-Designer with MIT License 6 votes vote down vote up
public static final void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS,
		final CtxCornerRadii RADII) {
	double x = BOUNDS.getX();
	double y = BOUNDS.getY();
	double width = BOUNDS.getWidth();
	double height = BOUNDS.getHeight();
	double xPlusWidth = x + width;
	double yPlusHeight = y + height;

	CTX.beginPath();
	CTX.moveTo(x + RADII.getTopLeft(), y);
	CTX.lineTo(xPlusWidth - RADII.getTopRight(), y);
	CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight());
	CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight());
	CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight);
	CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight);
	CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft());
	CTX.lineTo(x, y + RADII.getTopLeft());
	CTX.quadraticCurveTo(x, y, x + RADII.getTopLeft(), y);
	CTX.closePath();
}
 
Example 2
Source File: Helper.java    From charts with Apache License 2.0 6 votes vote down vote up
public static final void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS, final CtxCornerRadii RADII) {
    double x           = BOUNDS.getX();
    double y           = BOUNDS.getY();
    double width       = BOUNDS.getWidth();
    double height      = BOUNDS.getHeight();
    double xPlusWidth  = x + width;
    double yPlusHeight = y + height;

    CTX.beginPath();
    CTX.moveTo(x + RADII.getTopLeft(), y);
    CTX.lineTo(xPlusWidth - RADII.getTopRight(), y);
    CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight());
    CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight());
    CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight);
    CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight);
    CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft());
    CTX.lineTo(x, y + RADII.getTopLeft());
    CTX.quadraticCurveTo(x, y, x + RADII.getTopLeft(), y);
    CTX.closePath();
}
 
Example 3
Source File: Path.java    From charts with Apache License 2.0 6 votes vote down vote up
public void draw(final GraphicsContext CTX, final boolean FILL, final boolean STROKE) {
    PathIterator pi = getPathIterator(new Affine());

    CTX.setFillRule(WindingRule.WIND_EVEN_ODD == pi.getWindingRule() ? FillRule.EVEN_ODD : FillRule.NON_ZERO);
    CTX.beginPath();

    double[] seg = new double[6];
    int      segType;

    while(!pi.isDone()) {
        segType = pi.currentSegment(seg);
        switch (segType) {
            case PathIterator.MOVE_TO  : CTX.moveTo(seg[0], seg[1]); break;
            case PathIterator.LINE_TO  : CTX.lineTo(seg[0], seg[1]); break;
            case PathIterator.QUAD_TO  : CTX.quadraticCurveTo(seg[0], seg[1], seg[2], seg[3]);break;
            case PathIterator.BEZIER_TO: CTX.bezierCurveTo(seg[0], seg[1], seg[2], seg[3], seg[4], seg[5]);break;
            case PathIterator.CLOSE    : CTX.closePath();break;
            default                    : break;
        }
        pi.next();
    }

    if (FILL)   { CTX.setFill(fill); CTX.fill(); }
    if (STROKE) { CTX.setStroke(stroke); CTX.stroke(); }
}
 
Example 4
Source File: Helper.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
public static final void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS, final CtxCornerRadii RADII) {
    double x           = BOUNDS.getX();
    double y           = BOUNDS.getY();
    double width       = BOUNDS.getWidth();
    double height      = BOUNDS.getHeight();
    double xPlusWidth  = x + width;
    double yPlusHeight = y + height;

    CTX.beginPath();
    CTX.moveTo(x + RADII.getTopLeft(), y);
    CTX.lineTo(xPlusWidth - RADII.getTopRight(), y);
    CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight());
    CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight());
    CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight);
    CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight);
    CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft());
    CTX.lineTo(x, y + RADII.getTopLeft());
    CTX.quadraticCurveTo(x, y, x + RADII.getTopLeft(), y);
    CTX.closePath();
}
 
Example 5
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private static void applyPath(GraphicsContext pGraphics, Path pPath)
{
	pGraphics.beginPath();
	for(PathElement element : pPath.getElements())
	{
		if(element instanceof MoveTo)
		{
			pGraphics.moveTo(((int)((MoveTo) element).getX()) + 0.5, ((int)((MoveTo) element).getY()) + 0.5);
		}
		else if(element instanceof LineTo)
		{
			pGraphics.lineTo(((int)((LineTo) element).getX()) + 0.5, ((int)((LineTo) element).getY()) + 0.5);
		}
		else if (element instanceof QuadCurveTo)
		{
			QuadCurveTo curve = (QuadCurveTo) element;
			pGraphics.quadraticCurveTo(((int)curve.getControlX())+0.5, ((int)curve.getControlY()) + 0.5, 
					((int) curve.getX()) + 0.5, ((int) curve.getY()) + 0.5);
		}
	}
}