/** * Creates an image layer with the supplied texture tile. */ public ImageLayer (Tile tile) { setTile(tile); }
@Override protected void finalize () { setTile((Tile)null); } }
public void onEmit (Tile tile) { setTile(tile); } });
public void onEmit (Tile tile) { setTile(tile); } });
@Override public ImageLayer setTile (Tile tile) { if (tile == null || tile instanceof Texture) return super.setTile(tile); else throw new UnsupportedOperationException(); } @Override public ImageLayer setTile (RFuture<? extends Tile> tile) {
@Override public void apply (int index, ImageLayer layer) { Frame f = _frames[index]; layer.setTile(_tile); layer.region = f.bounds; layer.setTranslation(f.offset.x, f.offset.y); }
/** * Creates a canvas layer with the supplied backing canvas. The canvas will immediately be * uploaded to the GPU for display. */ public CanvasLayer (Graphics gfx, Canvas canvas) { this.gfx = gfx; this.canvas = canvas; super.setTile(canvas.image.createTexture(Texture.Config.DEFAULT)); }
@Override public void close() { super.close(); setTile((Tile)null); }
protected void update() { if (text == null) return; text.setTile(makeTextImage()); }
public void set(int idx) { this.valueIdx = idx; layer.setTile(game.ui.formatButton(prefix + toString(values.get(idx)))); }
protected void displayText (String text) { output.setTile(game.ui.wrapText(text, game.graphics.viewSize.width()-20, TextBlock.Align.LEFT)); }
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()); } }
@Override public void apply (int index, ImageLayer layer) { if (_tile != null) { layer.setTile(_tile); layer.setTranslation(0, 0); Rectangle r = layer.region; if (r == null) r = (layer.region = new Rectangle()); bounds(index, r); } }
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); }
/** * Sets the texture rendered by this layer to the texture provided by {@code source}. If {@code * source} is not yet ready, the texture will be set when it becomes ready. Until then any * previous texture will continue to be displayed. */ public ImageLayer setSource (TileSource source) { if (source.isLoaded()) setTile(source.tile()); else source.tileAsync().onSuccess(new Slot<Tile>() { public void onEmit (Tile tile) { setTile(tile); } }); return this; }
/** Informs this layer that a drawing operation has just completed. The backing canvas image data * is uploaded to the GPU. */ public void end () { Texture tex = (Texture)tile(); Image image = canvas.image; // if our texture is already the right size, just update it if (tex != null && tex.pixelWidth == image.pixelWidth() && tex.pixelHeight == image.pixelHeight()) tex.update(image); // otherwise we need to create a new texture (setTexture will unreference the old texture which // will cause it to be destroyed) else super.setTile(canvas.image.createTexture(Texture.Config.DEFAULT)); }
@Override public ImageLayer toLayer (ImageLayer target) { Canvas canvas = toCanvas(); target.setTile(canvas.toTexture()); target.setTranslation(style.effect.offsetX(), style.effect.offsetY()); return target; }
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); }
SignalView.Listener<Object> onDialogResult = result -> { String text = result == null ? "canceled" : String.valueOf(result); if (text.length() > 0) outputLayer.setTile(game.ui.formatText(text, false)); if (result instanceof String) game.storage.setItem("last_text", (String)result); };