/** Creates a uniformly formatted multiple-lines of text wrapped at {@code wrapWidth} and * left-aligned. */ public static Block block (Graphics gfx, String text, TextStyle style, float wrapWidth) { return new Block(gfx, text, style, new TextWrap(wrapWidth), TextBlock.Align.LEFT); }
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(); } }
public Texture wrapText(String text, float width, TextBlock.Align align) { TextLayout[] layouts = game.graphics.layoutText(text, TEXT_FMT, new TextWrap(width)); Canvas canvas = new TextBlock(layouts).toCanvas(game.graphics, align, 0xFF000000); return canvas.toTexture(); }
protected static CanvasImage wrapText(String text, float width, TextBlock.Align align) { TextLayout[] layouts = graphics().layoutText(text, TEXT_FMT, new TextWrap(width)); return new TextBlock(layouts).toImage(align, 0xFF000000); }
@Override public void init() { String text = "The quick brown fox jumped over the lazy dog."; TextFormat format = new TextFormat(new Font("Helvetica", 18)); TextBlock block = new TextBlock(game.graphics.layoutText(text, format, new TextWrap(100))); float x = 5; for (float scale : new float[] { 1f, 2f, 3f }) { float swidth = block.bounds.width() * scale, sheight = block.bounds.height() * scale; Canvas canvas = game.graphics.createCanvas(swidth, sheight); canvas.setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, swidth-0.5f, sheight-0.5f); canvas.scale(scale, scale); canvas.setFillColor(0xFF000000); block.fill(canvas, TextBlock.Align.RIGHT, 0, 0); game.rootLayer.addAt(new ImageLayer(canvas.toTexture()), x, 5); addInfo(canvas, x + swidth/2, sheight + 10); x += swidth + 5; } }
protected Texture makeTextImage() { TextFormat format = new TextFormat(new Font(font.value(), style.value(), 24)); float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : game.graphics.viewSize.width()*wrap.value()/100; TextBlock block = new TextBlock( game.graphics.layoutText(sample, format, new TextWrap(wrapWidth))); float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height()); float pad = 1/game.graphics.scale().factor; Canvas canvas = game.graphics.createCanvas(awidth+2*pad, aheight+2*pad); canvas.translate(pad, pad); canvas.setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight); render(canvas, block, align.value(), lineBounds.value()); return canvas.toTexture(); }
protected Image makeTextImage() { TextFormat format = new TextFormat(graphics().createFont(font.value(), style.value(), 24), true); float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : graphics().width()*wrap.value()/100; TextBlock block = new TextBlock(graphics().layoutText(sample, format, new TextWrap(wrapWidth))); float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height()); float pad = TextBlock.pad(); CanvasImage image = graphics().createImage(awidth+2*pad, aheight+2*pad); image.canvas().translate(pad, pad); image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight); render(image.canvas(), block, align.value(), lineBounds.value()); return image; }
@Override public void init() { String text = "The quick brown fox jumped over the lazy dog."; TextFormat format = new TextFormat(). withFont(graphics().createFont("Helvetica", Font.Style.PLAIN, 18)); TextBlock block = new TextBlock(graphics().layoutText(text, format, new TextWrap(100))); float x = 5; for (float scale : new float[] { 1f, 2f, 3f }) { float swidth = block.bounds.width() * scale, sheight = block.bounds.height() * scale; CanvasImage image = graphics().createImage(swidth, sheight); image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, swidth-0.5f, sheight-0.5f); image.canvas().scale(scale, scale); image.canvas().setFillColor(0xFF000000); block.fill(image.canvas(), TextBlock.Align.RIGHT, 0, 0); graphics().rootLayer().addAt(graphics().createImageLayer(image), x, 5); addInfo(image, x + swidth/2, sheight + 10); x += swidth + 5; } }