Package com.google.gwt.canvas.dom.client

Examples of com.google.gwt.canvas.dom.client.Context2d


        endPoint.getX(), endPoint.getY());
  }
 
  @Override
  public void visit(Surface surface) {
    Context2d context = surface.getContext();
    context.moveTo(startPointX, startPointY);
    context.quadraticCurveTo(controlPointX, controlPointY,
        endPointX, endPointY);
  }
View Full Code Here


    double radius = Math.min(width, height) / 2.0;
    double cx = width / 2.0;
    double cy = height / 2.0;

    // Clear the context.
    Context2d context = canvas.getContext2d();
    context.clearRect(0, 0, width, height);

    // Get the total weight of all slices.
    double totalWeight = 0;
    for (Slice slice : slices) {
      totalWeight += slice.weight;
    }

    // Draw the slices.
    double startAngle = -0.5 * Math.PI;
    for (Slice slice : slices) {
      double weight = slice.weight / totalWeight;
      double endAngle = startAngle + (weight * RADIANS_IN_CIRCLE);
      context.setFillStyle(slice.fill);
      context.beginPath();
      context.moveTo(cx, cy);
      context.arc(cx, cy, radius, startAngle, endAngle);
      context.fill();
      startAngle = endAngle;
    }
  }
View Full Code Here

import com.google.gwt.canvas.dom.client.Context2d;

public class Test {
  public void bla() {

    Context2d ctx = Canvas.createIfSupported().getContext2d();

    ctx.fillRect(0, 0, 150, 150); // Draw a rectangle with default settings
    ctx.save(); // Save the default state

    ctx.setFillStyle("#09F"); // Make changes to the settings
    ctx.fillRect(15, 15, 120, 120); // Draw a rectangle with new settings

    ctx.save(); // Save the current state
    ctx.setFillStyle("#FFF"); // Make changes to the settings
    ctx.setGlobalAlpha(0.5);
    ctx.fillRect(30, 30, 90, 90); // Draw a rectangle with new settings

    ctx.restore(); // Restore previous state
    ctx.fillRect(45, 45, 60, 60); // Draw a rectangle with restored settings

    ctx.restore(); // Restore original state
    ctx.fillRect(60, 60, 30, 30); // Draw a rectangle with restored settings
  }
View Full Code Here

            }
        }.schedule(scene.timeUntilNextStep());
    }

    private void render() {
        Context2d context = canvas.getContext2d();
        context.setFillStyle("white");
        context.setStrokeStyle("grey");
        context.fillRect(0, 0, 600, 600);
        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();
    }
View Full Code Here

    Canvas canvas = Canvas.createIfSupported();
    canvas.getElement().setPropertyInt("height", height);
   canvas.getElement().setPropertyInt("width", width);

    Context2d context = canvas.getContext2d();
    context.drawImage(imageElement, 0, 0);
    ImageData imageData = context.getImageData(0, 0, width,
        height);

    CanvasPixelArray canvasPixelArray = imageData.getData();

    for (int i = 0; i < canvasPixelArray.getLength(); i += 4) {
      canvasPixelArray.set(i, red);
      canvasPixelArray.set(i + 1, green);
      canvasPixelArray.set(i + 2, blue);
      canvasPixelArray.set(i + 3,
      canvasPixelArray.get(i + 3));
    }
    context.putImageData(imageData, 0, 0);


    return new ConvertedImageResource(
        canvas.toDataUrl("image/png"), resource.getWidth(),
        resource.getHeight());
View Full Code Here

        final double offsetY1 = Math.sin( theta ) * getElementRadius( element1 );

        final double offsetX2 = Math.cos( theta ) * getElementRadius( element2 );
        final double offsetY2 = Math.sin( theta ) * getElementRadius( element2 );

        final Context2d context = canvas.getContext2d();
        context.moveTo( element1.getCoordinate().getX() + offsetX1,
                        element1.getCoordinate().getY() + offsetY1 );
        context.lineTo( element2.getCoordinate().getX() - offsetX2,
                        element2.getCoordinate().getY() - offsetY2 );
        context.setStrokeStyle( CssColor.make( 100, 100, 100 ) );
        context.stroke();
    }
View Full Code Here

                                                        node );
    }

    @Override
    public void draw( final Canvas canvas ) {
        final Context2d context = canvas.getContext2d();
        context.setFillStyle( CssColor.make( 200, 100, 50 ) );
        context.beginPath();
        context.arc( c.getX(),
                     c.getY(),
                     NODE_RADIUS,
                     0,
                     Math.PI * 2.0,
                     true );
        context.closePath();
        context.fill();

        context.setFont( "10pt sans-serif" );
        context.setTextAlign( Context2d.TextAlign.CENTER );
        context.setTextBaseline( Context2d.TextBaseline.MIDDLE );
        context.setFillStyle( CssColor.make( 0, 0, 0 ) );
        context.fillText( getConstraintNodeText( node ),
                          c.getX(),
                          c.getY() );
    }
View Full Code Here

                                                        node );
    }

    @Override
    public void draw( final Canvas canvas ) {
        final Context2d context = canvas.getContext2d();
        context.setFillStyle( CssColor.make( 60, 200, 126 ) );
        context.beginPath();
        context.arc( c.getX(),
                     c.getY(),
                     NODE_RADIUS,
                     0,
                     Math.PI * 2.0,
                     true );
        context.closePath();
        context.fill();

        context.setFont( "10pt sans-serif" );
        context.setTextAlign( Context2d.TextAlign.CENTER );
        context.setTextBaseline( Context2d.TextBaseline.MIDDLE );
        context.setFillStyle( CssColor.make( 0, 0, 0 ) );
        context.fillText( getTypeNodeText( node ),
                          c.getX(),
                          c.getY() );
    }
View Full Code Here

TOP

Related Classes of com.google.gwt.canvas.dom.client.Context2d

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.