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.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;/*from   ww w. ja va 2  s  .c o m*/

    // 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 ww . j a  va  2s.co  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  ww  w.j  a  v a2s. c o m*/

    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.j a  v  a2s.c om*/

    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 w  ww .  j a v  a2 s.  c o m
    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.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw the grid.//from   w  w  w .  j a v a2  s.  c o  m
 * @param ctx A GWT Context2d object.
 */
protected void drawGrid(Context2d ctx) {
    AbstractGrid currentCell = upperLeft;
    AbstractGrid startOfRow = upperLeft;
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            if (this.isIncognita(currentCell)) {
                ctx.setFillStyle(TERRA_INCOGNITA_COLOR);
                ctx.beginPath();
                ctx.rect(j * cellSize, i * cellSize, cellSize, cellSize);
                ctx.closePath();
                ctx.fill();
            } else {
                if ((xholonConsole != null) && (currentCell == xholonConsole.getContext())) {
                    ctx.setFillStyle(COLOR_CONTEXT);
                } else {
                    ctx.setFillStyle(getColor(currentCell));
                }
                ctx.beginPath();
                ctx.rect(j * cellSize, i * cellSize, cellSize, cellSize);
                ctx.closePath();
                ctx.fill();
                if (useShapes) {
                    drawAgents(ctx, currentCell, j * cellSize, i * cellSize);
                }
            }
            currentCell = (AbstractGrid) currentCell.port[IGrid.P_EAST]; // get next cell
        }
        startOfRow = (AbstractGrid) startOfRow.port[IGrid.P_SOUTH]; // get start of next row
        currentCell = (AbstractGrid) startOfRow;
    }
}

From source file:org.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw a 1D CA grid.// ww w  . j  av a  2  s  .  c  o  m
 * @param ctx A GWT Context2d object.
 */
protected void draw1dCaGrid(Context2d ctx) {
    AbstractGrid currentCell = upperLeft;
    AbstractGrid startOfRow = upperLeft;
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            //ctx.setFillStyle(getColor(currentCell));
            if ((xholonConsole != null) && (currentCell == xholonConsole.getContext())) {
                ctx.setFillStyle(COLOR_CONTEXT);
            } else {
                ctx.setFillStyle(getColor(currentCell));
            }
            ctx.beginPath();
            ctx.rect(j * cellSize, i * cellSize, cellSize, cellSize);
            ctx.closePath();
            ctx.fill();
            if (useShapes) {
                drawAgents(ctx, currentCell, j * cellSize, i * cellSize);
            }
            currentCell = (AbstractGrid) currentCell.port[IGrid.P_CARIGHTNEIGHBOR]; // get next cell
        }
        startOfRow = (AbstractGrid) startOfRow.port[IGrid.P_CAFUTURESELF]; // get start of next row
        currentCell = (AbstractGrid) startOfRow;
    }
}

From source file:org.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw agents within the current grid cell.
 * Only one agent is drawn, for now./*  w  ww .j  a  v  a 2 s  .c  o m*/
 * GWT code to draw a triangle:
<code>
Canvas canvas = Canvas.createIfSupported();
Context2d context1 = canvas.getContext2d();
context1.beginPath();
context1.moveTo(25,0);
context1.lineTo(0,20);
context1.lineTo(25,40);
context1.lineTo(25,0);
context1.fill();
context1.closePath();
</code>
 * @param ctx A GWT Context2d object.
 * @param currentCell The grid cell that the agents will draw themselves in.
 * @param x X coordinate of the grid cell.
 * @param y Y coordinate of the grid cell.
 */
