From 2fe3bc6dc6ff8c70a19fafef7c30bb4c3dd2d751 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Wed, 27 Jul 2011 17:49:14 +0000 Subject: [PATCH] SDK : - fixed key event dispatching from sceneViewer to oglpanel - added a useCameraControl to avoid to have to override the onAnalog in each cameraController - added alternate way to rotate camera wuth the third mouse button - changed position of the view toolbar git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7929 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3/gde/core/scene/SceneApplication.java | 14 +-- .../gde/core/scene/SceneCameraController.java | 5 + .../controller/AbstractCameraController.java | 106 ++++++++++++------ .../controller/toolbars/CameraToolbar.java | 2 +- .../sceneviewer/SceneViewerTopComponent.java | 45 +++++--- .../actions/SwitchBackViewAction.java | 2 +- .../actions/SwitchBottomViewAction.java | 2 +- .../actions/SwitchFrontViewAction.java | 2 +- .../actions/SwitchLeftViewAction.java | 2 +- .../actions/SwitchRightViewAction.java | 2 +- .../actions/SwitchTopViewAction.java | 2 +- .../actions/ToggleOrthoPerspAction.java | 2 +- 12 files changed, 118 insertions(+), 68 deletions(-) diff --git a/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java b/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java index 150ff0a67..491dcace4 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java @@ -136,11 +136,7 @@ public class SceneApplication extends Application implements LookupProvider, Loo } } - public SceneCameraController getActiveCameraController() { - stateManager.getState(null); - return camController; - } - + private void loadFPSText() { @@ -385,8 +381,8 @@ public class SceneApplication extends Application implements LookupProvider, Loo } toolsNode.detachAllChildren(); rootNode.detachAllChildren(); - setHelpContext(null); - resetCam(); + setHelpContext(null); + // resetCam(); currentSceneRequest = null; lastError = ""; java.awt.EventQueue.invokeLater(new Runnable() { @@ -536,11 +532,11 @@ public class SceneApplication extends Application implements LookupProvider, Loo return progressHandle; } - public AbstractCameraController getActiveCamController() { + public AbstractCameraController getActiveCameraController() { return activeCamController; } - public void setActiveCamController(AbstractCameraController activeCamController) { + public void setActiveCameraController(AbstractCameraController activeCamController) { this.activeCamController = activeCamController; } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneCameraController.java b/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneCameraController.java index af2636b67..464092139 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneCameraController.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/scene/SceneCameraController.java @@ -49,4 +49,9 @@ public class SceneCameraController extends AbstractCameraController { protected void checkClick(int button, boolean pressed) { } + @Override + public boolean useCameraControls() { + return true; + } + } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/scene/controller/AbstractCameraController.java b/sdk/jme3-core/src/com/jme3/gde/core/scene/controller/AbstractCameraController.java index ef43f2622..0e92718d5 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/scene/controller/AbstractCameraController.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/scene/controller/AbstractCameraController.java @@ -32,6 +32,7 @@ import com.jme3.gde.core.scene.controller.toolbars.CameraToolbar; import com.jme3.gde.core.sceneviewer.SceneViewerTopComponent; import com.jme3.gde.core.util.CameraUtil.View; import com.jme3.input.InputManager; +import com.jme3.input.KeyInput; import com.jme3.input.RawInputListener; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.AnalogListener; @@ -81,6 +82,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen protected boolean checkDraggedR = false; protected boolean checkReleaseLeft = false; protected boolean checkReleaseRight = false; + protected boolean shiftModifier = false; public AbstractCameraController(Camera cam, InputManager inputManager) { this.cam = cam; @@ -96,35 +98,51 @@ public abstract class AbstractCameraController extends AbstractAppState implemen inputManager.addRawInputListener(this); inputManager.addListener(this, "MouseAxisX", "MouseAxisY", "MouseAxisX-", "MouseAxisY-", "MouseWheel", "MouseWheel-", "MouseButtonLeft", "MouseButtonMiddle", "MouseButtonRight"); SceneApplication.getApplication().getStateManager().attach(this); - SceneApplication.getApplication().setActiveCamController(this); + AbstractCameraController cc = SceneApplication.getApplication().getActiveCameraController(); + if (cc != null) { + cam.setLocation(cc.cam.getLocation()); + focus.set(cc.focus); + } + + SceneApplication.getApplication().setActiveCameraController(this); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { - - SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance(); - if (svtc != null) { - svtc.addAdditionnalToolbar(CameraToolbar.getInstance()); - } - + addAdditionnalToolbar(); } }); } + private void addAdditionnalToolbar() { + SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance(); + if (svtc != null) { + svtc.add(CameraToolbar.getInstance(), java.awt.BorderLayout.SOUTH);; + } + + } + + public void removeAdditionnalToolbar() { + + SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance(); + System.out.println("test remove" + svtc); + if (svtc != null) { + svtc.remove(CameraToolbar.getInstance()); + } + } + public void disable() { inputManager.removeRawInputListener(this); inputManager.removeListener(this); SceneApplication.getApplication().getStateManager().detach(this); - java.awt.EventQueue.invokeLater(new Runnable() { + if (SceneApplication.getApplication().getActiveCameraController() == this) { + java.awt.EventQueue.invokeLater(new Runnable() { - public void run() { + public void run() { + removeAdditionnalToolbar(); - SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance(); - if (svtc != null) { - svtc.removeAdditionnalToolbar(CameraToolbar.getInstance()); } - - } - }); + }); + } } public void setCamFocus(final Vector3f focus) { @@ -160,7 +178,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen Quaternion curRot = cam.getRotation().clone(); cam.setRotation(rot.mult(curRot)); - java.awt.EventQueue.invokeLater(new Runnable() { + java.awt.EventQueue.invokeLater(new Runnable() { public void run() { @@ -225,32 +243,32 @@ public abstract class AbstractCameraController extends AbstractAppState implemen float dist = cam.getLocation().distance(focus); switch (view) { case Front: - cam.setLocation(new Vector3f(focus.x, focus.y, focus.z+dist)); + cam.setLocation(new Vector3f(focus.x, focus.y, focus.z + dist)); cam.lookAt(focus, Vector3f.UNIT_Y); break; case Left: - cam.setLocation(new Vector3f(focus.x+dist, focus.y, focus.z)); - cam.lookAt(focus, Vector3f.UNIT_Y); + cam.setLocation(new Vector3f(focus.x + dist, focus.y, focus.z)); + cam.lookAt(focus, Vector3f.UNIT_Y); break; case Right: - cam.setLocation(new Vector3f(focus.x-dist, focus.y, focus.z)); + cam.setLocation(new Vector3f(focus.x - dist, focus.y, focus.z)); cam.lookAt(focus, Vector3f.UNIT_Y); break; case Back: - cam.setLocation(new Vector3f(focus.x, focus.y, focus.z-dist)); + cam.setLocation(new Vector3f(focus.x, focus.y, focus.z - dist)); cam.lookAt(focus, Vector3f.UNIT_Y); break; - case Top: - cam.setLocation(new Vector3f(focus.x, focus.y+dist, focus.z)); + case Top: + cam.setLocation(new Vector3f(focus.x, focus.y + dist, focus.z)); cam.lookAt(focus, Vector3f.UNIT_Z.mult(-1)); - + break; case Bottom: - cam.setLocation(new Vector3f(focus.x, focus.y-dist, focus.z)); + cam.setLocation(new Vector3f(focus.x, focus.y - dist, focus.z)); cam.lookAt(focus, Vector3f.UNIT_Z); break; case User: - default: + default: } return null; } @@ -279,43 +297,53 @@ public abstract class AbstractCameraController extends AbstractAppState implemen } } + public abstract boolean useCameraControls(); + public void onAnalog(String string, float f1, float f) { if ("MouseAxisX".equals(string)) { moved = true; movedR = true; - if (buttonDownL || buttonDownM) { + + if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) { rotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f); } - if (buttonDownR) { + if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) { panCamera(f1 * 2.5f, 0); } + } else if ("MouseAxisY".equals(string)) { moved = true; movedR = true; - if (buttonDownL || buttonDownM) { + + if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) { rotateCamera(cam.getLeft(), -f1 * 2.5f); } - if (buttonDownR) { + if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) { panCamera(0, -f1 * 2.5f); } + } else if ("MouseAxisX-".equals(string)) { moved = true; movedR = true; - if (buttonDownL || buttonDownM) { + + if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) { rotateCamera(Vector3f.UNIT_Y, f1 * 2.5f); } - if (buttonDownR) { + if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) { panCamera(-f1 * 2.5f, 0); } + } else if ("MouseAxisY-".equals(string)) { moved = true; movedR = true; - if (buttonDownL || buttonDownM) { + + if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) { rotateCamera(cam.getLeft(), f1 * 2.5f); } - if (buttonDownR) { + if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) { panCamera(0, f1 * 2.5f); } + } else if ("MouseWheel".equals(string)) { zoomCamera(.1f); } else if ("MouseWheel-".equals(string)) { @@ -355,6 +383,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen buttonDownR = pressed; } if ("MouseButtonMiddle".equals(string)) { + if (pressed) { if (!buttonDownM) { // mouse clicked checkClickM = true; @@ -398,6 +427,15 @@ public abstract class AbstractCameraController extends AbstractAppState implemen } public void onKeyEvent(KeyInputEvent kie) { + if (kie.isPressed()) { + if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) { + shiftModifier = true; + } + } else if (kie.isReleased()) { + if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) { + shiftModifier = false; + } + } } public void onTouchEvent(TouchEvent evt) { diff --git a/sdk/jme3-core/src/com/jme3/gde/core/scene/controller/toolbars/CameraToolbar.java b/sdk/jme3-core/src/com/jme3/gde/core/scene/controller/toolbars/CameraToolbar.java index e55679495..8a14996c0 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/scene/controller/toolbars/CameraToolbar.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/scene/controller/toolbars/CameraToolbar.java @@ -177,7 +177,7 @@ public class CameraToolbar extends javax.swing.JToolBar { }// //GEN-END:initComponents private void viewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewButtonActionPerformed - viewMenu.show(viewButton, viewButton.getX(), viewButton.getY() + viewButton.getHeight()); + viewMenu.show(viewButton, 0,- viewMenu.getHeight()); }//GEN-LAST:event_viewButtonActionPerformed private void frontMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_frontMenuItemActionPerformed diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/SceneViewerTopComponent.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/SceneViewerTopComponent.java index 3f42bd8a5..3556e791f 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/SceneViewerTopComponent.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/SceneViewerTopComponent.java @@ -28,8 +28,12 @@ import com.jme3.gde.core.filters.FilterExplorerTopComponent; import com.jme3.gde.core.scene.SceneApplication; import com.jme3.gde.core.scene.controller.toolbars.CameraToolbar; import com.jme3.gde.core.sceneviewer.actions.ToggleOrthoPerspAction; +import com.jme3.input.awt.AwtKeyInput; +import com.jme3.input.event.KeyInputEvent; import com.jme3.system.JmeCanvasContext; import java.awt.Canvas; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.util.logging.Logger; @@ -63,7 +67,6 @@ public final class SceneViewerTopComponent extends TopComponent { private SceneApplication app; private HelpCtx helpContext = new HelpCtx("com.jme3.gde.core.sceneviewer"); private Canvas oglCanvas; - public SceneViewerTopComponent() { initComponents(); @@ -71,12 +74,12 @@ public final class SceneViewerTopComponent extends TopComponent { setFocusable(true); setName(NbBundle.getMessage(SceneViewerTopComponent.class, "CTL_SceneViewerTopComponent")); setToolTipText(NbBundle.getMessage(SceneViewerTopComponent.class, "HINT_SceneViewerTopComponent")); - setIcon(ImageUtilities.loadImage(ICON_PATH, true)); + setIcon(ImageUtilities.loadImage(ICON_PATH, true)); try { app = SceneApplication.getApplication(); oglCanvas = ((JmeCanvasContext) app.getContext()).getCanvas(); oGLPanel.add(oglCanvas); - + } catch (Exception e) { Exceptions.printStackTrace(e); showOpenGLError(e.toString()); @@ -94,11 +97,30 @@ public final class SceneViewerTopComponent extends TopComponent { if (e.getWheelRotation() < 0) { action = "MouseWheel"; } - app.getActiveCamController().onAnalog(action, e.getWheelRotation(), 0); + app.getActiveCameraController().onAnalog(action, e.getWheelRotation(), 0); + } + }); + addKeyListener(new KeyListener() { + + public void keyTyped(KeyEvent evt) { + } + + public void keyPressed(KeyEvent evt) { + int code = AwtKeyInput.convertAwtKey(evt.getKeyCode()); + KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false); + keyEvent.setTime(evt.getWhen()); + app.getActiveCameraController().onKeyEvent(keyEvent); + } + + public void keyReleased(KeyEvent evt) { + int code = AwtKeyInput.convertAwtKey(evt.getKeyCode()); + KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, false); + keyEvent.setTime(evt.getWhen()); + + app.getActiveCameraController().onKeyEvent(keyEvent); } }); - - + } /** This method is called from within the constructor to @@ -200,7 +222,6 @@ public final class SceneViewerTopComponent extends TopComponent { private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed FilterExplorerTopComponent.findInstance().setFilterEnabled(jToggleButton1.isSelected()); }//GEN-LAST:event_jToggleButton1ActionPerformed - // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JToggleButton enableCamLight; private javax.swing.JToggleButton enableStats; @@ -212,7 +233,6 @@ public final class SceneViewerTopComponent extends TopComponent { private javax.swing.JPanel oGLPanel; // End of variables declaration//GEN-END:variables - /** * Gets default instance. Do not use directly: reserved for *.settings files only, * i.e. deserialization routines; otherwise you could get a non-deserialized instance. @@ -324,13 +344,4 @@ public final class SceneViewerTopComponent extends TopComponent { public UndoRedo getUndoRedo() { return Lookup.getDefault().lookup(UndoRedo.class); } - - - public void addAdditionnalToolbar(JToolBar tb){ - jToolBar1.add(tb,4); - } - - public void removeAdditionnalToolbar(JToolBar tb){ - jToolBar1.remove(tb); - } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBackViewAction.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBackViewAction.java index 033918a76..69cee51b4 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBackViewAction.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBackViewAction.java @@ -25,7 +25,7 @@ public final class SwitchBackViewAction implements ActionListener { if (svtc.hasFocus()) { - SceneApplication.getApplication().getActiveCamController().switchToView(View.Back); + SceneApplication.getApplication().getActiveCameraController().switchToView(View.Back); } } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBottomViewAction.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBottomViewAction.java index 0b1969a99..28d8a165f 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBottomViewAction.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBottomViewAction.java @@ -25,7 +25,7 @@ public final class SwitchBottomViewAction implements ActionListener { if (svtc.hasFocus()) { - SceneApplication.getApplication().getActiveCamController().switchToView(View.Bottom); + SceneApplication.getApplication().getActiveCameraController().switchToView(View.Bottom); } } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchFrontViewAction.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchFrontViewAction.java index be6cc8e0a..4357dbfd4 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchFrontViewAction.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchFrontViewAction.java @@ -26,7 +26,7 @@ public final class SwitchFrontViewAction implements ActionListener { if (svtc.hasFocus()) { - SceneApplication.getApplication().getActiveCamController().switchToView(View.Front); + SceneApplication.getApplication().getActiveCameraController().switchToView(View.Front); } } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchLeftViewAction.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchLeftViewAction.java index eba3913d4..5c3436fa4 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchLeftViewAction.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchLeftViewAction.java @@ -25,7 +25,7 @@ public final class SwitchLeftViewAction implements ActionListener { if (svtc.hasFocus()) { - SceneApplication.getApplication().getActiveCamController().switchToView(View.Left); + SceneApplication.getApplication().getActiveCameraController().switchToView(View.Left); } } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchRightViewAction.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchRightViewAction.java index c78aa6360..9988680e3 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchRightViewAction.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchRightViewAction.java @@ -25,7 +25,7 @@ public final class SwitchRightViewAction implements ActionListener { if (svtc.hasFocus()) { - SceneApplication.getApplication().getActiveCamController().switchToView(View.Right); + SceneApplication.getApplication().getActiveCameraController().switchToView(View.Right); } } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchTopViewAction.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchTopViewAction.java index 29715e0b6..5b84ca387 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchTopViewAction.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchTopViewAction.java @@ -25,7 +25,7 @@ public final class SwitchTopViewAction implements ActionListener { if (svtc.hasFocus()) { - SceneApplication.getApplication().getActiveCamController().switchToView(View.Top); + SceneApplication.getApplication().getActiveCameraController().switchToView(View.Top); } } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/ToggleOrthoPerspAction.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/ToggleOrthoPerspAction.java index cc338bfd7..cbbdb4dc0 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/ToggleOrthoPerspAction.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/ToggleOrthoPerspAction.java @@ -28,7 +28,7 @@ public final class ToggleOrthoPerspAction implements ActionListener { SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance(); if (svtc.hasFocus()) { - SceneApplication.getApplication().getActiveCamController().toggleOrthoPerspMode(); + SceneApplication.getApplication().getActiveCameraController().toggleOrthoPerspMode(); } }