@Override public Surface clear() { canvas.clear(); return this; }
/** Starts a drawing session into this glyph's canvas. Call {@link #end} when drawing is done. * Valid after {@link #prepare}. */ public Canvas begin () { return _layer.begin().clear(); }
public void paint(Canvas canvas) { canvas.clear(); rootLayer.paint(canvas, 1); }
protected void addAction(CanvasLayer actions, String action) { _actions.add(0, action); if (_actions.size() > 10) _actions.subList(10, _actions.size()).clear(); Canvas canvas = actions.begin(); canvas.clear(); StringBuilder buf = new StringBuilder(); for (String a : _actions) { if (buf.length() > 0) buf.append("\n"); buf.append(a); } canvas.setFillColor(0xFF000000); float y = 0; for (TextLayout layout : game.graphics.layoutText( buf.toString(), game.ui.TEXT_FMT, new TextWrap(300))) { canvas.fillText(layout, 0, y); y += layout.ascent() + layout.descent() + layout.leading(); } actions.end(); }
protected void addAction(String action) { _actions.add(0, action); if (_actions.size() > 10) _actions.subList(10, _actions.size()).clear(); _actionsImage.canvas().clear(); StringBuilder buf = new StringBuilder(); for (String a : _actions) { if (buf.length() > 0) buf.append("\n"); buf.append(a); } _actionsImage.canvas().setFillColor(0xFF000000); float y = 0; for (TextLayout layout : graphics().layoutText(buf.toString(), TEXT_FMT, new TextWrap(300))) { _actionsImage.canvas().fillText(layout, 0, y); y += layout.ascent() + layout.descent() + layout.leading(); } }
@Override public void paint(float delta) { super.paint(delta); int curSecs = (int)(elapsedMillis/1000); if (curSecs != lastSecs) { timeImg.canvas().clear(); timeImg.canvas().setStrokeColor(0xFF000000); timeImg.canvas().strokeRect(0, 0, 100, 100); timeImg.canvas().drawText(""+curSecs, 40, 55); lastSecs = curSecs; } // round the width so that it goes to zero sometimes (which should be fine) tileLayer.setWidth(Math.round(Math.abs(FloatMath.sin(elapsedMillis/2)) * 100)); }
public void paint() { if (!dirty) { return; } Canvas canvas = layer.begin(); canvas.clear(); canvas.setFillColor(0xFF202020); layout = game.graphics.layoutText(text, format, TextWrap.MANUAL); float yy = 0; for (int line = 0; line < layout.length; line++) { canvas.fillText(layout[line], 0, yy); yy += layout[line].size.height(); } // if (yy > layer.height()) { // game.log.error("Clipped"); // } layer.end(); dirty = false; } }
@Override public void update(int delta) { canvas.clear(); canvas.setStrokeWidth(3); canvas.setStrokeColor(0x88ff0000); noSegs += direction; if (noSegs > 50) direction = -1; if (noSegs < 20) direction = 1; final float r = 100; for (int ii = 0; ii < noSegs; ii++) { float angle = 2*FloatMath.PI * ii / noSegs; float x = (r * FloatMath.cos(angle)) + graphics().width() / 2; float y = (r * FloatMath.sin(angle)) + graphics().height() /2; canvas.strokeCircle(x, y, 100); } } }
/** Updates the HUDs rendered image. Call this after all of its values have been updated * (usually once per second). */ public void update () { // update all of our rows and compute layout metrics float width = 0, height = 0, labelWidth = 0; for (Row row : _rows) { row.update(); width = Math.max(row.size().width(), width); labelWidth = Math.max(row.labelWidth(), labelWidth); height += row.size().height(); } // add in borders width += 5*GAP; height += GAP*_rows.size()+GAP; // create a new image if necessary if (layer.width() < width || layer.height() < height) layer.resize(width, height); // clear our image and render our rows Canvas canvas = layer.begin(); canvas.clear(); canvas.setFillColor(_bgColor).fillRect(0, 0, width, height); canvas.setStrokeColor(_textColor).setFillColor(_textColor); float x = GAP, y = GAP, valueX = labelWidth+2*GAP; for (Row row : _rows) { row.render(canvas, x, y, valueX); y += row.size().height()+GAP; } layer.end(); }
public void paint() { if (!dirty) { return; } image.canvas().clear(); image.canvas().setFillColor(0xFF202020); layout = graphics().layoutText(text, format, TextWrap.MANUAL); float yy = 0; for (int line = 0; line < layout.length; line++) { image.canvas().fillText(layout[line], 0, yy); yy += layout[line].height(); } if (yy > image.height()) { log().error("Clipped"); } dirty = false; } }
@Override public void init() { CanvasLayer clayer = new CanvasLayer(game.graphics, game.graphics.viewSize); game.rootLayer.add(clayer); conns.add(game.update.connect(clock -> { Canvas canvas = clayer.begin(); canvas.clear(); canvas.setStrokeWidth(3); canvas.setStrokeColor(0x88ff0000); noSegs += direction; if (noSegs > 50) direction = -1; if (noSegs < 20) direction = 1; float r = 100; for (int ii = 0; ii < noSegs; ii++) { float angle = 2*FloatMath.PI * ii / noSegs; IDimension viewSize = game.plat.graphics().viewSize; float x = (r * FloatMath.cos(angle)) + viewSize.width() / 2; float y = (r * FloatMath.sin(angle)) + viewSize.height() /2; canvas.strokeCircle(x, y, 100); } clayer.end(); // reupload the image data })); } }
if (curSecs != lastSecs) { Canvas tcanvas = time.begin(); tcanvas.clear(); tcanvas.setStrokeColor(0xFF000000).strokeRect(0, 0, 99, 99); tcanvas.drawText(""+curSecs, 40, 55);