List of usage examples for com.google.gwt.canvas.dom.client Context2d translate
public final native void translate(double x, double y) ;
From source file:org.primordion.xholon.io.GridPanel.java
License:Open Source License
/** * Draw a polygon.//from ww w .j a v a 2 s.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.primordion.xholon.io.GridPanel.java
License:Open Source License
/** * Draw a regular polygon.//from w w w .j av a 2 s .c om * Example: <code> context.beginPath(); polygon(context,350,125,100,6,-Math.PI/2); context.fillStyle="rgba(51,128,255,0.75)"; context.fill(); context.stroke(); </code> * @param ctx A GWT Context2d object. * @param x X coordinate of the grid cell. * @param y Y coordinate of the grid cell. * @param radius * @param sides The number of sides in the polygon. This value must be >= 3. * @param startAngle Angle in radians. * @param anticlockwise Draw clockwise (false) or anticlockwise (true). * @see http://www.storminthecastle.com/2013/07/24/how-you-can-draw-regular-polygons-with-the-html5-canvas-api/ */ protected void drawPolygon(Context2d ctx, int x, int y, double radius, int sides, double startAngle, boolean anticlockwise) { if (sides < 3) return; double a = (Math.PI * 2) / sides; a = anticlockwise ? -a : a; ctx.save(); ctx.translate(x, y); ctx.rotate(startAngle); ctx.moveTo(radius, 0); for (int i = 1; i < sides; i++) { //double xcoor = radius * Math.cos(a * i); //double ycoor = radius * Math.sin(a * i); //System.out.println("i:" + i + " xcoor:" + xcoor + " ycoor:" + ycoor); //ctx.lineTo(xcoor, ycoor); ctx.lineTo(radius * Math.cos(a * i), radius * Math.sin(a * i)); } ctx.closePath(); ctx.restore(); }
From source file:org.rstudio.studio.client.workbench.views.vcs.dialog.graph.GraphLine.java
License:Open Source License
private void draw(Canvas canvas, GraphTheme theme) { int height = theme.getRowHeight(); int colWidth = theme.getColumnWidth(); double pad = theme.getVerticalLinePadding(); canvas.setCoordinateSpaceHeight(height); canvas.setCoordinateSpaceWidth(colWidth * getTotalWidth(theme)); Context2d ctx = canvas.getContext2d(); //ctx.clearRect(0, 0, colWidth * columns_.length, height); ctx.translate(colWidth / 2.0, 0); int startPos = -1; int endPos = -1; int nexusColumn = -1; for (int i = 0; i < columns_.length; i++) { GraphColumn c = columns_[i];/*ww w . j ava2 s. co m*/ if (!c.start) startPos++; if (!c.end) endPos++; ctx.setStrokeStyle(theme.getColorForId(c.id)); ctx.setLineWidth(theme.getStrokeWidth()); ctx.setLineJoin(LineJoin.ROUND); if (!c.nexus && !c.start && !c.end) { // Just draw a line from start to end position ctx.beginPath(); ctx.moveTo(startPos * colWidth, 0); ctx.lineTo(startPos * colWidth, pad); // This next lineTo helps ensure that the shape of the line looks // congruous to any specials on the same line ctx.lineTo(Math.min(startPos, endPos) * colWidth, height / 2.0); ctx.lineTo(endPos * colWidth, height - pad); ctx.lineTo(endPos * colWidth, height); ctx.stroke(); } else { // something special if (c.nexus) { nexusColumn = i; ctx.setFillStyle(theme.getColorForId(c.id)); } if (!c.start) { // draw from i to nexusColumn; ctx.beginPath(); ctx.moveTo(startPos * colWidth, 0); ctx.lineTo(startPos * colWidth, pad); ctx.lineTo(nexusColumn * colWidth, height / 2.0); ctx.stroke(); } if (!c.end) { // draw from nexusColumn to endPosition ctx.beginPath(); ctx.moveTo(nexusColumn * colWidth, height / 2.0); ctx.lineTo(endPos * colWidth, height - pad); ctx.lineTo(endPos * colWidth, height); ctx.stroke(); } } } // draw a circle on the nexus ctx.beginPath(); ctx.arc(nexusColumn * colWidth, height / 2.0, theme.getCircleRadius() + theme.getStrokeWidth(), 0, Math.PI * 2); ctx.closePath(); ctx.fill(); ctx.beginPath(); ctx.arc(nexusColumn * colWidth, height / 2.0, theme.getCircleRadius(), 0, Math.PI * 2); ctx.closePath(); ctx.setFillStyle("white"); ctx.fill(); }
From source file:org.rstudio.studio.client.workbench.views.vcs.diff.NavGutter.java
License:Open Source License
public void setData(CssColor background, ArrayList<CssColor> lines) { Canvas newCanvas = Canvas.createIfSupported(); newCanvas.setSize("100%", "100%"); newCanvas.setCoordinateSpaceWidth(10); newCanvas.setCoordinateSpaceHeight(lines.size()); Context2d ctx = newCanvas.getContext2d(); ctx.translate(0.5, 0.5); ctx.setFillStyle(background.value()); ctx.fillRect(0, 0, 10, lines.size()); for (int i = 0; i < lines.size(); i++) { CssColor color = lines.get(i);//from w w w.j av a2 s . c om if (color != null) { ctx.setFillStyle(color.value()); ctx.fillRect(0, i, 10, 1); } } container_.setWidget(newCanvas); }
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 ava 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.flash.FlashImmediateLayerCanvas.java
License:Apache License
void transform(Context2d ctx) { ctx.translate(originX, originY); ctx.transform(transform.m00(), transform.m01(), transform.m10(), transform.m11(), transform.tx() - originX, transform.ty() - originY);//w ww . j a v a 2 s. co m ctx.translate(-originX, -originY); }