protected void drawAgents(Context2d ctx, AbstractGrid currentCell, int x, int y) {
    IXholon agent = currentCell.getFirstChild(); // this should remain as getFirstChild()
    if (agent != null) {
        if (useIcons) {
            // Test of drawImage()
            String icon = ((IDecoration) agent.getXhc()).getIcon();
            if (icon != null) {
                drawImage(ctx, icon, x, y, cellSize, cellSize);
                return;
            }
        }
        ctx.setFillStyle(getColor(agent));
        int shape = getShape(agent);
        switch (shape) {
        case GPSHAPE_CIRCLE: // OK
        {
            ctx.beginPath();
            int xcentre = x + (int) (cellSize * 0.5);
            int ycentre = y + (int) (cellSize * 0.5);
            int radius = (int) (cellSize * 0.45);
            ctx.arc(xcentre, ycentre, radius, 0, Math.PI * 2);
            ctx.closePath();
            ctx.fill();
        }
            break;
        case GPSHAPE_TRIANGLE: // OK
        {
            int xCoor[] = { (int) (0.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize) };
            int yCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.0 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 3);

            //Polygon triangle = new Polygon(xCoor, yCoor, 3);
            //triangle.translate(x, y);
            //g.fillPolygon(triangle);

            /*ctx.save();
            ctx.translate(x, y);
            ctx.beginPath();
            ctx.moveTo(0.0*cellSize, 1.0*cellSize);
            ctx.lineTo(1.0*cellSize, 1.0*cellSize);
            ctx.lineTo(0.5*cellSize, 0.0*cellSize);
            ctx.lineTo(0.0*cellSize, 1.0*cellSize);
            ctx.fill();
            ctx.closePath();
            ctx.restore();*/
        }
            break;
        case GPSHAPE_RECTANGLE: // OK
        {
            int xCoor[] = { (int) (0.1 * cellSize), (int) (0.9 * cellSize), (int) (0.9 * cellSize),
                    (int) (0.1 * cellSize) };
            int yCoor[] = { (int) (0.9 * cellSize), (int) (0.9 * cellSize), (int) (0.1 * cellSize),
                    (int) (0.1 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 4);

            //Polygon rectangle = new Polygon(xCoor, yCoor, 4);
            //rectangle.translate(x, y);
            //g.fillPolygon(rectangle);

            /*ctx.save();
            ctx.translate(x, y);
            ctx.beginPath();
            ctx.moveTo(0.1*cellSize, 0.9*cellSize);
            ctx.lineTo(0.9*cellSize, 0.9*cellSize);
            ctx.lineTo(0.9*cellSize, 0.1*cellSize);
            ctx.lineTo(0.1*cellSize, 0.1*cellSize);
            ctx.lineTo(0.1*cellSize, 0.9*cellSize);
            ctx.fill();
            ctx.closePath();
            ctx.restore();*/
        }
            break;
        case GPSHAPE_PENTAGON: {
            int xCoor[] = { (int) (0.2 * cellSize), (int) (0.8 * cellSize), (int) (1.0 * cellSize),
                    (int) (0.5 * cellSize), (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.0 * cellSize), (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 5);

            //Polygon pentagon = new Polygon(xCoor, yCoor, 5);
            //pentagon.translate(x, y);
            //g.fillPolygon(pentagon);
        }
            break;
        case GPSHAPE_HEXAGON: {
            int xCoor[] = { (int) (0.25 * cellSize), (int) (0.75 * cellSize), (int) (1.0 * cellSize),
                    (int) (0.75 * cellSize), (int) (0.25 * cellSize), (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 6);

            //ctx.beginPath();
            //drawPolygon(ctx, x, y, 0.5, 6, 0, false);
            //ctx.fill();

            //Polygon hexagon = new Polygon(xCoor, yCoor, 6);
            //hexagon.translate(x, y);
            //g.fillPolygon(hexagon);
        }
            break;
        case GPSHAPE_OCTOGON: {
            int xCoor[] = { (int) (0.3 * cellSize), (int) (0.7 * cellSize), (int) (1.0 * cellSize),
                    (int) (1.0 * cellSize), (int) (0.7 * cellSize), (int) (0.3 * cellSize),
                    (int) (0.0 * cellSize), (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.7 * cellSize),
                    (int) (0.3 * cellSize), (int) (0.0 * cellSize), (int) (0.0 * cellSize),
                    (int) (0.3 * cellSize), (int) (0.7 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 8);

            //Polygon octogon = new Polygon(xCoor, yCoor, 8);
            //octogon.translate(x, y);
            //g.fillPolygon(octogon);
        }
            break;
        case GPSHAPE_STAR: {
            int xCoor[] = { (int) (0.5 * cellSize), (int) (1.0 * cellSize), (int) (0.8 * cellSize),
                    (int) (1.0 * cellSize), (int) (0.7 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.3 * cellSize), (int) (0.0 * cellSize), (int) (0.2 * cellSize),
                    (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (0.8 * cellSize), (int) (1.0 * cellSize), (int) (0.7 * cellSize),
                    (int) (0.4 * cellSize), (int) (0.4 * cellSize), (int) (0.0 * cellSize),
                    (int) (0.4 * cellSize), (int) (0.4 * cellSize), (int) (0.7 * cellSize),
                    (int) (1.0 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 10);

            //Polygon star = new Polygon(xCoor, yCoor, 10);
            //star.translate(x, y);
            //g.fillPolygon(star);
        }
            break;
        case GPSHAPE_TURTLE: {
            int xCoor[] = { (int) (0.5 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (0.7 * cellSize), (int) (1.0 * cellSize), (int) (0.0 * cellSize),
                    (int) (1.0 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 4);

            //Polygon turtle = new Polygon(xCoor, yCoor, 4);
            //turtle.translate(x, y);
            //g.fillPolygon(turtle);
        }
            break;
        case GPSHAPE_SMALLCIRCLE: {
            ctx.beginPath();
            int xcentre = x + (int) (cellSize * 0.5);
            int ycentre = y + (int) (cellSize * 0.5);
            int radius = (int) (cellSize * 0.25);
            ctx.arc(xcentre, ycentre, radius, 0, Math.PI * 2);
            ctx.closePath();
            ctx.fill();
        }
            break;
        case GPSHAPE_SMALLRECTANGLE: {
            int xCoor[] = { (int) (0.25 * cellSize), (int) (0.75 * cellSize), (int) (0.75 * cellSize),
                    (int) (0.25 * cellSize) };
            int yCoor[] = { (int) (0.75 * cellSize), (int) (0.75 * cellSize), (int) (0.25 * cellSize),
                    (int) (0.25 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 4);
        }
            break;
        case GPSHAPE_REVERSETRIANGLE: {
            int xCoor[] = { (int) (0.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (1.0 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 3);
        }
            break;
        case GPSHAPE_CROSS: {
            int xCoor[] = { (int) (0.33 * cellSize), (int) (0.67 * cellSize), (int) (0.67 * cellSize),
                    (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.67 * cellSize),
                    (int) (0.67 * cellSize), (int) (0.33 * cellSize), (int) (0.33 * cellSize),
                    (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (0.33 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (0.33 * cellSize),
                    (int) (0.33 * cellSize), (int) (0.67 * cellSize), (int) (0.67 * cellSize),
                    (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.67 * cellSize),
                    (int) (0.67 * cellSize), (int) (0.33 * cellSize), (int) (0.33 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 12);
        }
            break;
        case GPSHAPE_DIAMOND: {
            int xCoor[] = { (int) (0.5 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize),
                    (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (0.5 * cellSize), (int) (1.0 * cellSize),
                    (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 4);
        }
            break;
        case GPSHAPE_WYE: {
            int xCoor[] = { (int) (0.25 * cellSize), (int) (0.5 * cellSize), (int) (0.75 * cellSize),
                    (int) (1.0 * cellSize), (int) (0.75 * cellSize), (int) (0.75 * cellSize),
                    (int) (0.25 * cellSize), (int) (0.25 * cellSize), (int) (0.0 * cellSize), };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (0.25 * cellSize), (int) (0.0 * cellSize),
                    (int) (0.25 * cellSize), (int) (0.75 * cellSize), (int) (1.0 * cellSize),
                    (int) (1.0 * cellSize), (int) (0.75 * cellSize), (int) (0.25 * cellSize), };
            drawPolygon(ctx, x, y, xCoor, yCoor, 9);
        }
            break;
        case GPSHAPE_LRTRIANGLE: {
            int xCoor[] = { (int) (0.0 * cellSize), (int) (0.0 * cellSize), (int) (1.0 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 3);
        }
            break;
        case GPSHAPE_RLTRIANGLE: {
            int xCoor[] = { (int) (1.0 * cellSize), (int) (1.0 * cellSize), (int) (0.0 * cellSize) };
            int yCoor[] = { (int) (0.0 * cellSize), (int) (1.0 * cellSize), (int) (0.5 * cellSize) };
            drawPolygon(ctx, x, y, xCoor, yCoor, 3);
        }
            break;
        case GPSHAPE_JAVASCRIPTCODE:
            this.makeJsShape(ctx, ((IDecoration) agent.getXhc()).getSymbol().substring(JSCODE_INDICATOR_LEN), x,
                    y, cellSize);
            break;
        case GPSHAPE_NOSHAPE:
            break;
        default: // the agent's shape directly specifies the number of sides
        {
            ctx.beginPath();
            drawPolygon(ctx, x, y, cellSize * 0.5, shape, 0, false);
            ctx.fill();
        }

        }
    }
}

From source file:org.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw a polygon./*  www  .  java2s.c  o  m*/
 */
protected void drawPolygon(Context2d ctx, int x, int y, int xCoor[], int yCoor[], int sides) {
    ctx.save();
    ctx.translate(x, y);
    ctx.beginPath();
    ctx.moveTo(xCoor[0], yCoor[0]);
    for (int i = 1; i < sides; i++) {
        ctx.lineTo(xCoor[i], yCoor[i]);
    }
    ctx.lineTo(xCoor[0], yCoor[0]);
    ctx.fill();
    ctx.closePath();
    ctx.restore();
}

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();
        ctx.setLineWidth(BLADE_WIDTH);/* www .  jav  a  2  s.  com*/
        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();
    }
}