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

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

Introduction

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

Prototype

public final native void stroke() ;

Source Link

Document

Draws the current path with the current stroke style.

Usage

From source file:net.exclaimindustries.paste.braket.client.ui.BracketCell.java

License:BSD License

private void drawRightBracket() {
    Context2d con = initBracketCanvas(mCanvas);

    con.beginPath();//from  www. ja  v a2 s  .c o  m

    int width = mCanvas.getOffsetWidth();
    int height = mCanvas.getOffsetHeight();

    if (!mTerminus) {
        con.moveTo(width, height / 4.0);
        con.lineTo(width / 2.0, height / 4.0);
        con.lineTo(width / 2.0, (3.0 * height) / 4.0);
        con.lineTo(width, (3.0 * height) / 4.0);
        con.stroke();
    }

    con.moveTo(width / 2.0, height / 2.0);
    con.lineTo(0, height / 2.0);
    con.stroke();
}

From source file:net.exclaimindustries.paste.braket.client.ui.BracketCell.java

License:BSD License

private void drawFinalBracket() {
    Context2d con = initBracketCanvas(mCanvas);

    con.beginPath();//from ww  w .  j a v a 2  s .c  o  m

    int width = mCanvas.getOffsetWidth();
    int height = mCanvas.getOffsetHeight();

    con.moveTo(0, height / 2.0);
    con.lineTo(width, height / 2.0);
    con.stroke();
}

From source file:org.catrobat.html5player.client.Scene.java

License:Open Source License

/**
 * FOR TESING/*  ww w . j  a va  2s  .  com*/
 */
public void drawAxis() {
    Context2d ctx = sceneCanvas.getContext2d();

    ctx.beginPath();
    ctx.moveTo(getSceneWidth() / 2, 0);
    ctx.lineTo(getSceneWidth() / 2, getSceneHeight());
    ctx.stroke();
    ctx.closePath();

    ctx.beginPath();
    ctx.moveTo(0, getSceneHeight() / 2);
    ctx.lineTo(getSceneWidth(), getSceneHeight() / 2);
    ctx.stroke();
    ctx.closePath();
}

From source file:org.cesiumjs.cs.scene.interaction.MarkerGroup.java

License:Apache License

public static BillboardOptions createBillboard(DrawInteractionOptions options) {
    Canvas canvas = Canvas.createIfSupported();
    Context2d context = canvas.getContext2d();

    context.setFillStyle(options.color.toCssColorString());
    context.setStrokeStyle(options.outlineColor.toCssColorString());
    context.setLineWidth(options.outlineWidth);

    context.translate(canvas.getCoordinateSpaceWidth() / 2, canvas.getCoordinateSpaceHeight() / 2);
    context.beginPath();//from  w  w w. j  av a2s  .c om
    context.arc(0, 0, options.pixelSize, 0, Math.PI * 2, true);
    context.closePath();
    context.stroke();
    context.fill();

    BillboardOptions billboard = new BillboardOptions();
    billboard.horizontalOrigin = HorizontalOrigin.CENTER();
    billboard.verticalOrigin = VerticalOrigin.CENTER();
    billboard.imageCanvas = canvas.getCanvasElement();
    return billboard;
}

From source file:org.openstreetmap.beboj.client.actions.mapmode.edit.DrawWay.java

License:GNU General Public License

@Override
public void paint(Graphics2D g, MapView mv, Bounds bbox) {
    Context2d c = ((CanvasGraphics2D) g).getContext2d();

    // don't draw line if we don't know where to
    if (lastMousePos == null)
        return;/* ww w .  ja  v a2 s.c  om*/

    // don't draw line if mouse is outside window
    if (!Main.map.mapView.view.getBounds().contains(lastMousePos))
        return;

    Point p1 = mv.getPoint(lastNode);
    Point p2 = lastMousePos;

    c.setStrokeStyle("#ffff00");
    c.beginPath();
    c.moveTo(p1.x, p1.y);
    c.lineTo(p2.x, p2.y);
    c.stroke();
}

From source file:org.peergreen.vaadin.diagram.client.ui.IntermediateConnectorUI.java

License:Apache License

@Override
public void draw() {
    // Draw a line from the source port to the current mouse coordinates
    Context2d canvas = getCanvas();
    IPoint coordinates = getModel().getMouseCoordinates();

    canvas.save();//from w  w  w.j a v  a 2  s . c  o  m
    canvas.beginPath();
    canvas.setStrokeStyle("#000");
    canvas.moveTo(sourcePort.getConnectorX(), sourcePort.getConnectorY());
    canvas.lineTo(coordinates.getX(), coordinates.getY());
    canvas.closePath();
    canvas.stroke();
    canvas.restore();
}

From source file:org.primaresearch.web.gwt.client.ui.page.renderer.PolygonRendererHelper.java

License:Apache License

