void startTest(Test test) { clearTest(); currentTest = test; // setup root layer for next test rootLayer.disposeAll(); rootLayer.add(createWhiteBackground()); log.info("Starting " + currentTest.name); log.info(" Description: " + currentTest.descrip); currentTest.init(); if (currentTest.usesPositionalInputs()) { // slap on a Back button if the test is testing the usual means of backing out ImageLayer back = ui.createButton("Back", () -> displayMenuLater()); rootLayer.addAt(back, graphics.viewSize.width() - back.width() - 10, 10); } }
/** Creates a root layer clipped to the specified dimensions. This is rarely what you want. */ public RootLayer (float width, float height) { super(width, height); setState(State.ADDED); } }
game.rootLayer.add(new Layer() { @Override protected void paintImpl (Surface surf) { surf.setFillColor(0xFFFFCC99).fillRect( game.rootLayer.addAt(clayer.setOrigin(100, 100), 130, 130); game.rootLayer.addAt(new ClippedLayer(100, 100) { protected void paintClipped (Surface surf) { surf.setFillColor(0xFF99CCFF).fillRect(0, 0, 100, 100); game.rootLayer.addAt(new ClippedLayer(100, 100) { protected void paintClipped (Surface surf) { surf.setFillColor(0xFF99CCFF).fillRect(0, 0, 100, 100);
protected float addTest(float lx, float ly, Layer layer, float lwidth, float lheight, String descrip, float twidth) { game.rootLayer.addAt(layer, lx + (twidth-lwidth)/2, ly); return addDescrip(descrip, lx, ly + lheight + 5, twidth); }
public TripleDemo (Platform plat) { super(plat, 25); // update our "simulation" 40 times per second game = this; // jam ourselves into a global variable, woo! new Pointer(plat, rootLayer, true); // wire up event dispatch screens.push(new DemoMenuScreen(screens)); // start off with our menu screen // show debug rectangles when D key is pressed; dump scene graph on shift-D plat.input().keyboardEvents.collect(Keyboard.isKey(Key.D)).connect(event -> { Layer.DEBUG_RECTS = event.down; if (event.down && event.isShiftDown()) { rootLayer.debugPrint(plat.log()); } }); } }
@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); })); } }
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(); }
/** * Renders the main scene graph into the OpenGL frame buffer. */ protected void paintScene () { viewSurf.saveTx(); viewSurf.begin(); viewSurf.clear(cred, cgreen, cblue, calpha); try { rootLayer.paint(viewSurf); } finally { viewSurf.end(); viewSurf.restoreTx(); } }
public SceneGame (Platform plat, int updateRate) { super(plat, updateRate); GL20 gl = plat.graphics().gl; gl.glDisable(GL20.GL_CULL_FACE); gl.glEnable(GL20.GL_BLEND); gl.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA); defaultBatch = createDefaultBatch(gl); viewSurf = new Surface(plat.graphics(), plat.graphics().defaultRenderTarget, defaultBatch); rootLayer = new RootLayer(); paint.connect(new Slot<Clock>() { public void onEmit (Clock clock) { paintScene(); } }).atPrio(scenePaintPrio()); }
setFillColor(Color.rgb(0, 0, 255)).fillRect(0, bwidth/2, bwidth, bheight/2). end().close(); game.rootLayer.add(new ImageLayer(bg.texture)); game.rootLayer.addAt(new ImageLayer(imtex), offset, offset); game.rootLayer.addAt(new ImageLayer(imtex), offset, offset + 2*height); game.rootLayer.addAt(new ImageLayer(surf.texture), offset + width, offset); game.rootLayer.addAt(new ImageLayer(surf.texture), offset + width, offset + 2*height); game.rootLayer.addAt(new ImageLayer(cantex), offset + 2*width, offset); game.rootLayer.addAt(new ImageLayer(cantex), offset + 2*width, offset + 2*height); }); game.rootLayer.addAt(new ImageLayer(truth), 3 * width, 0);
private void addTestLayer(String descrip, int width, int height, Layer layer) { // if this layer won't fit in this row, wrap down to the next if (nextX + width > game.graphics.viewSize.width()) { nextY += (maxY + GAP); nextX = GAP; maxY = 0; } // add the layer and its description below game.rootLayer.addAt(layer, nextX, nextY); ImageLayer dlayer = createDescripLayer(descrip, width); game.rootLayer.addAt(dlayer, nextX + Math.round((width-dlayer.width())/2), nextY + height + 2); // update our positioning info nextX += (width + GAP); maxY = Math.max(maxY, height+dlayer.height()+2); }
Layer.DEBUG_RECTS = event.down; if (event.down && event.isShiftDown()) { rootLayer.debugPrint(log);
@Override public void init () { float spacing = 5; float y = spacing, x = spacing, nextX = spacing; for (Mode mode : host.enumerateModes()) { ImageLayer button = game.ui.createButton(mode.toString(), () -> host.setMode(mode)); game.rootLayer.add(button); if (y + button.height() + spacing >= game.graphics.viewSize.height()) { x = nextX + spacing; y = spacing; } button.setTranslation(x, y); y += button.height() + spacing; nextX = Math.max(nextX, x + button.width()); } } }
void displayMenu() { clearTest(); rootLayer.disposeAll(); rootLayer.add(createWhiteBackground()); float gap = 20, x = gap, y = gap, maxHeight = 0; String info = "Renderer: gl (batch=" + defaultBatch + ")" + " / Screen: " + graphics.screenSize() + " / Window: " + graphics.viewSize; Texture infoTex = ui.formatText(info, false); rootLayer.addAt(new ImageLayer(infoTex), x, y); y += infoTex.displayHeight + gap; for (final Test test : tests) { if (!test.available()) continue; ImageLayer button = ui.createButton(test.name, () -> startTest(test)); if (x + button.width() > graphics.viewSize.width() - gap) { x = gap; y += maxHeight + gap; maxHeight = 0; } maxHeight = Math.max(maxHeight, button.height()); rootLayer.addAt(button, x, y); x += button.width() + gap; } }
game.rootLayer.addAt(preventDefault.layer, x, y); x += preventDefault.layer.width() + 5; game.rootLayer.addAt(capture.layer, x, y); x += capture.layer.width() + 5; game.rootLayer.addAt(mouse.layer, x, y); y += mouse.layer.height() + 5; game.rootLayer.addAt(pointer.layer, x, y); y += pointer.layer.height() + 5; game.rootLayer.addAt(touch.layer, x, y); logger = new TextLogger(375, 15, logFormat); logger.layer.setTranslation(x, y); game.rootLayer.add(logger.layer); y += logger.layer.height() + 5; motionLabel = new TextMapper(375, 6, logFormat); motionLabel.layer.setTranslation(x, y); game.rootLayer.add(motionLabel.layer);
protected float addButton (String text, float x, float y, Runnable onClick) { ImageLayer button = game.ui.createButton(text, onClick); game.rootLayer.addAt(button, x, y); return x + button.width() + 10; }
@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); } } }
/** Creates an unclipped root layer. This is almost always what you want. */ public RootLayer () { setState(State.ADDED); }
protected float addDescrip(String descrip, float x, float y, float width) { ImageLayer layer = createDescripLayer(descrip, width); game.rootLayer.addAt(layer, Math.round(x + (width - layer.width())/2), y); return y + layer.height(); }