Skip to content

Commit 052c45e

Browse files
committed
feat: add camera movement shortcut for trackpad users
1 parent 150ff6a commit 052c45e

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

packages/@dcl/inspector/src/components/Renderer/Shortcuts/Shortcuts.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,16 @@
136136
border-radius: 4px;
137137
background-color: var(--base-13);
138138
}
139+
140+
.Shortcuts > .Overlay .Item .Description.Vertical {
141+
display: flex;
142+
flex-direction: column;
143+
align-items: flex-start;
144+
gap: 12px;
145+
}
146+
147+
.Shortcuts > .Overlay .Item .Description.Vertical > div {
148+
display: flex;
149+
align-items: center;
150+
gap: 4px;
151+
}

packages/@dcl/inspector/src/components/Renderer/Shortcuts/Shortcuts.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,14 @@ const Shortcuts: React.FC<Props> = ({ canvas, onResetCamera, onZoomIn, onZoomOut
8282
</div>
8383
<div className="Item">
8484
<div className="Title">Rotate Camera</div>
85-
<div className="Description">
86-
<span className="Key">Right Mouse Button</span>+<span className="Key">Drag</span>
85+
<div className="Description Vertical">
86+
<div>
87+
<span className="Key">Right Mouse Button</span>+<span className="Key">Drag</span>
88+
</div>
89+
<span className="Option">or</span>
90+
<div>
91+
Hold <span className="Key">{isMac ? 'Option' : 'Alt'}</span>+<span className="Key">Click & Drag</span>
92+
</div>
8793
</div>
8894
</div>
8995
<div className="Item">

packages/@dcl/inspector/src/lib/babylon/decentraland/camera.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import mitt, { Emitter } from 'mitt'
44

55
import { Keys, keyState } from './keys'
66
import { EcsEntity } from './EcsEntity'
7-
import { RIGHT_BUTTON } from './mouse-utils'
7+
import { LEFT_BUTTON, RIGHT_BUTTON } from './mouse-utils'
88
import { fitSphereIntoCameraFrustum } from '../../logic/math'
99
import { PARCEL_SIZE } from '../../utils/scene'
1010

@@ -140,7 +140,7 @@ export class CameraManager {
140140
const mouseInput = camera.inputs.attached.mouse as BABYLON.FreeCameraMouseInput
141141
camera.target = center
142142

143-
mouseInput.buttons = [RIGHT_BUTTON] // disable all buttons except right mouse button
143+
mouseInput.buttons = [RIGHT_BUTTON] // move camera with right mouse button only
144144

145145
camera.inertia = 0
146146
camera.speed = this.speeds[this.speedIndex]
@@ -163,18 +163,30 @@ export class CameraManager {
163163
return false
164164
}
165165

166-
let holdingMouseButton = false
166+
scene.onPreKeyboardObservable.add((ev) => {
167+
const isAltKeyDown = ev.type === BABYLON.KeyboardEventTypes.KEYDOWN && ev.event.inputIndex === Keys.KEY_ALT
168+
169+
if (isAltKeyDown) {
170+
mouseInput.buttons = [LEFT_BUTTON, RIGHT_BUTTON] // move camera with left/right mouse buttons
171+
} else {
172+
mouseInput.buttons = [RIGHT_BUTTON] // move camera with right mouse button only
173+
// reattach control to avoid camera sticking to the pointer bug...
174+
this.reattachControl()
175+
}
176+
})
177+
178+
let holdingRightMouseButton = false
167179
scene.onPointerObservable.add((ev) => {
168180
if (ev.type === BABYLON.PointerEventTypes.POINTERDOWN && ev.event.button === RIGHT_BUTTON) {
169-
holdingMouseButton = true
181+
holdingRightMouseButton = true
170182
}
171183
if (ev.type === BABYLON.PointerEventTypes.POINTERUP && ev.event.button === RIGHT_BUTTON) {
172-
holdingMouseButton = false
184+
holdingRightMouseButton = false
173185
}
174186
if (ev.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
175187
const browserEvent = ev.event as BABYLON.IWheelEvent
176188

177-
if (holdingMouseButton || isCameraMoving()) {
189+
if (holdingRightMouseButton || isCameraMoving()) {
178190
if (browserEvent.deltaY < 0) this.changeSpeed(SpeedIncrement.FASTER)
179191
else if (browserEvent.deltaY > 0) this.changeSpeed(SpeedIncrement.SLOWER)
180192
} else {

packages/@dcl/inspector/src/lib/babylon/decentraland/keys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export enum Keys {
2121
KEY_SHIFT = -1,
2222
KEY_CTRL = -2,
2323
KEY_SPACE = 32,
24+
KEY_ALT = 18,
2425

2526
KEY_E = 69,
2627
KEY_Q = 81

0 commit comments

Comments
 (0)