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

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

Introduction

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

Prototype

public final native void setLineWidth(double lineWidth) ;

Source Link

Document

Sets the line-width.

Usage

From source file:org.rstudio.core.client.widget.ProgressSpinner.java

License:Open Source License

private void redraw() {
    Context2d ctx = canvas_.getContext2d();
    double center = COORD_SIZE / 2;
    // clear canvas (we draw with an alpha channel so otherwise would stack)
    ctx.clearRect(0, 0, COORD_SIZE, COORD_SIZE);
    for (int i = 0; i < NUM_BLADES; i++) {
        // compute angle for this blade
        double theta = ((2 * Math.PI) / NUM_BLADES) * i;
        double sin = Math.sin(theta);
        double cos = Math.cos(theta);

        // set line drawing context
        ctx.beginPath();/*from   w w w  . ja  v  a  2  s. c  om*/
        ctx.setLineWidth(BLADE_WIDTH);
        ctx.setLineCap(LineCap.ROUND);

        // compute transparency for this blade
        double alpha = 1.0 - (((double) ((i + frame_) % NUM_BLADES)) / ((double) NUM_BLADES));
        ctx.setStrokeStyle("rgba(" + color_ + ", " + alpha + ")");

        // draw the blade
        ctx.moveTo(center + sin * innerRadius_, center + cos * innerRadius_);
        ctx.lineTo(center + sin * outerRadius_, center + cos * outerRadius_);
        ctx.stroke();
    }
}

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 ww w  . j a v  a2s  .  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);/* ww  w  . j a v  a  2s . c om*/
    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();
}