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:examples.geometry.demos.TriangulationExample.java

License:Open Source License

@Override
protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) {
    return new ControllableShape[] { new ControllableShape(canvas, eventBus) {
        {/*ww w.ja  va  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:forplay.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  v a  2 s .c  o  m*/
            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_ARC: {
            double curX = x, curY = 0;
            double radius = list.get(i++);
            x = list.get(i++);
            y = list.get(i++);
            ctx.arcTo(curX, curY, x, y, radius);
            break;
        }
        case CMD_CLOSE: {
            ctx.closePath();
            break;
        }

        default:
            throw new AssertionError("Corrupt command list");
        }
    }
}

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

License:BSD License

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

    con.beginPath();

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

    if (!mTerminus) {
        con.moveTo(0, height / 4.0);/*  ww w .j  a  v a  2s .c om*/
        con.lineTo(width / 2.0, height / 4.0);
        con.lineTo(width / 2.0, (3.0 * height) / 4.0);
        con.lineTo(0, (3.0 * height) / 4);
        con.stroke();
    }

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

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

License:BSD License

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

    con.beginPath();

    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();//from  ww w.jav a 2s.  c o  m
    }

    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();

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

    con.moveTo(0, height / 2.0);/*from  ww w.j ava  2s.  c  o  m*/
    con.lineTo(width, height / 2.0);
    con.stroke();
}

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

License:Open Source License

/**
 * FOR TESING/*from w  w w.j a v a 2s .  co  m*/
 */
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();
    context.arc(0, 0, options.pixelSize, 0, Math.PI * 2, true);
    context.closePath();//from w w w.  j  a  va  2s .  c  o  m
    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.cleanlogic.cesiumjs4gwt.showcase.examples.ParticleSystemFireworks.java

License:Apache License

private CanvasElement getImage() {
    if (!Cesium.defined(particleCanvas)) {
        particleCanvas = RootPanel.get().getElement().getOwnerDocument().createCanvasElement();
        particleCanvas.setWidth(20);/*from   w  w w. j a  v  a  2s .c  om*/
        particleCanvas.setHeight(20);
        Context2d context2d = particleCanvas.getContext2d();
        context2d.beginPath();
        context2d.arc(8, 8, 8, 0, Math.TWO_PI(), true);
        context2d.closePath();
        context2d.setFillStyle("rgb(255, 255, 255)");
        context2d.fill();
        Cesium.log(particleCanvas);
    }
    return particleCanvas;
}

From source file:org.cruxframework.crux.widgets.client.colorpicker.HuePicker.java

License:Apache License

private void drawGradient() {
    Context2d ctx = canvas.getContext2d();

    // draw gradient
    ctx.setFillStyle("#ffffff");
    ctx.fillRect(0, 0, 26, 180);/*from   ww  w  . ja va 2  s  .c  o  m*/
    for (int y = 0; y <= 179; y++) {
        String hex = ColorUtils.hsl2hex(y * 2, 100, 100);
        ctx.setFillStyle("#" + hex);
        ctx.fillRect(3, y, 20, 1);
    }

    // draw handle
    if (handleY >= 0) {
        ctx.setFillStyle("#000000");

        ctx.beginPath();
        ctx.moveTo(3, handleY);
        ctx.lineTo(0, handleY - 3);
        ctx.lineTo(0, handleY + 3);
        ctx.closePath();
        ctx.fill();

        ctx.moveTo(23, handleY);
        ctx.lineTo(26, handleY - 3);
        ctx.lineTo(26, handleY + 3);
        ctx.closePath();
        ctx.fill();
    }
}

From source file:org.cruxframework.crux.widgets.client.colorpicker.SaturationLightnessPicker.java

License:Apache License

private void drawGradient(boolean drawHandle) {
    Context2d ctx = canvas.getContext2d();

    // draw gradient
    for (int x = 0; x <= 179; x++) {
        CanvasGradient grad = ctx.createLinearGradient(x, 0, x, 179);
        int s = Math.round(x * 100 / 179);
        String hex = ColorUtils.hsl2hex(hue, s, 0);
        grad.addColorStop(0, "#" + hex);
        hex = ColorUtils.hsl2hex(hue, s, 100);
        grad.addColorStop(1, "#" + hex);
        ctx.setFillStyle(grad);/*  w  ww  .  j  av a  2s .  co m*/
        ctx.fillRect(x, 0, 1, 180);
    }

    // draw handle
    if (drawHandle) {
        ctx.beginPath();
        ctx.arc(handleX, handleY, 3, 0, Math.PI * 2, false);
        ctx.closePath();
        ctx.setFillStyle("#ffffff");
        ctx.fill();

        ctx.beginPath();
        ctx.arc(handleX, handleY, 2, 0, Math.PI * 2, false);
        ctx.closePath();
        ctx.setFillStyle("#000000");
        ctx.fill();
    }
}