diff options
author | Joshua Slack <[email protected]> | 2017-08-11 13:08:22 -0500 |
---|---|---|
committer | Joshua Slack <[email protected]> | 2017-08-11 13:08:22 -0500 |
commit | 276240b3c9fda93e2ec76816b6d5f4307b549790 (patch) | |
tree | 7b381a9324e00a09560c8b4c74b760b6751b486f /ardor3d-examples/src | |
parent | 26591a1f8df4ceddd68e50fbce73c645cbe8c98b (diff) |
Updated example to also incorporate popup-menus
Diffstat (limited to 'ardor3d-examples/src')
-rw-r--r-- | ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java index 1dfa5b2..13dedb2 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java @@ -32,7 +32,9 @@ import com.ardor3d.extension.ui.UIComboBox; import com.ardor3d.extension.ui.UIContainer; import com.ardor3d.extension.ui.UIFrame; import com.ardor3d.extension.ui.UIHud; +import com.ardor3d.extension.ui.UIMenuItem; import com.ardor3d.extension.ui.UIPanel; +import com.ardor3d.extension.ui.UIPopupMenu; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.backdrop.EmptyBackdrop; import com.ardor3d.extension.ui.border.EmptyBorder; @@ -47,6 +49,7 @@ import com.ardor3d.framework.Canvas; import com.ardor3d.image.Texture; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; +import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.KeyReleasedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; @@ -306,11 +309,74 @@ public class InteractUIExample extends ExampleBase { manager.setActiveWidget(pulseWidget); } })); + manager.getLogicalLayer().registerTrigger( + new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { + @Override + public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { + showMenu(); + } + })); + manager.getLogicalLayer().registerTrigger( + new InputTrigger(new KeyReleasedCondition(Key.SPACE), new TriggerAction() { + @Override + public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { + hideMenu(); + } + })); // add some filters manager.addFilter(new PlaneBoundaryFilter(new Plane(Vector3.UNIT_Y, 0))); } + UIPopupMenu menu; + + protected void showMenu() { + if (menu == null) { + menu = new UIPopupMenu(); + menu.addItem(new UIMenuItem("Add Node After", null, true, new ActionListener() { + @Override + public void actionPerformed(final ActionEvent event) { + final Spatial spat = manager.getSpatialTarget(); + if (spat == null) { + return; + } + createMarkerAfter(spat); + } + })); + menu.addItem(new UIMenuItem("Delete Node", null, true, new ActionListener() { + @Override + public void actionPerformed(final ActionEvent event) { + final Spatial spat = manager.getSpatialTarget(); + if (spat == null) { + return; + } + removeMarker(spat); + } + })); + menu.updateMinimumSizeFromContents(); + menu.pack(); + menu.layout(); + } + + hud.closePopupMenus(); + + final Spatial spat = manager.getSpatialTarget(); + if (spat == null) { + return; + } + + hud.showSubPopupMenu(menu); + + tempVec.zero(); + tempVec.set(Camera.getCurrentCamera().getScreenCoordinates(spat.getWorldTransform().applyForward(tempVec))); + tempVec.setZ(0); + menu.showAt((int) tempVec.getX(), (int) tempVec.getY()); + } + + protected void hideMenu() { + hud.closePopupMenus(); + } + @Override protected void processPicks(final PrimitivePickResults pickResults) { final PickData pick = pickResults.findFirstIntersectingPickData(); |