List of usage examples for com.google.gwt.canvas.dom.client Context2d scale
public final native void scale(double x, double y) ;
From source file:org.geomajas.gwt2.example.client.sample.rendering.CanvasImageElement.java
License:Open Source License
@Override public void paint(Canvas canvas, Matrix matrix) { /*/* w ww.j a v a2 s . c o m*/ * paint image on canvas based on the original and with the transformations of the matrix. * */ Context2d context2d = canvas.getContext2d(); context2d.save(); boolean xReversal = matrix.getXx() < 0; boolean yReversal = matrix.getYy() < 0; context2d.scale(xReversal ? -1 : 1, yReversal ? -1 : 1); double xValue = xReversal ? box.getMaxX() * -1 : box.getX(); double yValue = yReversal ? box.getMaxY() * -1 : box.getY(); context2d.drawImage(hiddenImageCanvas.getCanvasElement(), xValue, yValue, box.getWidth(), box.getHeight()); context2d.restore(); }
From source file:org.teavm.samples.benchmark.gwt.BenchmarkStarter.java
License:Apache License
private void render() { Context2d context = canvas.getContext2d(); context.setFillStyle("white"); context.setStrokeStyle("grey"); context.fillRect(0, 0, 600, 600);//from w w w . j a va 2s . c o m 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(); }
From source file:playn.html.HtmlImageLayerCanvas.java
License:Apache License
@Override public void paint(Context2d ctx, float parentAlpha) { if (!visible() || !img.isReady()) return;/*from w w w . j a va 2 s.c om*/ ctx.save(); transform(ctx); ctx.setGlobalAlpha(parentAlpha * alpha); float width = width(); float height = height(); if (repeatX || repeatY) { updatePattern(ctx); ctx.setFillStyle(pattern); ctx.beginPath(); ctx.rect(0, 0, width, height); ctx.scale(repeatX ? 1 : width / img.width(), repeatY ? 1 : height / img.height()); ctx.fill(); } else { ((HtmlCanvas.Drawable) img).draw(ctx, 0, 0, width, height); } ctx.restore(); }