@Override public void onSuccess(Image image) { groundTruthLayer = graphics().createImageLayer(image); rootLayer.addAt(groundTruthLayer, 3 * width, 0); }
@Override public void onSuccess(Image image) { rootLayer.addAt(graphics().createImageLayer(image), 5*width, 0); addDescrip("ground truth", 5*width, offset+height, width); }
protected float addTest(float lx, float ly, Layer layer, float lwidth, float lheight, String descrip, float twidth) { graphics().rootLayer().addAt(layer, lx + (twidth-lwidth)/2, ly); return addDescrip(descrip, lx, ly + lheight + 5, twidth); }
protected float addDescrip(String descrip, float x, float y, float width) { ImageLayer layer = createDescripLayer(descrip, width); graphics().rootLayer().addAt(layer, Math.round(x + (width - layer.width())/2), y); return y + layer.height(); }
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 > graphics().width()) { nextY += (maxY + GAP); nextX = GAP; maxY = 0; } // add the layer and its description below graphics().rootLayer().addAt(layer, nextX, nextY); ImageLayer dlayer = createDescripLayer(descrip, width); graphics().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); }
protected float addButton (String text, Runnable onClick, float x, float y) { ImageLayer button = createButton(text, onClick); graphics().rootLayer().addAt(button, x, y); return x + button.width() + 10; }
protected void fragment(String source, Image image, float ox, float oy) { float hw = image.width()/2f, hh = image.height()/2f; Image ul = image.subImage(0, 0, hw, hh); Image ur = image.subImage(hw, 0, hw, hh); Image ll = image.subImage(0, hh, hw, hh); Image lr = image.subImage(hw, hh, hw, hh); Image ctr = image.subImage(hw/2, hh/2, hw, hh); float dx = hw + 10, dy = hh + 10; GroupLayer group = graphics().createGroupLayer(); group.addAt(graphics().createImageLayer(ul), 0, 0); group.addAt(graphics().createImageLayer(ur), dx, 0); group.addAt(graphics().createImageLayer(ll), 0, dy); group.addAt(graphics().createImageLayer(lr), dx, dy); group.addAt(graphics().createImageLayer(ctr), dx/2, 2*dy); float xoff = image.width() + 20; group.addAt(scaleLayer(graphics().createImageLayer(ul), 2), xoff, 0); group.addAt(scaleLayer(graphics().createImageLayer(ur), 2), xoff+2*dx, 0); group.addAt(scaleLayer(graphics().createImageLayer(ll), 2), xoff, 2*dy); group.addAt(scaleLayer(graphics().createImageLayer(lr), 2), xoff+2*dx, 2*dy); graphics().rootLayer().addAt(group, ox, oy); addDescrip(source + " split into subimages, and scaled", ox, oy + image.height()*2 + 25, 3*image.width()+40); }
@Override public void onSuccess(Image image) { // once the image loads, create our layers imageLayer1 = graphics().createImageLayer(image); SurfaceImage surface1 = graphics().createSurface(image.width(), image.height()); surface1.surface().drawImage(image, 0, 0); surfaceLayer1 = graphics().createImageLayer(surface1); CanvasImage canvas1 = graphics().createImage(image.width(), image.height()); canvas1.canvas().drawImage(image, 0, 0); canvasLayer1 = graphics().createImageLayer(canvas1); imageLayer2 = graphics().createImageLayer(image); SurfaceImage surface2 = graphics().createSurface(image.width(), image.height()); surface2.surface().drawImage(image, 0, 0); surfaceLayer2 = graphics().createImageLayer(surface2); CanvasImage canvas2 = graphics().createImage(image.width(), image.height()); canvas2.canvas().drawImage(image, 0, 0); canvasLayer2 = graphics().createImageLayer(canvas2); // add layers to the rootLayer rootLayer.addAt(imageLayer1, offset, offset); rootLayer.addAt(surfaceLayer1, offset + width, offset); rootLayer.addAt(canvasLayer1, offset + 2 * width, offset); rootLayer.addAt(imageLayer2, offset, offset + 2 * height); rootLayer.addAt(surfaceLayer2, offset + width, offset + 2 * height); rootLayer.addAt(canvasLayer2, offset + 2 * width, offset + 2 * height); }
String instructions = "Click one of the buttons below to display the text entry UI."; ImageLayer instLayer = graphics().createImageLayer(formatText(instructions, false)); graphics().rootLayer().addAt(instLayer, 50, 50); graphics().rootLayer().addAt(outputLayer, 50, 150); graphics().rootLayer().addAt(button, x, 100); x += button.width() + 10;
@Override public void init() { setLifecycleListener(new LifecycleListener() { private double start = currentTime(); private int elapsed() { return (int)Math.round((currentTime() - start)/1000); } @Override public void onPause() { log().info("Paused " + elapsed()); notifications.add("Paused at " + elapsed() + "s"); } @Override public void onResume() { log().info("Resumed " + elapsed()); notifications.add("Resumed at " + elapsed() + "s"); updateDisplay(); } @Override public void onExit() {} // nada }); layer = graphics().createImageLayer(); updateDisplay(); graphics().rootLayer().addAt(layer, 15, 15); }
group.addAt(graphics().createImageLayer(orange), owidth/2, 0); rotator = graphics().createImageLayer(orange); group.addAt(rotator.setOrigin(owidth/2, oheight/2), 2*owidth, oheight/2); rotator.setRotation(FloatMath.PI/2); graphics().rootLayer().addAt(group, x, y); addDescrip("Added to rootLayer", x, y+theight+gap, twidth); x += twidth+gap; graphics().rootLayer().addAt(graphics().createImmediateLayer(new ImmediateLayer.Renderer() { public void render (Surface surf) { x += twidth+gap; graphics().rootLayer().addAt(graphics().createImmediateLayer(new ImmediateLayer.Renderer() { public void render (Surface surf) { surf.translate(-gap, -gap).drawLayer(group); x += twidth+gap; graphics().rootLayer().addAt(graphics().createImmediateLayer(new ImmediateLayer.Renderer() { public void render (Surface surf) { surf.translate(-gap, -gap).drawLayer(group); graphics().rootLayer().addAt(graphics().createImageLayer(image), x, y); addDescrip("SurfaceImage drawLayer (won't animate)", x, y+theight+gap, twidth); x += twidth+gap;
@Override public void init() { Image princess1 = assets().getImage("images/princess.png"); Image princess2 = assets().getImage("images/princess.png"); Image star1 = assets().getImage("images/star.png"); Image star2 = assets().getImage("images/star.png"); // configure the second princess and (64x64) star images as mipmapped princess2.setMipmapped(true); star2.setMipmapped(true); float phwidth = 101/2f, phheight = 171/2f; // avoid having to wait for images player1 = graphics().createImageLayer(princess1); player1.setOrigin(phwidth, phheight); graphics().rootLayer().addAt(player1, 100, 100); player2 = graphics().createImageLayer(princess2); player2.setOrigin(phwidth, phheight); graphics().rootLayer().addAt(player2, 250, 100); float shwidth = 64/2, shheight = 64/2; // avoid having to wait for images slayer1 = graphics().createImageLayer(star1); slayer1.setOrigin(shwidth, shheight); graphics().rootLayer().addAt(slayer1, 100, 250); slayer2 = graphics().createImageLayer(star2); slayer2.setOrigin(shwidth, shheight); graphics().rootLayer().addAt(slayer2, 250, 250); pointer().setListener(new Pointer.Adapter() { @Override public void onPointerStart(Pointer.Event event) { pointerPressed = true; } @Override public void onPointerEnd(Pointer.Event event) { pointerPressed = false; } @Override public void onPointerCancel(Pointer.Event event) { pointerPressed = false; } }); }
groupLayer.addAt(graphics().createImageLayer(image).setAlpha(0.5f), x, offset); addDescrip("image\nimg layer a=0.5", x, offset + height, width); x += width; groupLayer.addAt(graphics().createImageLayer(surf1), x, offset); addDescrip("surface a=0.5\nimg layer a=1", x, offset + height, width); x += width; groupLayer.addAt(graphics().createImageLayer(surf2).setAlpha(0.5f), x, offset); addDescrip("surface a=1\nimg layer a=0.5", x, offset + height, width); x += width; groupLayer.addAt(graphics().createImageLayer(canvas1).setAlpha(0.5f), x, offset); addDescrip("canvas a=1\nimg layer a=0.5", x, offset + height, width); x += width; groupLayer.addAt(graphics().createImageLayer(canvas2), x, offset); addDescrip("canvas a=0.5\nimg layer a=1", x, offset + height, width); x += width; groupLayer.addAt(graphics().createImageLayer(image).setAlpha(0.5f), x, offset + 2 * height); x += width; groupLayer.addAt(graphics().createImageLayer(surf1b), x, offset + 2 * height); x += width; groupLayer.addAt(graphics().createImageLayer(surf2b).setAlpha(0.5f), x, offset + 2 * height); x += width;
i1.setOrigin(i1.width()/2, i1.height()/2); g1.addAt(i1, 50, 50); rootLayer.addAt(g1, 75, 25); g2.setOrigin(50, 50); g2.addAt(graphics().createImageLayer(img), (100 - img.width())/2, (100 - img.height())/2); rootLayer.addAt(g2, 200, 75); inner.addAt(graphics().createImageLayer(img), (100 - img.width())/2, (100 - img.height())/2); g3 = graphics().createGroupLayer(100, 100); g3.add(inner); rootLayer.addAt(g3, 275, 25); s1.setOrigin(s1.width()/2, s1.height()/2); g4.addAt(s1, 50, 50); rootLayer.addAt(g4, 400, 25); g5Inner.addAt(graphics().createImageLayer(img).setScale(2), -img.width(), -img.height()); g5Inner.addAt(graphics().createImageLayer(img).setScale(2), -img.width(), img.height()); g5Inner.addAt(graphics().createImageLayer(img).setScale(2), img.width(), -img.height()); g5Inner.addAt(graphics().createImageLayer(img).setScale(2), img.width(), img.height()); g5 = graphics().createGroupLayer(100, 100); g5.addAt(g5Inner, -25, -25); rootLayer.addAt(g5, 525, 25);
rootLayer.addAt(ilayer, 130, 130); rootLayer.addAt(graphics().createImmediateLayer(100, 100, new ImmediateLayer.Renderer() { public void render (Surface surf) { surf.setFillColor(0xFF99CCFF); rootLayer.addAt(graphics().createImmediateLayer(100, 100, new ImmediateLayer.Renderer() { public void render (Surface surf) { surf.setFillColor(0xFF99CCFF);
protected void addInfo (CanvasImage image, float cx, float y) { TextLayout ilayout = graphics().layoutText(image.width() + "x" + image.height(), infoFormat); CanvasImage iimage = graphics().createImage(ilayout.width(), ilayout.height()); iimage.canvas().setFillColor(0xFF000000).fillText(ilayout, 0, 0); graphics().rootLayer().addAt(graphics().createImageLayer(iimage), cx - iimage.width()/2, y); }
@Override public void init() { float x = 50; final Sound fanfare = loadSound("sounds/fanfare"); x = addButton("Play Fanfare", new Runnable() { public void run() { fanfare.play(); addAction("Played Fanfare."); } }, x, 100); Sound lfanfare = loadSound("sounds/fanfare"); lfanfare.setLooping(true); x = addLoopButtons("Fanfare", lfanfare, x); final Sound bling = loadSound("sounds/bling"); x = addButton("Play Bling", new Runnable() { public void run() { bling.play(); addAction("Played Bling."); } }, x, 100); Sound lbling = loadSound("sounds/bling"); lbling.setLooping(true); x = addLoopButtons("Bling", lbling, x); graphics().rootLayer().addAt(graphics().createImageLayer(_actionsImage), 50, 150); }
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); } }
@Override public void init() { String text = "The quick brown fox jumped over the lazy dog."; TextFormat format = new TextFormat(). withFont(graphics().createFont("Helvetica", Font.Style.PLAIN, 18)); TextBlock block = new TextBlock(graphics().layoutText(text, format, new TextWrap(100))); float x = 5; for (float scale : new float[] { 1f, 2f, 3f }) { float swidth = block.bounds.width() * scale, sheight = block.bounds.height() * scale; CanvasImage image = graphics().createImage(swidth, sheight); image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, swidth-0.5f, sheight-0.5f); image.canvas().scale(scale, scale); image.canvas().setFillColor(0xFF000000); block.fill(image.canvas(), TextBlock.Align.RIGHT, 0, 0); graphics().rootLayer().addAt(graphics().createImageLayer(image), x, 5); addInfo(image, x + swidth/2, sheight + 10); x += swidth + 5; } }