From 002008590f23021b46eb43b20e386b970364b997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20LAGIER?= Date: Tue, 25 Jun 2024 17:49:10 +0200 Subject: [PATCH] feature : add camera control keyboardEnabledOnlyIfMouseover --- .../scene/CameraControl/CameraControl.js | 20 +++++++++++++++++++ .../lib/handlers/KeyboardAxisViewHandler.js | 2 +- .../handlers/KeyboardPanRotateDollyHandler.js | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/viewer/scene/CameraControl/CameraControl.js b/src/viewer/scene/CameraControl/CameraControl.js index 0ecab2c743..8c552b3448 100644 --- a/src/viewer/scene/CameraControl/CameraControl.js +++ b/src/viewer/scene/CameraControl/CameraControl.js @@ -649,6 +649,8 @@ class CameraControl extends Component { snapToEdge: DEFAULT_SNAP_EDGE, snapRadius: DEFAULT_SNAP_PICK_RADIUS, + keyboardEnabledOnlyIfMouseover: true, + // Rotation dragRotationRate: 360.0, @@ -959,6 +961,24 @@ class CameraControl extends Component { get snapRadius() { return this._configs.snapRadius; } + + /** + * If `true`, the keyboard shortcuts are enabled ONLY if the mouse is over the canvas. + * + * @param {boolean} value + */ + set keyboardEnabledOnlyIfMouseover(value) { + this._configs.keyboardEnabledOnlyIfMouseover = !!value; + } + + /** + * Gets whether the keyboard shortcuts are enabled ONLY if the mouse is over the canvas or ALWAYS. + * + * @returns {boolean} + */ + get keyboardEnabledOnlyIfMouseover() { + return this._configs.keyboardEnabledOnlyIfMouseover; + } /** * Sets the current navigation mode. diff --git a/src/viewer/scene/CameraControl/lib/handlers/KeyboardAxisViewHandler.js b/src/viewer/scene/CameraControl/lib/handlers/KeyboardAxisViewHandler.js index a1bb852033..ede42ce3a5 100644 --- a/src/viewer/scene/CameraControl/lib/handlers/KeyboardAxisViewHandler.js +++ b/src/viewer/scene/CameraControl/lib/handlers/KeyboardAxisViewHandler.js @@ -29,7 +29,7 @@ class KeyboardAxisViewHandler { return; } - if (!states.mouseover) { + if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) { return; } diff --git a/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js b/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js index 2076aaff1a..ec82fec9ee 100644 --- a/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js +++ b/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js @@ -22,7 +22,7 @@ class KeyboardPanRotateDollyHandler { if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) { return; } - if (!states.mouseover) { + if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) { return; } keyDownMap[keyCode] = true; @@ -53,7 +53,7 @@ class KeyboardPanRotateDollyHandler { return; } - if (!states.mouseover) { + if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) { return; }