2023-10-29 22:02:07 +03:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed, ref, shallowRef } from 'vue'
|
|
|
|
|
2024-01-25 12:41:37 +03:00
|
|
|
import { usePointer } from '@/composables/events'
|
2024-08-08 15:12:05 +03:00
|
|
|
import { useKeyboard } from '@/composables/keyboard'
|
2024-01-25 12:41:37 +03:00
|
|
|
import { useNavigator } from '@/composables/navigator'
|
2023-12-19 20:58:11 +03:00
|
|
|
import type { Vec2 } from '@/util/data/vec2'
|
2023-10-29 22:02:07 +03:00
|
|
|
|
|
|
|
const viewportNode = ref<HTMLElement>()
|
|
|
|
|
2024-08-08 15:12:05 +03:00
|
|
|
const keyboard = useKeyboard()
|
|
|
|
const navigator = useNavigator(viewportNode, keyboard)
|
2023-10-29 22:02:07 +03:00
|
|
|
|
|
|
|
const selectionAnchor = shallowRef<Vec2>()
|
|
|
|
|
|
|
|
const selection = usePointer((_, __, eventType) => {
|
|
|
|
if (selection.dragging && selectionAnchor.value == null) {
|
|
|
|
selectionAnchor.value = navigator.sceneMousePos?.copy()
|
|
|
|
} else if (eventType === 'stop') {
|
|
|
|
selectionAnchor.value = undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const scaledMousePos = computed(() => navigator.sceneMousePos?.scale(navigator.scale))
|
|
|
|
const scaledSelectionAnchor = computed(() => selectionAnchor.value?.scale(navigator.scale))
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-09-20 19:31:45 +03:00
|
|
|
<div ref="viewportNode" style="cursor: none; height: 100%" v-on="selection.events">
|
2023-10-29 22:02:07 +03:00
|
|
|
<slot
|
|
|
|
:scaledMousePos="scaledMousePos"
|
|
|
|
:scaledSelectionAnchor="scaledSelectionAnchor"
|
|
|
|
:navigator="navigator"
|
|
|
|
></slot>
|
|
|
|
</div>
|
|
|
|
</template>
|