@Override public Layer render () { return new ImageLayer(source); } @Override public RFuture<Icon> state () {
protected ImageLayer createDescripLayer(String descrip, float width) { return new ImageLayer(game.ui.wrapText(descrip, width, TextBlock.Align.CENTER)); }
/** Creates an image large enough to accommodate this styled text, renders it therein and * applies it to {@code layer}, adjusting its translation per the effect renderer. */ public abstract ImageLayer toLayer (ImageLayer target);
/** * Starts a flipbook animation in a new image layer which is created and added to {@code box}. * When the flipbook animation is complete, the newly created image layer will not be disposed * automatically. This allows the animation to be repeated, if desired. The caller must dispose * eventually the image layer, or more likely, dispose {@code box} which will cause the created * image layer to be disposed. */ public Animation.Flip flipbook (GroupLayer box, Flipbook book) { ImageLayer image = new ImageLayer(); box.add(image); return flipbook(image, book); }
public ImageLayer createButton (String label, Runnable onClick) { ImageLayer layer = new ImageLayer(formatButton(label)); layer.events().connect(new Pointer.Listener() { @Override public void onStart (Pointer.Interaction iact) { onClick.run(); } }); return layer; } }
private void addTestCanvas(String descrip, int width, int height, Drawer drawer) { Canvas canvas = createCanvas(width, height, drawer); addTestLayer(descrip, width, height, new ImageLayer(canvas.toTexture())); }
protected void update (Texture tex) { if (tex == null) { // we should never be going back to null but handle it anyway if (_ilayer != null) _ilayer.close(); _ilayer = null; return; } if (_ilayer == null) layer.add(_ilayer = new ImageLayer()); _ilayer.setTile(tex); }
protected Texture (Symbol symbol) { _layer = new ImageLayer(symbol.tile); _layer.setOrigin(symbol.origin.x(), symbol.origin.y()); _symbol = symbol; }
@Override protected Instance instantiate (IDimension size) { ImageLayer layer = new ImageLayer(source); layer.setSize(size.width(), size.height()); return new LayerInstance(size, layer); } };
private void addTestCanvas(String descrip, int width, int height, String imagePath, ImageDrawer drawer) { Canvas target = game.graphics.createCanvas(width, height); ImageLayer layer = new ImageLayer().setSize(width, height); game.assets.getImage(imagePath).state.onSuccess(image -> { drawer.draw(target, image); layer.setTile(target.toTexture()); }); addTestLayer(descrip, width, height, layer); }
@Override public void init() { double start = game.plat.time(); conns.add(game.plat.lifecycle.connect(event -> { switch (event) { case PAUSE: game.log.info("Paused " + elapsed(start)); notifications.add("Paused at " + elapsed(start) + "s"); break; case RESUME: game.log.info("Resumed " + elapsed(start)); notifications.add("Resumed at " + elapsed(start) + "s"); updateDisplay(); break; default: break; // nada } })); game.rootLayer.addAt(layer = new ImageLayer(), 15, 15); updateDisplay(); }
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); } }
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; }
@Override public void init() { 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]; Canvas canvas = game.graphics.createCanvas(width, height); canvas.setFillColor(fills[ii]).fillRect(0, 0, width, height); canvas.setFillColor(0xFF000000).drawText(depth + "/" + ii, 5, 15); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setDepth(depth).setTranslation(225-50*depth, 125+25*depth); game.rootLayer.add(layer); } } }
protected Entity createBullet (float x, float y, float vx, float vy, float angle, int exps) { Entity bullet = create(true); bullet.add(type, sprite, opos, pos, vel, radius, expires); Canvas canvas = graphics().createCanvas(5, 2); canvas.setFillColor(0xFFFFFFFF).fillRect(0, 0, 5, 2); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setOrigin(2.5f, 1); layer.setRotation(angle); int id = bullet.id; type.set(id, BULLET); sprite.set(id, layer); opos.set(id, x, y); pos.set(id, x, y); vel.set(id, vx, vy); radius.set(id, 2); expires.set(id, exps); return bullet; }
@Override public void init () { // remove the background layer added by default game.rootLayer.disposeAll(); // add a grey square TextureSurface surf = game.createSurface(width, height); surf.begin().setFillColor(Color.rgb(200, 200, 200)).fillRect(0, 0, width, height).end().close(); ImageLayer square = new ImageLayer(surf.texture); game.rootLayer.add(square); conns.add(game.paint.connect(clock -> { float t = clock.tick / 1000f; IDimension vsize = game.plat.graphics().viewSize; square.setTranslation((FloatMath.cos(t) + 1) * (vsize.width() - width)/2, (FloatMath.sin(t) + 1) * (vsize.height() - height)/2); })); } }
@Override protected Instance instantiate (final IDimension size) { Canvas canvas = _gfx.createCanvas(size); if (_borderWidth > 0) { canvas.setFillColor(_borderColor).fillRoundRect( 0, 0, size.width(), size.height(), _radius); // scale the inner radius based on the ratio of the inner height to the full height; // this improves the uniformity of the border substantially float iwidth = size.width() - 2*_borderWidth, iheight = size.height() - 2*_borderWidth; float iradius = _borderRadius * (iheight / size.height()); canvas.setFillColor(_bgColor).fillRoundRect( _borderWidth, _borderWidth, iwidth, iheight, iradius); } else { canvas.setFillColor(_bgColor).fillRoundRect(0, 0, size.width(), size.height(), _radius); } ImageLayer layer = new ImageLayer(canvas.toTexture()); return new LayerInstance(size, layer); }
@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 Entity createAsteroid (Size sz, float x, float y, float vx, float vy) { Entity ast = create(true); ast.add(type, size, sprite, opos, pos, vel, spin, radius); float side = sz.size; int iidx = rando.getInt(8); float ah = asteroids.height(); ImageLayer layer = new ImageLayer(asteroids.region(iidx*ah, 0, ah, ah)); layer.setOrigin(ah/2, ah/2); layer.setScale(side/ah); layer.setRotation(rando.getFloat(MathUtil.TAU)); int id = ast.id; type.set(id, ASTEROID); size.set(id, sz); sprite.set(id, layer); spin.set(id, rando.getInRange(-MAXSPIN, MAXSPIN)); opos.set(id, x, y); pos.set(id, x, y); vel.set(id, vx, vy); radius.set(id, side*0.425f); return ast; }
protected Entity createShip (float x, float y) { Entity ship = create(true); ship.add(type, sprite, opos, pos, vel, spin, radius); Canvas canvas = graphics().createCanvas(30, 20); Path path = canvas.createPath(); path.moveTo(0, 0).lineTo(30, 10).lineTo(0, 20).close(); canvas.setFillColor(0xFFCC99FF).fillPath(path); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setOrigin(15, 10); layer.setRotation(-MathUtil.HALF_PI); int id = ship.id; type.set(id, SHIP); sprite.set(id, layer); opos.set(id, x, y); pos.set(id, x, y); vel.set(id, 0, 0); radius.set(id, 10); return ship; }