-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pages): implement space + lmb panning
- Loading branch information
1 parent
d54a5be
commit df9272f
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...s/PagesLayout/MainContent/DisplayPage/DisplayScreens/DisplayWorld/DisplayPanningBoard.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<template> | ||
<div | ||
v-if="enabled" | ||
style="position: absolute; left: 0; top: 0; right: 0; bottom: 0" | ||
:style="{ cursor: grabbing ? 'grabbing' : 'grab' }" | ||
@pointerdown.left="onLeftPointerDown" | ||
></div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { listenPointerEvents, Vec2 } from '@stdlib/misc'; | ||
import { useEventListener } from '@vueuse/core'; | ||
import type { Page } from 'src/code/pages/page/page'; | ||
const page = inject<Page>('page')!; | ||
const enabled = ref(false); | ||
const grabbing = ref(false); | ||
useEventListener('keydown', async (event) => { | ||
const target = event.target as HTMLElement; | ||
const isEditingInput = | ||
target.nodeName === 'INPUT' || | ||
target.nodeName === 'TEXTAREA' || | ||
target.isContentEditable; | ||
if ( | ||
!isEditingInput && | ||
page.activeElem.react.value?.type !== 'note' && | ||
event.code === 'Space' && | ||
!enabled.value | ||
) { | ||
enabled.value = true; | ||
} | ||
}); | ||
useEventListener('keyup', async (event) => { | ||
if (event.code === 'Space') { | ||
enabled.value = false; | ||
} | ||
}); | ||
let lastClientPos: Vec2; | ||
function onLeftPointerDown(event: PointerEvent) { | ||
lastClientPos = new Vec2(event.clientX, event.clientY); | ||
grabbing.value = true; | ||
listenPointerEvents(event, { | ||
move: onLeftPointerMove, | ||
up: onLeftPointerUp, | ||
}); | ||
} | ||
function onLeftPointerMove(event: PointerEvent) { | ||
const clientPos = new Vec2(event.clientX, event.clientY); | ||
const delta = page.sizes.screenToWorld2D(clientPos.sub(lastClientPos)); | ||
page.camera.react.pos = page.camera.react.pos.sub(delta); | ||
lastClientPos = clientPos; | ||
} | ||
function onLeftPointerUp() { | ||
grabbing.value = false; | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters