public void addAt(GroupLayer self, Layer layer, float tx, float ty) { layer.setTranslation(tx, ty); self.add(layer); }
void startTest(Test test) { clearTest(); currentTest = test; // setup root layer for next test clearRoot(); GroupLayer root = graphics().rootLayer(); root.add(createWhiteBackground()); log().info("Starting " + currentTest.getName()); log().info(" Description: " + currentTest.getDescription()); currentTest.init(); if (currentTest.usesPositionalInputs()) { // slap on a Back button if the test is testing the usual means of backing out ImageLayer back = Test.createButton("Back", new Runnable() { public void run () { displayMenuLater(); } }); root.addAt(back, graphics().width() - back.width(), 0); } }
private void addTestLayer(int width, int height, Layer layer) { // if this layer won't fit in this row, wrap down to the next if (nextX + width > graphics().width()) { nextY += (maxY + GAP); nextX = GAP; maxY = 0; } layer.setTranslation(nextX, nextY); graphics().rootLayer().add(layer); // update our positioning info nextX += (width + GAP); maxY = Math.max(maxY, height); }
clearRoot(); GroupLayer root = graphics().rootLayer(); root.add(createWhiteBackground());
@Override public void done(Image image) { groundTruthLayer = graphics().createImageLayer(image); groundTruthLayer.transform().translate(3 * width, 0); rootLayer.add(groundTruthLayer); }
@Override public void done(Image image) { groundTruthLayer = graphics().createImageLayer(image); groundTruthLayer.transform().translate(4 * width, 0); rootLayer.add(groundTruthLayer); }
protected void addToRow (ImageLayer layer) { graphics().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 > graphics().width() * .6f) newRow(); }
@Override public void init () { final float spacing = 5; float y = spacing, x = spacing, nextX = spacing; for (final Mode mode : host.enumerateModes()) { ImageLayer button = createButton(mode.toString(), new Runnable() { @Override public void run () { host.setMode(mode); } }); graphics().rootLayer().add(button); if (y + button.height() + spacing >= graphics().height()) { x = nextX + spacing; y = spacing; } button.setTranslation(x, y); y += button.height() + spacing; nextX = Math.max(nextX, x + button.width()); } }
@Override public void init() { CanvasImage canvasImage = graphics().createImage(graphics().width(), graphics().height()); canvas = canvasImage.canvas(); graphics().rootLayer().add(graphics().createImageLayer(canvasImage)); }
@Override public void done(Image image) { // once the image loads, create our layers imageLayer1 = graphics().createImageLayer(image); surfaceLayer1 = graphics().createSurfaceLayer(image.width(), image.height()); surfaceLayer1.surface().drawImage(image, 0, 0); CanvasImage canvas1 = graphics().createImage(image.width(), image.height()); canvas1.canvas().drawImage(image, 0, 0); canvasLayer1 = graphics().createImageLayer(canvas1); imageLayer2 = graphics().createImageLayer(image); surfaceLayer2 = graphics().createSurfaceLayer(image.width(), image.height()); surfaceLayer2.surface().drawImage(image, 0, 0); CanvasImage canvas2 = graphics().createImage(image.width(), image.height()); canvas2.canvas().drawImage(image, 0, 0); canvasLayer2 = graphics().createImageLayer(canvas2); // add layers to the rootLayer imageLayer1.transform().translate(offset, offset); rootLayer.add(imageLayer1); surfaceLayer1.transform().translate(offset + width, offset); rootLayer.add(surfaceLayer1); canvasLayer1.transform().translate(offset + 2 * width, offset); rootLayer.add(canvasLayer1); imageLayer2.transform().translate(offset, offset + 2 * height); rootLayer.add(imageLayer2); surfaceLayer2.transform().translate(offset + width, offset + 2 * height); rootLayer.add(surfaceLayer2); canvasLayer2.transform().translate(offset + 2 * width, offset + 2 * height); rootLayer.add(canvasLayer2); }
@Override public void init() { GroupLayer rootLayer = graphics().rootLayer(); CanvasImage image = graphics().createImage(250, 25); image.canvas().drawText(rootLayer.getClass().getName(), 0, 15); ImageLayer info = graphics().createImageLayer(image); info.setTranslation(5, 5); rootLayer.add(info); 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]; image = graphics().createImage(width, height); image.canvas().setFillColor(fills[ii]); image.canvas().fillRect(0, 0, width, height); image.canvas().setFillColor(0xFF000000); image.canvas().drawText(depth + "/" + ii, 5, 15); ImageLayer layer = graphics().createImageLayer(image); layer.setDepth(depth); layer.setTranslation(225-50*depth, 125+25*depth); rootLayer.add(layer); } } }
@Override public void init() { GroupLayer rootLayer = graphics().rootLayer(); CanvasImage image = graphics().createImage(250, 20); image.canvas().drawText(rootLayer.getClass().getName(), 0, 15); ImageLayer info = graphics().createImageLayer(image); info.setTranslation(5, 5); rootLayer.add(info); 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]; image = graphics().createImage(width, height); image.canvas().setFillColor(fills[ii]); image.canvas().fillRect(0, 0, width, height); image.canvas().setFillColor(0xFF000000); image.canvas().drawText(depth + "/" + ii, 5, 15); ImageLayer layer = graphics().createImageLayer(image); layer.setDepth(depth); layer.setTranslation(225-50*depth, 125+25*depth); rootLayer.add(layer); } } }
@Override public void init() { // remove the background layer added by default graphics().rootLayer().removeAll(); // add a grey square SurfaceImage surf = graphics().createSurface(width, height); surf.surface().setFillColor(Color.rgb(200, 200, 200)); surf.surface().fillRect(0, 0, width, height); square = graphics().createImageLayer(surf); graphics().rootLayer().add(square); }
groupLayer.add(imageLayer1); surfaceLayer1.transform().translate(offset + width, offset); surfaceLayer1.setAlpha(0.5f); groupLayer.add(surfaceLayer1); canvasLayer1.transform().translate(offset + 2 * width, offset); canvasLayer1.setAlpha(0.5f); groupLayer.add(canvasLayer1); canvasLayer3.transform().translate(offset + 3 * width, offset); groupLayer.add(canvasLayer3); groupLayer.add(imageLayer2); surfaceLayer2.transform().translate(offset + width, offset + 2 * height); surfaceLayer2.setAlpha(0.5f); groupLayer.add(surfaceLayer2); canvasLayer2.transform().translate(offset + 2 * width, offset + 2 * height); canvasLayer2.setAlpha(0.5f); groupLayer.add(canvasLayer2); canvasLayer4.transform().translate(offset + 3 * width, offset + 2 * height); groupLayer.add(canvasLayer4);
@Override public void init() { // remove the background layer added by default graphics().rootLayer().clear(); // add a grey square square = graphics().createSurfaceLayer(width, height); square.surface().setFillColor(Color.rgb(200, 200, 200)); square.surface().fillRect(0, 0, square.surface().width(), square.surface().height()); graphics().rootLayer().add(square); }
@Override public void init () { GroupLayer slider = graphics().createGroupLayer(); CanvasImage image = graphics().createImage(WIDTH + 10, HEIGHT); image.canvas().setFillColor(0xff808080); image.canvas().fillRect(0, 0, WIDTH + 10, HEIGHT); ImageLayer bg = graphics().createImageLayer(image); slider.add(bg); image = graphics().createImage(WIDTH, HWIDTH); image.canvas().setFillColor(0xffffffff); image.canvas().fillRect(0, 0, WIDTH, HWIDTH); image.canvas().setStrokeColor(0xff000000); image.canvas().drawLine(0, HWIDTH / 2, WIDTH, HWIDTH / 2); image.canvas().setStrokeColor(0xffff0000); image.canvas().strokeRect(0, 0, WIDTH - 1, HWIDTH - 1); slider.add(il = graphics().createImageLayer(image)); il.setOrigin(0, HWIDTH / 2); il.setTranslation(0, HEIGHT / 2); il.setDepth(1); graphics().rootLayer().add(slider); slider.setTranslation(25, 25); bg.addListener(new Mouse.LayerAdapter() { @Override public void onMouseWheelScroll (WheelEvent event) { float y = il.ty() + event.velocity(); y = Math.max(0, Math.min(y, HEIGHT)); il.setTranslation(0, y); } }); }
protected ImageLayer createLabel(String text, GroupLayer parent, int fg, int bg, float x, float y, float padding) { TextLayout layout = graphics().layoutText(text, baseFormat); float twidth = layout.width() + padding * 2; float theight = layout.height() + padding * 2; CanvasImage image = graphics().createImage(twidth, theight); if (bg != 0) { image.canvas().setFillColor(bg); image.canvas().fillRect(0, 0, twidth, theight); } image.canvas().setFillColor(fg); image.canvas().fillText(layout, padding, padding); ImageLayer imageLayer = graphics().createImageLayer(image); imageLayer.setTranslation(x, y); parent.add(imageLayer); return imageLayer; }
void nextTest() { currentTest = (currentTest + 1) % tests.length; // setup root layer for next test graphics().rootLayer().clear(); ImmediateLayer bg = graphics().createImmediateLayer(new ImmediateLayer.Renderer() { public void render(Surface surf) { surf.setFillColor(Color.rgb(255, 255, 255)); surf.fillRect(0, 0, graphics().width(), graphics().height()); } }); bg.setDepth(Float.NEGATIVE_INFINITY); // render behind everything graphics().rootLayer().add(bg); log().info("Starting " + currentTest().getName()); log().info(" Description: " + currentTest().getDescription()); currentTest().init(); }
layer1.setRotation(FloatMath.PI/8); layer1.setTranslation(50, 50); graphics().rootLayer().add(layer1); if (touch().hasTouch()) { layer1.addListener((Touch.LayerListener)new Mover(layer1)); layer2.setRotation(FloatMath.PI/4); layer2.setTranslation(150, 50); graphics().rootLayer().add(layer2); if (touch().hasTouch()) { layer2.addListener((Touch.LayerListener)new Mover(layer2)); layer3.setRotation(-FloatMath.PI/4); layer3.setTranslation(50, 150); graphics().rootLayer().add(layer3); if (touch().hasTouch()) { layer3.addListener((Touch.LayerListener)new Mover(layer3));