List of usage examples for com.google.gwt.canvas.dom.client Context2d fill
public final native void fill() ;
From source file:anagram.client.Ball.java
License:Apache License
public void draw(Context2d context) { context.setFillStyle(color);/*from w w w .ja va 2 s . com*/ context.beginPath(); context.arc(pos.x, pos.y, radius, 0, Math.PI * 2.0, true); context.closePath(); context.fill(); }
From source file:com.google.gwt.maeglin89273.shared.test.volcanogame.component.FireBall.java
@Override public void draw(Context2d context) { context.setFillStyle(ballColor);/*from w w w .ja v a 2 s.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 ava 2s . c o m */ 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.philbeaudoin.quebec.client.scene.Arrow.java
License:Apache License
@Override public void drawUntransformed(double time, Context2d context) { context.beginPath();//w ww .j a v a 2s . co m 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); 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();/*from w ww . j av a2s . co m*/ 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); 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 va2 s . c om*/ */ 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();// ww w . j a v a 2s. c o m sprite.toAbsolute(); // 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(); } }
From source file:edu.umb.jsPedigrees.client.Pelican.PelicanPerson.java
License:Open Source License
public void drawSymbol() { Context2d ctx = canvas.getContext2d(); // clear old symbol ctx.clearRect(0, 0, symbolSize + 1, symbolSize + 1); ctx.setStrokeStyle(CssColor.make("0,0,0")); ctx.setLineWidth(1.0f);/* w w w. j a v a 2 s . co m*/ if (sex == male) { ctx.strokeRect(0, 0, symbolSize, symbolSize); if (affection == affected) { ctx.fillRect(0, 0, symbolSize, symbolSize); } } if (sex == female) { // g2.drawArc(0,0,symbolSize,symbolSize,0,360); ctx.beginPath(); ctx.arc(symbolSize / 2, symbolSize / 2, (symbolSize / 2) - 1, 0, 360); if (affection == affected) { ctx.fill(); } else { ctx.stroke(); } } }
From source file:examples.geometry.AbstractExample.java
License:Open Source License
@Override public void draw() { Context2d context = canvas.getContext2d(); // reset/*from w ww . j ava2s . c o m*/ context.clearRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight()); context.setFillStyle("black"); context.setStrokeStyle("black"); context.setLineWidth(1); for (ControllableShape shape : getControllableShapes()) { // e.gc.setForeground(canvas.getDisplay().getSystemColor(shape.shapeColor)); // e.gc.setBackground(canvas.getDisplay().getSystemColor(shape.shapeColor)); shape.onDraw(canvas); } for (ControllableShape shape : getControllableShapes()) { if (shape.isActive()) { FillStrokeStyle fillStyle = context.getFillStyle(); for (ControlPoint cp : shape.controlPoints) { context.beginPath(); context.arc(cp.getX(), cp.getY(), shape.controlRadius, 0, 180); context.setFillStyle(shape.controlColor); context.fill(); context.closePath(); } context.setFillStyle(fillStyle); } } }
From source file:examples.geometry.containment.PolygonEllipseContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override/*from w w w. j a v a2s . c om*/ public void createControlPoints() { ControlPoint center = addControlPoint(new Point(300, 300)); ControlPoint a = addControlPoint(new Point(400, 300)); ControlPoint b = addControlPoint(new Point(300, 200)); a.setYLink(center); b.setXLink(center); } @Override public Ellipse createGeometry() { double a = Math.abs(points.get(0).getPoint().x - points.get(1).getPoint().x); double b = Math.abs(points.get(0).getPoint().y - points.get(2).getPoint().y); return new Ellipse(points.get(0).getPoint().x - a, points.get(0).getPoint().y - b, 2 * a, 2 * b); } @Override public void drawShape() { Ellipse ellipse = createGeometry(); CanvasDrawer.drawOval(ellipse, canvas.getContext2d()); } @Override public void fillShape(CssColor color) { Ellipse ellipse = createGeometry(); Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getFillStyle(); CanvasDrawer.drawOval(ellipse, context2d); context2d.setFillStyle(color.value()); context2d.fill(); context2d.setFillStyle(style); } }; }