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

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

Introduction

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

Prototype

public final native void beginPath() ;

Source Link

Document

Begins a new path.

Usage

From source file:org.rstudio.studio.client.workbench.views.vcs.dialog.graph.GraphLine.java

License:Open Source License

private void draw(Canvas canvas, GraphTheme theme) {
    int height = theme.getRowHeight();
    int colWidth = theme.getColumnWidth();
    double pad = theme.getVerticalLinePadding();

    canvas.setCoordinateSpaceHeight(height);
    canvas.setCoordinateSpaceWidth(colWidth * getTotalWidth(theme));
    Context2d ctx = canvas.getContext2d();

    //ctx.clearRect(0, 0, colWidth * columns_.length, height);

    ctx.translate(colWidth / 2.0, 0);/*from   w  w  w. j av  a  2 s  .c  o  m*/

    int startPos = -1;
    int endPos = -1;
    int nexusColumn = -1;
    for (int i = 0; i < columns_.length; i++) {
        GraphColumn c = columns_[i];

        if (!c.start)
            startPos++;
        if (!c.end)
            endPos++;

        ctx.setStrokeStyle(theme.getColorForId(c.id));
        ctx.setLineWidth(theme.getStrokeWidth());
        ctx.setLineJoin(LineJoin.ROUND);

        if (!c.nexus && !c.start && !c.end) {
            // Just draw a line from start to end position

            ctx.beginPath();
            ctx.moveTo(startPos * colWidth, 0);
            ctx.lineTo(startPos * colWidth, pad);
            // This next lineTo helps ensure that the shape of the line looks
            // congruous to any specials on the same line
            ctx.lineTo(Math.min(startPos, endPos) * colWidth, height / 2.0);
            ctx.lineTo(endPos * colWidth, height - pad);
            ctx.lineTo(endPos * colWidth, height);
            ctx.stroke();
        } else {
            // something special

            if (c.nexus) {
                nexusColumn = i;
                ctx.setFillStyle(theme.getColorForId(c.id));
            }

            if (!c.start) {
                // draw from i to nexusColumn;
                ctx.beginPath();
                ctx.moveTo(startPos * colWidth, 0);
                ctx.lineTo(startPos * colWidth, pad);
                ctx.lineTo(nexusColumn * colWidth, height / 2.0);
                ctx.stroke();
            }

            if (!c.end) {
                // draw from nexusColumn to endPosition
                ctx.beginPath();
                ctx.moveTo(nexusColumn * colWidth, height / 2.0);
                ctx.lineTo(endPos * colWidth, height - pad);
                ctx.lineTo(endPos * colWidth, height);
                ctx.stroke();
            }

        }
    }

    // draw a circle on the nexus
    ctx.beginPath();
    ctx.arc(nexusColumn * colWidth, height / 2.0, theme.getCircleRadius() + theme.getStrokeWidth(), 0,
            Math.PI * 2);
    ctx.closePath();
    ctx.fill();

    ctx.beginPath();
    ctx.arc(nexusColumn * colWidth, height / 2.0, theme.getCircleRadius(), 0, Math.PI * 2);
    ctx.closePath();
    ctx.setFillStyle("white");
    ctx.fill();

}

From source file:org.teavm.samples.benchmark.gwt.BenchmarkStarter.java

License:Apache License

private void render() {
    Context2d context = canvas.getContext2d();
    context.setFillStyle("white");
    context.setStrokeStyle("grey");
    context.fillRect(0, 0, 600, 600);/*  www.  j av  a  2s.  co  m*/
    context.save();
    context.translate(0, 600);
    context.scale(1, -1);
    context.scale(100, 100);
    context.setLineWidth(0.01);
    for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
        Vec2 center = body.getPosition();
        context.save();
        context.translate(center.x, center.y);
        context.rotate(body.getAngle());
        for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
            Shape shape = fixture.getShape();
            if (shape.getType() == ShapeType.CIRCLE) {
                CircleShape circle = (CircleShape) shape;
                context.beginPath();
                context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
                context.closePath();
                context.stroke();
            } else if (shape.getType() == ShapeType.POLYGON) {
                PolygonShape poly = (PolygonShape) shape;
                Vec2[] vertices = poly.getVertices();
                context.beginPath();
                context.moveTo(vertices[0].x, vertices[0].y);
                for (int i = 1; i < poly.getVertexCount(); ++i) {
                    context.lineTo(vertices[i].x, vertices[i].y);
                }
                context.closePath();
                context.stroke();
            }
        }
        context.restore();
    }
    context.restore();
}

From source file:playn.html.HtmlImageLayerCanvas.java

License:Apache License

@Override
public void paint(Context2d ctx, float parentAlpha) {
    if (!visible() || !img.isReady())
        return;/*  w  w w.  j av a 2 s  . co m*/

    ctx.save();
    transform(ctx);
    ctx.setGlobalAlpha(parentAlpha * alpha);

    float width = width();
    float height = height();
    if (repeatX || repeatY) {
        updatePattern(ctx);
        ctx.setFillStyle(pattern);
        ctx.beginPath();
        ctx.rect(0, 0, width, height);
        ctx.scale(repeatX ? 1 : width / img.width(), repeatY ? 1 : height / img.height());
        ctx.fill();
    } else {
        ((HtmlCanvas.Drawable) img).draw(ctx, 0, 0, width, height);
    }

    ctx.restore();
}

From source file:playn.html.HtmlPath.java

License:Apache License

void replay(Context2d ctx) {
    ctx.beginPath();

    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++);//from   w w  w  . ja  va2 s. c  om
            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.BracketConnectorRenderer.java

License:Apache License

private void drawTop(final Context2d ctx, final double midX, final double minX, final double maxX,
        final double y1, final double y2) {
    final double maxY = y1 - RADIUS;
    final double minY = y2 + RADIUS;

    // Draw top of bracket
    ctx.beginPath();
    ctx.moveTo(midX, maxY);//from  w w w  . j  a va  2 s  .c  o m
    ctx.arc(minX, maxY, RADIUS, 0, HALF_PI);
    ctx.moveTo(midX, maxY);
    ctx.lineTo(midX, minY);
    ctx.moveTo(midX, minY);
    ctx.arc(maxX, minY, RADIUS, Math.PI, ONE_AND_HALF_PI);
    ctx.setStrokeStyle(lineColor);
    ctx.stroke();
}

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

License:Apache License

private void drawBottom(final Context2d ctx, final double midX, final double minX, final double maxX,
        final double y1, final double y2) {
    final double minY = y1 + RADIUS;
    final double maxY = y2 - RADIUS;

    // Draw bottom of bracket
    ctx.beginPath();
    ctx.moveTo(minX, y1);//from w w w .j a v  a2 s  .co m
    ctx.arc(minX, minY, RADIUS, ONE_AND_HALF_PI, 0);
    ctx.moveTo(midX, minY);
    ctx.lineTo(midX, maxY);
    ctx.moveTo(maxX, y2);
    ctx.arc(maxX, maxY, RADIUS, HALF_PI, Math.PI);
    ctx.setStrokeStyle(lineColor);
    ctx.stroke();
}

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();
    ctx.moveTo(x + radius, y);/*from w  w  w  . j av a 2  s .c  o  m*/
    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();
    }
}

From source file:web.diva.client.somclust.view.MaxTreeZoomImage.java

public void buffer(Context2d back, Context2d front) {
    front.beginPath();
    front.clearRect(0, 0, width, height);
    front.drawImage(back.getCanvas(), 0, 0);
}