public void render (Canvas canvas, float x, float y, float valueX) { canvas.fillText(_layout, x, y); } protected TextLayout _layout;
protected void updateDisplay() { StringBuffer buf = new StringBuffer(); if (notifications.isEmpty()) { buf.append("No notifications. Pause and resume the game to generate some."); } else { buf.append("Notifications:\n"); for (String note : notifications) buf.append(note).append("\n"); } TextLayout layout = game.graphics.layoutText(buf.toString(), new TextFormat()); Canvas canvas = game.graphics.createCanvas(layout.size); canvas.setFillColor(0xFF000000).fillText(layout, 0, 0); layer.setTile(canvas.toTexture()); } }
public void render (Canvas canvas, float x, float y, float valueX) { if (header) canvas.drawLine(0, y-1, canvas.width, y-1); canvas.fillText(layout, x, y); float by = y + layout.size.height(); if (header) canvas.drawLine(0, by, canvas.width, by); } });
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(); } }
protected void updateDisplay() { StringBuffer buf = new StringBuffer(); if (notifications.isEmpty()) { buf.append("No notifications. Pause and resume the game to generate some."); } else { buf.append("Notifications:\n"); for (String note : notifications) buf.append(note).append("\n"); } TextLayout layout = graphics().layoutText(buf.toString(), new TextFormat()); CanvasImage image = graphics().createImage(layout.width(), layout.height()); image.canvas().setFillColor(0xFF000000); image.canvas().fillText(layout, 0, 0); layer.setImage(image); } }
protected Texture makeLabel(String label) { TextLayout layout = game.graphics.layoutText(label, new TextFormat()); Canvas canvas = game.graphics.createCanvas(layout.size); canvas.setFillColor(0xFF000000).fillText(layout, 0, 0); return canvas.toTexture(); }
public void draw(Canvas canvas) { canvas.setFillColor(0xFFCCCCCC).fillRect(0, 0, 50, 50); canvas.setFillColor(0xFFCCCCCC).fillRect(50, 50, 50, 50); TextLayout capF = graphics().layoutText("F", new TextFormat().withFont(F_FONT)); float theta = -FloatMath.PI/4, tsin = FloatMath.sin(theta), tcos = FloatMath.cos(theta); canvas.setFillColor(0xFF000000).fillText(capF, 0, 0); canvas.transform(tcos, -tsin, tsin, tcos, 50, 50); canvas.setFillColor(0xFF000000).fillText(capF, 0, 0); } });
public void draw(Canvas canvas) { // draw a rounded rect directly canvas.setFillGradient(graphics().createLinearGradient( 0, 0, 100, 100, new int[] { 0xFF0000FF, 0xFF00FF00 }, new float[] { 0, 1 })); TextLayout capF = graphics().layoutText("F", new TextFormat().withFont(F_FONT.derive(96))); canvas.fillText(capF, 15, 5); } });
/** * Fills {@code lines} into {@code canvas} at the specified coordinates, using the specified * alignment. */ public void fill(Canvas canvas, Align align, float x, float y) { float sy = y + bounds.y(); for (TextLayout line : lines) { float sx = x + bounds.x() + align.getX(line.size.width(), textWidth()); canvas.fillText(line, sx, sy); sy += line.ascent() + line.descent() + line.leading(); } }
/** * Fills {@code lines} into {@code canvas} at the specified coordinates, using the specified * alignment. */ public void fill(Canvas canvas, Align align, float x, float y) { float sy = y + bounds.y(); for (TextLayout line : lines) { float sx = x + bounds.x() + align.getX(line.size.width(), textWidth()); canvas.fillText(line, sx, sy); sy += line.ascent() + line.descent() + line.leading(); } }
/** * Fills {@code lines} into {@code canvas} at the specified coordinates, using the specified * alignment. */ public void fill(Canvas canvas, Align align, float x, float y) { float sy = y + bounds.y(); for (TextLayout line : lines) { float sx = x + bounds.x() + align.getX(line.width(), textWidth()); canvas.fillText(line, sx, sy); sy += line.ascent() + line.descent() + line.leading(); } }
@Override public void render (Canvas canvas, TextLayout layout, int textColor, boolean underlined, float x, float y) { canvas.save(); canvas.setFillColor(textColor); if (underlined) { IRectangle bounds = layout.bounds; float sx = x + bounds.x(), sy = y + bounds.y() + bounds.height() + 1; canvas.fillRect(sx, sy, bounds.width(), 1); } canvas.fillText(layout, x, y); canvas.restore(); } };
protected void addInfo (Canvas canvas, float cx, float y) { TextFormat infoFormat = new TextFormat(new Font("Helvetica", 12)); TextLayout ilayout = game.graphics.layoutText(canvas.width + "x" + canvas.height, infoFormat); Canvas iimage = game.graphics.createCanvas(ilayout.size); iimage.setFillColor(0xFF000000).fillText(ilayout, 0, 0); game.rootLayer.addAt(new ImageLayer(iimage.toTexture()), cx - iimage.width/2, y); } }
protected Image makeLabel(String label) { TextLayout layout = graphics().layoutText(label, new TextFormat()); CanvasImage image = graphics().createImage(layout.width(), layout.height()); image.canvas().setFillColor(0xFF000000); image.canvas().fillText(layout, 0, 0); return image; }
protected ImageLayer createLabel(String text, GroupLayer parent, int fg, int bg, float x, float y, float padding) { TextLayout layout = game.graphics.layoutText(text, baseFormat); float twidth = layout.size.width() + padding * 2; float theight = layout.size.height() + padding * 2; Canvas canvas = game.graphics.createCanvas(twidth, theight); if (bg != 0) canvas.setFillColor(bg).fillRect(0, 0, twidth, theight); canvas.setFillColor(fg).fillText(layout, padding, padding); ImageLayer imageLayer = new ImageLayer(canvas.toTexture()); parent.addAt(imageLayer, x, y); return imageLayer; }
public Texture formatText (TextFormat format, String text, boolean border) { TextLayout layout = game.graphics.layoutText(text, format); float margin = border ? 10 : 0; float width = layout.size.width()+2*margin, height = layout.size.height()+2*margin; Canvas canvas = game.graphics.createCanvas(width, height); if (border) canvas.setFillColor(0xFFCCCCCC).fillRect(0, 0, canvas.width, canvas.height); canvas.setFillColor(0xFF000000).fillText(layout, margin, margin); if (border) canvas.setStrokeColor(0xFF000000).strokeRect(0, 0, width-1, height-1); return canvas.toTexture(); }
protected static CanvasImage formatText (TextFormat format, String text, boolean border) { TextLayout layout = graphics().layoutText(text, format); float margin = border ? 10 : 0; float width = layout.width()+2*margin, height = layout.height()+2*margin; CanvasImage image = graphics().createImage(width, height); image.canvas().setStrokeColor(0xFF000000); image.canvas().setFillColor(0xFF000000); image.canvas().fillText(layout, margin, margin); if (border) image.canvas().strokeRect(0, 0, width-1, height-1); return image; }
protected void addInfo (CanvasImage image, float cx, float y) { TextLayout ilayout = graphics().layoutText(image.width() + "x" + image.height(), infoFormat); CanvasImage iimage = graphics().createImage(ilayout.width(), ilayout.height()); iimage.canvas().setFillColor(0xFF000000).fillText(ilayout, 0, 0); graphics().rootLayer().addAt(graphics().createImageLayer(iimage), cx - iimage.width()/2, y); }
public static Image makeButtonImage(String label) { TextLayout layout = graphics().layoutText(label, BUTTON_FMT); CanvasImage image = graphics().createImage(layout.width()+10, layout.height()+10); image.canvas().setFillColor(0xFFCCCCCC); image.canvas().fillRect(0, 0, image.width(), image.height()); image.canvas().setFillColor(0xFF000000); image.canvas().fillText(layout, 5, 5); image.canvas().setStrokeColor(0xFF000000); image.canvas().strokeRect(0, 0, image.width()-1, image.height()-1); return image; }