List of usage examples for com.google.gwt.canvas.dom.client Context2d clearRect
public final native void clearRect(double x, double y, double w, double h) ;
From source file:com.fullmetalgalaxy.client.game.context.WgtContextMinimap.java
License:Open Source License
public void redraw() { assert GameEngine.model() != null; Game game = GameEngine.model().getGame(); // if( m_lastResfreshTurn != game.getCurrentTimeStep() || // m_lastResfreshGameId != game.getId() ) {/*from ww w. jav a 2s . c o m*/ m_lastResfreshTurn = game.getCurrentTimeStep(); m_lastResfreshGameId = game.getId(); canvas.setCoordinateSpaceWidth(game.getLandWidth() * 8); canvas.setCoordinateSpaceHeight(game.getLandHeight() * 8 + 4); Context2d gc = canvas.getContext2d(); gc.clearRect(0, 0, game.getLandWidth(), game.getLandHeight()); // draw lands ImageElement[] images = new ImageElement[LandType.values().length]; for (int iLand = 0; iLand < LandType.values().length; iLand++) { LandType land = LandType.values()[iLand]; Image img = new Image("/images/board/" + game.getPlanetType().getFolderName() + "/minimap/" + land.getImageName(game.getCurrentTide())); img.addLoadHandler(new LoadHandler() { @Override public void onLoad(LoadEvent event) { m_lastResfreshTurn = -1; m_lastResfreshGameId = -1; } }); images[iLand] = ImageElement.as(img.getElement()); Image.prefetch(img.getUrl()); } for (int ix = 0; ix < game.getLandWidth(); ix++) { for (int iy = 0; iy < game.getLandHeight(); iy++) { if (game.getLand(ix, iy) == LandType.Montain) { gc.drawImage(images[game.getLand(ix, iy).ordinal()], ix * 8, iy * 8 + (ix % 2) * 4, 8, 8); } else { gc.drawImage(images[game.getLand(ix, iy).ordinal()], ix * 8, iy * 8 + (ix % 2) * 4, 8, 8); } } } // draw units for (EbToken token : game.getSetToken()) { if (token.getLocation() == Location.Board && token.getColor() != EnuColor.None) { gc.drawImage(tokenImages[token.getColor()], token.getPosition().getX() * 8, token.getPosition().getY() * 8 + (token.getPosition().getX() % 2) * 4, 8, 8); for (AnBoardPosition position : token.getExtraPositions(game.getCoordinateSystem())) { gc.drawImage(tokenImages[token.getColor()], position.getX() * 8, position.getY() * 8 + (position.getX() % 2) * 4, 8, 8); } } } } if (game.getStatus() == GameStatus.Open || game.getStatus() == GameStatus.Pause) { m_panel.add(new Image(Icons.s_instance.pause32()), FmpConstant.miniMapWidth / 2 - 16, FmpConstant.miniMapHeight / 2 - 16); m_panel.add(new Label("En Pause"), 0, FmpConstant.miniMapHeight / 2 + 30); } else if (game.isFinished()) { m_panel.add(new Label("Partie termine"), 0, FmpConstant.miniMapHeight / 2 - 40); m_panel.add(new Image(Icons.s_instance.winner32()), FmpConstant.miniMapWidth / 2 - 16, FmpConstant.miniMapHeight / 2 - 16); String strWinner = ""; EbTeam winnerTeam = game.getWinnerTeam(); if ((winnerTeam != null)) { strWinner += winnerTeam.getCompany().getFullName() + ":\n"; for (EbRegistration registration : winnerTeam.getPlayers(game.getPreview())) if (registration.haveAccount()) { strWinner += registration.getAccount().getPseudo() + "\n"; } } m_panel.add(new Label(strWinner), 0, FmpConstant.miniMapHeight / 2 + 30); } }
From source file:com.google.gwt.sample.mobilewebapp.client.desktop.PieChart.java
License:Apache License
/** * Redraw the pie chart.//from w ww . j av a2s .c om */ 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.java33.vizpres.client.view.visualization.CanvasViz.java
License:Open Source License
/** * Renders the percent data values using the Canvas 2D API as horizontal * bars with a text label./*from w w w. j a va2s.c om*/ * * @param values Is the list of values to render. */ @Override public void setData(final List<PercentValue> values) { if (canvas != null) { final Context2d ctx = canvas.getContext2d(); ctx.clearRect(0, 0, width, height); ctx.setTextBaseline(Context2d.TextBaseline.TOP); if (values != null) { final int n = values.size(); for (int i = 0; i < n; i += 1) { final int rowY = i * ROW_HEIGHT; final int percent = values.get(i).percentage; final double barWidth = (double) (percent * width) / 100.0; ctx.setFillStyle("#ff6600"); ctx.fillRect(0, rowY, barWidth, BAR_HEIGHT); ctx.setFillStyle("#ffffff"); ctx.fillText(Integer.toString(percent), 4, rowY + TEXT_HEIGHT / 2); } } } }
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 .j a 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.sencha.gxt.chart.client.draw.engine.Canvas2d.java
License:sencha.com license
@Override public void renderSprite(Sprite sprite) { if (surfaceElement == null) { return;//from w w w.j av a 2s .c o m } if (!sprite.isDirty()) { return; } if (REDRAW_ALL) { component.redrawSurface(); } else { //clear this item's bbox, both old and new PreciseRectangle oldBbox = renderedBbox.get(sprite); PreciseRectangle newBbox = sprite.getBBox(); Context2d ctx = getContext(); //TODO invert this logic to cut two lines of code, and see about shorting this out better if (oldBbox != null && (oldBbox.contains(newBbox.getX(), newBbox.getY()) && oldBbox .contains(newBbox.getX() + newBbox.getWidth(), newBbox.getY() + newBbox.getHeight()))) { ctx.clearRect(oldBbox.getX(), oldBbox.getY(), oldBbox.getWidth(), oldBbox.getHeight()); } else if (oldBbox == null || (newBbox.contains(oldBbox.getX(), oldBbox.getY()) && newBbox .contains(oldBbox.getX() + oldBbox.getWidth(), oldBbox.getY() + oldBbox.getHeight()))) { //TODO if null, only clear if something is above the new sprite... ctx.clearRect(newBbox.getX(), newBbox.getY(), newBbox.getWidth(), newBbox.getHeight()); } else { ctx.clearRect(oldBbox.getX(), oldBbox.getY(), oldBbox.getWidth(), oldBbox.getHeight()); ctx.clearRect(newBbox.getX(), newBbox.getY(), newBbox.getWidth(), newBbox.getHeight()); } //in order, re-render all items that intersect the bbox, ending with the element itself //-first, find all sprites in the old bbox, or the new bbox //-sort both, merge the lists, removing duplicates (this is slightly smaller than the union) List<Sprite> oldBoxSprites = getIntersectingSprites(oldBbox); List<Sprite> newBoxSprites = getIntersectingSprites(oldBbox); //could be a list, but needs to avoid dups LinkedHashSet<Sprite> sprites = new LinkedHashSet<Sprite>(oldBoxSprites); sprites.addAll(newBoxSprites); Collections.sort(newBoxSprites, zIndexComparator()); for (Sprite s : sprites) { //TODO artificial clip to limit to what has been cleared append(s); } } }
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);//from www .j a v a2s . com 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
public void remove() { Context2d context = canvas.getContext2d(); context.clearRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight()); }
From source file:examples.geometry.AbstractExample.java
License:Open Source License
@Override public void draw() { Context2d context = canvas.getContext2d(); // reset//ww w. j ava 2 s . c om 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.AbstractContainmentExample.java
License:Open Source License
@Override public void draw() { Context2d context2d = canvas.getContext2d(); context2d.clearRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceWidth()); IGeometry cs1geometry = controllableShape1.createGeometry(); IGeometry cs2geometry = controllableShape2.createGeometry(); if (computeIntersects(cs1geometry, cs2geometry)) { controllableShape2.fillShape(INTERSECTS_COLOR); }/* w w w .j a va 2 s.com*/ if (computeContains(cs1geometry, cs2geometry)) { controllableShape2.fillShape(CONTAINS_COLOR); } controllableShape1.drawShape(); controllableShape2.drawShape(); controllableShape1.drawControlPoints(); controllableShape2.drawControlPoints(); }
From source file:org.oscim.gdx.client.GwtCanvas.java
License:Open Source License
@Override public void setBitmap(Bitmap bitmap) { this.bitmap = (GwtBitmap) bitmap; Context2d ctx = this.bitmap.pixmap.getContext(); ctx.clearRect(0, 0, this.bitmap.getWidth(), this.bitmap.getHeight()); ctx.setLineJoin(LineJoin.BEVEL);// w w w . ja v a 2 s . c om }