Example usage for com.google.gwt.canvas.dom.client Context2d quadraticCurveTo

List of usage examples for com.google.gwt.canvas.dom.client Context2d quadraticCurveTo

Introduction

In this page you can find the example usage for com.google.gwt.canvas.dom.client Context2d quadraticCurveTo.

Prototype

public final native void quadraticCurveTo(double cpx, double cpy, double x, double y) ;

Source Link

Document

Draws a quadratic B\u00e9zier curve from the current point to the point (x, y), with control point (cpx, cpy).

Usage

From source file:com.sencha.gxt.chart.client.draw.engine.Canvas2d.java

License:sencha.com license

private PathCommand appendPathCommands(Context2d ctx, List<PathCommand> commands, PrecisePoint currentPoint,
        PrecisePoint movePoint, PrecisePoint curvePoint, PrecisePoint quadraticPoint) {
    PathCommand last = null;/*from  w  w  w  . ja v  a  2s.c o m*/
    for (PathCommand cmd : commands) {
        last = cmd;
        if (cmd instanceof MoveTo) {
            MoveTo move = (MoveTo) cmd;

            quadraticPoint.setX(currentPoint.getX());
            quadraticPoint.setY(currentPoint.getY());
            movePoint.setX(move.getX());
            movePoint.setY(move.getY());
            currentPoint.setX(move.getX());
            currentPoint.setY(move.getY());
            curvePoint.setX(move.getX());
            curvePoint.setY(move.getY());

            ctx.moveTo(move.getX(), move.getY());
        } else if (cmd instanceof LineTo) {
            LineTo line = (LineTo) cmd;

            quadraticPoint.setX(currentPoint.getX());
            quadraticPoint.setY(currentPoint.getY());
            currentPoint.setX(line.getX());
            currentPoint.setY(line.getY());
            curvePoint.setX(line.getX());
            curvePoint.setY(line.getY());

            ctx.lineTo(line.getX(), line.getY());
        } else if (cmd instanceof CurveTo) {
            CurveTo curve = (CurveTo) cmd;

            quadraticPoint.setX(currentPoint.getX());
            quadraticPoint.setY(currentPoint.getY());
            currentPoint.setX(curve.getX());
            currentPoint.setY(curve.getY());
            curvePoint.setX(curve.getX2());
            curvePoint.setY(curve.getY2());

            ctx.bezierCurveTo(curve.getX1(), curve.getY1(), curve.getX2(), curve.getY2(), curve.getX(),
                    curve.getY());
        } else if (cmd instanceof CurveToQuadratic) {
            CurveToQuadratic curve = (CurveToQuadratic) cmd;
            double ax = 2.0 * curve.getX1() / 3.0;
            double ay = 2.0 * curve.getY1() / 3.0;

            quadraticPoint.setX(curve.getX1());
            quadraticPoint.setY(curve.getY1());
            currentPoint.setX(curve.getX() / 3.0 + ax);
            currentPoint.setY(curve.getY() / 3.0 + ay);
            curvePoint.setX(curve.getX1());
            curvePoint.setY(curve.getY1());

            ctx.quadraticCurveTo(curve.getX1(), curve.getY1(), curve.getX(), curve.getY());
        } else if (cmd instanceof ClosePath) {
            quadraticPoint.setX(currentPoint.getX());
            quadraticPoint.setY(currentPoint.getY());

            ctx.closePath();
        } else {
            assert cmd instanceof EllipticalArc || cmd instanceof CurveToQuadraticSmooth
                    || cmd instanceof CurveToSmooth || cmd instanceof LineToHorizontal
                    || cmd instanceof LineToVertical : cmd.getClass() + " is not yet implemented";
            last = appendPathCommands(ctx, cmd.toCurve(currentPoint, movePoint, curvePoint, quadraticPoint),
                    currentPoint, movePoint, curvePoint, quadraticPoint);
            CurveTo curve = (CurveTo) last;
            currentPoint.setX(curve.getX());
            currentPoint.setY(curve.getY());
            curvePoint.setX(curve.getX2());
            curvePoint.setY(curve.getY2());
        }

    }
    return last;
}

