@Override public void render (Canvas canvas, float x, float y) { float bx = _bounds.x, ly = y + _bounds.y; for (TextLayout layout : _layouts) { float lx = x + bx + align.getX(style.effect.adjustWidth(layout.size.width()), _bounds.width-_bounds.x); style.effect.render(canvas, layout, style.textColor, style.underlined, lx, ly); ly += layout.ascent() + layout.descent() + layout.leading(); } }
/** Computes the bounds of a block of text. The {@code x} component of the bounds may be * positive, indicating that the text should be rendered at that offset. This is to account for * the fact that some text renders to the left of its reported origin due to font * extravagance. */ public static Rectangle getBounds(TextLayout[] lines, Rectangle into) { // some font glyphs start rendering at a negative inset, blowing outside their bounding box // (naughty!); in such cases, we use xAdjust to shift everything to the right to ensure that we // don't paint outside our reported bounding box (so that someone can create a single canvas of // bounding box size and render this text layout into it at (0,0) and nothing will get cut off) float xAdjust = 0, twidth = 0, theight = 0; for (TextLayout layout : lines) { IRectangle bounds = layout.bounds(); xAdjust = Math.max(xAdjust, -Math.min(0, bounds.x())); // we use layout.width() here not bounds width because layout width includes extra space // needed for lines that start rendering at a positive x offset whereas bounds.width() is // only the precise width of the rendered text twidth = Math.max(twidth, layout.width()); if (layout != lines[0]) theight += layout.leading(); // leading only applied to lines after 0 theight += layout.ascent() + layout.descent(); } into.setBounds(xAdjust, 0, xAdjust+twidth, theight); return into; }
public TextLogger(float wid, int lines, TextFormat format) { super(wid, graphics().layoutText(".", format).height() * lines, format); this.lineCount = lines; }
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); } }
/** Computes the bounds of a block of text. The {@code x} component of the bounds may be * positive, indicating that the text should be rendered at that offset. This is to account for * the fact that some text renders to the left of its reported origin due to font * extravagance. */ public static Rectangle getBounds(TextLayout[] lines, Rectangle into) { // some font glyphs start rendering at a negative inset, blowing outside their bounding box // (naughty!); in such cases, we use xAdjust to shift everything to the right to ensure that we // don't paint outside our reported bounding box (so that someone can create a single canvas of // bounding box size and render this text layout into it at (0,0) and nothing will get cut off) float xAdjust = 0, twidth = 0, theight = 0; for (TextLayout layout : lines) { IRectangle bounds = layout.bounds; xAdjust = Math.max(xAdjust, -Math.min(0, bounds.x())); // we use layout.width() here not bounds width because layout width includes extra space // needed for lines that start rendering at a positive x offset whereas bounds.width() is // only the precise width of the rendered text twidth = Math.max(twidth, layout.size.width()); if (layout != lines[0]) theight += layout.leading(); // leading only applied to lines after 0 theight += layout.ascent() + layout.descent(); } into.setBounds(xAdjust, 0, xAdjust+twidth, theight); return into; }
/** * Strokes {@code lines} into {@code canvas} at the specified coordinates, using the specified * alignment. */ public void stroke(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.strokeText(line, sx, sy); sy += line.ascent() + line.descent() + line.leading(); } }
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; }
public TextMapper(float wid, int lines, TextFormat format) { super(wid, graphics().layoutText(".", format).height() * lines, format); }
/** Computes the bounds of a block of text. The {@code x} component of the bounds may be * positive, indicating that the text should be rendered at that offset. This is to account for * the fact that some text renders to the left of its reported origin due to font * extravagance. */ public static Rectangle getBounds(TextLayout[] lines, Rectangle into) { // some font glyphs start rendering at a negative inset, blowing outside their bounding box // (naughty!); in such cases, we use xAdjust to shift everything to the right to ensure that we // don't paint outside our reported bounding box (so that someone can create a single canvas of // bounding box size and render this text layout into it at (0,0) and nothing will get cut off) float xAdjust = 0, twidth = 0, theight = 0; for (TextLayout layout : lines) { IRectangle bounds = layout.bounds; xAdjust = Math.max(xAdjust, -Math.min(0, bounds.x())); // we use layout.width() here not bounds width because layout width includes extra space // needed for lines that start rendering at a positive x offset whereas bounds.width() is // only the precise width of the rendered text twidth = Math.max(twidth, layout.size.width()); if (layout != lines[0]) theight += layout.leading(); // leading only applied to lines after 0 theight += layout.ascent() + layout.descent(); } into.setBounds(xAdjust, 0, xAdjust+twidth, theight); return into; }
/** * 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(); } }
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 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; } }
/** * 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(); } }
protected void render (Canvas canvas, String strokeFill, TextBlock block, TextBlock.Align align, int color, float x, float y, boolean showBounds) { float sy = y + block.bounds.y(); for (TextLayout layout : block.lines) { float sx = x + block.bounds.x() + align.getX( layout.width(), block.bounds.width()-block.bounds.x()); if (showBounds) { IRectangle lbounds = layout.bounds(); canvas.setStrokeColor(0xFFFFCCCC).setStrokeWidth(1); canvas.strokeRect(sx+lbounds.x(), sy+lbounds.y(), lbounds.width(), lbounds.height()); } if (strokeFill.equals("Fill")) { canvas.setFillColor(color).fillText(layout, sx, sy); } else { canvas.setStrokeColor(color).strokeText(layout, sx, sy); } sy += layout.ascent() + layout.descent() + layout.leading(); } }
protected ImageLayer createLabel(String text, GroupLayer parent, int fg, int bg, float x, float y, float padding) { TextLayout layout = graphics().layoutText(text, baseFormat); float twidth = layout.width() + padding * 2; float theight = layout.height() + padding * 2; CanvasImage image = graphics().createImage(twidth, theight); if (bg != 0) { image.canvas().setFillColor(bg); image.canvas().fillRect(0, 0, twidth, theight); } image.canvas().setFillColor(fg); image.canvas().fillText(layout, padding, padding); ImageLayer imageLayer = graphics().createImageLayer(image); imageLayer.setTranslation(x, y); parent.add(imageLayer); return imageLayer; }
/** * Strokes {@code lines} into {@code canvas} at the specified coordinates, using the specified * alignment. */ public void stroke(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.strokeText(line, sx, sy); sy += line.ascent() + line.descent() + line.leading(); } }
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; }
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(); }