playn.core.Graphics类的使用及代码示例

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

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

Graphics介绍

[英]Provides access to graphics information and services.
[中]提供对图形信息和服务的访问。

代码示例

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

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

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

/** Creates a canvas large enough to accommodate this styled text, and renders it therein. The
 * canvas will include a one pixel border beyond the size of the styled text which is needed
 * to accommodate antialiasing. */
public Canvas toCanvas () {
  float pad = 1/_gfx.scale().factor;
  Canvas canvas = _gfx.createCanvas(width()+2*pad, height()+2*pad);
  render(canvas, pad, pad);
  return canvas;
}

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

/** Creates a texture surface which is {@code width x height} in display units.
 * A managed backing texture will be automatically created. */
public TextureSurface (Graphics gfx, QuadBatch defaultBatch, float width, float height) {
 this(gfx, defaultBatch, gfx.createTexture(width, height, Texture.Config.DEFAULT));
}

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

public Label(float wid, float hei, TextFormat format) {
 image = graphics().createImage(wid, hei);
 layer = graphics().createImageLayer(image);
 this.format = format;
}

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

@Override
public void init() {
 CanvasImage canvasImage = graphics().createImage(graphics().width(), graphics().height());
 canvas = canvasImage.canvas();
 graphics().rootLayer().add(graphics().createImageLayer(canvasImage));
}

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

private Canvas createCanvas(int width, int height, Drawer drawer) {
 Canvas canvas = game.graphics.createCanvas(width, height);
 drawer.draw(canvas);
 return canvas;
}

代码示例来源: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: playn/playn

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

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

public void render(Surface surf) {
  surf.setFillColor(0xFFFFFFFF).fillRect(0, 0, graphics().width(), graphics().height());
 }
});

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

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

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

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

代码示例来源: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;
}

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

@Override public void init() {
 Canvas canvas = game.graphics.createCanvas(2*r, 2*r);
 canvas.setFillColor(0xFF99CCFF).fillCircle(r, r, r);
 fragment("CanvasImage", canvas.toTexture(), 250, 160);
  Texture subtex = game.graphics.createTexture(
   otile.width(), otile.height(), Texture.Config.DEFAULT.repeat(true, true));
  new TextureSurface(game.graphics, game.defaultBatch, subtex).begin().
  Canvas split = game.graphics.createCanvas(orange.width(), orange.height());
  split.draw(orange.region(  0,   0, phw, phh), phw, phh);
  split.draw(orange.region(phw,   0, phw, phh),   0, phh);

代码示例来源:origin: com.googlecode.playn/playn-tests-core

private void addTestLayer(int width, int height, Layer layer) {
 // if this layer won't fit in this row, wrap down to the next
 if (nextX + width > graphics().width()) {
  nextY += (maxY + GAP);
  nextX = GAP;
  maxY = 0;
 }
 layer.setTranslation(nextX, nextY);
 graphics().rootLayer().add(layer);
 // update our positioning info
 nextX += (width + GAP);
 maxY = Math.max(maxY, height);
}

代码示例来源:origin: stackoverflow.com

@Override
public void paintComponent(Graphics g)
{
  g.scale(zoomFactor, zoomFactor);
  // Change the size of the panel
  setSize(origWidth * zoomFactor, origHeight * zoomFactor);
  // Re-Layout the panel
  validate();
  super.paintComponent(g);
}

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

@Override
 public void init() {
  GroupLayer rootLayer = graphics().rootLayer();

  CanvasImage image = graphics().createImage(250, 25);
  image.canvas().drawText(rootLayer.getClass().getName(), 0, 15);
  ImageLayer info = graphics().createImageLayer(image);
  info.setTranslation(5, 5);
  rootLayer.add(info);

  int[] depths = { 0, -1, 1, 3, 2, -4, -3, 4, -2 };
  int[] fills = { 0xFF99CCFF, 0xFFFFFF33, 0xFF9933FF, 0xFF999999, 0xFFFF0033,
          0xFF00CC00, 0xFFFF9900, 0xFF0066FF, 0x0FFCC6666 };
  int width = 200, height = 200;
  for (int ii = 0; ii < depths.length; ii++) {
   int depth = depths[ii];
   image = graphics().createImage(width, height);
   image.canvas().setFillColor(fills[ii]);
   image.canvas().fillRect(0, 0, width, height);
   image.canvas().setFillColor(0xFF000000);
   image.canvas().drawText(depth + "/" + ii, 5, 15);
   ImageLayer layer = graphics().createImageLayer(image);
   layer.setDepth(depth);
   layer.setTranslation(225-50*depth, 125+25*depth);
   rootLayer.add(layer);
  }
 }
}

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

void displayMenu() {
 clearTest();
 clearRoot();
 GroupLayer root = graphics().rootLayer();
 root.add(createWhiteBackground());
 if (graphics().ctx() == null) {
  info += "canvas";
 } else {
  info += "gl (quads=" + graphics().ctx().quadShaderInfo() + " tris=" +
   graphics().ctx().trisShaderInfo() + ")";
 graphics().rootLayer().addAt(graphics().createImageLayer(infoImg), x, y);
 y += infoImg.height() + gap;
  if (x + button.width() > graphics().width() - gap) {
   x = gap;
   y += maxHeight + gap;

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

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

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

@Override public void init () {
 GroupLayer slider = graphics().createGroupLayer();
 CanvasImage image = graphics().createImage(WIDTH + 10, HEIGHT);
 image.canvas().setFillColor(0xff808080);
 image.canvas().fillRect(0, 0, WIDTH + 10, HEIGHT);
 ImageLayer bg = graphics().createImageLayer(image);
 slider.add(bg);
 image = graphics().createImage(WIDTH, HWIDTH);
 image.canvas().setFillColor(0xffffffff);
 image.canvas().fillRect(0, 0, WIDTH, HWIDTH);
 image.canvas().setStrokeColor(0xff000000);
 image.canvas().drawLine(0, HWIDTH / 2, WIDTH, HWIDTH / 2);
 image.canvas().setStrokeColor(0xffff0000);
 image.canvas().strokeRect(0, 0, WIDTH - 1, HWIDTH - 1);
 slider.add(il = graphics().createImageLayer(image));
 il.setOrigin(0, HWIDTH / 2);
 il.setTranslation(0, HEIGHT / 2);
 il.setDepth(1);
 graphics().rootLayer().add(slider);
 slider.setTranslation(25, 25);
 bg.addListener(new Mouse.LayerAdapter() {
  @Override public void onMouseWheelScroll (WheelEvent event) {
   float y = il.ty() + event.velocity();
   y = Math.max(0, Math.min(y, HEIGHT));
   il.setTranslation(0, y);
  }
 });
}

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

protected ImageLayer createLabel(String text, int bg, float x, float y) {
 return createLabel(text, graphics().rootLayer(), 0xFF202020, bg, x, y, 0);
}

相关文章