List of usage examples for com.google.gwt.canvas.dom.client Context2d bezierCurveTo
public final native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y) ;
From source file:com.philbeaudoin.quebec.client.scene.Arrow.java
License:Apache License
@Override public void drawUntransformed(double time, Context2d context) { context.beginPath();//from ww w .ja v a 2s .c om context.moveTo(from.getX(), from.getY()); context.bezierCurveTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY()); context.lineTo(p4.getX(), p4.getY()); context.lineTo(to.getX(), to.getY()); context.lineTo(p5.getX(), p5.getY()); context.lineTo(p6.getX(), p6.getY()); context.bezierCurveTo(p2.getX(), p2.getY(), p1.getX(), p1.getY(), from.getX(), from.getY()); context.setLineWidth(0.0045); context.setStrokeStyle("#aaa"); context.stroke(); context.setLineWidth(0.001); context.setStrokeStyle("#000"); context.stroke(); context.fill(); }
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 . j a 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:gwt.g2d.client.graphics.visitor.BezierCurveVisitor.java
License:Apache License
@Override public void visit(Surface surface) { Context2d context = surface.getContext(); context.moveTo(startPointX, startPointY); context.bezierCurveTo(controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, endPointX, endPointY); }
From source file:playn.html.HtmlPath.java
License:Apache License
void replay(Context2d ctx) { ctx.beginPath();/* w w w.j a va 2 s. c o m*/ 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"); } } }