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:examples.geometry.containment.PolygonLineContainment.java

License:Open Source License

@Override
protected AbstractControllableShape createControllableShape2(final Canvas canvas) {
    return new AbstractControllableShape(canvas) {
        @Override// w  ww . ja va  2s.c  om
        public void createControlPoints() {
            addControlPoint(new Point(100, 100));
            addControlPoint(new Point(300, 300));
        }

        @Override
        public Line createGeometry() {
            Point[] points = getControlPoints();
            return new Line(points[0], points[1]);
        }

        @Override
        public void drawShape() {
            Line line = createGeometry();
            Context2d c = canvas.getContext2d();
            c.beginPath();
            c.moveTo(line.getX1(), line.getY1());
            c.lineTo(line.getX2(), line.getY2());
            c.closePath();
            c.stroke();
        }

        @Override
        public void fillShape(CssColor color) {
            Context2d context2d = canvas.getContext2d();
            FillStrokeStyle style = context2d.getFillStyle();
            context2d.setLineWidth(3);
            context2d.setStrokeStyle(color.value());

            drawShape();

            context2d.setLineWidth(1);
            //            context2d.setStrokeStyle(CssColor.make(0, 0, 0).value());
            context2d.setStrokeStyle(style);
        }
    };
}

From source file:examples.geometry.containment.PolygonPolylineContainment.java

License:Open Source License

@Override
protected AbstractControllableShape createControllableShape2(final Canvas canvas) {
    return new AbstractControllableShape(canvas) {
        @Override// ww w .  jav  a 2 s  .  c om
        public void createControlPoints() {
            addControlPoint(new Point(100, 100));
            addControlPoint(new Point(100, 300));
            addControlPoint(new Point(300, 300));
            addControlPoint(new Point(300, 100));
        }

        @Override
        public Polyline createGeometry() {
            Point[] points = getControlPoints();
            Polyline polyline = new Polyline(points);
            return polyline;
        }

        @Override
        public void drawShape() {
            Polyline polyline = createGeometry();
            CanvasDrawer.strokePath(polyline.toPath(), canvas.getContext2d());
        }

        @Override
        public void fillShape(CssColor color) {
            Context2d context2d = canvas.getContext2d();
            FillStrokeStyle style = context2d.getStrokeStyle();
            context2d.setLineWidth(3);
            context2d.setStrokeStyle(color.value());

            drawShape();

            context2d.setLineWidth(1);
            //            context2d.setStrokeStyle(CssColor.make(0, 0, 0).value());
            context2d.setStrokeStyle(style);
        }
    };
}

From source file:examples.geometry.demos.RingOutlineExample.java

License:Open Source License

@Override
protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) {
    return new ControllableShape[] { new ControllableShape(canvas, eventBus) {
        {/*ww  w .  j a  v  a 2s .  c om*/
            addControlPoints(new Point(100, 100), new Point(400, 100), new Point(400, 200));
            addControlPoints(new Point(400, 100), new Point(400, 400), new Point(300, 400));
            addControlPoints(new Point(400, 400), new Point(100, 400), new Point(100, 300));
            addControlPoints(new Point(100, 400), new Point(100, 100), new Point(200, 100));
        }

        @Override
        public Ring getShape() {
            Point[] cp = getPoints();

            Polygon[] polygons = new Polygon[cp.length / 3];
            for (int i = 0; i < polygons.length; i++) {
                polygons[i] = new Polygon(cp[3 * i], cp[3 * i + 1], cp[3 * i + 2]);
            }

            return new Ring(polygons);
        }

        @Override
        public void onDraw(Canvas canvas) {
            Context2d context = canvas.getContext2d();
            Ring ring = getShape();

            context.setStrokeStyle("black");
            double lineWidth = context.getLineWidth();
            context.setLineWidth(1);

            for (Polyline outline : ring.getOutlines()) {
                context.beginPath();
                for (Line l : outline.getCurves()) {
                    Point p1 = l.getP1();
                    Point p2 = l.getP2();

                    context.moveTo(p1.x, p1.y);
                    context.lineTo(p2.x, p2.y);
                    context.setLineWidth(lineWidth + 1);
                    context.stroke();
                }
                context.closePath();
            }

            context.setLineWidth(lineWidth);
        }
    } };
}

