public void run() { Panel panel = new Panel(); panel.add( new Node() { @Override public void draw(GFX g) { doDraw(g, this); } @Override public Bounds getVisualBounds() { return new Bounds(0, 0, 300, 300); } @Override public Bounds getInputBounds() { return getVisualBounds(); } }); font = Font.name("League Gothic").size(120).resolve(); font2 = Font.name("League Gothic").size(60).resolve(); try { image = Image.create(ImageIO.read(Presentation.class.getResource("Test01.png"))); } catch (IOException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } Stage stage = Stage.createStage(); stage.setContent(panel); stage.setWidth(1024); stage.setHeight(768); }
public void show(Node node, double x, double y) { if (sharedContextMenu != null) { sharedContextMenu.setVisible(false); sharedLayer.remove(sharedContextMenu); } Stage stage = node.getParent().getStage(); sharedLayer = stage.getPopupLayer(); Point2D pt = NodeUtils.convertToScene(node, x, y); pt = NodeUtils.convertFromScene(sharedLayer, pt); setTranslateX(pt.getX() + 2); setTranslateY(pt.getY()); setVisible(true); sharedContextMenu = this; sharedLayer.add(this); }
@Override protected void setPressed(boolean pressed) { super.setPressed(pressed); if (pressed) { if (!popupadded) { Stage stage = getParent().getStage(); stage.getPopupLayer().add(popup); } Point2D pt = NodeUtils.convertToScene(this, 0, getHeight()); popup.setTranslateX(Math.round(Math.max(pt.getX(), 0))); popup.setTranslateY(Math.round(Math.max(pt.getY(), 0))); popup.setVisible(true); EventBus.getSystem().setPressedNode(popup); } else { // popup.setVisible(false); } }
private void doDraw(GFX g, Node node) { String text = "Welcome to Bedrock"; String text2 = "by josh marinacci"; g.drawImage(image, 0, 0); Stage s = node.getParent().getStage(); double x = 0; double y = 0; x = (s.getWidth() - font.getWidth(text)) / 2; y = (s.getHeight() / 2) - font.getDescender(); g.setPaint(FlatColor.BLACK); g.drawText(text, font, x + 4, y + 4); g.setPaint(FlatColor.WHITE); g.drawText(text, font, x, y); x = (s.getWidth() - font2.getWidth(text2)) / 2; y = y + font2.getAscender() + font2.getDescender(); g.setPaint(FlatColor.BLACK); g.drawText(text2, font2, x + 4, y + 4); g.setPaint(FlatColor.WHITE); g.drawText(text2, font2, x, y); }