From source file:forplay.html.HtmlPath.java

License:Apache License

void replay(Context2d ctx) {
    ctx.beginPath();/*from ww  w. j av  a2 s.com*/

    int len = list.length(), i = 0;
    double x = 0, y = 0;
    while (i < len) {
        switch ((int) list.get(i++)) {
        case CMD_MOVE: {
            x = list.get(i++);
            y = list.get(i++);
            ctx.moveTo(x, y);
            break;
        }
        case CMD_LINE: {
            x = list.get(i++);
            y = list.get(i++);
            ctx.lineTo(x, y);
            break;
        }
        case CMD_QUAD: {
            double cpx = list.get(i++);
            double cpy = list.get(i++);
            x = list.get(i++);
            y = list.get(i++);
            ctx.quadraticCurveTo(cpx, cpy, x, y);
            break;
        }
        case CMD_ARC: {
            double curX = x, curY = 0;
            double radius = list.get(i++);
            x = list.get(i++);
            y = list.get(i++);
            ctx.arcTo(curX, curY, x, y, radius);
            break;
        }
        case CMD_CLOSE: {
            ctx.closePath();
            break;
        }

        default:
            throw new AssertionError("Corrupt command list");
        }
    }
}

From source file:gwt.g2d.client.graphics.visitor.QuadraticCurveVisitor.java

License:Apache License

@Override
public void visit(Surface surface) {
    Context2d context = surface.getContext();
    context.moveTo(startPointX, startPointY);
    context.quadraticCurveTo(controlPointX, controlPointY, endPointX, endPointY);
}

From source file:playn.html.HtmlPath.java

License:Apache License

void replay(Context2d ctx) {
    ctx.beginPath();//from   ww w  .  ja  v a  2s. com

    int len = list.length(), i = 0;
    double x = 0, y = 0;
    while (i < len) {
        switch ((int) list.get(i++)) {
        case CMD_MOVE: {
            x = list.get(i++);
            y = list.get(i++);
            ctx.moveTo(x, y);
            break;
        }
        case CMD_LINE: {
            x = list.get(i++);
            y = list.get(i++);
            ctx.lineTo(x, y);
            break;
        }
        case CMD_QUAD: {
            double cpx = list.get(i++);
            double cpy = list.get(i++);
            x = list.get(i++);
            y = list.get(i++);
            ctx.quadraticCurveTo(cpx, cpy, x, y);
            break;
        }
        case CMD_BEZIER: {
            double c1x = list.get(i++), c1y = list.get(i++);
            double c2x = list.get(i++), c2y = list.get(i++);
            x = list.get(i++);
            y = list.get(i++);
            ctx.bezierCurveTo(c1x, c1y, c2x, c2y, x, y);
            break;
        }
        case CMD_CLOSE: {
            ctx.closePath();
            break;
        }

        default:
            throw new AssertionError("Corrupt command list");
        }
    }
}

From source file:stroom.widget.htree.client.RoundedRectangle.java

License:Apache License

public void draw(final Context2d ctx, final double x, final double y, final double width, final double height,
        final double radius, final FillStrokeStyle fill, final FillStrokeStyle stroke) {
    ctx.beginPath();//from   w  w w .j  a  v a  2 s  . c  om
    ctx.moveTo(x + radius, y);
    ctx.lineTo(x + width - radius, y);
    ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
    ctx.lineTo(x + width, y + height - radius);
    ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
    ctx.lineTo(x + radius, y + height);
    ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
    ctx.lineTo(x, y + radius);
    ctx.quadraticCurveTo(x, y, x + radius, y);
    ctx.closePath();

    if (fill != null) {
        ctx.setFillStyle(fill);
        ctx.fill();
    }

    if (stroke != null) {
        ctx.setStrokeStyle(stroke);
        ctx.stroke();
    }
}