From source file:examples.geometry.demos.TriangulationExample.java

License:Open Source License

@Override
protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) {
    return new ControllableShape[] { new ControllableShape(canvas, eventBus) {
        {//from  www  .  ja  v  a  2s .c  o  m
            addControlPoints(new Point(300 / 2, 100 / 2), new Point(100 / 2, 200 / 2),
                    new Point(200 / 2, 300 / 2), new Point(100 / 2, 500 / 2), new Point(300 / 2, 400 / 2),
                    new Point(500 / 2, 600 / 2), new Point(600 / 2, 300 / 2), new Point(500 / 2, 400 / 2),
                    new Point(500 / 2, 200 / 2), new Point(300 / 2, 200 / 2));
        }

        @Override
        public Polygon getShape() {
            Polygon p = new Polygon(getPoints());
            return p;
        }

        @Override
        public void onDraw(Canvas canvas) {
            Context2d context = canvas.getContext2d();
            Polygon p = getShape();

            Polygon[] triangulation;
            try {
                triangulation = p.getTriangulation();
            } catch (NonSimplePolygonException x) {
                triangulation = new Polygon[] { p };
            }

            for (Polygon triangle : triangulation) {
                context.beginPath();
                context.setStrokeStyle("red");

                for (Line s : triangle.getOutlineSegments()) {
                    Point p1 = s.getP1();
                    Point p2 = s.getP2();
                    context.moveTo(p1.x, p1.y);
                    context.lineTo(p2.x, p2.y);
                    context.stroke();
                }
                context.closePath();
            }

            double lineWidth = context.getLineWidth();
            context.setLineWidth(lineWidth + 2);
            context.setStrokeStyle("black");

            context.beginPath();
            for (Line s : p.getOutlineSegments()) {
                Point p1 = s.getP1();
                Point p2 = s.getP2();
                context.moveTo(p1.x, p1.y);
                context.lineTo(p2.x, p2.y);
                context.stroke();
            }
            context.closePath();
            context.setLineWidth(lineWidth);
        }
    } };
}

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

License:BSD License

private Context2d initBracketCanvas(Canvas can) {
    can.setCoordinateSpaceHeight(can.getOffsetHeight());
    can.setCoordinateSpaceWidth(can.getOffsetWidth());

    Context2d con = can.getContext2d();

    con.setLineWidth(3);

    return con;//from   w  w  w . j a va 2 s .  co  m
}

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 a  2s  .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.oscim.gdx.client.GwtCanvas.java

License:Open Source License

@Override
public void drawText(String string, float x, float y, Paint fill, Paint stroke) {
    if (bitmap == null) {
        //log.debug("no bitmap set");
        return;/*ww  w .  ja v  a 2s .  c om*/
    }

    GwtPaint p = (GwtPaint) fill;

    if (p.stroke && GwtGdxGraphics.NO_STROKE_TEXT)
        return;

    Context2d ctx = bitmap.pixmap.getContext();
    ctx.setFont(p.font);

    if (p.stroke) {
        ctx.setLineWidth(p.strokeWidth);
        ctx.setStrokeStyle(p.color);
        ctx.strokeText(string, (int) (x + 1), (int) (y + 1));
    } else {
        ctx.setFillStyle(p.color);
        ctx.fillText(string, (int) (x + 1), (int) (y + 1));
    }
}

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

License:Apache License

/**
 * Draws a polygon/*from  w w  w .  j  av a2  s . com*/
 * @param context Canvas
 * @param polygon List of points
 * @param style Colours and line width
 * @param zoomFactor Current zoom
 * @param outline Set to <code>true</code> to draw the polygon outline
 * @param fill Set to <code>true</code> to fill the polygon
 */
public static void drawPolygon(Context2d context, Polygon polygon, RenderStyle style, double zoomFactor,
        boolean outline, boolean fill) {
    setLineColor(context, style);
    setFillColor(context, style);
    context.setLineWidth(style.getLineWidth() / zoomFactor);
    drawPolygon(context, polygon, outline, fill);
}

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