List of usage examples for com.badlogic.gdx.scenes.scene2d Stage addListener
public boolean addListener(EventListener listener)
From source file:com.agateau.ui.RefreshHelper.java
License:Apache License
private void installEventListener(Stage stage) { if (stage == null) { return;/*from www . java 2 s . c om*/ } stage.addListener(new InputListener() { @Override public boolean keyUp(InputEvent event, int keycode) { if (keycode == Input.Keys.F5) { NLog.i("Refreshing"); Gdx.app.postRunnable(new Runnable() { @Override public void run() { try { refresh(); } catch (Exception exc) { NLog.e("Refresh failed: %s", exc); } } }); return true; } return false; } }); }
From source file:com.gdx.extension.ui.menu.MenuBar.java
License:Apache License
/** * Add a {@link ContextMenu context menu}. * /* w ww. ja va2 s. c o m*/ * @param actor the button that will open the {@link ContextMenu context menu} * @param menu the {@link ContextMenu context menu} to add * @param stage the stage where to display the {@link ContextMenu context menu} * * @return the {@link Cell cell} where the button opening the {@link ContextMenu context menu} was added */ public Cell<?> addContextMenu(final Button actor, final ContextMenu menu, final Stage stage) { stage.addActor(menu); menuBind.put(actor, menu); if (!isInitialized) { isInitialized = true; stage.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { Actor _target = event.getTarget(); if (_target instanceof ContextMenu || _target instanceof SubMenuItem) return false; else if (_target instanceof Label) { Actor _parent = _target.getParent(); if (_parent instanceof TextButton) { if (menuBind.containsKey(_parent)) return true; } else if (_parent instanceof SubMenuItem) return true; } closeMenu(); isOpen = false; return true; } }); } actor.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (button != Buttons.LEFT) return false; closeMenu(); lastOpened = menu; isOpen = !isOpen; return true; } @Override public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { if (!isOpen) return; closeMenu(); lastOpened = menu; menu.setVisible(true); actor.localToStageCoordinates(temp); menu.setPosition(temp.x, temp.y); temp.set(0f, 0f); } }); return super.add(actor).minWidth(actor.getWidth()); }
From source file:com.kotcrab.vis.editor.ui.scene.entityproperties.ComponentSelectDialog.java
License:Apache License
@Override protected void setStage(Stage stage) { super.setStage(stage); if (stage != null) { properties.addListener(inputListener); stage.addListener(inputListener); }/* www. j ava 2 s . c o m*/ }
From source file:com.mobidevelop.maps.editor.ui.utils.Tooltips.java
License:Apache License
public Tooltips(TooltipStyle style, Stage stage) { this.tooltips = new ObjectMap<Actor, String>(); this.stage = stage; this.tooltipStyle = style; this.listener = new InputListener() { @Override/* w w w .ja va 2 s . c om*/ public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { Actor actor = event.getTarget(); while (actor.getParent() != null) { if (tooltips.containsKey(actor)) { if (hide != null && hide.isScheduled()) { hide.cancel(); } if (tooltip == null) { final Actor finalActor = actor; show = new Task() { @Override public void run() { showTooltip(finalActor); } }; Timer.schedule(show, 1); } else { showTooltip(actor); } break; } actor = actor.getParent(); } } @Override public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) { if (show != null && show.isScheduled()) { show.cancel(); } hideTooltip(); } @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (show != null && show.isScheduled()) { show.cancel(); } hideTooltipImmediate(); return false; } }; stage.addListener(listener); }
From source file:com.o2d.pkayjava.editor.plugins.ninepatch.MainPanel.java
License:Apache License
public void setListeners(Stage stage) { stage.addListener(new InputListener() { @Override//from ww w. j a va 2 s . com public boolean scrolled(InputEvent event, float x, float y, int amount) { editingZone.zoomBy(amount); return false; } }); }
From source file:com.vlaaad.common.GdxHelper.java
License:Open Source License
public static void showStageEvents(final Stage stage) { EventListener listener = new EventListener() { private final Vector2 tmp = new Vector2(); private Actor actor = new Actor() { @Override//from w w w.j av a 2 s. c o m public void draw(Batch batch, float parentAlpha) { if (target == null) return; batch.end(); Config.shapeRenderer.begin(ShapeRenderer.ShapeType.Line); Config.shapeRenderer.setProjectionMatrix(stage.getCamera().combined); Gdx.gl.glLineWidth(6); Config.shapeRenderer.setColor(Color.ORANGE); Vector2 pos = target.localToStageCoordinates(tmp.set(0, 0)); float x = pos.x, y = pos.y; Vector2 top = target.localToStageCoordinates(tmp.set(target.getWidth(), target.getHeight())); float maxX = top.x, maxY = top.y; Config.shapeRenderer.rect(x, y, maxX - x, maxY - y); Config.shapeRenderer.end(); batch.begin(); } }; { stage.addActor(actor); } public Actor target; @Override public boolean handle(Event event) { target = event.getTarget(); return false; } }; stage.addListener(listener); }
From source file:com.vlaaad.common.tutorial.tasks.WaitHideWindow.java
License:Open Source License
@Override public void start(final Callback callback) { final Stage stage = resources.get("stage"); stage.addListener(new WindowListener() { @Override/*from w ww. java 2 s . c o m*/ protected void hide(WindowEvent event) { if (windowClass.isInstance(event.getWindow())) { stage.removeListener(this); callback.taskEnded(); } } }); }
From source file:com.vlaaad.common.tutorial.tasks.WaitWindowHidden.java
License:Open Source License
@Override public void start(final Callback callback) { final Stage stage = resources.get("stage"); stage.addListener(new WindowListener() { @Override/* w w w . j av a2s . com*/ protected void hidden(WindowEvent event) { if (windowClass.isInstance(event.getWindow())) { stage.removeListener(this); callback.taskEnded(); } } }); }
From source file:com.vlaaad.common.tutorial.tasks.WaitWindowShow.java
License:Open Source License
@Override public void start(final Callback callback) { final Stage stage = resources.get("stage"); stage.addListener(new WindowListener() { @Override/*from w ww . j a va2 s. c om*/ protected void show(WindowEvent event) { if (windowClass.isInstance(event.getWindow())) { stage.removeListener(this); callback.taskEnded(); } } }); }
From source file:com.vlaaad.common.tutorial.tasks.WaitWindowShown.java
License:Open Source License
@Override public void start(final Callback callback) { final Stage stage = resources.get("stage"); listener = new WindowListener() { @Override/* w w w.j av a 2 s . c o m*/ protected void shown(WindowEvent event) { if (windowClass.isInstance(event.getWindow())) { stage.removeListener(this); callback.taskEnded(); } } }; stage.addListener(listener); }