public void addAt(GroupLayer self, Layer layer, float tx, float ty) { layer.setTranslation(tx, ty); self.add(layer); }
/** * Returns the index of the given layer within its parent, or -1 if the parent is null. */ public static int indexInParent (Layer layer) { GroupLayer parent = layer.parent(); if (parent == null) { return -1; } for (int ii = parent.size()-1; ii >= 0; ii--) { if (parent.get(ii) == layer) { return ii; } } throw new AssertionError(); }
public void destroyAll(GroupLayer self) { AbstractLayer[] toDestroy = children.toArray(new AbstractLayer[children.size()]); // remove all of the children efficiently self.removeAll(); // now that the children have been detached, destroy them for (AbstractLayer child : toDestroy) { child.destroy(); } }
/** * Gets the layer underneath the given screen coordinates, ignoring hit testers. This is * useful for inspecting the scene graph for debugging purposes, and is not intended for use * is shipped code. The layer returned is the one that has a size and is the deepest within * the graph and contains the coordinate. */ public static Layer.HasSize layerUnderPoint (float x, float y) { GroupLayer root = PlayN.graphics().rootLayer(); Point p = new Point(x, y); root.transform().inverseTransform(p, p); p.x += root.originX(); p.y += root.originY(); return layerUnderPoint(root, p); }
public void onTouchStart(Event.Impl[] touches) { if (!enabled) return; if (listener != null) listener.onTouchStart(touches); GroupLayer root = PlayN.graphics().rootLayer(); if (root.interactive()) { for (Event.Impl event : touches) { Point p = new Point(event.x(), event.y()); root.transform().inverseTransform(p, p); p.x += root.originX(); p.y += root.originY(); AbstractLayer hitLayer = (AbstractLayer)root.hitTest(p); if (hitLayer != null) { activeLayers.put(event.id(), hitLayer); dispatcher.dispatch(hitLayer, LayerListener.class, event, START); } } } }
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() { // 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); }
@Override public void onSuccess(Image image) { groundTruthLayer = graphics().createImageLayer(image); rootLayer.addAt(groundTruthLayer, 3 * width, 0); }
@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); } }); }
public void destroy(GroupLayer self) { self.destroyAll(); }
protected boolean onMouseDown(ButtonEvent.Impl event) { if (!enabled) return false; event.flags().setPreventDefault(false); if (listener != null) { listener.onMouseDown(event); } GroupLayer root = PlayN.graphics().rootLayer(); if (root.interactive()) { Point p = new Point(event.x(), event.y()); root.transform().inverseTransform(p, p); p.x += root.originX(); p.y += root.originY(); activeLayer = (AbstractLayer)root.hitTest(p); if (activeLayer != null) { dispatcher.dispatch(activeLayer, LayerListener.class, event, DOWN); } } return event.flags().getPreventDefault(); }
@Override public void onSuccess(Image image) { rootLayer.addAt(graphics().createImageLayer(image), 5*width, 0); addDescrip("ground truth", 5*width, offset+height, width); }
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(); }
protected boolean onPointerStart(Event.Impl event, boolean preventDefault) { if (!enabled) return preventDefault; event.flags().setPreventDefault(preventDefault); if (listener != null) { listener.onPointerStart(event); } GroupLayer root = PlayN.graphics().rootLayer(); if (root.interactive()) { Point p = new Point(event.x(), event.y()); root.transform().inverseTransform(p, p); p.x += root.originX(); p.y += root.originY(); active.layer = (AbstractLayer)root.hitTest(p); if (active.layer != null) { event.captureState = active; dispatcher.dispatch(Listener.class, event, START, CANCEL); } } return event.flags().getPreventDefault(); }
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); }