Skip to content

Commit

Permalink
feature : add camera control keyboardEnabledOnlyIfMouseover
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurtil authored Jun 25, 2024
1 parent d5d7874 commit 0020085
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/viewer/scene/CameraControl/CameraControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ class CameraControl extends Component {
snapToEdge: DEFAULT_SNAP_EDGE,
snapRadius: DEFAULT_SNAP_PICK_RADIUS,

keyboardEnabledOnlyIfMouseover: true,

// Rotation

dragRotationRate: 360.0,
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KeyboardAxisViewHandler {
return;
}

if (!states.mouseover) {
if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +53,7 @@ class KeyboardPanRotateDollyHandler {
return;
}

if (!states.mouseover) {
if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) {
return;
}

Expand Down

0 comments on commit 0020085

Please sign in to comment.