diff options
author | Julien Gouesse <[email protected]> | 2014-02-04 22:51:21 +0100 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2014-02-04 22:51:21 +0100 |
commit | 0c699e774b621ce6140ebe96b9a1517c8b8f96be (patch) | |
tree | 208c722d31e2fd120adc00b74cf221628faae802 | |
parent | 2d1e48d0c20a09d3000b28bdeda034a9870fef88 (diff) |
Adds some missing override annotations, removes the useless AWT dependencies from NEWT and SWT examples, uses the heavyweight SWT GLCanvas of JOGL instead of Eclipse SWT canvas (which is unmaintained) and adds an example using JoglNewtSwtCanvas
5 files changed, 61 insertions, 41 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/ExampleScene.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/ExampleScene.java index 819348d..9011c80 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/ExampleScene.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/ExampleScene.java @@ -36,17 +36,19 @@ public final class ExampleScene implements Scene { return root; } + @Override @MainThread public boolean renderUnto(final Renderer renderer) { // Execute renderQueue item - GameTaskQueueManager.getManager(ContextManager.getCurrentContext()).getQueue(GameTaskQueue.RENDER).execute( - renderer); + GameTaskQueueManager.getManager(ContextManager.getCurrentContext()).getQueue(GameTaskQueue.RENDER) + .execute(renderer); ContextGarbageCollector.doRuntimeCleanup(renderer); renderer.draw(root); return true; } + @Override public PickResults doPick(final Ray3 pickRay) { // does nothing. return null; diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java index f190e1e..57128bf 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtDesktopExample.java @@ -129,8 +129,8 @@ public class JoglAwtDesktopExample { private static MouseCursor createMouseCursor(final AWTImageLoader awtImageLoader, final String resourceName) throws IOException { - final com.ardor3d.image.Image image = awtImageLoader.load(ResourceLocatorTool.getClassPathResourceAsStream( - JoglAwtDesktopExample.class, resourceName), false); + final com.ardor3d.image.Image image = awtImageLoader.load( + ResourceLocatorTool.getClassPathResourceAsStream(JoglAwtDesktopExample.class, resourceName), false); return new MouseCursor("cursor1", image, 0, image.getHeight() - 1); } @@ -159,6 +159,7 @@ public class JoglAwtDesktopExample { logicalLayer.registerInput(theCanvas, pl); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.H), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != theCanvas) { return; @@ -174,6 +175,7 @@ public class JoglAwtDesktopExample { } })); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.J), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != theCanvas) { return; @@ -190,8 +192,8 @@ public class JoglAwtDesktopExample { final Camera cam = theCanvas.getCanvasRenderer().getCamera(); if (cam != null) { cam.resize(theCanvas.getWidth(), theCanvas.getHeight()); - cam.setFrustumPerspective(cam.getFovY(), theCanvas.getWidth() / (float) theCanvas.getHeight(), cam - .getFrustumNear(), cam.getFrustumFar()); + cam.setFrustumPerspective(cam.getFovY(), theCanvas.getWidth() / (float) theCanvas.getHeight(), + cam.getFrustumNear(), cam.getFrustumFar()); } } }); @@ -205,6 +207,7 @@ public class JoglAwtDesktopExample { private static class MyExit implements Exit { private volatile boolean exit = false; + @Override public void exit() { exit = true; } diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java index 4a13137..9b902f1 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglAwtExample.java @@ -170,6 +170,7 @@ public class JoglAwtExample { logicalLayer.registerInput(theCanvas, pl); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.H), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != theCanvas) { return; @@ -185,6 +186,7 @@ public class JoglAwtExample { } })); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.J), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != theCanvas) { return; @@ -201,6 +203,7 @@ public class JoglAwtExample { private static class MyExit implements Exit { private volatile boolean exit = false; + @Override public void exit() { exit = true; } diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java index 2dcad67..b3778f6 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglNewtAwtExample.java @@ -29,15 +29,15 @@ import com.ardor3d.framework.DisplaySettings; import com.ardor3d.framework.FrameHandler; import com.ardor3d.framework.jogl.JoglCanvasRenderer; import com.ardor3d.framework.jogl.JoglNewtAwtCanvas; -import com.ardor3d.image.util.awt.AWTImageLoader; +import com.ardor3d.image.util.jogl.JoglImageLoader; import com.ardor3d.input.ControllerWrapper; import com.ardor3d.input.Key; import com.ardor3d.input.MouseCursor; import com.ardor3d.input.PhysicalLayer; -import com.ardor3d.input.awt.AwtFocusWrapper; -import com.ardor3d.input.awt.AwtKeyboardWrapper; -import com.ardor3d.input.awt.AwtMouseManager; -import com.ardor3d.input.awt.AwtMouseWrapper; +import com.ardor3d.input.jogl.JoglNewtFocusWrapper; +import com.ardor3d.input.jogl.JoglNewtKeyboardWrapper; +import com.ardor3d.input.jogl.JoglNewtMouseManager; +import com.ardor3d.input.jogl.JoglNewtMouseWrapper; import com.ardor3d.input.logical.DummyControllerWrapper; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; @@ -49,7 +49,8 @@ import com.ardor3d.util.resource.ResourceLocatorTool; import com.ardor3d.util.resource.SimpleResourceLocator; /** - * This examples demonstrates how to render OpenGL (via JOGL) on a AWT canvas. + * This examples demonstrates how to render OpenGL (via JOGL) on a NEWT AWT canvas. FIXME update the thumbnail and the + * description */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.canvas.JoglAwtExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/canvas_JoglAwtExample.jpg", // @@ -78,7 +79,7 @@ public class JoglNewtAwtExample { frameWork.addUpdater(game1); frameWork.addUpdater(game2); - final JFrame frame = new JFrame("AWT Example"); + final JFrame frame = new JFrame("NEWT AWT Example"); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { @@ -88,7 +89,7 @@ public class JoglNewtAwtExample { frame.setLayout(new GridLayout(2, 3)); - AWTImageLoader.registerLoader(); + JoglImageLoader.registerLoader(); try { final SimpleResourceLocator srl = new SimpleResourceLocator(ResourceLocatorTool.getClassPathResource( @@ -98,9 +99,9 @@ public class JoglNewtAwtExample { ex.printStackTrace(); } - final AWTImageLoader awtImageLoader = new AWTImageLoader(); - _cursor1 = createMouseCursor(awtImageLoader, "com/ardor3d/example/media/input/wait_cursor.png"); - _cursor2 = createMouseCursor(awtImageLoader, "com/ardor3d/example/media/input/movedata.gif"); + final JoglImageLoader joglImageLoader = new JoglImageLoader(); + _cursor1 = createMouseCursor(joglImageLoader, "com/ardor3d/example/media/input/wait_cursor.png"); + _cursor2 = createMouseCursor(joglImageLoader, "com/ardor3d/example/media/input/movedata.gif"); addCanvas(frame, scene1, logicalLayer, frameWork); frame.add(new JLabel( @@ -138,9 +139,9 @@ public class JoglNewtAwtExample { System.exit(0); } - private static MouseCursor createMouseCursor(final AWTImageLoader awtImageLoader, final String resourceName) + private static MouseCursor createMouseCursor(final JoglImageLoader joglImageLoader, final String resourceName) throws IOException { - final com.ardor3d.image.Image image = awtImageLoader.load( + final com.ardor3d.image.Image image = joglImageLoader.load( ResourceLocatorTool.getClassPathResourceAsStream(JoglNewtAwtExample.class, resourceName), false); return new MouseCursor("cursor1", image, 0, image.getHeight() - 1); @@ -160,10 +161,10 @@ public class JoglNewtAwtExample { theCanvas.setSize(new Dimension(400, 300)); theCanvas.setVisible(true); - final AwtKeyboardWrapper keyboardWrapper = new AwtKeyboardWrapper(theCanvas); - final AwtFocusWrapper focusWrapper = new AwtFocusWrapper(theCanvas); - final AwtMouseManager mouseManager = new AwtMouseManager(theCanvas); - final AwtMouseWrapper mouseWrapper = new AwtMouseWrapper(theCanvas, mouseManager); + final JoglNewtKeyboardWrapper keyboardWrapper = new JoglNewtKeyboardWrapper(theCanvas); + final JoglNewtFocusWrapper focusWrapper = new JoglNewtFocusWrapper(theCanvas); + final JoglNewtMouseManager mouseManager = new JoglNewtMouseManager(theCanvas); + final JoglNewtMouseWrapper mouseWrapper = new JoglNewtMouseWrapper(theCanvas, mouseManager); final ControllerWrapper controllerWrapper = new DummyControllerWrapper(); final PhysicalLayer pl = new PhysicalLayer(keyboardWrapper, mouseWrapper, controllerWrapper, focusWrapper); @@ -171,6 +172,7 @@ public class JoglNewtAwtExample { logicalLayer.registerInput(theCanvas, pl); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.H), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != theCanvas) { return; @@ -186,6 +188,7 @@ public class JoglNewtAwtExample { } })); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.J), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != theCanvas) { return; @@ -202,6 +205,7 @@ public class JoglNewtAwtExample { private static class MyExit implements Exit { private volatile boolean exit = false; + @Override public void exit() { exit = true; } diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java index 15f2e92..3026828 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/canvas/JoglSwtExample.java @@ -36,10 +36,11 @@ import org.eclipse.swt.widgets.TabItem; import com.ardor3d.example.Purpose; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.CanvasRenderer; +import com.ardor3d.framework.DisplaySettings; import com.ardor3d.framework.FrameHandler; import com.ardor3d.framework.jogl.JoglCanvasRenderer; -import com.ardor3d.framework.swt.SwtCanvas; -import com.ardor3d.image.util.awt.AWTImageLoader; +import com.ardor3d.framework.jogl.JoglSwtCanvas; +import com.ardor3d.image.util.jogl.JoglImageLoader; import com.ardor3d.input.ControllerWrapper; import com.ardor3d.input.GrabbedState; import com.ardor3d.input.Key; @@ -107,8 +108,10 @@ public class JoglSwtExample { fileItem.setMenu(submenu); final MenuItem item = new MenuItem(submenu, SWT.PUSH); item.addListener(SWT.Selection, new Listener() { + @Override public void handleEvent(final Event e) { Display.getDefault().asyncExec(new Runnable() { + @Override public void run() { addNewCanvas(tabFolder, scene, frameWork, logicalLayer); } @@ -118,7 +121,7 @@ public class JoglSwtExample { item.setText("Add &3d Canvas"); item.setAccelerator(SWT.MOD1 + '3'); - AWTImageLoader.registerLoader(); + JoglImageLoader.registerLoader(); try { final SimpleResourceLocator srl = new SimpleResourceLocator(ResourceLocatorTool.getClassPathResource( @@ -177,31 +180,30 @@ public class JoglSwtExample { canvasParent.layout(); - final SwtCanvas canvas1 = new SwtCanvas(topLeft, SWT.NONE, data); + final DisplaySettings settings = new DisplaySettings(400, 300, 24, 0, 0, 16, 0, 0, false, false); + final JoglCanvasRenderer canvasRenderer1 = new JoglCanvasRenderer(scene); - canvas1.setCanvasRenderer(canvasRenderer1); + final JoglSwtCanvas canvas1 = new JoglSwtCanvas(settings, canvasRenderer1, topLeft, SWT.NONE); frameWork.addCanvas(canvas1); canvas1.addControlListener(newResizeHandler(canvas1, canvasRenderer1)); - canvas1.setFocus(); - final SwtCanvas canvas2 = new SwtCanvas(bottomLeft, SWT.NONE, data); final JoglCanvasRenderer canvasRenderer2 = new JoglCanvasRenderer(scene); - canvas2.setCanvasRenderer(canvasRenderer2); + final JoglSwtCanvas canvas2 = new JoglSwtCanvas(settings, canvasRenderer2, bottomLeft, SWT.NONE); frameWork.addCanvas(canvas2); canvas2.addControlListener(newResizeHandler(canvas2, canvasRenderer2)); - final SwtCanvas canvas3 = new SwtCanvas(topRight, SWT.NONE, data); final JoglCanvasRenderer canvasRenderer3 = new JoglCanvasRenderer(scene); - canvas3.setCanvasRenderer(canvasRenderer3); + final JoglSwtCanvas canvas3 = new JoglSwtCanvas(settings, canvasRenderer3, topRight, SWT.NONE); frameWork.addCanvas(canvas3); canvas3.addControlListener(newResizeHandler(canvas3, canvasRenderer3)); - final SwtCanvas canvas4 = new SwtCanvas(bottomRight, SWT.NONE, data); final JoglCanvasRenderer canvasRenderer4 = new JoglCanvasRenderer(scene); - canvas4.setCanvasRenderer(canvasRenderer4); + final JoglSwtCanvas canvas4 = new JoglSwtCanvas(settings, canvasRenderer4, bottomRight, SWT.NONE); frameWork.addCanvas(canvas4); canvas4.addControlListener(newResizeHandler(canvas4, canvasRenderer4)); + canvas1.setFocus(); + final SwtKeyboardWrapper keyboardWrapper = new SwtKeyboardWrapper(canvas1); final SwtMouseWrapper mouseWrapper = new SwtMouseWrapper(canvas1); final SwtFocusWrapper focusWrapper = new SwtFocusWrapper(canvas1); @@ -213,6 +215,7 @@ public class JoglSwtExample { logicalLayer.registerInput(canvas1, pl); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.H), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != canvas1) { return; @@ -228,6 +231,7 @@ public class JoglSwtExample { } })); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.J), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != canvas1) { return; @@ -237,6 +241,7 @@ public class JoglSwtExample { } })); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.G), new TriggerAction() { + @Override public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { if (source != canvas1) { return; @@ -247,10 +252,10 @@ public class JoglSwtExample { } })); - final AWTImageLoader awtImageLoader = new AWTImageLoader(); + final JoglImageLoader joglImageLoader = new JoglImageLoader(); try { - _cursor1 = createMouseCursor(awtImageLoader, "com/ardor3d/example/media/input/wait_cursor.png"); - _cursor2 = createMouseCursor(awtImageLoader, "com/ardor3d/example/media/input/movedata.gif"); + _cursor1 = createMouseCursor(joglImageLoader, "com/ardor3d/example/media/input/wait_cursor.png"); + _cursor2 = createMouseCursor(joglImageLoader, "com/ardor3d/example/media/input/movedata.gif"); } catch (final IOException ioe) { ioe.printStackTrace(); } @@ -258,18 +263,20 @@ public class JoglSwtExample { _showCursor1.put(canvas1, true); } - private static MouseCursor createMouseCursor(final AWTImageLoader awtImageLoader, final String resourceName) + private static MouseCursor createMouseCursor(final JoglImageLoader joglImageLoader, final String resourceName) throws IOException { - final com.ardor3d.image.Image image = awtImageLoader.load( + final com.ardor3d.image.Image image = joglImageLoader.load( ResourceLocatorTool.getClassPathResourceAsStream(JoglSwtExample.class, resourceName), false); return new MouseCursor("cursor1", image, 0, image.getHeight() - 1); } - static ControlListener newResizeHandler(final SwtCanvas swtCanvas, final CanvasRenderer canvasRenderer) { + static ControlListener newResizeHandler(final JoglSwtCanvas swtCanvas, final CanvasRenderer canvasRenderer) { final ControlListener retVal = new ControlListener() { + @Override public void controlMoved(final ControlEvent e) {} + @Override public void controlResized(final ControlEvent event) { final Rectangle size = swtCanvas.getClientArea(); if ((size.width == 0) && (size.height == 0)) { @@ -292,6 +299,7 @@ public class JoglSwtExample { private static class MyExit implements Exit { private volatile boolean exit = false; + @Override public void exit() { exit = true; } |