@Override protected void addTextSize ( Dimension into, IDimension lsize, TextLayout tmplLayout) { into.width += tmplLayout.size.width(); into.height += tmplLayout.size.height(); } };
public void onEmit (Throwable err) { addDescrip("Error: " + err.getMessage(), 10, errY, game.graphics.viewSize.width()-20); errY += 30; } };
/** * 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()); }
/** 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 size of this rectangle to the supplied dimensions. */ public void setSize (IDimension d) { setSize(d.width(), d.height()); }
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 nwidth = nscreen.size().width(); float ostart = 0, nstart = -nwidth, range = nwidth; float offset = pct * range; oscreen.layer.setTx(ostart + offset); nscreen.layer.setTx(nstart + offset); } };
/** 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 addToRow (ImageLayer layer) { game.rootLayer.add(layer.setTranslation(row.x + row.width, row.y)); row.width += layer.width() + 45; row.height = Math.max(row.height, layer.height()); if (row.width > game.graphics.viewSize.width() * .6f) newRow(); }
/** * 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); } };
@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); } });
/** * Fills {@code lines} into {@code canvas} at the specified coordinates, using the specified * alignment. */ public void fill(Canvas canvas, Align align, float x, float y) { float sy = y + bounds.y(); for (TextLayout line : lines) { float sx = x + bounds.x() + align.getX(line.size.width(), textWidth()); canvas.fillText(line, sx, sy); sy += line.ascent() + line.descent() + line.leading(); } }
@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()); } }
/** * Strokes {@code lines} into {@code canvas} at the specified coordinates, using the specified * alignment. */ public void stroke(Canvas canvas, Align align, float x, float y) { float sy = y + bounds.y(); for (TextLayout line : lines) { float sx = x + bounds.x() + align.getX(line.size.width(), textWidth()); canvas.strokeText(line, sx, sy); sy += line.ascent() + line.descent() + line.leading(); } }
@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); }}); }
public void onEmit (Library lib) { final Movie movie = lib.createMovie("walk"); movie.layer().setTranslation(size().width()/2, 300); main.layer.add(movie.layer()); closeOnHide(paint.connect(new Slot<Clock>() { public void onEmit (Clock clock) { movie.paint(clock); } })); } });