@Override protected void addTextSize ( Dimension into, IDimension lsize, TextLayout tmplLayout) { into.width += tmplLayout.size.width(); into.height += tmplLayout.size.height(); } };
/** * Creates a canvas layer with a backing canvas of {@code size} (in display units). This layer * will display nothing until a {@link #begin}/{@link #end} pair is used to render something to * its backing canvas. */ public CanvasLayer (Graphics gfx, IDimension size) { this(gfx, size.width(), size.height()); }
/** * Creates a dimension with width and height equal to the supplied dimension. */ public Dimension (IDimension d) { this(d.width(), d.height()); }
/** Ensures that the canvas image is at least the specified dimensions and cleared to all * transparent pixels. Also creates and adds the image layer to the parent layer if needed. */ public void prepare (Graphics gfx, IDimension dim) { prepare(gfx, dim.width(), dim.height()); }
/** * Sets the magnitudes of this dimension to be equal to the supplied dimension. */ public void setSize (IDimension d) { setSize(d.width(), d.height()); }
/** Updates the size of this clipped layer, and hence its clipping rectangle. */ public ClippedLayer setSize (IDimension size) { return setSize(size.width(), size.height()); }
/** Sizes this element to its preferred size, computed using the supplied hints. */ public Root pack (float widthHint, float heightHint) { IDimension psize = preferredSize(widthHint, heightHint); setSize(psize.width(), psize.height()); return this; }
protected void paintImpl (Surface surf) { surf.setFillColor(0xFFFFFFFF).fillRect( 0, 0, graphics.viewSize.width(), graphics.viewSize.height()); } };
public void update (Screen oscreen, Screen nscreen, float pct) { float oheight = oscreen.size().height(); float ostart = 0, nstart = oheight, range = -oheight; float offset = pct * range; oscreen.layer.setTy(ostart + offset); nscreen.layer.setTy(nstart + offset); } };
/** * Updates the value to a new dimension with the current height and the given width. */ public void updateWidth (float width) { update(new Dimension(width, get().height())); }
/** * Constructs a rectangle with upper-left corner at the supplied point and with the supplied * dimensions. */ public Rectangle (XY p, IDimension d) { setBounds(p.x(), p.y(), d.width(), d.height()); }
/** * Sets the location, size, angular extents, and closure type of this arc to the specified * values. */ public void setArc (XY point, IDimension size, float start, float extent, int type) { setArc(point.x(), point.y(), size.width(), size.height(), start, extent, type); }
@Override protected Instance instantiate (IDimension size) { ImageLayer layer = new ImageLayer(source); layer.setSize(size.width(), size.height()); return new LayerInstance(size, layer); } };
/** * Sets the location and size of the framing rectangle of this shape to the supplied values. */ public void setFrame (XY loc, IDimension size) { setFrame(loc.x(), loc.y(), size.width(), size.height()); }
@Override protected void paintImpl (Surface surf) { surf.setFillColor(0xFFFFCC99).fillRect( 0, 0, game.graphics.viewSize.width(), game.graphics.viewSize.height()); // fill a rect that will be covered except for one pixel by the clipped immediate layers surf.setFillColor(0xFF000000); surf.fillRect(29, 29, 152, 152); surf.fillRect(259, 29, 102, 102); surf.fillRect(389, 29, 102, 102); } });
@Override public void onWheel (Mouse.WheelEvent event, Mouse.Interaction iact) { // scale so each wheel notch is 1/4 the screen dimension float delta = event.velocity * .25f; if (vrange.active()) scrollY(ypos() + (int)(delta * viewSize().height())); else scrollX(xpos() + (int)(delta * viewSize().width())); } });
@Override public void layout (Container<?> elems, float left, float top, float width, float height) { for (Element<?> elem : elems) { if (!elem.isVisible()) continue; Constraint c = constraint(elem); IDimension psize = c.psize(this, elem); // this should return a cached size IPoint pos = c.pos(width, height, psize); setBounds(elem, left + pos.x(), top + pos.y(), psize.width(), psize.height()); } }
@Override public void onEmit () { float tx = 100 + rando.getFloat(size().width()-200); float ty = 100 + rando.getFloat(size().height()-200); explode1.layer.setTranslation(tx, ty); explode2.layer.setTranslation(tx, ty); explode1.generator = Generator.impulse(200); explode2.generator = Generator.impulse(200); }}); }
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; }