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. --- .../renderer/utils/atlas/TestAtlasPacker.java | 5 +-- .../com/ardor3d/example/ui/PopOverUIExample.java | 46 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) (limited to 'ardor3d-examples') 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()); -- cgit v1.2.3