private static void drawPolygon(Context2d context, Polygon polygon, boolean outline, boolean fill) {
    if (polygon == null || polygon.getSize() < 3 || (!outline && !fill))
        return;/*from   w  w w  .  ja  v a 2 s.  com*/

    context.beginPath();
    context.moveTo(polygon.getPoint(0).x, polygon.getPoint(0).y);
    for (int i = 1; i < polygon.getSize(); i++)
        context.lineTo(polygon.getPoint(i).x, polygon.getPoint(i).y);
    context.lineTo(polygon.getPoint(0).x, polygon.getPoint(0).y);
    if (fill)
        context.fill();
    if (outline)
        context.stroke();
}

From source file:org.primaresearch.web.gwt.client.ui.page.tool.drawing.EditOutlineTool.java

License:Apache License

@Override
public void render(PageRenderer renderer) {
    if (!isEnabled())
        return;//www.ja v  a  2  s  . c  o m

    Context2d context = renderer.getContext();

    //Draw the selected outline in red
    RenderStyle style = new RenderStyle("rgb(255,0,0)", "transparent", 1.0);
    PolygonRendererHelper.drawPolygon(context, polygon, style, renderer.getZoomFactor(), true, false);

    //Delete mode
    if (deletePointsMode) {
        if (currentPolygonPoint != null) {
            context.setFillStyle(DELETE_POINT_FILL_COLOR);
            context.setStrokeStyle(DELETE_POINT_LINE_COLOR);
            context.setLineWidth(1.0 / renderer.getZoomFactor());

            //Cross
            context.beginPath();
            int size = (int) (3.0 / view.getZoomFactor());
            context.moveTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - 3 * size);
            context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y - size);
            context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y - 3 * size);
            context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y - 2 * size);
            context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y);
            context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y + 2 * size);
            context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + 3 * size);
            context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y + size);
            context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + 3 * size);
            context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y + 2 * size);
            context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y);
            context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y - 2 * size);
            context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - 3 * size);

            context.fill();
            context.stroke();
        }
    }
    //Add or move mode
    else {
        //Move point
        if (currentPolygonPoint != null) {
            context.setFillStyle(POINT_HIGHLIGHT_FILL_COLOR);
            context.setStrokeStyle(POINT_HIGHLIGHT_LINE_COLOR);
            context.setLineWidth(1.0 / renderer.getZoomFactor());

            int size = (int) (3.0 / view.getZoomFactor());

            //Rect in centre
            context.beginPath();
            context.rect(currentPolygonPoint.x - size, currentPolygonPoint.y - size, 2 * size + 1,
                    2 * size + 1);
            context.fill();
            context.stroke();

            //Arrows
            // Left
            context.beginPath();
            context.moveTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + size);
            context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - size);
            context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y);
            context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + size);
            context.fill();
            context.stroke();
            // Right
            context.beginPath();
            context.moveTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + size);
            context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y - size);
            context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y);
            context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + size);
            context.fill();
            context.stroke();
            // Top
            context.beginPath();
            context.moveTo(currentPolygonPoint.x + size, currentPolygonPoint.y - 2 * size);
            context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y - 2 * size);
            context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y - 3 * size);
            context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y - 2 * size);
            context.fill();
            context.stroke();
            // Bottom
            context.beginPath();
            context.moveTo(currentPolygonPoint.x + size, currentPolygonPoint.y + 2 * size);
            context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y + 2 * size);
            context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y + 3 * size);
            context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y + 2 * size);
            context.fill();
            context.stroke();
        }

        //Add point
        if (newPolygonPointCandidate != null) {
            context.setFillStyle(POINT_HIGHLIGHT_FILL_COLOR);
            context.setStrokeStyle(POINT_HIGHLIGHT_LINE_COLOR);
            context.setLineWidth(1.0 / renderer.getZoomFactor());

            //Plus sign
            context.beginPath();
            int size = (int) (3.0 / view.getZoomFactor());
            context.moveTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - 3 * size);
            context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y - 3 * size);
            context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y - size);
            context.lineTo(newPolygonPointCandidate.x + 3 * size, newPolygonPointCandidate.y - size);
            context.lineTo(newPolygonPointCandidate.x + 3 * size, newPolygonPointCandidate.y + size);
            context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y + size);
            context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y + 3 * size);
            context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y + 3 * size);
            context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y + size);
            context.lineTo(newPolygonPointCandidate.x - 3 * size, newPolygonPointCandidate.y + size);
            context.lineTo(newPolygonPointCandidate.x - 3 * size, newPolygonPointCandidate.y - size);
            context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - size);
            context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - 3 * size);

            context.fill();
            context.stroke();
        }
    }
}

From source file:org.primaresearch.web.gwt.client.ui.page.tool.drawing.RectangleTool.java

License:Apache License

@Override
public void render(PageRenderer renderer) {
    if (p1 == null || !isEnabled())
        return;//  w  w  w.ja v a2 s .  com
    Context2d context = renderer.getContext();

    //Blue rectangle
    context.setStrokeStyle(CssColor.make(0, 128, 255));
    context.setLineWidth(1.0 / renderer.getZoomFactor());

    int x1 = Math.min(p1.x, p2.x);
    int x2 = Math.max(p1.x, p2.x);
    int y1 = Math.min(p1.y, p2.y);
    int y2 = Math.max(p1.y, p2.y);

    context.beginPath();
    context.rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
    context.stroke();
}

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();/*  w w w  . j  av  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();
    }
}