protected ImageLayer createLabel(String text, int bg, float x, float y) { return createLabel(text, graphics().rootLayer(), 0xFF202020, bg, x, y, 0); }
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(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); }
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 clearRoot() { GroupLayer root = graphics().rootLayer(); for (int ii = root.size()-1; ii >= 0; ii--) root.get(ii).destroy(); }
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() { // 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 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); }
/** * 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); }
@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()); } }
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(); }
@Override public void init() { CanvasImage canvasImage = graphics().createImage(graphics().width(), graphics().height()); canvas = canvasImage.canvas(); graphics().rootLayer().add(graphics().createImageLayer(canvasImage)); }
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); } } } }
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); }
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(); }
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(); }
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; } }