List of usage examples for com.google.gwt.canvas.dom.client Context2d beginPath
public final native void beginPath() ;
From source file:anagram.client.Ball.java
License:Apache License
public void draw(Context2d context) { context.setFillStyle(color);//from ww w. j a v a 2 s. c om context.beginPath(); context.arc(pos.x, pos.y, radius, 0, Math.PI * 2.0, true); context.closePath(); context.fill(); }
From source file:anagram.client.Lens.java
License:Apache License
public void draw(Context2d back, Context2d front) { front.drawImage(back.getCanvas(), 0, 0); if (!GWT.isScript()) { // in devmode this effect is slow so we disable it here } else {/*w w w .j a v a 2 s . co m*/ ImageData frontData = front.getImageData((int) (pos.x - radius), (int) (pos.y - radius), 2 * radius, 2 * radius); CanvasPixelArray frontPixels = frontData.getData(); ImageData backData = back.getImageData((int) (pos.x - radius), (int) (pos.y - radius), 2 * radius, 2 * radius); CanvasPixelArray backPixels = backData.getData(); int srcIdx, dstIdx; for (int i = lensArray.length - 1; i >= 0; i--) { dstIdx = 4 * lensArray[i][0]; srcIdx = 4 * lensArray[i][1]; frontPixels.set(dstIdx + 0, backPixels.get(srcIdx + 0)); frontPixels.set(dstIdx + 1, backPixels.get(srcIdx + 1)); frontPixels.set(dstIdx + 2, backPixels.get(srcIdx + 2)); } front.putImageData(frontData, (int) (pos.x - radius), (int) (pos.y - radius)); } front.setStrokeStyle(strokeStyle); front.beginPath(); front.arc(pos.x, pos.y, radius, 0, Math.PI * 2, true); front.closePath(); front.stroke(); }
From source file:com.google.gwt.maeglin89273.shared.test.volcanogame.component.FireBall.java
@Override public void draw(Context2d context) { context.setFillStyle(ballColor);/* w w w. ja v a2s . c o m*/ //context.setShadowColor(ballShadowColor.toString()); context.beginPath(); context.arc(position.getX(), position.getY(), radius, 0, 2 * Math.PI); context.closePath(); context.fill(); }
From source file:com.google.gwt.sample.mobilewebapp.client.desktop.PieChart.java
License:Apache License
/** * Redraw the pie chart.// w ww . j ava2 s. com */ public void redraw() { if (!isAttached()) { return; } // Get the dimensions of the chart. int width = canvas.getCoordinateSpaceWidth(); int height = canvas.getCoordinateSpaceHeight(); 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; } }
From source file:com.kk_electronic.kkportal.debug.modules.UsageGraph.java
License:Open Source License
@Inject public UsageGraph(CpuUsage model) { Context2d context = canvas.getContext2d(); model.addDisplay(this); context.setLineWidth(1);//from ww w. ja v a2 s.c o m context.setStrokeStyle("black"); canvas.getElement().getStyle().setBorderWidth(borderSize, Unit.PX); canvas.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); canvas.getElement().getStyle().setBorderColor(borderColor); context.beginPath(); context.moveTo(1, 1); context.lineTo(1, 50); context.lineTo(100, 50); context.lineTo(50, 1); context.closePath(); context.stroke(); timer.scheduleRepeating(100); }
From source file:com.kk_electronic.kkportal.debug.modules.UsageGraph.java
License:Open Source License
private void drawPath(List<? extends Double> values, double shift) { if (values == null || values.isEmpty()) return;/*from ww w . ja va 2s .c o m*/ Context2d context = canvas.getContext2d(); // context.setTransform(m11, m12, m21, m22, dx, dy) context.clearRect(0, 0, canvas.getOffsetWidth(), canvas.getCoordinateSpaceHeight()); // context.clear(); context.beginPath(); double pixelpersecond = canvas.getCoordinateSpaceWidth() / magicNumber; int o = Math.max(60 - values.size(), 0); // How many missing values context.moveTo((o - shift * 2 - 1) * pixelpersecond, canvas.getCoordinateSpaceHeight() * values.get(0)); for (int i = 1, l = values.size(); i < l; i++) { double x = (i + o - shift * 2 - 1) * pixelpersecond; double y = canvas.getCoordinateSpaceHeight() * (1 - values.get(i)); context.lineTo(x, y); } context.stroke(); }
From source file:com.philbeaudoin.quebec.client.scene.Arrow.java
License:Apache License
@Override public void drawUntransformed(double time, Context2d context) { context.beginPath(); context.moveTo(from.getX(), from.getY()); context.bezierCurveTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY()); context.lineTo(p4.getX(), p4.getY()); context.lineTo(to.getX(), to.getY()); context.lineTo(p5.getX(), p5.getY()); context.lineTo(p6.getX(), p6.getY()); context.bezierCurveTo(p2.getX(), p2.getY(), p1.getX(), p1.getY(), from.getX(), from.getY()); context.setLineWidth(0.0045);//from w w w . ja va2s. co m context.setStrokeStyle("#aaa"); context.stroke(); context.setLineWidth(0.001); context.setStrokeStyle("#000"); context.stroke(); context.fill(); }
From source file:com.philbeaudoin.quebec.client.scene.Callout.java
License:Apache License
@Override public void drawUntransformed(double time, Context2d context) { context.beginPath(); context.moveTo(p1.getX(), p1.getY()); context.lineTo(to.getX(), to.getY()); context.lineTo(p3.getX(), p3.getY()); context.lineTo(p1.getX(), p1.getY()); context.setLineWidth(0.002);//from w ww . j a va 2 s.com context.setStrokeStyle("#000"); context.stroke(); context.setFillStyle("#aaa"); context.fill(); }
From source file:com.sencha.gxt.chart.client.draw.engine.Canvas2d.java
License:sencha.com license
/** * In the Canvas2d class, this method does more or less what renderSprite does in SVG and VML - it * actually renders the sprite to the dom. * @param sprite the sprite to draw//w ww . j a va 2s. c o m */ protected void append(Sprite sprite) { if (sprite.isHidden() || sprite.getOpacity() == 0) { return; } Context2d ctx = getContext(); ctx.save(); //set global stuff, fill, stroke, clip, etc //clip - deal with translation or normal rectangle if (sprite.getClipRectangle() != null) { PreciseRectangle clip = sprite.getClipRectangle(); if (sprite.getScaling() != null || sprite.getTranslation() != null || sprite.getRotation() != null) { PathSprite transPath = new PathSprite(new RectangleSprite(clip)); transPath = transPath.map(sprite.transformMatrix()); appendPath(ctx, transPath); } else { ctx.beginPath(); ctx.rect(clip.getX(), clip.getY(), clip.getWidth(), clip.getHeight()); ctx.closePath(); } ctx.clip(); } if (sprite.getScaling() != null || sprite.getTranslation() != null || sprite.getRotation() != null || (component.isViewBox() && viewbox != null)) { Matrix matrix = sprite.transformMatrix(); if (matrix != null) { //TODO consider replacing this transform call with three distinct calls to translate/scale/rotate if cheaper ctx.transform(matrix.get(0, 0), matrix.get(1, 0), matrix.get(0, 1), matrix.get(1, 1), matrix.get(0, 2), matrix.get(1, 2)); } if (component.isViewBox() && viewbox != null) { double size = Math.min(getWidth() / viewbox.getWidth(), getHeight() / viewbox.getHeight()); ctx.scale(size, size); ctx.translate(-viewbox.getX(), -viewbox.getY()); } } //TODO see about caching colors via the dirty flag? If we don't use a color/gradient for a pass or three, dump it double opacity = Double.isNaN(sprite.getOpacity()) ? 1.0 : sprite.getOpacity(); PreciseRectangle untransformedBbox = sprite.getPathSprite().dimensions(); if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setLineWidth(Double.isNaN(sprite.getStrokeWidth()) ? 1.0 : sprite.getStrokeWidth()); ctx.setStrokeStyle(getColor(sprite.getStroke(), untransformedBbox));//TODO read bbox from cache } if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setFillStyle(getColor(sprite.getFill(), untransformedBbox));//TODO read bbox from cache } if (sprite instanceof PathSprite) { appendPath(ctx, (PathSprite) sprite); } else if (sprite instanceof TextSprite) { TextSprite text = (TextSprite) sprite; //TODO style and weight ctx.setFont(text.getFontSize() + "px " + text.getFont()); ctx.setTextAlign(getTextAlign(text.getTextAnchor())); ctx.setTextBaseline(getTextBaseline(text.getTextBaseline())); ctx.fillText(text.getText(), text.getX(), text.getY()); } else if (sprite instanceof RectangleSprite) { RectangleSprite rect = (RectangleSprite) sprite; if (Double.isNaN(rect.getRadius()) || rect.getRadius() == 0) { if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setGlobalAlpha( Double.isNaN(sprite.getFillOpacity()) ? opacity : opacity * sprite.getFillOpacity()); ctx.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); } if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setGlobalAlpha(Double.isNaN(sprite.getStrokeOpacity()) ? opacity : opacity * sprite.getStrokeOpacity()); ctx.strokeRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); } } else { appendPath(ctx, rect.getPathSprite()); } } else if (sprite instanceof CircleSprite) { CircleSprite circle = (CircleSprite) sprite; ctx.beginPath(); ctx.arc(circle.getCenterX(), circle.getCenterY(), circle.getRadius(), 0, 2 * Math.PI); ctx.closePath(); if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setGlobalAlpha( Double.isNaN(sprite.getFillOpacity()) ? opacity : opacity * sprite.getFillOpacity()); ctx.fill(); } if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setGlobalAlpha( Double.isNaN(sprite.getStrokeOpacity()) ? opacity : opacity * sprite.getStrokeOpacity()); ctx.stroke(); } } else if (sprite instanceof EllipseSprite) { appendPath(ctx, sprite.getPathSprite()); } else if (sprite instanceof ImageSprite) { ImageSprite image = (ImageSprite) sprite; ImageElement elt = Document.get().createImageElement(); elt.setSrc(image.getResource().getSafeUri().asString()); ctx.drawImage(elt, image.getX(), image.getY(), image.getWidth(), image.getHeight()); } ctx.restore(); if (!REDRAW_ALL) { renderedBbox.put(sprite, getBBox(sprite)); } sprite.clearDirtyFlags(); }
From source file:com.sencha.gxt.chart.client.draw.engine.Canvas2d.java
License:sencha.com license
protected void appendPath(Context2d ctx, PathSprite sprite) { ctx.beginPath(); sprite.toAbsolute();/* w ww . j ava 2 s .c o m*/ // sprite = sprite.copy().toCurve(); PrecisePoint currentPoint = new PrecisePoint(); PrecisePoint movePoint = new PrecisePoint(); PrecisePoint curvePoint = new PrecisePoint(); PrecisePoint quadraticPoint = new PrecisePoint(); appendPathCommands(ctx, sprite.getCommands(), currentPoint, movePoint, curvePoint, quadraticPoint); double opacity = Double.isNaN(sprite.getOpacity()) ? 1.0 : sprite.getOpacity(); if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setGlobalAlpha(Double.isNaN(sprite.getFillOpacity()) ? opacity : opacity * sprite.getFillOpacity()); ctx.fill(); } if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setLineCap(sprite.getStrokeLineCap() == null ? LineCap.BUTT : sprite.getStrokeLineCap()); ctx.setLineJoin(sprite.getStrokeLineJoin() == null ? LineJoin.MITER : sprite.getStrokeLineJoin()); ctx.setMiterLimit(sprite.getMiterLimit() == Double.NaN ? 4 : sprite.getMiterLimit()); ctx.setGlobalAlpha( Double.isNaN(sprite.getStrokeOpacity()) ? opacity : opacity * sprite.getStrokeOpacity()); ctx.stroke(); } }