@Override public Surface scale(float sx, float sy) { canvas.scale(sx, sy); return this; }
@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; } }
@Override public void paint(Canvas canvas, float parentAlpha) { if (!visible() || img == null || !img.isReady()) return; canvas.save(); canvas.setAlpha(parentAlpha * alpha()); transform(canvas); float width = width(), height = height(); boolean repX = img.repeatX(), repY = img.repeatY(); if (repX || repY) { if (pattern == null || repX != patternRepeatX || repY != patternRepeatY) { patternRepeatX = repX; patternRepeatY = repY; pattern = img.toPattern(); } canvas.setFillPattern(pattern); float xScale = repX ? 1 : width / img.width(), yScale = repY ? 1 : height / img.height(); canvas.scale(xScale, yScale); canvas.fillRect(0, 0, width / xScale, height / yScale); } else { canvas.drawImage(img, 0, 0, width, height); } canvas.restore(); } }
@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; } }