From e647796e2aef9a2088baab606520e7c32aacc03f Mon Sep 17 00:00:00 2001 From: Joshua Slack Date: Mon, 25 Sep 2017 14:05:09 -0500 Subject: Simplified UIPopupMenu to extend UIContainer instead of UIFrame. Updated UIMenuItem to simplify adding nested menus Updated UIPieMenu to extend UIPopupMenu, to make it easier to reuse menu code. Added new UI example showing off hierarchical Popup and Pie menus --- .../com/ardor3d/example/ui/InteractUIExample.java | 4 +- .../com/ardor3d/example/ui/PopOverUIExample.java | 289 +++++++++++++++++++++ .../example/i18n/example_descriptions.properties | 1 + 3 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java (limited to 'ardor3d-examples') 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 45a3478..2e1e44e 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 @@ -421,8 +421,10 @@ public class InteractUIExample extends ExampleBase { tempVec.set(Camera.getCurrentCamera().getScreenCoordinates(spat.getWorldTransform().applyForward(tempVec))); tempVec.setZ(0); menu.showAt((int) tempVec.getX(), (int) tempVec.getY()); - _mouseManager.setPosition((int) tempVec.getX(), (int) tempVec.getY() + 1); _mouseManager.setPosition((int) tempVec.getX(), (int) tempVec.getY()); + if (menu.getCenterItem() != null) { + menu.getCenterItem().mouseEntered((int) tempVec.getX(), (int) tempVec.getY(), null); + } } protected void hideMenu() { diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java new file mode 100644 index 0000000..2f1c69e --- /dev/null +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java @@ -0,0 +1,289 @@ +/** + * Copyright (c) 2008-2017 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at . + */ + +package com.ardor3d.example.ui; + +import com.ardor3d.bounding.BoundingBox; +import com.ardor3d.example.ExampleBase; +import com.ardor3d.example.Purpose; +import com.ardor3d.extension.ui.UIButton; +import com.ardor3d.extension.ui.UIComponent; +import com.ardor3d.extension.ui.UIHud; +import com.ardor3d.extension.ui.UIMenuItem; +import com.ardor3d.extension.ui.UIPieMenu; +import com.ardor3d.extension.ui.UIPieMenuItem; +import com.ardor3d.extension.ui.UIPopupMenu; +import com.ardor3d.extension.ui.event.ActionEvent; +import com.ardor3d.extension.ui.event.ActionListener; +import com.ardor3d.extension.ui.util.Insets; +import com.ardor3d.image.Texture; +import com.ardor3d.math.ColorRGBA; +import com.ardor3d.math.MathUtils; +import com.ardor3d.math.Matrix3; +import com.ardor3d.math.Vector3; +import com.ardor3d.math.type.ReadOnlyVector3; +import com.ardor3d.renderer.Camera; +import com.ardor3d.renderer.Renderer; +import com.ardor3d.renderer.state.MaterialState; +import com.ardor3d.renderer.state.MaterialState.ColorMaterial; +import com.ardor3d.renderer.state.RenderState.StateType; +import com.ardor3d.renderer.state.TextureState; +import com.ardor3d.scenegraph.controller.SpatialController; +import com.ardor3d.scenegraph.shape.Box; +import com.ardor3d.util.ReadOnlyTimer; +import com.ardor3d.util.TextureManager; + +/** + * Illustrates the use of Popup and Pie menus. + */ +@Purpose(htmlDescriptionKey = "com.ardor3d.example.ui.PopOverUIExample", // +thumbnailPath = "com/ardor3d/example/media/thumbnails/ui_PopOverUIExample.jpg", // +maxHeapMemory = 64) +public class PopOverUIExample extends ExampleBase implements ActionListener { + private static final String[] COLORS = new String[] { "Red", "White", "Blue", "Black" }; + private static final String[] SPINS = new String[] { "None", "Around X", "Around Y", "Around Z" }; + private static final String[] TEXS = new String[] { "None", "Logo", "Ball", "Clock" }; + + UIHud hud; + private Box box; + + public static void main(final String[] args) { + start(PopOverUIExample.class); + } + + @Override + protected void initExample() { + _canvas.setTitle("PopOver UI Example"); + + UIComponent.setUseTransparency(true); + + // Add a spinning 3D box to show behind UI. + box = new Box("Box", new Vector3(0, 0, 0), 5, 5, 5); + box.setModelBound(new BoundingBox()); + box.setTranslation(new Vector3(0, 0, -15)); + _root.attachChild(box); + + final MaterialState ms = new MaterialState(); + ms.setColorMaterial(ColorMaterial.Diffuse); + box.setRenderState(ms); + + setTexture("Logo"); + setSpin("Around Y"); + + hud = new UIHud(); + hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud.setMouseManager(_mouseManager); + final Camera cam = _canvas.getCanvasRenderer().getCamera(); + + final UIButton dropButton = new UIButton("Drop Menu"); + dropButton.setPadding(new Insets(6, 15, 6, 15)); + dropButton.setHudXY(cam.getWidth() / 10 - dropButton.getLocalComponentWidth() / 2, + cam.getHeight() - dropButton.getLocalComponentHeight() - 5); + dropButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(final ActionEvent event) { + showPopupMenu(dropButton.getHudX(), dropButton.getHudY()); + } + }); + hud.add(dropButton); + + final UIButton pieButton = new UIButton("Pie Menu"); + pieButton.setPadding(new Insets(6, 15, 6, 15)); + pieButton.setHudXY(9 * cam.getWidth() / 10 - pieButton.getLocalComponentWidth() / 2, cam.getHeight() + - pieButton.getLocalComponentHeight() - 5); + pieButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(final ActionEvent event) { + showPieMenu(cam.getWidth() / 2, cam.getHeight() / 2); + } + }); + hud.add(pieButton); + } + + @Override + public void actionPerformed(final ActionEvent event) { + final UIButton src = (UIButton) event.getSource(); + final String command = src.getActionCommand(); + switch (command) { + case "Color": + setColor(src.getText()); + return; + case "Spin": + setSpin(src.getText()); + return; + case "Texture": + setTexture(src.getText()); + return; + } + } + + protected void showPopupMenu(final int hudX, final int hudY) { + final UIPopupMenu menu = new UIPopupMenu(); + final int minWidth = 120; + + final UIPopupMenu colorMenu = new UIPopupMenu(); + colorMenu.setMinimumContentSize(minWidth, 5); + menu.addItem(new UIMenuItem("Set Color...", null, colorMenu)); + AddMenuItems(colorMenu, "Color", false, COLORS); + + final UIPopupMenu spinMenu = new UIPopupMenu(); + spinMenu.setMinimumContentSize(minWidth, 5); + menu.addItem(new UIMenuItem("Set Spin...", null, spinMenu)); + AddMenuItems(spinMenu, "Spin", false, SPINS); + + final UIPopupMenu texMenu = new UIPopupMenu(); + texMenu.setMinimumContentSize(minWidth, 5); + menu.addItem(new UIMenuItem("Set Texture...", null, texMenu)); + AddMenuItems(texMenu, "Texture", false, TEXS); + + menu.updateMinimumSizeFromContents(); + menu.layout(); + + hud.closePopupMenus(); + + hud.showSubPopupMenu(menu); + menu.showAt(hudX, hudY); + } + + protected void showPieMenu(final int hudX, final int hudY) { + final UIPieMenu menu = new UIPieMenu(hud, 70, 200); + + final UIPieMenu colorMenu = new UIPieMenu(hud); + menu.addItem(new UIPieMenuItem("Set Color...", null, colorMenu, 100)); + AddMenuItems(colorMenu, "Color", true, COLORS); + + final UIPieMenu spinMenu = new UIPieMenu(hud); + menu.addItem(new UIPieMenuItem("Set Spin...", null, spinMenu, 100)); + AddMenuItems(spinMenu, "Spin", true, SPINS); + + final UIPieMenu texMenu = new UIPieMenu(hud); + menu.addItem(new UIPieMenuItem("Set Texture...", null, texMenu, 100)); + AddMenuItems(texMenu, "Texture", true, TEXS); + + menu.setCenterItem(new UIPieMenuItem("Cancel", null, true, null)); + + menu.updateMinimumSizeFromContents(); + menu.layout(); + + hud.closePopupMenus(); + + hud.showSubPopupMenu(menu); + menu.showAt(hudX, hudY); + _mouseManager.setPosition(hudX, hudY); + if (menu.getCenterItem() != null) { + menu.getCenterItem().mouseEntered(hudX, hudY, null); + } + + } + + private void AddMenuItems(final UIPopupMenu parent, final String actionCommand, final boolean pie, + final String[] colors) { + for (final String color : colors) { + final UIMenuItem item = pie ? new UIPieMenuItem(color, null, true, this) : new UIMenuItem(color, null, + true, this); + item.setActionCommand(actionCommand); + parent.addItem(item); + } + } + + private void setColor(final String text) { + switch (text) { + case "Red": + box.setDefaultColor(ColorRGBA.RED); + break; + case "Blue": + box.setDefaultColor(ColorRGBA.BLUE); + break; + case "Black": + box.setDefaultColor(ColorRGBA.BLACK); + break; + default: + case "White": + box.setDefaultColor(ColorRGBA.WHITE); + break; + } + } + + private void setSpin(final String text) { + box.clearControllers(); + final ReadOnlyVector3 axis; + switch (text) { + case "None": + return; + case "Around X": + axis = Vector3.UNIT_X; + break; + case "Around Y": + axis = Vector3.UNIT_Y; + break; + default: + case "Around Z": + axis = Vector3.UNIT_Z; + break; + } + box.addController(new SpatialController() { + private final Matrix3 rotate = new Matrix3(); + private double angle = 0; + + public void update(final double time, final Box caller) { + angle += time * 50; + angle %= 360; + rotate.fromAngleNormalAxis(angle * MathUtils.DEG_TO_RAD, axis); + caller.setRotation(rotate); + } + }); + } + + private void setTexture(final String text) { + // Add a texture to the box. + final TextureState ts = new TextureState(); + + String imageFile; + switch (text) { + case "None": + box.clearRenderState(StateType.Texture); + box.updateWorldRenderStates(true); + return; + case "Ball": + imageFile = "images/ball.png"; + break; + case "Clock": + imageFile = "images/clock.png"; + break; + case "Logo": + default: + imageFile = "images/ardor3d_white_256.jpg"; + break; + } + + final Texture tex = TextureManager.load(imageFile, Texture.MinificationFilter.Trilinear, true); + ts.setTexture(tex); + box.setRenderState(ts); + box.updateWorldRenderStates(true); + } + + @Override + protected void updateLogicalLayer(final ReadOnlyTimer timer) { + hud.getLogicalLayer().checkTriggers(timer.getTimePerFrame()); + } + + @Override + protected void renderExample(final Renderer renderer) { + super.renderExample(renderer); + renderer.renderBuckets(); + renderer.draw(hud); + } + + @Override + protected void updateExample(final ReadOnlyTimer timer) { + hud.updateGeometricState(timer.getTimePerFrame()); + } + +} diff --git a/ardor3d-examples/src/main/resources/com/ardor3d/example/i18n/example_descriptions.properties b/ardor3d-examples/src/main/resources/com/ardor3d/example/i18n/example_descriptions.properties index fad9b46..5ba0fbf 100644 --- a/ardor3d-examples/src/main/resources/com/ardor3d/example/i18n/example_descriptions.properties +++ b/ardor3d-examples/src/main/resources/com/ardor3d/example/i18n/example_descriptions.properties @@ -85,5 +85,6 @@ com.ardor3d.example.terrain.ShapesPlusProceduralTerrainExample=Example showing t com.ardor3d.example.terrain.TerrainWaterExample=Example showing how to combine the terrain and water systems. Requires GLSL support. com.ardor3d.example.terrain.ZupTerrainExample=Example showing the Geometry Clipmap Terrain system with 'MegaTextures' using Z-Up. This is done by flipping the terrain system from y-up to z-up and inverting interactions with it back to the y-up terrain coordinate space. Requires GLSL support. com.ardor3d.example.ui.BMTextExample=Illustrates how to modify text properties (e.g. font, color, alignment) and display on a canvas. +com.ardor3d.example.ui.PopOverUIExample=Illustrates the use of Popup and Pie menus. com.ardor3d.example.ui.RotatingUIExample=Illustrates how to display and move GUI primitatives (e.g. RadioButton, Lable, TabbedPane) on a canvas. com.ardor3d.example.ui.SimpleUIExample=Illustrates how to display GUI primitatives (e.g. RadioButton, Lable, TabbedPane) on a canvas. -- cgit v1.2.3 From 496263aac829dd0837ba65997b41ef2851022b3c Mon Sep 17 00:00:00 2001 From: Joshua Slack Date: Fri, 29 Sep 2017 17:25:24 -0500 Subject: Added centerOn method to UIComponent to make it simpler to center a component on another component or the hud. Fixed issue in sliders when min value is not 0. Clean up warnings. --- .gitignore | 1 + .../src/main/java/com/ardor3d/image/Texture1D.java | 19 ++++++--- .../src/main/java/com/ardor3d/image/Texture2D.java | 17 +++++--- .../renderer/utils/atlas/TestAtlasPacker.java | 5 +-- .../com/ardor3d/example/ui/PopOverUIExample.java | 46 ++++++++++++++++++++++ .../com/ardor3d/renderer/jogl/JoglRenderer.java | 9 ++--- .../java/com/ardor3d/extension/ui/UIComponent.java | 14 +++++++ .../java/com/ardor3d/extension/ui/UISlider.java | 20 +++++----- .../com/ardor3d/extension/ui/UISliderKnob.java | 13 +++--- .../java/com/ardor3d/extension/ui/UITextField.java | 16 ++++---- 10 files changed, 116 insertions(+), 44 deletions(-) (limited to 'ardor3d-examples') diff --git a/.gitignore b/.gitignore index 35a5496..ab9aa9a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target/ .project .classpath .gradle/ +*/build/* \ No newline at end of file diff --git a/ardor3d-core/src/main/java/com/ardor3d/image/Texture1D.java b/ardor3d-core/src/main/java/com/ardor3d/image/Texture1D.java index 5ba42cd..20d3866 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/image/Texture1D.java +++ b/ardor3d-core/src/main/java/com/ardor3d/image/Texture1D.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -32,13 +32,13 @@ public class Texture1D extends Texture { /** * setWrap sets the wrap mode of this texture for a particular axis. - * + * * @param axis * the texture axis to define a wrapmode on. * @param mode * the wrap mode for the given axis of the texture. * @throws IllegalArgumentException - * if axis or mode are null + * if axis or mode are null or invalid */ @Override public void setWrap(final WrapAxis axis, final WrapMode mode) { @@ -51,12 +51,16 @@ public class Texture1D extends Texture { case S: _wrapS = mode; break; + case R: + case T: + default: + throw new IllegalArgumentException("invalid WrapAxis: " + axis); } } /** * setWrap sets the wrap mode of this texture for all axis. - * + * * @param mode * the wrap mode for the given axis of the texture. * @throws IllegalArgumentException @@ -72,7 +76,7 @@ public class Texture1D extends Texture { /** * getWrap returns the wrap mode for a given coordinate axis on this texture. - * + * * @param axis * the axis to return for * @return the wrap mode of the texture. @@ -84,8 +88,11 @@ public class Texture1D extends Texture { switch (axis) { case S: return _wrapS; + case R: + case T: + default: + throw new IllegalArgumentException("invalid WrapAxis: " + axis); } - throw new IllegalArgumentException("invalid WrapAxis: " + axis); } @Override diff --git a/ardor3d-core/src/main/java/com/ardor3d/image/Texture2D.java b/ardor3d-core/src/main/java/com/ardor3d/image/Texture2D.java index dc54a94..61e9b3e 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/image/Texture2D.java +++ b/ardor3d-core/src/main/java/com/ardor3d/image/Texture2D.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -34,13 +34,13 @@ public class Texture2D extends Texture { /** * setWrap sets the wrap mode of this texture for a particular axis. - * + * * @param axis * the texture axis to define a wrapmode on. * @param mode * the wrap mode for the given axis of the texture. * @throws IllegalArgumentException - * if axis or mode are null + * if axis or mode are null or invalid */ @Override public void setWrap(final WrapAxis axis, final WrapMode mode) { @@ -56,12 +56,15 @@ public class Texture2D extends Texture { case T: _wrapT = mode; break; + case R: + default: + throw new IllegalArgumentException("invalid WrapAxis: " + axis); } } /** * setWrap sets the wrap mode of this texture for all axis. - * + * * @param mode * the wrap mode for the given axis of the texture. * @throws IllegalArgumentException @@ -78,7 +81,7 @@ public class Texture2D extends Texture { /** * getWrap returns the wrap mode for a given coordinate axis on this texture. - * + * * @param axis * the axis to return for * @return the wrap mode of the texture. @@ -92,8 +95,10 @@ public class Texture2D extends Texture { return _wrapS; case T: return _wrapT; + case R: + default: + throw new IllegalArgumentException("invalid WrapAxis: " + axis); } - throw new IllegalArgumentException("invalid WrapAxis: " + axis); } @Override diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/TestAtlasPacker.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/TestAtlasPacker.java index 06db12a..7f83f13 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/TestAtlasPacker.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/utils/atlas/TestAtlasPacker.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -15,7 +15,6 @@ import java.util.Random; import javax.swing.JFrame; import javax.swing.JPanel; -import com.ardor3d.extension.atlas.AtlasNode; import com.ardor3d.extension.atlas.AtlasPacker; /** @@ -30,7 +29,7 @@ public class TestAtlasPacker { final Random rand = new Random(); for (int i = 0; i < 2000; i++) { - final AtlasNode node = packer.insert(rand.nextInt(100) + 10, rand.nextInt(100) + 10); + packer.insert(rand.nextInt(100) + 10, rand.nextInt(100) + 10); } final JFrame frame = new JFrame("Pack"); diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java index 2f1c69e..31799f1 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java @@ -10,18 +10,27 @@ package com.ardor3d.example.ui; +import java.util.EnumSet; + import com.ardor3d.bounding.BoundingBox; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; +import com.ardor3d.extension.ui.Orientation; import com.ardor3d.extension.ui.UIButton; import com.ardor3d.extension.ui.UIComponent; +import com.ardor3d.extension.ui.UIFrame; +import com.ardor3d.extension.ui.UIFrame.FrameButtons; import com.ardor3d.extension.ui.UIHud; import com.ardor3d.extension.ui.UIMenuItem; +import com.ardor3d.extension.ui.UIPanel; import com.ardor3d.extension.ui.UIPieMenu; import com.ardor3d.extension.ui.UIPieMenuItem; import com.ardor3d.extension.ui.UIPopupMenu; +import com.ardor3d.extension.ui.UISlider; +import com.ardor3d.extension.ui.UITextField; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; +import com.ardor3d.extension.ui.layout.RowLayout; import com.ardor3d.extension.ui.util.Insets; import com.ardor3d.image.Texture; import com.ardor3d.math.ColorRGBA; @@ -50,6 +59,7 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { private static final String[] COLORS = new String[] { "Red", "White", "Blue", "Black" }; private static final String[] SPINS = new String[] { "None", "Around X", "Around Y", "Around Z" }; private static final String[] TEXS = new String[] { "None", "Logo", "Ball", "Clock" }; + private static final String[] SCALE = new String[] { "Scale..." }; UIHud hud; private Box box; @@ -121,6 +131,9 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { case "Texture": setTexture(src.getText()); return; + case "Scale": + showScaleDialog(); + return; } } @@ -143,6 +156,8 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { menu.addItem(new UIMenuItem("Set Texture...", null, texMenu)); AddMenuItems(texMenu, "Texture", false, TEXS); + AddMenuItems(menu, "Scale", false, SCALE); + menu.updateMinimumSizeFromContents(); menu.layout(); @@ -167,6 +182,8 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { menu.addItem(new UIPieMenuItem("Set Texture...", null, texMenu, 100)); AddMenuItems(texMenu, "Texture", true, TEXS); + AddMenuItems(menu, "Scale", true, SCALE); + menu.setCenterItem(new UIPieMenuItem("Cancel", null, true, null)); menu.updateMinimumSizeFromContents(); @@ -269,6 +286,35 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { box.updateWorldRenderStates(true); } + private void showScaleDialog() { + final UIFrame scaleDialog = new UIFrame("Set Scale...", EnumSet.of(FrameButtons.CLOSE)); + scaleDialog.setResizeable(false); + final UIPanel contentPanel = scaleDialog.getContentPanel(); + contentPanel.setLayout(new RowLayout(true, false, false)); + + final UISlider scaleSlider = new UISlider(Orientation.Horizontal, 1, 20, (int) (box.getScale().getX() * 10)); + scaleSlider.setMinimumContentWidth(200); + contentPanel.add(scaleSlider); + + final UITextField scaleTextField = new UITextField(); + scaleTextField.setEditable(false); + scaleTextField.setText("1.0"); + scaleTextField.setMinimumContentWidth(30); + contentPanel.add(scaleTextField); + + scaleSlider.addActionListener(new ActionListener() { + @Override + public void actionPerformed(final ActionEvent event) { + box.setScale(scaleSlider.getValue() / 10.0); + scaleTextField.setText(String.format("%.1f", box.getScale().getX())); + } + }); + + hud.add(scaleDialog); + scaleDialog.pack(235, 80); + scaleDialog.centerOn(hud); + } + @Override protected void updateLogicalLayer(final ReadOnlyTimer timer) { hud.getLogicalLayer().checkTriggers(timer.getTimePerFrame()); diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java index 1e15e65..cf0ffc5 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -109,7 +109,7 @@ import com.jogamp.opengl.util.GLBuffers; /** * JoglRenderer provides an implementation of the Renderer interface using the JOGL API. - * + * * @see com.ardor3d.renderer.Renderer */ public class JoglRenderer extends AbstractRenderer { @@ -856,7 +856,6 @@ public class JoglRenderer extends AbstractRenderer { enabledTextures |= (2 << i); } - @SuppressWarnings("null") final FloatBufferData textureBufferData = textureCoords.get(i); final FloatBuffer textureBuffer = textureBufferData.getBuffer(); @@ -1160,7 +1159,6 @@ public class JoglRenderer extends AbstractRenderer { checkAndSetTextureArrayUnit(i, gl, rendRecord, caps); // grab a vboID and make sure it exists and is up to date. - @SuppressWarnings("null") final FloatBufferData data = textureCoords.get(i); final int vboID = setupVBO(data, context); @@ -1338,7 +1336,6 @@ public class JoglRenderer extends AbstractRenderer { } } - @SuppressWarnings("null") private void initializeInterleavedVBO(final RenderContext context, final FloatBufferData interleaved, final FloatBufferData vertexCoords, final FloatBufferData normalCoords, final FloatBufferData colorCoords, final List textureCoords, final int bufferSize) { @@ -1879,7 +1876,7 @@ public class JoglRenderer extends AbstractRenderer { /** * Start a new display list. All further renderer commands that can be stored in a display list are part of this new * list until {@link #endDisplayList()} is called. - * + * * @return id of new display list */ @Override diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java index 69ea13f..051dc65 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java @@ -816,6 +816,20 @@ public abstract class UIComponent extends Node implements UIKeyHandler { */ public void detachedFromHud() {} + public void centerOn(final UIHud hud) { + final int centerX = hud.getWidth() / 2; + final int centerY = hud.getHeight() / 2; + + setHudXY(centerX - getLocalComponentWidth() / 2, centerY - getLocalComponentHeight() / 2); + } + + public void centerOn(final UIComponent comp) { + final int centerX = comp.getHudX() + comp.getLocalComponentWidth() / 2; + final int centerY = comp.getHudY() + comp.getLocalComponentHeight() / 2; + + setHudXY(centerX - getLocalComponentWidth() / 2, centerY - getLocalComponentHeight() / 2); + } + /** * @return current screen x coordinate of this component's origin (usually its lower left corner.) */ diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UISlider.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UISlider.java index 0cd086e..2fce752 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UISlider.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UISlider.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -43,7 +43,7 @@ public class UISlider extends UIContainer { /** * create a slider widget with a default range of [0,100]. Initial value is 50. - * + * * @param orientation * the orientation of the slider (Orientation.Horizontal or Orientation.Vertical) */ @@ -53,7 +53,7 @@ public class UISlider extends UIContainer { /** * create a slider widget with a default range of [minValue,maxOffset] and the given initialValue. - * + * * @param orientation * the orientation of the slider (Orientation.Horizontal or Orientation.Vertical) * @param minValue @@ -150,7 +150,7 @@ public class UISlider extends UIContainer { /** * Set the value on this slider - * + * * @param value * the new value. Clamps between min and max values. */ @@ -164,9 +164,10 @@ public class UISlider extends UIContainer { */ private void updateKnob() { if ((float) (_model.getMaxValue() - _model.getMinValue()) != 0) { - _knob.setPosition(_model.getCurrentValue() / (float) (_model.getMaxValue() - _model.getMinValue())); + _knob.setPosition((_model.getCurrentValue() - _model.getMinValue()) + / (float) (_model.getMaxValue() - _model.getMinValue())); } else { - _knob.setPosition(_model.getMinValue()); + _knob.setPosition(0); } } @@ -196,7 +197,7 @@ public class UISlider extends UIContainer { /** * Add the specified listener to this slider's list of listeners notified when it has changed. - * + * * @param listener * the listener to add */ @@ -206,7 +207,7 @@ public class UISlider extends UIContainer { /** * Remove a listener from this slider's list of listeners. - * + * * @param listener * the listener to remove * @return true if the listener was removed. @@ -220,7 +221,8 @@ public class UISlider extends UIContainer { */ void knobReleased() { if (_snapToValues) { - setValue(Math.round(_knob.getPosition() * (_model.getMaxValue() - _model.getMinValue()))); + setValue(Math.round(_knob.getPosition() * (_model.getMaxValue() - _model.getMinValue())) + + _model.getMinValue()); } } diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UISliderKnob.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UISliderKnob.java index 8790618..dfa8938 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UISliderKnob.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UISliderKnob.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -11,6 +11,7 @@ package com.ardor3d.extension.ui; import com.ardor3d.extension.ui.event.DragListener; +import com.ardor3d.extension.ui.model.SliderModel; import com.ardor3d.input.InputState; import com.ardor3d.input.MouseButton; import com.ardor3d.math.MathUtils; @@ -34,7 +35,7 @@ public class UISliderKnob extends UIContainer { /** * Construct a new knob for the given slider. - * + * * @param slider * the parent slider. */ @@ -66,7 +67,7 @@ public class UISliderKnob extends UIContainer { /** * Sets the current position of the knob handle - * + * * @param newPosition * the new position as a percent [0.0, 1.0] */ @@ -222,9 +223,9 @@ public class UISliderKnob extends UIContainer { setPosition(position); // set the value on the slider's model directly to avoid circular looping logic. - _parentSlider.getModel().setCurrentValue( - Math.round(getPosition() - * (_parentSlider.getModel().getMaxValue() - _parentSlider.getModel().getMinValue())), + final SliderModel model = _parentSlider.getModel(); + model.setCurrentValue( + Math.round(getPosition() * (model.getMaxValue() - model.getMinValue())) + model.getMinValue(), _parentSlider); } diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UITextField.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UITextField.java index 3a70e1f..26e6688 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UITextField.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UITextField.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -16,8 +16,8 @@ import java.util.List; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; import com.ardor3d.extension.ui.text.DefaultLatinTextFieldKeyHandler; -import com.ardor3d.extension.ui.text.UIKeyHandler; import com.ardor3d.extension.ui.text.TextSelection.SelectionState; +import com.ardor3d.extension.ui.text.UIKeyHandler; import com.ardor3d.input.InputState; import com.ardor3d.input.Key; import com.ardor3d.input.MouseButton; @@ -91,7 +91,7 @@ public class UITextField extends AbstractUITextEntryComponent { /** * Add the specified listener to this button's list of listeners notified when pressed. - * + * * @param listener */ public void addActionListener(final ActionListener listener) { @@ -100,7 +100,7 @@ public class UITextField extends AbstractUITextEntryComponent { /** * Remove the given listener from the notification list. - * + * * @param listener */ public boolean removeActionListener(final ActionListener listener) { @@ -108,7 +108,7 @@ public class UITextField extends AbstractUITextEntryComponent { } /** - * Removes all of this button's listeners from notification list. + * Removes all of this field's listeners from notification list. */ public void removeAllListeners() { _listeners.clear(); @@ -184,7 +184,7 @@ public class UITextField extends AbstractUITextEntryComponent { if (isEditable() && getCurrentState().equals(_writingState) && getCaret().isShowing()) { getCaret().draw(r, this, _uiText != null ? _uiText.getLineHeight(getCaretPosition()) : UIComponent.getDefaultFontSize(), x, - y); + y); } } @@ -206,12 +206,12 @@ public class UITextField extends AbstractUITextEntryComponent { @Override public void mouseEntered(final int mouseX, final int mouseY, final InputState state) { - // TODO: set cursor to text entry + // TODO: set cursor to text entry } @Override public void mouseDeparted(final int mouseX, final int mouseY, final InputState state) { - // TODO: set cursor to default + // TODO: set cursor to default } @Override -- cgit v1.2.3 From 3b324b3c4dde3f18c255c59817f14f12f6467dc7 Mon Sep 17 00:00:00 2001 From: Joshua Slack Date: Thu, 12 Oct 2017 16:32:49 -0500 Subject: Added ability to set a spacing between elements in RowLayout --- .../com/ardor3d/example/ui/SimpleUIExample.java | 4 ++-- .../com/ardor3d/extension/ui/layout/RowLayout.java | 28 +++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'ardor3d-examples') diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java index 8c756e5..59d8192 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -28,9 +28,9 @@ import com.ardor3d.extension.ui.UIRadioButton; import com.ardor3d.extension.ui.UIScrollPanel; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.UITabbedPane; +import com.ardor3d.extension.ui.UITabbedPane.TabPlacement; import com.ardor3d.extension.ui.UITextArea; import com.ardor3d.extension.ui.UITextField; -import com.ardor3d.extension.ui.UITabbedPane.TabPlacement; import com.ardor3d.extension.ui.backdrop.MultiImageBackdrop; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/RowLayout.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/RowLayout.java index 82fb762..a7fd43c 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/RowLayout.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/RowLayout.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -29,10 +29,11 @@ public class RowLayout extends UILayout { private final boolean _horizontal; private final boolean _expandsHorizontally; private final boolean _expandsVertically; + private int _spacing = 0; /** * Construct a new RowLayout - * + * * @param horizontal * true if we should lay out horizontally, false if vertically */ @@ -42,7 +43,7 @@ public class RowLayout extends UILayout { /** * Construct a new RowLayout - * + * * @param horizontal * true if we should lay out horizontally, false if vertically * @param expandsHorizontally @@ -74,7 +75,7 @@ public class RowLayout extends UILayout { } /** - * + * * @return true (the default) if vertical free space in the container should be divided up among the child * components. */ @@ -115,7 +116,8 @@ public class RowLayout extends UILayout { if (!comps.isEmpty()) { // Determine how much space we feel we need. - final int reqSpace = _horizontal ? getSumOfAllWidths(content) : getSumOfAllHeights(content); + final int reqSpace = _spacing * (comps.size() - 1) + + (_horizontal ? getSumOfAllWidths(content) : getSumOfAllHeights(content)); // How much extra space do we have? int freeSpace = (_horizontal ? container.getContentWidth() : container.getContentHeight()) - reqSpace; @@ -179,13 +181,13 @@ public class RowLayout extends UILayout { final Rectangle2 rect = comp.getRelativeComponentBounds(storeA); if (_horizontal) { - comp.setLocalXY(x - rect.getX(), Math.max(container.getContentHeight() / 2 - rect.getHeight() / 2 - - rect.getY(), 0)); - x += rect.getWidth(); + comp.setLocalXY(x - rect.getX(), + Math.max(container.getContentHeight() / 2 - rect.getHeight() / 2 - rect.getY(), 0)); + x += rect.getWidth() + _spacing; } else { comp.setLocalXY(Math.max(container.getContentWidth() / 2 - rect.getWidth() / 2 - rect.getX(), 0), y - rect.getY()); - y += rect.getHeight(); + y += rect.getHeight() + _spacing; } } } @@ -252,4 +254,12 @@ public class RowLayout extends UILayout { } return sum; } + + public int getSpacing() { + return _spacing; + } + + public void setSpacing(final int spacing) { + _spacing = spacing; + } } -- cgit v1.2.3 From fd6f4654f290521487dcc1cd9ac700e3b94ecd0e Mon Sep 17 00:00:00 2001 From: Joshua Slack Date: Wed, 18 Oct 2017 22:58:08 -0500 Subject: Cleanup of pack/layout/updateMinimum calls. Components can be packed now. Removed pack(int,int) - should use setMinimum on contents to dictate appropriate pack size. Can still use setContentSize if specific size needed. UIHud now requires a Canvas to construct, cleaning up the ambiguous use of Camera.getCurrent and making it easier to use a hud size. Cleaned up examples to use nicer flow. --- .../benchmark/ball/BubbleMarkUIExample.java | 61 ++++++++------- .../example/effect/NewDynamicSmokerExample.java | 11 ++- .../example/pipeline/AnimationCopyExample.java | 31 ++++---- .../example/pipeline/AnimationStateExample.java | 17 ++-- .../ardor3d/example/pipeline/ColladaExample.java | 13 ++-- .../example/renderer/GeneratedTexturesExample.java | 23 +++--- .../terrain/MountainShadowTerrainExample.java | 2 +- .../com/ardor3d/example/ui/InteractUIExample.java | 91 +++++++++------------- .../com/ardor3d/example/ui/PopOverUIExample.java | 21 ++--- .../com/ardor3d/example/ui/RotatingUIExample.java | 13 ++-- .../com/ardor3d/example/ui/SimpleUIExample.java | 9 +-- .../ardor3d/extension/ui/FloatingUIContainer.java | 39 ---------- .../java/com/ardor3d/extension/ui/UIComponent.java | 53 +++++++++---- .../java/com/ardor3d/extension/ui/UIFrame.java | 64 ++------------- .../main/java/com/ardor3d/extension/ui/UIHud.java | 27 +++---- .../com/ardor3d/extension/ui/UIProgressBar.java | 13 ++-- .../java/com/ardor3d/extension/ui/UIScrollBar.java | 9 +-- .../java/com/ardor3d/extension/ui/UITooltip.java | 9 +-- .../extension/ui/event/FrameResizeListener.java | 10 +-- .../java/com/ardor3d/extension/ui/skin/Skin.java | 6 +- .../extension/ui/skin/generic/GenericSkin.java | 12 +-- 21 files changed, 208 insertions(+), 326 deletions(-) delete mode 100644 ardor3d-ui/src/main/java/com/ardor3d/extension/ui/FloatingUIContainer.java (limited to 'ardor3d-examples') diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java index 8e8e2d4..5d05024 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/benchmark/ball/BubbleMarkUIExample.java @@ -3,13 +3,15 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ package com.ardor3d.example.benchmark.ball; +import java.util.concurrent.Callable; + import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.ui.UICheckBox; @@ -17,6 +19,7 @@ import com.ardor3d.extension.ui.UIContainer; import com.ardor3d.extension.ui.UIFrame; import com.ardor3d.extension.ui.UIHud; import com.ardor3d.extension.ui.UILabel; +import com.ardor3d.extension.ui.UIPanel; import com.ardor3d.extension.ui.UIRadioButton; import com.ardor3d.extension.ui.backdrop.SolidBackdrop; import com.ardor3d.extension.ui.event.ActionEvent; @@ -30,6 +33,7 @@ import com.ardor3d.image.Texture; import com.ardor3d.image.TextureStoreFormat; import com.ardor3d.math.ColorRGBA; import com.ardor3d.ui.text.BasicText; +import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.TextureManager; @@ -69,16 +73,15 @@ public class BubbleMarkUIExample extends ExampleBase { final int width = _canvas.getCanvasRenderer().getCamera().getWidth(); final int height = _canvas.getCanvasRenderer().getCamera().getHeight(); - hud = new UIHud(); + hud = new UIHud(_canvas); // Add Frame for balls _ballFrame = new UIFrame("Bubbles"); - _ballFrame.updateMinimumSizeFromContents(); - _ballFrame.pack(500, 300); - _ballFrame.layout(); + _ballFrame.getContentPanel().setMinimumContentSize(600, 300); _ballFrame.setResizeable(false); _ballFrame.setHudXY(5, 5); _ballFrame.setUseStandin(false); + _ballFrame.pack(); hud.add(_ballFrame); // Add background @@ -93,35 +96,39 @@ public class BubbleMarkUIExample extends ExampleBase { // Add fps display frameRateLabel = BasicText.createDefaultTextLabel("fpsLabel", ""); - frameRateLabel.setTranslation(5, _canvas.getCanvasRenderer().getCamera().getHeight() - 5 - - frameRateLabel.getHeight(), 0); + frameRateLabel.setTranslation(5, hud.getHeight() - 5 - frameRateLabel.getHeight(), 0); frameRateLabel.setTextColor(ColorRGBA.WHITE); frameRateLabel.getSceneHints().setOrthoOrder(-1); _root.attachChild(frameRateLabel); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud.setupInput(_physicalLayer, _logicalLayer); } private void buildConfigFrame(final int width, final int height) { _configFrame = new UIFrame("Config"); - _configFrame.updateMinimumSizeFromContents(); - _configFrame.pack(320, 240); + final UIPanel panel = _configFrame.getContentPanel(); + panel.setLayout(new AnchorLayout()); + panel.setMinimumContentSize(320, 240); _configFrame.setUseStandin(true); - _configFrame.setHudXY(width - _configFrame.getLocalComponentWidth() - 5, height - - _configFrame.getLocalComponentHeight() - 5); - - _configFrame.getContentPanel().setLayout(new AnchorLayout()); + _configFrame.setHudXY(width - _configFrame.getLocalComponentWidth() - 5, + height - _configFrame.getLocalComponentHeight() - 5); final UICheckBox vsync = new UICheckBox("Enable vsync"); - vsync.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, _configFrame.getContentPanel(), - Alignment.TOP_LEFT, 5, -5)); + vsync.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, panel, Alignment.TOP_LEFT, 5, -5)); vsync.setSelectable(true); vsync.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { - _canvas.setVSyncEnabled(vsync.isSelected()); + GameTaskQueueManager.getManager(_canvas.getCanvasRenderer().getRenderContext()).render( + new Callable() { + public Void call() throws Exception { + _canvas.setVSyncEnabled(vsync.isSelected()); + return null; + } + }); + } }); - _configFrame.getContentPanel().add(vsync); + panel.add(vsync); final UICheckBox collide = new UICheckBox("Enable ball-ball collision"); collide.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, vsync, Alignment.BOTTOM_LEFT, 0, -5)); @@ -132,11 +139,11 @@ public class BubbleMarkUIExample extends ExampleBase { skipBallCollide = !collide.isSelected(); } }); - _configFrame.getContentPanel().add(collide); + panel.add(collide); final UILabel ballsLabel = new UILabel("# of balls:"); ballsLabel.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, collide, Alignment.BOTTOM_LEFT, 0, -15)); - _configFrame.getContentPanel().add(ballsLabel); + panel.add(ballsLabel); final ButtonGroup ballsGroup = new ButtonGroup(); @@ -150,7 +157,7 @@ public class BubbleMarkUIExample extends ExampleBase { } }); balls16.setGroup(ballsGroup); - _configFrame.getContentPanel().add(balls16); + panel.add(balls16); final UIRadioButton balls32 = new UIRadioButton("32"); balls32.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, balls16, Alignment.BOTTOM_LEFT, 0, -5)); @@ -162,7 +169,7 @@ public class BubbleMarkUIExample extends ExampleBase { } }); balls32.setGroup(ballsGroup); - _configFrame.getContentPanel().add(balls32); + panel.add(balls32); final UIRadioButton balls64 = new UIRadioButton("64"); balls64.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, balls32, Alignment.BOTTOM_LEFT, 0, -5)); @@ -174,7 +181,7 @@ public class BubbleMarkUIExample extends ExampleBase { } }); balls64.setGroup(ballsGroup); - _configFrame.getContentPanel().add(balls64); + panel.add(balls64); final UIRadioButton balls128 = new UIRadioButton("128"); balls128.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, balls64, Alignment.BOTTOM_LEFT, 0, -5)); @@ -186,9 +193,9 @@ public class BubbleMarkUIExample extends ExampleBase { } }); balls128.setGroup(ballsGroup); - _configFrame.getContentPanel().add(balls128); + panel.add(balls128); - _configFrame.layout(); + _configFrame.pack(); } @Override @@ -209,8 +216,8 @@ public class BubbleMarkUIExample extends ExampleBase { // Add balls for (int i = 0; i < balls.length; i++) { - final BallComponent ballComp = new BallComponent("ball", tex, Ball.radius * 2, Ball.radius * 2, container - .getContentWidth(), container.getContentHeight()); + final BallComponent ballComp = new BallComponent("ball", tex, Ball.radius * 2, Ball.radius * 2, + container.getContentWidth(), container.getContentHeight()); container.add(ballComp); balls[i] = ballComp; } diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java index 739beba..c307b77 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/effect/NewDynamicSmokerExample.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -236,8 +236,8 @@ public class NewDynamicSmokerExample extends ExampleBase { private void addUI() { // setup hud - hud = new UIHud(); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud = new UIHud(_canvas); + hud.setupInput(_physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); final UIFrame frame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class)); @@ -307,9 +307,8 @@ public class NewDynamicSmokerExample extends ExampleBase { frame.setContentPanel(panel); frame.pack(); - final Camera cam = _canvas.getCanvasRenderer().getCamera(); - frame.setLocalXY(cam.getWidth() - frame.getLocalComponentWidth(), - cam.getHeight() - frame.getLocalComponentHeight()); + frame.setLocalXY(hud.getWidth() - frame.getLocalComponentWidth(), + hud.getHeight() - frame.getLocalComponentHeight()); hud.add(frame); } } diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java index 6ff67d7..7909261 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationCopyExample.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -145,24 +145,23 @@ public class AnimationCopyExample extends ExampleBase { } private void createHUD() { - hud = new UIHud(); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud = new UIHud(_canvas); + hud.setupInput(_physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); // Add fps display frameRateLabel = new UILabel("X"); - frameRateLabel.setHudXY(5, - _canvas.getCanvasRenderer().getCamera().getHeight() - 5 - frameRateLabel.getContentHeight()); + frameRateLabel.setHudXY(5, hud.getHeight() - 5 - frameRateLabel.getContentHeight()); frameRateLabel.setForegroundColor(ColorRGBA.WHITE); hud.add(frameRateLabel); final UIFrame optionsFrame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class)); - final UIPanel basePanel = optionsFrame.getContentPanel(); - basePanel.setLayout(new AnchorLayout()); + final UIPanel panel = optionsFrame.getContentPanel(); + panel.setLayout(new AnchorLayout()); runWalkButton = new UIButton("Start running..."); - runWalkButton.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, basePanel, Alignment.TOP_LEFT, 5, -5)); + runWalkButton.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, panel, Alignment.TOP_LEFT, 5, -5)); runWalkButton.addActionListener(new ActionListener() { boolean walk = true; @@ -180,7 +179,7 @@ public class AnimationCopyExample extends ExampleBase { } } }); - basePanel.add(runWalkButton); + panel.add(runWalkButton); punchButton = new UIButton("PUNCH!"); punchButton @@ -191,7 +190,7 @@ public class AnimationCopyExample extends ExampleBase { punchButton.setEnabled(false); } }); - basePanel.add(punchButton); + panel.add(punchButton); headCheck = new UICheckBox("Procedurally turn head"); headCheck.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, punchButton, Alignment.BOTTOM_LEFT, 0, -5)); @@ -202,7 +201,7 @@ public class AnimationCopyExample extends ExampleBase { manager.getValuesStore().put("head_blend", headCheck.isSelected() ? 1.0 : 0.0); } }); - basePanel.add(headCheck); + panel.add(headCheck); final UICheckBox gpuSkinningCheck = new UICheckBox("Use GPU skinning"); gpuSkinningCheck @@ -228,7 +227,7 @@ public class AnimationCopyExample extends ExampleBase { }, true); } }); - basePanel.add(gpuSkinningCheck); + panel.add(gpuSkinningCheck); final UICheckBox vboCheck = new UICheckBox("Use VBO"); vboCheck.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, gpuSkinningCheck, Alignment.BOTTOM_LEFT, 0, -5)); @@ -239,7 +238,7 @@ public class AnimationCopyExample extends ExampleBase { gpuShader.setUseAttributeVBO(vboCheck.isSelected()); } }); - basePanel.add(vboCheck); + panel.add(vboCheck); final UICheckBox skeletonCheck = new UICheckBox("Show skeleton"); final UICheckBox boneLabelCheck = new UICheckBox("Show joint labels"); @@ -252,7 +251,7 @@ public class AnimationCopyExample extends ExampleBase { boneLabelCheck.setEnabled(showSkeleton); } }); - basePanel.add(skeletonCheck); + panel.add(skeletonCheck); boneLabelCheck.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, skeletonCheck, Alignment.BOTTOM_LEFT, 0, -5)); @@ -264,10 +263,8 @@ public class AnimationCopyExample extends ExampleBase { showJointLabels = boneLabelCheck.isSelected(); } }); - basePanel.add(boneLabelCheck); + panel.add(boneLabelCheck); - optionsFrame.updateMinimumSizeFromContents(); - optionsFrame.layout(); optionsFrame.pack(); optionsFrame.setUseStandin(true); diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java index 44b3407..8a87497 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/AnimationStateExample.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -140,14 +140,13 @@ public class AnimationStateExample extends ExampleBase { } private void createHUD() { - hud = new UIHud(); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud = new UIHud(_canvas); + hud.setupInput(_physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); // Add fps display frameRateLabel = new UILabel("X"); - frameRateLabel.setHudXY(5, - _canvas.getCanvasRenderer().getCamera().getHeight() - 5 - frameRateLabel.getContentHeight()); + frameRateLabel.setHudXY(5, hud.getHeight() - 5 - frameRateLabel.getContentHeight()); frameRateLabel.setForegroundColor(ColorRGBA.WHITE); hud.add(frameRateLabel); @@ -179,7 +178,7 @@ public class AnimationStateExample extends ExampleBase { punchButton = new UIButton("PUNCH!"); punchButton - .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, runWalkButton, Alignment.BOTTOM_LEFT, 0, -5)); + .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, runWalkButton, Alignment.BOTTOM_LEFT, 0, -5)); punchButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { manager.findAnimationLayer("punch").setCurrentState("punch_right", true); @@ -206,7 +205,7 @@ public class AnimationStateExample extends ExampleBase { stopButton = new UIButton("Stop"); stopButton - .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, playPauseButton, Alignment.BOTTOM_LEFT, 0, -5)); + .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, playPauseButton, Alignment.BOTTOM_LEFT, 0, -5)); stopButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { manager.stop(); @@ -217,7 +216,7 @@ public class AnimationStateExample extends ExampleBase { final UICheckBox resetAnimCheck = new UICheckBox("Reset Animation On Stop"); resetAnimCheck - .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, stopButton, Alignment.BOTTOM_LEFT, 0, -5)); + .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, stopButton, Alignment.BOTTOM_LEFT, 0, -5)); resetAnimCheck.setSelected(false); resetAnimCheck.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { @@ -289,8 +288,6 @@ public class AnimationStateExample extends ExampleBase { }); basePanel.add(boneLabelCheck); - optionsFrame.updateMinimumSizeFromContents(); - optionsFrame.layout(); optionsFrame.pack(); optionsFrame.setUseStandin(true); diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java index f9c93d2..750a727 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ColladaExample.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -132,14 +132,13 @@ public class ColladaExample extends ExampleBase { _root.attachChild(t1); _root.getSceneHints().setCullHint(CullHint.Never); - hud = new UIHud(); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud = new UIHud(_canvas); + hud.setupInput(_physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); // Add fps display frameRateLabel = new UILabel("X"); - frameRateLabel.setHudXY(5, - _canvas.getCanvasRenderer().getCamera().getHeight() - 5 - frameRateLabel.getContentHeight()); + frameRateLabel.setHudXY(5, hud.getHeight() - 5 - frameRateLabel.getContentHeight()); frameRateLabel.setForegroundColor(ColorRGBA.WHITE); hud.add(frameRateLabel); @@ -166,7 +165,7 @@ public class ColladaExample extends ExampleBase { final UICheckBox skinCheck = new UICheckBox("Show skin mesh"); skinCheck - .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, loadSceneButton, Alignment.BOTTOM_LEFT, 0, -5)); + .setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, loadSceneButton, Alignment.BOTTOM_LEFT, 0, -5)); skinCheck.setSelected(true); skinCheck.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { @@ -198,8 +197,6 @@ public class ColladaExample extends ExampleBase { }); basePanel.add(boneLabelCheck); - optionsFrame.updateMinimumSizeFromContents(); - optionsFrame.layout(); optionsFrame.pack(); optionsFrame.setUseStandin(true); diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java index 4fdc002..74c68b3 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/GeneratedTexturesExample.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -144,8 +144,8 @@ public class GeneratedTexturesExample extends ExampleBase { padding = wside / 10; // Set up hud - hud = new UIHud(); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud = new UIHud(_canvas); + hud.setupInput(_physicalLayer, _logicalLayer); // Set up the frames for (int i = 0; i < views.length; i++) { @@ -246,8 +246,7 @@ public class GeneratedTexturesExample extends ExampleBase { zoomed = null; } - final int endY = 0, endX = (_canvas.getCanvasRenderer().getCamera().getWidth() - _canvas.getCanvasRenderer() - .getCamera().getHeight()) / 2; + final int endY = 0, endX = (hud.getWidth() - hud.getHeight()) / 2; // add an animator to do the zoom uiPanel.addController(new SpatialController() { @@ -270,12 +269,12 @@ public class GeneratedTexturesExample extends ExampleBase { // use an scurve to smoothly zoom final float sCurve = MathUtils.scurve5(ratio); - final float size = sCurve * (_canvas.getCanvasRenderer().getCamera().getHeight() - hside) + hside; + final float size = sCurve * (hud.getHeight() - hside) + hside; parent.setLocalComponentSize((int) (size * hside / wside), (int) size); // use an scurve to smoothly shift origin - parent.setHudXY(Math.round(MathUtils.lerp(sCurve, originX, endX)), Math.round(MathUtils.lerp(sCurve, - originY, endY))); + parent.setHudXY(Math.round(MathUtils.lerp(sCurve, originX, endX)), + Math.round(MathUtils.lerp(sCurve, originY, endY))); parent.layout(); } @@ -414,8 +413,8 @@ public class GeneratedTexturesExample extends ExampleBase { final Function3D combinedWood = Functions.add(baseWood, woodGrain); final Function3D perturbedWood = new TurbulenceFunction3D(combinedWood, 1 / 256.0, 4, 4.0); final Function3D translatedWood = Functions.translateInput(perturbedWood, 0, 0, 1.5); - final Function3D rotatedWood = Functions.rotateInput(translatedWood, new Matrix3().fromAngles( - MathUtils.DEG_TO_RAD * 6, 0, 0)); + final Function3D rotatedWood = Functions.rotateInput(translatedWood, + new Matrix3().fromAngles(MathUtils.DEG_TO_RAD * 6, 0, 0)); final Function3D finalWood = new TurbulenceFunction3D(rotatedWood, 1 / 512.0, 2, 2.0); final ReadOnlyColorRGBA[] woodColors = new ReadOnlyColorRGBA[256]; @@ -442,8 +441,8 @@ public class GeneratedTexturesExample extends ExampleBase { // Build up our function final Function3D primaryJade = new RidgeFunction3D(Functions.simplexNoise(), 6, 2.0, 2.207); final Function3D baseSecondaryJade = new CylinderFunction3D(2); - final Function3D rotatedBaseSecondaryJade = Functions.rotateInput(baseSecondaryJade, new Matrix3().fromAngles( - 0, MathUtils.DEG_TO_RAD * 65, MathUtils.DEG_TO_RAD * 85)); + final Function3D rotatedBaseSecondaryJade = Functions.rotateInput(baseSecondaryJade, + new Matrix3().fromAngles(0, MathUtils.DEG_TO_RAD * 65, MathUtils.DEG_TO_RAD * 85)); final Function3D perturbedBaseSecondaryJade = new TurbulenceFunction3D(rotatedBaseSecondaryJade, 1.0 / 4.0, 4, 4.0); final Function3D secondaryJade = Functions.scaleBias(perturbedBaseSecondaryJade, .25, 0); diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java index d25912d..6d334be 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/terrain/MountainShadowTerrainExample.java @@ -1 +1 @@ -/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ package com.ardor3d.example.terrain; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.EnumSet; import java.util.concurrent.Callable; import javax.imageio.ImageIO; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.model.collada.jdom.ColladaImporter; import com.ardor3d.extension.model.collada.jdom.data.ColladaStorage; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass.Filter; import com.ardor3d.extension.shadow.map.ShadowCasterManager; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.UrlInputSupplier; import com.ardor3d.extension.terrain.heightmap.ImageHeightMap; import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider; import com.ardor3d.extension.ui.Orientation; import com.ardor3d.extension.ui.UIButton; import com.ardor3d.extension.ui.UIFrame; import com.ardor3d.extension.ui.UIFrame.FrameButtons; import com.ardor3d.extension.ui.UIHud; import com.ardor3d.extension.ui.UILabel; import com.ardor3d.extension.ui.UIPanel; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; import com.ardor3d.extension.ui.layout.RowLayout; import com.ardor3d.extension.ui.text.StyleConstants; import com.ardor3d.extension.ui.util.Insets; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.image.Image; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture2D; import com.ardor3d.image.util.awt.AWTImageLoader; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.MathUtils; import com.ardor3d.math.Quaternion; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.renderer.state.RenderState.StateType; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.hint.TextureCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.util.GameTaskQueue; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.geom.Debugger; import com.ardor3d.util.resource.ResourceLocatorTool; /** * Example showing the Geometry Clipmap Terrain system with 'MegaTextures' where the terrain data is provided from a * float array populated from a heightmap generated from an Image. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.ImageMapTerrainExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_ImageMapTerrainExample.jpg", // maxHeapMemory = 128) public class MountainShadowTerrainExample extends ExampleBase { private final float farPlane = 8000.0f; /** Quads used for debug showing shadowmaps. */ private Quad _orthoQuad[]; private Terrain terrain; private final Node terrainNode = new Node("terrain"); private boolean groundCamera = false; private Camera terrainCamera; /** Text fields used to present info about the example. */ private final UILabel _exampleInfo[] = new UILabel[2]; /** Pssm shadow map pass. */ private ParallelSplitShadowMapPass _pssmPass; private DirectionalLight light; private double lightTime; private boolean moveLight = false; private UIHud hud; public static void main(final String[] args) { ExampleBase._minDepthBits = 24; ExampleBase.start(MountainShadowTerrainExample.class); } @Override protected void renderExample(final Renderer renderer) { // Lazy init since it needs the renderer... if (!_pssmPass.isInitialised()) { _pssmPass.init(renderer); _pssmPass.setPssmShader(terrain.getGeometryClipmapShader()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { terrain.getClipTextureState().setTexture(_pssmPass.getShadowMapTexture(i), i + 1); } for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { terrain.getGeometryClipmapShader().setUniform("shadowMap" + i, i + 1); } } terrain.getGeometryClipmapShader().setUniform("lightDir", light.getDirection()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { TextureState screen = (TextureState) _orthoQuad[i].getLocalRenderState(StateType.Texture); Texture copy; if (screen == null) { screen = new TextureState(); _orthoQuad[i].setRenderState(screen); copy = new Texture2D(); screen.setTexture(copy); _orthoQuad[i].updateGeometricState(0.0); } else { copy = screen.getTexture(); } copy.setTextureKey(_pssmPass.getShadowMapTexture(i).getTextureKey()); } // XXX: Use a rougher LOD for shadows - tweak? terrain.setMinVisibleLevel(4); // Update shadowmaps - this will update our terrain camera to light pos _pssmPass.updateShadowMaps(renderer); // XXX: reset LOD for drawing from view camera terrain.setMinVisibleLevel(0); // Render scene and terrain with shadows terrainNode.onDraw(renderer); _root.onDraw(renderer); // Render overlay shadows for all objects except the terrain renderer.renderBuckets(); _pssmPass.renderShadowedScene(renderer); renderer.renderBuckets(); // draw ui renderer.draw(hud); } private double counter = 0; private int frames = 0; @Override protected void updateExample(final ReadOnlyTimer timer) { counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } final Camera camera = _canvas.getCanvasRenderer().getCamera(); // Make sure camera is above terrain final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()); if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getY() < height + 3)) { camera.setLocation(new Vector3(camera.getLocation().getX(), height + 3, camera.getLocation().getZ())); terrainCamera.set(camera); } else { terrainCamera.set(_canvas.getCanvasRenderer().getCamera()); } // move terrain to view pos terrainNode.updateGeometricState(timer.getTimePerFrame()); hud.updateGeometricState(timer.getTimePerFrame()); if (moveLight) { lightTime += timer.getTimePerFrame(); light.setDirection(new Vector3(Math.sin(lightTime), -.8, Math.cos(lightTime)).normalizeLocal()); } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain Example"); final Camera canvasCamera = _canvas.getCanvasRenderer().getCamera(); canvasCamera.setLocation(new Vector3(2176, 790, 688)); canvasCamera.lookAt(new Vector3(canvasCamera.getLocation()).addLocal(-0.87105768019686, -0.4349655341112313, 0.22817427967541867), Vector3.UNIT_Y); canvasCamera.setFrustumPerspective(45.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer(); final RenderContext renderContext = canvasRenderer.getRenderContext(); final Renderer renderer = canvasRenderer.getRenderer(); GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable() { @Override public Void call() throws Exception { renderer.setBackgroundColor(ColorRGBA.BLUE); return null; } }); _controlHandle.setMoveSpeed(400); setupDefaultStates(); addRover(); addUI(); // Initialize PSSM shadows _pssmPass = new ParallelSplitShadowMapPass(light, 2048, 4); _pssmPass.setFiltering(Filter.None); _pssmPass.setRenderShadowedScene(false); _pssmPass.setKeepMainShader(true); // _pssmPass.setMinimumLightDistance(500); // XXX: Tune this _pssmPass.setUseSceneTexturing(false); _pssmPass.setUseObjectCullFace(false); _pssmPass.getShadowOffsetState().setFactor(1.1f); _pssmPass.getShadowOffsetState().setUnits(4.0f); // _pssmPass.setDrawDebug(true); // TODO: backside lock test final Quad floor = new Quad("floor", 2048, 2048); floor.updateModelBound(); floor.setRotation(new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_X)); floor.setTranslation(1024, 0, 1024); terrainNode.attachChild(floor); _pssmPass.addBoundsReceiver(terrainNode); // Add objects that will get shadowed through overlay render _pssmPass.add(_root); // Add our occluders that will produce shadows ShadowCasterManager.INSTANCE.addSpatial(terrainNode); ShadowCasterManager.INSTANCE.addSpatial(_root); final int quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10; _orthoQuad = new Quad[ParallelSplitShadowMapPass._MAX_SPLITS]; for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { _orthoQuad[i] = new Quad("OrthoQuad", quadSize, quadSize); _orthoQuad[i].setTranslation(new Vector3(quadSize / 2 + 5 + (quadSize + 5) * i, quadSize / 2 + 5, 1)); _orthoQuad[i].setScale(1, -1, 1); _orthoQuad[i].getSceneHints().setRenderBucketType(RenderBucketType.Ortho); _orthoQuad[i].getSceneHints().setLightCombineMode(LightCombineMode.Off); _orthoQuad[i].getSceneHints().setTextureCombineMode(TextureCombineMode.Replace); _orthoQuad[i].getSceneHints().setCullHint(CullHint.Never); hud.attachChild(_orthoQuad[i]); } try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); // IMAGE LOADING AND CONVERSION TO HEIGHTMAP DONE HERE final BufferedImage heightmap = ImageIO.read(ResourceLocatorTool.getClassPathResource( MountainShadowTerrainExample.class, "com/ardor3d/example/media/images/heightmap.jpg")); final Image ardorImage = AWTImageLoader.makeArdor3dImage(heightmap, false); final float[] heightMap = ImageHeightMap.generateHeightMap(ardorImage, 0.05f, .33f); // END OF IMAGE CONVERSION final int SIZE = ardorImage.getWidth(); final ArrayTerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(5, 2048, 5), true); terrainDataProvider.setHeightMax(0.34f); final TerrainBuilder builder = new TerrainBuilder(terrainDataProvider, terrainCamera) .setShowDebugPanels(true); terrain = builder.build(); terrain.setPixelShader(new UrlInputSupplier(ResourceLocatorTool.getClassPathResource( ShadowedTerrainExample.class, "com/ardor3d/extension/terrain/shadowedGeometryClipmapShader_normalMap.frag"))); terrain.reloadShader(); terrain.getGeometryClipmapShader().setUniform("normalMap", 5); terrainNode.attachChild(terrain); terrain.setCullingEnabled(false); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); } final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() / 2; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = new UILabel("Text"); _exampleInfo[i].setForegroundColor(ColorRGBA.WHITE, true); _exampleInfo[i].addFontStyle(StyleConstants.KEY_SIZE, 16); _exampleInfo[i].addFontStyle(StyleConstants.KEY_BOLD, Boolean.TRUE); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); hud.add(_exampleInfo[i]); } updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FOUR), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(1000); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); } private void addRover() { try { final ColladaStorage storage = new ColladaImporter().load("collada/sketchup/NASA Mars Rover.dae"); final Node rover = storage.getScene(); rover.setTranslation(440, 102, 160.1); rover.setScale(3); rover.setRotation(new Quaternion().fromAngleAxis(-MathUtils.HALF_PI, Vector3.UNIT_X)); _root.attachChild(rover); } catch (final IOException ex) { ex.printStackTrace(); } } private void setupDefaultStates() { terrainNode.setRenderState(_lightState); terrainNode.setRenderState(_wireframeState); terrainNode.setRenderState(new ZBufferState()); _lightState.detachAll(); light = new DirectionalLight(); light.setEnabled(true); light.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); light.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); light.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); light.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(light); _lightState.setEnabled(true); final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); terrainNode.setRenderState(fs); } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("[1/2/3/4] Moving speed: " + _controlHandle.getMoveSpeed() * 3.6 + " km/h"); _exampleInfo[1].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); } @Override protected void updateLogicalLayer(final ReadOnlyTimer timer) { hud.getLogicalLayer().checkTriggers(timer.getTimePerFrame()); } @Override protected void renderDebug(final Renderer renderer) { super.renderDebug(renderer); if (_showBounds) { Debugger.drawBounds(terrainNode, renderer, true); } } private void addUI() { // setup hud hud = new UIHud(); hud.setupInput(_canvas, _physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); final UIFrame frame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class)); frame.setResizeable(false); final UILabel distLabel = new UILabel("Max Shadow Distance: 1500"); final UISlider distSlider = new UISlider(Orientation.Horizontal, 0, 2000, 1500); distSlider.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setMaxShadowDistance(distSlider.getValue()); distLabel.setText("Max Shadow Distance: " + distSlider.getValue()); } }); final UIButton updateCamera = new UIButton("Update Shadow Camera"); updateCamera.setSelectable(true); updateCamera.setSelected(true); updateCamera.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setUpdateMainCamera(updateCamera.isSelected()); updateText(); } }); final UIButton rotateLight = new UIButton("Rotate Light"); rotateLight.setSelectable(true); rotateLight.setSelected(false); rotateLight.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { moveLight = rotateLight.isSelected(); updateText(); } }); final UIPanel panel = new UIPanel(new RowLayout(false, true, false)); panel.setPadding(new Insets(10, 20, 10, 20)); panel.add(distLabel); panel.add(distSlider); panel.add(updateCamera); panel.add(rotateLight); frame.setContentPanel(panel); frame.pack(); final Camera cam = _canvas.getCanvasRenderer().getCamera(); frame.setLocalXY(cam.getWidth() - frame.getLocalComponentWidth(), cam.getHeight() - frame.getLocalComponentHeight()); hud.add(frame); } } \ No newline at end of file +/** * Copyright (c) 2008-2012 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ package com.ardor3d.example.terrain; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.EnumSet; import java.util.concurrent.Callable; import javax.imageio.ImageIO; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.extension.model.collada.jdom.ColladaImporter; import com.ardor3d.extension.model.collada.jdom.data.ColladaStorage; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass; import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass.Filter; import com.ardor3d.extension.shadow.map.ShadowCasterManager; import com.ardor3d.extension.terrain.client.Terrain; import com.ardor3d.extension.terrain.client.TerrainBuilder; import com.ardor3d.extension.terrain.client.UrlInputSupplier; import com.ardor3d.extension.terrain.heightmap.ImageHeightMap; import com.ardor3d.extension.terrain.providers.array.ArrayTerrainDataProvider; import com.ardor3d.extension.ui.Orientation; import com.ardor3d.extension.ui.UIButton; import com.ardor3d.extension.ui.UIFrame; import com.ardor3d.extension.ui.UIFrame.FrameButtons; import com.ardor3d.extension.ui.UIHud; import com.ardor3d.extension.ui.UILabel; import com.ardor3d.extension.ui.UIPanel; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; import com.ardor3d.extension.ui.layout.RowLayout; import com.ardor3d.extension.ui.text.StyleConstants; import com.ardor3d.extension.ui.util.Insets; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; import com.ardor3d.image.Image; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture2D; import com.ardor3d.image.util.awt.AWTImageLoader; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.light.DirectionalLight; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.MathUtils; import com.ardor3d.math.Quaternion; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.FogState; import com.ardor3d.renderer.state.FogState.DensityFunction; import com.ardor3d.renderer.state.RenderState.StateType; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.hint.TextureCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.util.GameTaskQueue; import com.ardor3d.util.GameTaskQueueManager; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.geom.Debugger; import com.ardor3d.util.resource.ResourceLocatorTool; /** * Example showing the Geometry Clipmap Terrain system with 'MegaTextures' where the terrain data is provided from a * float array populated from a heightmap generated from an Image. Requires GLSL support. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.terrain.ImageMapTerrainExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/terrain_ImageMapTerrainExample.jpg", // maxHeapMemory = 128) public class MountainShadowTerrainExample extends ExampleBase { private final float farPlane = 8000.0f; /** Quads used for debug showing shadowmaps. */ private Quad _orthoQuad[]; private Terrain terrain; private final Node terrainNode = new Node("terrain"); private boolean groundCamera = false; private Camera terrainCamera; /** Text fields used to present info about the example. */ private final UILabel _exampleInfo[] = new UILabel[2]; /** Pssm shadow map pass. */ private ParallelSplitShadowMapPass _pssmPass; private DirectionalLight light; private double lightTime; private boolean moveLight = false; private UIHud hud; public static void main(final String[] args) { ExampleBase._minDepthBits = 24; ExampleBase.start(MountainShadowTerrainExample.class); } @Override protected void renderExample(final Renderer renderer) { // Lazy init since it needs the renderer... if (!_pssmPass.isInitialised()) { _pssmPass.init(renderer); _pssmPass.setPssmShader(terrain.getGeometryClipmapShader()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { terrain.getClipTextureState().setTexture(_pssmPass.getShadowMapTexture(i), i + 1); } for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { terrain.getGeometryClipmapShader().setUniform("shadowMap" + i, i + 1); } } terrain.getGeometryClipmapShader().setUniform("lightDir", light.getDirection()); for (int i = 0; i < _pssmPass.getNumOfSplits(); i++) { TextureState screen = (TextureState) _orthoQuad[i].getLocalRenderState(StateType.Texture); Texture copy; if (screen == null) { screen = new TextureState(); _orthoQuad[i].setRenderState(screen); copy = new Texture2D(); screen.setTexture(copy); _orthoQuad[i].updateGeometricState(0.0); } else { copy = screen.getTexture(); } copy.setTextureKey(_pssmPass.getShadowMapTexture(i).getTextureKey()); } // XXX: Use a rougher LOD for shadows - tweak? terrain.setMinVisibleLevel(4); // Update shadowmaps - this will update our terrain camera to light pos _pssmPass.updateShadowMaps(renderer); // XXX: reset LOD for drawing from view camera terrain.setMinVisibleLevel(0); // Render scene and terrain with shadows terrainNode.onDraw(renderer); _root.onDraw(renderer); // Render overlay shadows for all objects except the terrain renderer.renderBuckets(); _pssmPass.renderShadowedScene(renderer); renderer.renderBuckets(); // draw ui renderer.draw(hud); } private double counter = 0; private int frames = 0; @Override protected void updateExample(final ReadOnlyTimer timer) { counter += timer.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } final Camera camera = _canvas.getCanvasRenderer().getCamera(); // Make sure camera is above terrain final double height = terrain.getHeightAt(camera.getLocation().getX(), camera.getLocation().getZ()); if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getY() < height + 3)) { camera.setLocation(new Vector3(camera.getLocation().getX(), height + 3, camera.getLocation().getZ())); terrainCamera.set(camera); } else { terrainCamera.set(_canvas.getCanvasRenderer().getCamera()); } // move terrain to view pos terrainNode.updateGeometricState(timer.getTimePerFrame()); hud.updateGeometricState(timer.getTimePerFrame()); if (moveLight) { lightTime += timer.getTimePerFrame(); light.setDirection(new Vector3(Math.sin(lightTime), -.8, Math.cos(lightTime)).normalizeLocal()); } } /** * Initialize pssm pass and scene. */ @Override protected void initExample() { // Setup main camera. _canvas.setTitle("Terrain Example"); final Camera canvasCamera = _canvas.getCanvasRenderer().getCamera(); canvasCamera.setLocation(new Vector3(2176, 790, 688)); canvasCamera.lookAt(new Vector3(canvasCamera.getLocation()).addLocal(-0.87105768019686, -0.4349655341112313, 0.22817427967541867), Vector3.UNIT_Y); canvasCamera.setFrustumPerspective(45.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); final CanvasRenderer canvasRenderer = _canvas.getCanvasRenderer(); final RenderContext renderContext = canvasRenderer.getRenderContext(); final Renderer renderer = canvasRenderer.getRenderer(); GameTaskQueueManager.getManager(renderContext).getQueue(GameTaskQueue.RENDER).enqueue(new Callable() { @Override public Void call() throws Exception { renderer.setBackgroundColor(ColorRGBA.BLUE); return null; } }); _controlHandle.setMoveSpeed(400); setupDefaultStates(); addRover(); addUI(); // Initialize PSSM shadows _pssmPass = new ParallelSplitShadowMapPass(light, 2048, 4); _pssmPass.setFiltering(Filter.None); _pssmPass.setRenderShadowedScene(false); _pssmPass.setKeepMainShader(true); // _pssmPass.setMinimumLightDistance(500); // XXX: Tune this _pssmPass.setUseSceneTexturing(false); _pssmPass.setUseObjectCullFace(false); _pssmPass.getShadowOffsetState().setFactor(1.1f); _pssmPass.getShadowOffsetState().setUnits(4.0f); // _pssmPass.setDrawDebug(true); // TODO: backside lock test final Quad floor = new Quad("floor", 2048, 2048); floor.updateModelBound(); floor.setRotation(new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_X)); floor.setTranslation(1024, 0, 1024); terrainNode.attachChild(floor); _pssmPass.addBoundsReceiver(terrainNode); // Add objects that will get shadowed through overlay render _pssmPass.add(_root); // Add our occluders that will produce shadows ShadowCasterManager.INSTANCE.addSpatial(terrainNode); ShadowCasterManager.INSTANCE.addSpatial(_root); final int quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10; _orthoQuad = new Quad[ParallelSplitShadowMapPass._MAX_SPLITS]; for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) { _orthoQuad[i] = new Quad("OrthoQuad", quadSize, quadSize); _orthoQuad[i].setTranslation(new Vector3(quadSize / 2 + 5 + (quadSize + 5) * i, quadSize / 2 + 5, 1)); _orthoQuad[i].setScale(1, -1, 1); _orthoQuad[i].getSceneHints().setRenderBucketType(RenderBucketType.Ortho); _orthoQuad[i].getSceneHints().setLightCombineMode(LightCombineMode.Off); _orthoQuad[i].getSceneHints().setTextureCombineMode(TextureCombineMode.Replace); _orthoQuad[i].getSceneHints().setCullHint(CullHint.Never); hud.attachChild(_orthoQuad[i]); } try { // Keep a separate camera to be able to freeze terrain update final Camera camera = _canvas.getCanvasRenderer().getCamera(); terrainCamera = new Camera(camera); // IMAGE LOADING AND CONVERSION TO HEIGHTMAP DONE HERE final BufferedImage heightmap = ImageIO.read(ResourceLocatorTool.getClassPathResource( MountainShadowTerrainExample.class, "com/ardor3d/example/media/images/heightmap.jpg")); final Image ardorImage = AWTImageLoader.makeArdor3dImage(heightmap, false); final float[] heightMap = ImageHeightMap.generateHeightMap(ardorImage, 0.05f, .33f); // END OF IMAGE CONVERSION final int SIZE = ardorImage.getWidth(); final ArrayTerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(5, 2048, 5), true); terrainDataProvider.setHeightMax(0.34f); final TerrainBuilder builder = new TerrainBuilder(terrainDataProvider, terrainCamera) .setShowDebugPanels(true); terrain = builder.build(); terrain.setPixelShader(new UrlInputSupplier(ResourceLocatorTool.getClassPathResource( ShadowedTerrainExample.class, "com/ardor3d/extension/terrain/shadowedGeometryClipmapShader_normalMap.frag"))); terrain.reloadShader(); terrain.getGeometryClipmapShader().setUniform("normalMap", 5); terrainNode.attachChild(terrain); terrain.setCullingEnabled(false); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); } final double infoStartY = _canvas.getCanvasRenderer().getCamera().getHeight() / 2; for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = new UILabel("Text"); _exampleInfo[i].setForegroundColor(ColorRGBA.WHITE, true); _exampleInfo[i].addFontStyle(StyleConstants.KEY_SIZE, 16); _exampleInfo[i].addFontStyle(StyleConstants.KEY_BOLD, Boolean.TRUE); _exampleInfo[i].setTranslation(new Vector3(10, infoStartY - i * 20, 0)); hud.add(_exampleInfo[i]); } updateText(); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ONE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(5); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.TWO), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(50); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.THREE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(400); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.FOUR), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { _controlHandle.setMoveSpeed(1000); updateText(); } })); _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() { @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { groundCamera = !groundCamera; updateText(); } })); } private void addRover() { try { final ColladaStorage storage = new ColladaImporter().load("collada/sketchup/NASA Mars Rover.dae"); final Node rover = storage.getScene(); rover.setTranslation(440, 102, 160.1); rover.setScale(3); rover.setRotation(new Quaternion().fromAngleAxis(-MathUtils.HALF_PI, Vector3.UNIT_X)); _root.attachChild(rover); } catch (final IOException ex) { ex.printStackTrace(); } } private void setupDefaultStates() { terrainNode.setRenderState(_lightState); terrainNode.setRenderState(_wireframeState); terrainNode.setRenderState(new ZBufferState()); _lightState.detachAll(); light = new DirectionalLight(); light.setEnabled(true); light.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); light.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); light.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); light.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); _lightState.attach(light); _lightState.setEnabled(true); final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); terrainNode.setRenderState(fs); } /** * Update text information. */ private void updateText() { _exampleInfo[0].setText("[1/2/3/4] Moving speed: " + _controlHandle.getMoveSpeed() * 3.6 + " km/h"); _exampleInfo[1].setText("[SPACE] Toggle fly/walk: " + (groundCamera ? "walk" : "fly")); } @Override protected void updateLogicalLayer(final ReadOnlyTimer timer) { hud.getLogicalLayer().checkTriggers(timer.getTimePerFrame()); } @Override protected void renderDebug(final Renderer renderer) { super.renderDebug(renderer); if (_showBounds) { Debugger.drawBounds(terrainNode, renderer, true); } } private void addUI() { // setup hud hud = new UIHud(_canvas); hud.setupInput(_physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); final UIFrame frame = new UIFrame("Controls", EnumSet.noneOf(FrameButtons.class)); frame.setResizeable(false); final UILabel distLabel = new UILabel("Max Shadow Distance: 1500"); final UISlider distSlider = new UISlider(Orientation.Horizontal, 0, 2000, 1500); distSlider.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setMaxShadowDistance(distSlider.getValue()); distLabel.setText("Max Shadow Distance: " + distSlider.getValue()); } }); final UIButton updateCamera = new UIButton("Update Shadow Camera"); updateCamera.setSelectable(true); updateCamera.setSelected(true); updateCamera.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { _pssmPass.setUpdateMainCamera(updateCamera.isSelected()); updateText(); } }); final UIButton rotateLight = new UIButton("Rotate Light"); rotateLight.setSelectable(true); rotateLight.setSelected(false); rotateLight.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { moveLight = rotateLight.isSelected(); updateText(); } }); final UIPanel panel = new UIPanel(new RowLayout(false, true, false)); panel.setPadding(new Insets(10, 20, 10, 20)); panel.add(distLabel); panel.add(distSlider); panel.add(updateCamera); panel.add(rotateLight); frame.setContentPanel(panel); frame.pack(); frame.setLocalXY(hud.getWidth() - frame.getLocalComponentWidth(), hud.getHeight() - frame.getLocalComponentHeight()); hud.add(frame); } } \ No newline at end of file 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 2e1e44e..0a405dc 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 @@ -26,19 +26,16 @@ import com.ardor3d.extension.interact.widget.BasicFilterList; import com.ardor3d.extension.interact.widget.IFilterList; import com.ardor3d.extension.interact.widget.MovePlanarWidget; import com.ardor3d.extension.interact.widget.MovePlanarWidget.MovePlane; -import com.ardor3d.extension.ui.FloatingUIContainer; import com.ardor3d.extension.ui.Orientation; import com.ardor3d.extension.ui.UIButton; 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.UIPanel; import com.ardor3d.extension.ui.UIPieMenu; import com.ardor3d.extension.ui.UIPieMenuItem; import com.ardor3d.extension.ui.UISlider; import com.ardor3d.extension.ui.backdrop.EmptyBackdrop; -import com.ardor3d.extension.ui.border.EmptyBorder; import com.ardor3d.extension.ui.event.ActionEvent; import com.ardor3d.extension.ui.event.ActionListener; import com.ardor3d.extension.ui.event.SelectionListener; @@ -87,7 +84,7 @@ thumbnailPath = "com/ardor3d/example/media/thumbnails/interact_InteractUIExample maxHeapMemory = 64) public class InteractUIExample extends ExampleBase { - final UIHud hud = new UIHud(); + private UIHud hud; private InteractManager manager; private MovePlanarWidget moveWidget; private InsertMarkerUIWidget insertWidget; @@ -121,6 +118,7 @@ public class InteractUIExample extends ExampleBase { @Override protected void initExample() { _canvas.setTitle("Interact Example"); + hud = new UIHud(_canvas); final Camera camera = _canvas.getCanvasRenderer().getCamera(); camera.setLocation(15, 11, -9); @@ -273,7 +271,7 @@ public class InteractUIExample extends ExampleBase { manager = new InteractManager(new MarkerState()); manager.setupInput(_canvas, _physicalLayer, _logicalLayer); - hud.setupInput(_canvas, _physicalLayer, manager.getLogicalLayer()); + hud.setupInput(_physicalLayer, manager.getLogicalLayer()); hud.setMouseManager(_mouseManager); final BasicFilterList filterList = new BasicFilterList(); @@ -447,7 +445,7 @@ public class InteractUIExample extends ExampleBase { class InsertMarkerUIWidget extends AbstractInteractWidget { - UIFrame popupFrame; + UIPanel uiPanel; public InsertMarkerUIWidget(final IFilterList filterList) { super(filterList); @@ -495,16 +493,11 @@ public class InteractUIExample extends ExampleBase { } }); - popupFrame = new FloatingUIContainer(); - popupFrame.getContentPanel().add(centerPanel); - popupFrame.getBasePanel().setBackdrop(new EmptyBackdrop()); - popupFrame.getBasePanel().setBorder(new EmptyBorder()); + uiPanel = new UIPanel(); + uiPanel.add(centerPanel); + uiPanel.pack(); - popupFrame.updateMinimumSizeFromContents(); - popupFrame.layout(); - popupFrame.pack(); - - _handle = popupFrame; + _handle = uiPanel; } private void AddButton(final UIContainer parent, final String label, final ActionListener actionListener) { @@ -527,7 +520,7 @@ public class InteractUIExample extends ExampleBase { tempVec.zero(); tempVec.set(Camera.getCurrentCamera().getScreenCoordinates(spat.getWorldTransform().applyForward(tempVec))); tempVec.setZ(0); - tempVec.subtractLocal(popupFrame.getContentWidth() / 2, -10, 0); + tempVec.subtractLocal(uiPanel.getContentWidth() / 2, -10, 0); _handle.setTranslation(tempVec); _handle.updateWorldTransform(true); } @@ -537,14 +530,14 @@ public class InteractUIExample extends ExampleBase { super.receivedControl(manager); final Spatial spat = manager.getSpatialTarget(); if (spat != null) { - hud.add(popupFrame); + hud.add(uiPanel); } } @Override public void lostControl(final InteractManager manager) { super.lostControl(manager); - hud.remove(popupFrame); + hud.remove(uiPanel); } @Override @@ -553,9 +546,9 @@ public class InteractUIExample extends ExampleBase { if (manager.getActiveWidget() == this) { final Spatial spat = manager.getSpatialTarget(); if (spat == null) { - hud.remove(popupFrame); + hud.remove(uiPanel); } else { - hud.add(popupFrame); + hud.add(uiPanel); } } } @@ -563,7 +556,7 @@ public class InteractUIExample extends ExampleBase { class ColorSelectUIWidget extends AbstractInteractWidget { - UIFrame popupFrame; + UIPanel uiPanel; ColorRGBA unconsumedColor; public ColorSelectUIWidget(final IFilterList filterList) { @@ -574,13 +567,13 @@ public class InteractUIExample extends ExampleBase { private void createFrame() { - final UIPanel centerPanel = new UIPanel(null); + final UIPanel centerPanel = new UIPanel(); centerPanel.setBackdrop(new EmptyBackdrop()); centerPanel.setLayoutData(BorderLayoutData.CENTER); final UIComboBox combo = new UIComboBox(new DefaultComboBoxModel("White", "Black", "Red", "Green", "Blue", "Yellow", "Magenta", "Cyan")); - combo.setLocalComponentWidth(100); + combo.setMinimumContentWidth(100); combo.addSelectionListener(new SelectionListener() { @Override public void selectionChanged(final UIComboBox component, final Object newValue) { @@ -598,16 +591,11 @@ public class InteractUIExample extends ExampleBase { }); centerPanel.add(combo); - popupFrame = new FloatingUIContainer(); - popupFrame.getContentPanel().add(centerPanel); - popupFrame.getBasePanel().setBackdrop(new EmptyBackdrop()); - popupFrame.getBasePanel().setBorder(null); - - popupFrame.updateMinimumSizeFromContents(); - popupFrame.layout(); - popupFrame.pack(); + uiPanel = new UIPanel(); + uiPanel.add(centerPanel); + uiPanel.pack(); - _handle = popupFrame; + _handle = uiPanel; } @Override @@ -620,7 +608,7 @@ public class InteractUIExample extends ExampleBase { tempVec.zero(); tempVec.set(Camera.getCurrentCamera().getScreenCoordinates(spat.getWorldTransform().applyForward(tempVec))); tempVec.setZ(0); - tempVec.subtractLocal(popupFrame.getContentWidth() / 2, -20, 0); + tempVec.subtractLocal(uiPanel.getContentWidth() / 2, -20, 0); _handle.setTranslation(tempVec); _handle.updateWorldTransform(true); } @@ -630,14 +618,14 @@ public class InteractUIExample extends ExampleBase { super.receivedControl(manager); final Spatial spat = manager.getSpatialTarget(); if (spat != null) { - hud.add(popupFrame); + hud.add(uiPanel); } } @Override public void lostControl(final InteractManager manager) { super.lostControl(manager); - hud.remove(popupFrame); + hud.remove(uiPanel); } @Override @@ -657,9 +645,9 @@ public class InteractUIExample extends ExampleBase { if (manager.getActiveWidget() == this) { final Spatial spat = manager.getSpatialTarget(); if (spat == null) { - hud.remove(popupFrame); + hud.remove(uiPanel); } else { - hud.add(popupFrame); + hud.add(uiPanel); } } } @@ -667,7 +655,7 @@ public class InteractUIExample extends ExampleBase { class PulseControlUIWidget extends AbstractInteractWidget { - UIFrame popupFrame; + UIPanel uiPanel; Double unconsumedPulse; public PulseControlUIWidget(final IFilterList filterList) { @@ -678,7 +666,7 @@ public class InteractUIExample extends ExampleBase { private void createFrame() { - final UIPanel centerPanel = new UIPanel(null); + final UIPanel centerPanel = new UIPanel(); centerPanel.setBackdrop(new EmptyBackdrop()); centerPanel.setLayoutData(BorderLayoutData.CENTER); @@ -694,19 +682,14 @@ public class InteractUIExample extends ExampleBase { } } }); - slider.setLocalComponentWidth(100); + slider.setMinimumContentWidth(100); centerPanel.add(slider); - popupFrame = new FloatingUIContainer(); - popupFrame.getContentPanel().add(centerPanel); - popupFrame.getBasePanel().setBackdrop(new EmptyBackdrop()); - popupFrame.getBasePanel().setBorder(null); - - popupFrame.updateMinimumSizeFromContents(); - popupFrame.layout(); - popupFrame.pack(); + uiPanel = new UIPanel(); + uiPanel.add(centerPanel); + uiPanel.pack(); - _handle = popupFrame; + _handle = uiPanel; } @Override @@ -719,7 +702,7 @@ public class InteractUIExample extends ExampleBase { tempVec.zero(); tempVec.set(Camera.getCurrentCamera().getScreenCoordinates(spat.getWorldTransform().applyForward(tempVec))); tempVec.setZ(0); - tempVec.subtractLocal(popupFrame.getContentWidth() / 2, -20, 0); + tempVec.subtractLocal(uiPanel.getContentWidth() / 2, -20, 0); _handle.setTranslation(tempVec); _handle.updateWorldTransform(true); } @@ -729,14 +712,14 @@ public class InteractUIExample extends ExampleBase { super.receivedControl(manager); final Spatial spat = manager.getSpatialTarget(); if (spat != null) { - hud.add(popupFrame); + hud.add(uiPanel); } } @Override public void lostControl(final InteractManager manager) { super.lostControl(manager); - hud.remove(popupFrame); + hud.remove(uiPanel); } @Override @@ -756,9 +739,9 @@ public class InteractUIExample extends ExampleBase { if (manager.getActiveWidget() == this) { final Spatial spat = manager.getSpatialTarget(); if (spat == null) { - hud.remove(popupFrame); + hud.remove(uiPanel); } else { - hud.add(popupFrame); + hud.add(uiPanel); } } } diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java index 31799f1..5e6953c 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/PopOverUIExample.java @@ -38,7 +38,6 @@ import com.ardor3d.math.MathUtils; import com.ardor3d.math.Matrix3; import com.ardor3d.math.Vector3; import com.ardor3d.math.type.ReadOnlyVector3; -import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.state.MaterialState; import com.ardor3d.renderer.state.MaterialState.ColorMaterial; @@ -87,15 +86,14 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { setTexture("Logo"); setSpin("Around Y"); - hud = new UIHud(); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud = new UIHud(_canvas); + hud.setupInput(_physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); - final Camera cam = _canvas.getCanvasRenderer().getCamera(); final UIButton dropButton = new UIButton("Drop Menu"); dropButton.setPadding(new Insets(6, 15, 6, 15)); - dropButton.setHudXY(cam.getWidth() / 10 - dropButton.getLocalComponentWidth() / 2, - cam.getHeight() - dropButton.getLocalComponentHeight() - 5); + dropButton.setHudXY(hud.getWidth() / 10 - dropButton.getLocalComponentWidth() / 2, + hud.getHeight() - dropButton.getLocalComponentHeight() - 5); dropButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { @@ -106,12 +104,12 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { final UIButton pieButton = new UIButton("Pie Menu"); pieButton.setPadding(new Insets(6, 15, 6, 15)); - pieButton.setHudXY(9 * cam.getWidth() / 10 - pieButton.getLocalComponentWidth() / 2, cam.getHeight() + pieButton.setHudXY(9 * hud.getWidth() / 10 - pieButton.getLocalComponentWidth() / 2, hud.getHeight() - pieButton.getLocalComponentHeight() - 5); pieButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { - showPieMenu(cam.getWidth() / 2, cam.getHeight() / 2); + showPieMenu(hud.getWidth() / 2, hud.getHeight() / 2); } }); hud.add(pieButton); @@ -290,7 +288,10 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { final UIFrame scaleDialog = new UIFrame("Set Scale...", EnumSet.of(FrameButtons.CLOSE)); scaleDialog.setResizeable(false); final UIPanel contentPanel = scaleDialog.getContentPanel(); - contentPanel.setLayout(new RowLayout(true, false, false)); + final RowLayout layout = new RowLayout(true, false, false); + layout.setSpacing(4); + contentPanel.setLayout(layout); + contentPanel.setMargin(new Insets(0, 5, 0, 5)); final UISlider scaleSlider = new UISlider(Orientation.Horizontal, 1, 20, (int) (box.getScale().getX() * 10)); scaleSlider.setMinimumContentWidth(200); @@ -311,7 +312,7 @@ public class PopOverUIExample extends ExampleBase implements ActionListener { }); hud.add(scaleDialog); - scaleDialog.pack(235, 80); + scaleDialog.pack(); scaleDialog.centerOn(hud); } diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java index 8251e99..7784d4d 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/RotatingUIExample.java @@ -52,13 +52,10 @@ public class RotatingUIExample extends ExampleBase { final UIFrame frame = new UIFrame("Sample"); frame.setContentPanel(panel); - frame.updateMinimumSizeFromContents(); - frame.layout(); - frame.pack(300, 200); + frame.pack(); frame.setUseStandin(false); frame.setOpacity(1f); - frame.setLocationRelativeTo(_canvas.getCanvasRenderer().getCamera()); frame.setName("sample"); final Matrix3 rotate = new Matrix3(); @@ -66,11 +63,11 @@ public class RotatingUIExample extends ExampleBase { rotate.fromAngleNormalAxis(45 * MathUtils.DEG_TO_RAD, axis); frame.setRotation(rotate); - hud = new UIHud(); + hud = new UIHud(_canvas); hud.add(frame); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud.setupInput(_physicalLayer, _logicalLayer); - frame.setLocationRelativeTo(_canvas.getCanvasRenderer().getCamera()); + frame.centerOn(hud); } private UIPanel makePanel() { @@ -105,6 +102,8 @@ public class RotatingUIExample extends ExampleBase { }); rotatingLabel.setLayoutData(BorderLayoutData.NORTH); + panel.setMinimumContentSize(300, 200); + return panel; } diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java index 59d8192..0ecc8ad 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java @@ -125,13 +125,10 @@ public class SimpleUIExample extends ExampleBase { frame = new UIFrame("UI Sample"); frame.setContentPanel(pane); - frame.updateMinimumSizeFromContents(); - frame.layout(); frame.pack(); frame.setUseStandin(true); frame.setOpacity(1f); - frame.setLocationRelativeTo(_canvas.getCanvasRenderer().getCamera()); frame.setName("sample"); // Uncomment #1... @@ -152,10 +149,12 @@ public class SimpleUIExample extends ExampleBase { // } // }); - hud = new UIHud(); + hud = new UIHud(_canvas); hud.add(frame); - hud.setupInput(_canvas, _physicalLayer, _logicalLayer); + hud.setupInput(_physicalLayer, _logicalLayer); hud.setMouseManager(_mouseManager); + + frame.centerOn(hud); } private UIPanel makeLoginPanel() { diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/FloatingUIContainer.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/FloatingUIContainer.java deleted file mode 100644 index 1958016..0000000 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/FloatingUIContainer.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) 2008-2012 Ardor Labs, Inc. - * - * This file is part of Ardor3D. - * - * Ardor3D is free software: you can redistribute it and/or modify it - * under the terms of its license which may be found in the accompanying - * LICENSE file or at . - */ - -package com.ardor3d.extension.ui; - -import com.ardor3d.extension.ui.border.EmptyBorder; -import com.ardor3d.extension.ui.layout.RowLayout; - -/** - * An simple, undecorated frame meant for showing content in the UI that can not be moved or resized by the user. - */ -public class FloatingUIContainer extends UIFrame { - - public FloatingUIContainer() { - super(null); - setDecorated(false); - getContentPanel().setBorder(new EmptyBorder()); - getContentPanel().setLayout(new RowLayout(false)); - setBackdrop(null); - - applySuperSkin(); - } - - protected void applySuperSkin() { - super.applySkin(); - } - - @Override - protected void applySkin() { - ; - } -} diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java index a1782bd..3d875d7 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java @@ -417,11 +417,13 @@ public abstract class UIComponent extends Node implements UIKeyHandler { } protected int getMaximumContentWidth() { - return _maximumContentsSize.getWidth() > 0 ? _maximumContentsSize.getWidth() : UIComponent.DEFAULT_MAX_CONTENT_SIZE; + return _maximumContentsSize.getWidth() > 0 ? _maximumContentsSize.getWidth() + : UIComponent.DEFAULT_MAX_CONTENT_SIZE; } protected int getMaximumContentHeight() { - return _maximumContentsSize.getHeight() > 0 ? _maximumContentsSize.getHeight() : UIComponent.DEFAULT_MAX_CONTENT_SIZE; + return _maximumContentsSize.getHeight() > 0 ? _maximumContentsSize.getHeight() + : UIComponent.DEFAULT_MAX_CONTENT_SIZE; } /** @@ -623,6 +625,15 @@ public abstract class UIComponent extends Node implements UIKeyHandler { setContentSize(getMinimumContentWidth(), getMinimumContentHeight()); } + /** + * Resize the container to fit the minimum size of its content panel. + */ + public void pack() { + updateMinimumSizeFromContents(); + setContentSize(getMinimumContentWidth(), getMinimumContentHeight()); + layout(); + } + /** * Attempt to force this component to fit in the given rectangle. * @@ -850,18 +861,35 @@ public abstract class UIComponent extends Node implements UIKeyHandler { */ public void detachedFromHud() {} + /** + * Centers this frame on the view of the camera + * + * @param cam + * the camera to center on. + */ public void centerOn(final UIHud hud) { - final int centerX = hud.getWidth() / 2; - final int centerY = hud.getHeight() / 2; - - setHudXY(centerX - getLocalComponentWidth() / 2, centerY - getLocalComponentHeight() / 2); + final Rectangle2 rectA = getRelativeComponentBounds(null); + int x = (hud.getWidth() - rectA.getWidth()) / 2; + int y = (hud.getHeight() - rectA.getHeight()) / 2; + x -= rectA.getX(); + y -= rectA.getY(); + setHudXY(x, y); } + /** + * Centers this component on the location of the given component. + * + * @param comp + * the component to center on. + */ public void centerOn(final UIComponent comp) { - final int centerX = comp.getHudX() + comp.getLocalComponentWidth() / 2; - final int centerY = comp.getHudY() + comp.getLocalComponentHeight() / 2; - - setHudXY(centerX - getLocalComponentWidth() / 2, centerY - getLocalComponentHeight() / 2); + final Rectangle2 rectA = comp.getRelativeComponentBounds(null); + final Rectangle2 rectB = getRelativeComponentBounds(null); + int x = (rectA.getWidth() - rectB.getWidth()) / 2; + int y = (rectA.getHeight() - rectB.getHeight()) / 2; + x += comp.getHudX() - rectA.getX() + rectB.getX(); + y += comp.getHudY() - rectA.getY() + rectB.getY(); + setHudXY(x, y); } /** @@ -1397,10 +1425,7 @@ public abstract class UIComponent extends Node implements UIKeyHandler { // set contents and size ttip.getLabel().setText(getTooltipText()); - ttip.updateMinimumSizeFromContents(); - ttip.getLabel().compact(); - ttip.compact(); - ttip.layout(); + ttip.pack(); // set position based on CURRENT mouse location. int x = hud.getLastMouseX(); diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIFrame.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIFrame.java index aea3c60..a71fadd 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIFrame.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIFrame.java @@ -19,8 +19,6 @@ import com.ardor3d.extension.ui.event.FrameDragListener; import com.ardor3d.extension.ui.layout.BorderLayout; import com.ardor3d.extension.ui.layout.BorderLayoutData; import com.ardor3d.math.ColorRGBA; -import com.ardor3d.math.Rectangle2; -import com.ardor3d.renderer.Camera; import com.ardor3d.scenegraph.Spatial; import com.ardor3d.scenegraph.visitor.Visitor; import com.ardor3d.util.GameTaskQueueManager; @@ -30,11 +28,6 @@ import com.ardor3d.util.GameTaskQueueManager; * resized. Frames can also have their opacity individually assigned which will affect all elements drawn within them. */ public class UIFrame extends UIContainer { - /** Minimum height we'll allow during manual resize */ - public static int MIN_FRAME_HEIGHT = 60; - /** Minimum width we'll allow during manual resize */ - public static int MIN_FRAME_WIDTH = 100; - /** The main panel containing the contents panel and status bar of the frame. */ private final UIPanel _basePanel; /** The panel meant to hold the contents of the frame. */ @@ -237,39 +230,6 @@ public class UIFrame extends UIContainer { _parent = null; } - /** - * Centers this frame on the location of the given component. - * - * @param comp - * the component to center on. - */ - public void setLocationRelativeTo(final UIComponent comp) { - final Rectangle2 rectA = comp.getRelativeComponentBounds(null); - final Rectangle2 rectB = getRelativeComponentBounds(null); - int x = (rectA.getWidth() - rectB.getWidth()) / 2; - int y = (rectA.getHeight() - rectB.getHeight()) / 2; - x += comp.getHudX() - rectA.getX() + rectB.getX(); - y += comp.getHudY() - rectA.getY() + rectB.getY(); - setHudXY(x, y); - updateGeometricState(0); - } - - /** - * Centers this frame on the view of the camera - * - * @param cam - * the camera to center on. - */ - public void setLocationRelativeTo(final Camera cam) { - final Rectangle2 rectA = getRelativeComponentBounds(null); - int x = (cam.getWidth() - rectA.getWidth()) / 2; - int y = (cam.getHeight() - rectA.getHeight()) / 2; - x -= rectA.getX(); - y -= rectA.getY(); - setHudXY(x, y); - updateGeometricState(0); - } - /** * @return this frame's title bar */ @@ -352,26 +312,14 @@ public class UIFrame extends UIContainer { } } - /** - * Resize the frame to fit the minimum size of its content panel. - */ + @Override public void pack() { updateMinimumSizeFromContents(); - pack(_contentPanel.getMinimumLocalComponentWidth(), _contentPanel.getMinimumLocalComponentHeight()); - } - - /** - * Resize the frame to fit its content panel to the given dimensions - * - * @param contentWidth - * our desired content panel width - * @param contentHeight - * our desired content panel height - */ - public void pack(final int contentWidth, final int contentHeight) { // grab the desired width and height of the frame. - final int width = contentWidth + _basePanel.getTotalLeft() + _basePanel.getTotalRight(); - int height = contentHeight + _basePanel.getTotalTop() + _basePanel.getTotalBottom(); + final int width = _contentPanel.getMinimumLocalComponentWidth() + _basePanel.getTotalLeft() + + _basePanel.getTotalRight(); + int height = _contentPanel.getMinimumLocalComponentHeight() + _basePanel.getTotalTop() + + _basePanel.getTotalBottom(); // add in our frame chrome, if it is enabled. if (isDecorated()) { @@ -379,7 +327,7 @@ public class UIFrame extends UIContainer { } // Set our size, obeying min sizes. - setLocalComponentSize(Math.max(width, UIFrame.MIN_FRAME_WIDTH), Math.max(height, UIFrame.MIN_FRAME_HEIGHT)); + setLocalComponentSize(width, height); // Layout the panel layout(); diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIHud.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIHud.java index a11736b..576835c 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIHud.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIHud.java @@ -36,7 +36,6 @@ import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; -import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.ZBufferState; @@ -121,11 +120,14 @@ public class UIHud extends Node { */ private final List _popovers = Lists.newArrayList(); + private final Canvas _canvas; + /** - * Construct a new UIHud + * Construct a new UIHud for a given canvas */ - public UIHud() { + public UIHud(final Canvas canvas) { setName("UIHud"); + _canvas = canvas; getSceneHints().setCullHint(CullHint.Never); getSceneHints().setRenderBucketType(RenderBucketType.Skip); @@ -483,9 +485,9 @@ public class UIHud extends Node { * @param forwardTo * a LogicalLayer to send unconsumed (by the UI) input events to. */ - public void setupInput(final Canvas canvas, final PhysicalLayer physicalLayer, final LogicalLayer forwardTo) { + public void setupInput(final PhysicalLayer physicalLayer, final LogicalLayer forwardTo) { // Set up this logical layer to listen for events from the given canvas and PhysicalLayer - _logicalLayer.registerInput(canvas, physicalLayer); + _logicalLayer.registerInput(_canvas, physicalLayer); // Set up forwarding for events not consumed. if (forwardTo != null) { @@ -604,7 +606,6 @@ public class UIHud extends Node { final MouseState previousMState = inputStates.getPrevious().getMouseState(); final MouseState currentMState = current.getMouseState(); if (previousMState != currentMState) { - // Check for presses. if (currentMState.hasButtonState(ButtonState.DOWN)) { final EnumSet pressed = currentMState.getButtonsPressedSince(previousMState); @@ -842,21 +843,11 @@ public class UIHud extends Node { } public int getWidth() { - final Camera cam = Camera.getCurrentCamera(); - if (cam != null) { - return cam.getWidth(); - } else { - return 1; - } + return _canvas.getCanvasRenderer().getCamera().getWidth(); } public int getHeight() { - final Camera cam = Camera.getCurrentCamera(); - if (cam != null) { - return cam.getHeight(); - } else { - return 1; - } + return _canvas.getCanvasRenderer().getCamera().getHeight(); } public void closePopupMenus() { diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIProgressBar.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIProgressBar.java index ebb9ace..f3cc6df 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIProgressBar.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIProgressBar.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -44,7 +44,7 @@ public class UIProgressBar extends UIPanel { /** * Construct a new progress bar with the given attributes. - * + * * @param labelText * text to show next to the progress bar * @param horizontal @@ -76,10 +76,7 @@ public class UIProgressBar extends UIPanel { applySkin(); - updateMinimumSizeFromContents(); - compact(); - - layout(); + pack(); } @Override @@ -99,7 +96,7 @@ public class UIProgressBar extends UIPanel { /** * Takes affect on next call to layout() - * + * * @param horizontal * true for horizontal bar, false for vertical. */ @@ -113,7 +110,7 @@ public class UIProgressBar extends UIPanel { /** * Triggers layout if value is not same as current value. - * + * * @param value */ public void setPercentFilled(final double value) { diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIScrollBar.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIScrollBar.java index d077a7b..83d4c9d 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIScrollBar.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIScrollBar.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -49,11 +49,8 @@ public class UIScrollBar extends UIPanel { btBottomRight.setLayoutData(BorderLayoutData.EAST); } applySkin(); + pack(); - updateMinimumSizeFromContents(); - compact(); - - layout(); final ActionListener al = new ActionListener() { public void actionPerformed(final ActionEvent event) { int direction; @@ -96,7 +93,7 @@ public class UIScrollBar extends UIPanel { /** * Add the specified listener to this scrollbar's list of listeners notified when it's changed. - * + * * @param listener */ public void addActionListener(final ActionListener listener) { diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UITooltip.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UITooltip.java index b1dcd7b..635b104 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UITooltip.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UITooltip.java @@ -3,18 +3,17 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ package com.ardor3d.extension.ui; - /** * Defines a component used by the hud to display floating tool tips. */ -public class UITooltip extends FloatingUIContainer { +public class UITooltip extends UIContainer { private final AbstractLabelUIComponent _label; @@ -24,12 +23,10 @@ public class UITooltip extends FloatingUIContainer { public UITooltip() { // setup our text label _label = new UILabel(""); - getContentPanel().add(_label); + add(_label); // initially this is not visible setVisible(false); - - applySuperSkin(); } /** diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/event/FrameResizeListener.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/event/FrameResizeListener.java index 47a5d5c..1dc9cf0 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/event/FrameResizeListener.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/event/FrameResizeListener.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ @@ -65,10 +65,6 @@ public final class FrameResizeListener implements DragListener { // Set the new width to the initial width + the change in mouse x position. int newWidth = _initialLocalComponentWidth + x - _initialX; - if (newWidth < UIFrame.MIN_FRAME_WIDTH) { - // don't let us get smaller than min size - newWidth = UIFrame.MIN_FRAME_WIDTH; - } if (newWidth < frame.getMinimumLocalComponentWidth()) { // don't let us get smaller than frame min size newWidth = frame.getMinimumLocalComponentWidth(); @@ -80,10 +76,6 @@ public final class FrameResizeListener implements DragListener { // Set the new height to the initial height + the change in mouse y position. int newHeight = _initialLocalComponentHeight - (y - _initialY); - if (newHeight < UIFrame.MIN_FRAME_HEIGHT) { - // don't let us get smaller than absolute min size - newHeight = UIFrame.MIN_FRAME_HEIGHT; - } if (newHeight < frame.getMinimumLocalComponentHeight()) { // don't let us get smaller than frame min size newHeight = frame.getMinimumLocalComponentHeight(); diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/Skin.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/Skin.java index 6d024cf..d7fcfa4 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/Skin.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/Skin.java @@ -78,12 +78,12 @@ public abstract class Skin { applyToPopupMenu((UIPopupMenu) component); } else if (component instanceof UIPanel) { applyToPanel((UIPanel) component); + } else if (component instanceof UITooltip) { + applyToTooltip((UITooltip) component); } // 5. FRAME TYPES - else if (component instanceof UITooltip) { - applyToTooltip((UITooltip) component); - } else if (component instanceof UIFrame) { + else if (component instanceof UIFrame) { applyToFrame((UIFrame) component); } diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/generic/GenericSkin.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/generic/GenericSkin.java index 1c49dcf..60851b6 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/generic/GenericSkin.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/generic/GenericSkin.java @@ -314,8 +314,7 @@ public class GenericSkin extends Skin { state.setMargin(new Insets(1, 1, 1, 1)); } closeButton.refreshState(); - closeButton.updateMinimumSizeFromContents(); - closeButton.compact(); + closeButton.pack(); closeButton .setMaximumContentSize(closeButton.getContentWidth(), closeButton.getContentHeight()); } @@ -335,8 +334,7 @@ public class GenericSkin extends Skin { state.setMargin(new Insets(1, 1, 1, 1)); } minimizeButton.refreshState(); - minimizeButton.updateMinimumSizeFromContents(); - minimizeButton.compact(); + minimizeButton.pack(); minimizeButton.setMaximumContentSize(minimizeButton.getContentWidth(), minimizeButton.getContentHeight()); } @@ -356,8 +354,7 @@ public class GenericSkin extends Skin { state.setMargin(new Insets(1, 1, 1, 1)); } expandButton.refreshState(); - expandButton.updateMinimumSizeFromContents(); - expandButton.compact(); + expandButton.pack(); expandButton.setMaximumContentSize(expandButton.getContentWidth(), expandButton.getContentHeight()); } @@ -377,8 +374,7 @@ public class GenericSkin extends Skin { state.setMargin(new Insets(1, 1, 1, 1)); } helpButton.refreshState(); - helpButton.updateMinimumSizeFromContents(); - helpButton.compact(); + helpButton.pack(); helpButton.setMaximumContentSize(helpButton.getContentWidth(), helpButton.getContentHeight()); } } -- cgit v1.2.3 From 57bb9ed523b3a47a358a6348bce052eaff88fe97 Mon Sep 17 00:00:00 2001 From: Joshua Slack Date: Thu, 19 Oct 2017 11:25:34 -0500 Subject: Small tweak to fix scroll bug in example --- .../src/main/java/com/ardor3d/example/ui/SimpleUIExample.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ardor3d-examples') diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java index 0ecc8ad..86044ac 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/SimpleUIExample.java @@ -202,7 +202,7 @@ public class SimpleUIExample extends ExampleBase { final ActionListener actionListener = new ActionListener() { public void actionPerformed(final ActionEvent event) { - applyChat(historyArea, chatField); + applyChat(historyArea, chatField, scrollArea); } }; chatButton.addActionListener(actionListener); @@ -217,11 +217,12 @@ public class SimpleUIExample extends ExampleBase { return chatPanel; } - private void applyChat(final UITextArea historyArea, final UITextField chatField) { + private void applyChat(final UITextArea historyArea, final UITextField chatField, final UIScrollPanel scrollArea) { final String text = chatField.getText(); if (text.length() > 0) { historyArea.setText(historyArea.getText() + "\n" + text); chatField.setText(""); + scrollArea.layout(); } } -- cgit v1.2.3 From 2fcedf5a18d680093a396f89fb55d79fbd1fb4cb Mon Sep 17 00:00:00 2001 From: Joshua Slack Date: Thu, 4 Jan 2018 13:19:57 -0600 Subject: Small tweak to eclipse project settings --- ardor3d-animation/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-awt/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-core/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-effects/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-examples/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-extras/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-jogl/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-lwjgl/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-swt/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-terrain/.settings/org.eclipse.jdt.ui.prefs | 2 +- ardor3d-ui/.settings/org.eclipse.jdt.ui.prefs | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) (limited to 'ardor3d-examples') diff --git a/ardor3d-animation/.settings/org.eclipse.jdt.ui.prefs b/ardor3d-animation/.settings/org.eclipse.jdt.ui.prefs index 583471d..b79d20f 100644 --- a/ardor3d-animation/.settings/org.eclipse.jdt.ui.prefs +++ b/ardor3d-animation/.settings/org.eclipse.jdt.ui.prefs @@ -2,7 +2,7 @@ cleanup_settings_version=2 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true org.eclipse.jdt.ui.javadoc=false -org.eclipse.jdt.ui.text.custom_code_templates=