playn.core.Graphics.layoutText()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中playn.core.Graphics.layoutText()方法的一些代码示例,展示了Graphics.layoutText()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics.layoutText()方法的具体详情如下:
包路径:playn.core.Graphics
类名称:Graphics
方法名:layoutText

Graphics.layoutText介绍

[英]Lays out a single line of text using the specified format. The text may subsequently be rendered on a canvas via Canvas#fillText(TextLayout,float,float).
[中]使用指定的格式布置单行文本。随后可通过canvas#fillText(文本布局、浮动、浮动)在画布上呈现文本。

代码示例

代码示例来源:origin: threerings/tripleplay

public Span (Graphics gfx, String text, TextStyle style) {
  super(gfx, text, style);
  _layout = gfx.layoutText(text, style);
}

代码示例来源:origin: playn/playn

public TextLogger(float wid, int lines, TextFormat format) {
 super(wid, game.graphics.layoutText(".", format).size.height() * lines, format);
 this.lineCount = lines;
}

代码示例来源:origin: threerings/tripleplay

public void update () {
  _layout = _game.plat.graphics().layoutText(String.valueOf(label.get()), _fmt);
}
public float labelWidth () { return 0; }

代码示例来源:origin: threerings/playn

public TextLogger(float wid, int lines, TextFormat format) {
 super(wid, graphics().layoutText(".", format).height() * lines, format);
 this.lineCount = lines;
}

代码示例来源:origin: threerings/playn

public TextMapper(float wid, int lines, TextFormat format) {
 super(wid, graphics().layoutText(".", format).height() * lines, format);
}

代码示例来源:origin: playn/playn

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();
}

代码示例来源:origin: threerings/tripleplay

public void update () {
  _vlayout = _game.plat.graphics().layoutText(String.valueOf(value.get()), _fmt);
  _size.setSize(llayout.size.width() + GAP + _vlayout.size.width(),
         Math.max(llayout.size.height(), _vlayout.size.height()));
}
public float labelWidth () { return llayout.size.width(); }

代码示例来源:origin: threerings/tripleplay

public Block (Graphics gfx, String text, TextStyle style, TextWrap wrap,
       TextBlock.Align align) {
  super(gfx, text, style);
  assert wrap != null && align != null;
  this.wrap = wrap;
  this.align = align;
  _layouts = gfx.layoutText(text, style, wrap);
  _bounds = TextBlock.getBounds(_layouts, new Rectangle());
  _bounds.width = style.effect.adjustWidth(_bounds.width);
  _bounds.height = style.effect.adjustHeight(_bounds.height);
}

代码示例来源:origin: threerings/playn

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);
}

代码示例来源:origin: playn/playn

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();
}

代码示例来源:origin: threerings/playn

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);
 }
});

代码示例来源:origin: playn/playn

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);
 }
}

代码示例来源:origin: threerings/playn

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;
}

代码示例来源:origin: playn/playn

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;
}

代码示例来源:origin: playn/playn

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();
}

代码示例来源:origin: threerings/playn

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;
}

代码示例来源:origin: threerings/playn

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);
 }
});

代码示例来源:origin: threerings/playn

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);
}

代码示例来源:origin: threerings/playn

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;
}

代码示例来源:origin: threerings/playn

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;
}

相关文章