Skip to content

Commit

Permalink
rector: turn drawEvent into composable
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrosman committed May 12, 2024
1 parent 508a09f commit 3ffff52
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/components/PaintEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,27 @@ function getActiveTool() {
return props.tools?.find(tool => tool.type === settings.value.tool)
}
function getDrawEvent(): DrawEvent {
return {
settings: settings.value,
activeShape,
isDrawing: isSwiping,
tools: props.tools,
posStart, posEnd,
left, right, top, bottom,
width, height,
minX, maxX, minY, maxY
}
}
const drawEvent = computed<DrawEvent>(() => ({
settings: settings.value,
activeShape,
isDrawing: isSwiping,
tools: props.tools,
posStart, posEnd,
left, right, top, bottom,
width, height,
minX, maxX, minY, maxY
}))
const { posStart, posEnd, isSwiping } = usePointerSwipe(svgRef, {
threshold: 0,
onSwipeStart(e) {
const activeTool = getActiveTool()
const drawEvent = getDrawEvent()
activeShape.value = activeTool?.onDrawStart?.(drawEvent) ?? activeShape.value
activeShape.value = getActiveTool()?.onDrawStart?.(drawEvent.value) ?? activeShape.value
},
onSwipe(e) {
const activeTool = getActiveTool()
const drawEvent = getDrawEvent()
activeShape.value = activeTool?.onDraw?.(drawEvent) ?? activeShape.value
activeShape.value = getActiveTool()?.onDraw?.(drawEvent.value) ?? activeShape.value
},
onSwipeEnd() {
const activeTool = getActiveTool()
const drawEvent = getDrawEvent()
activeShape.value = activeTool?.onDrawEnd?.(drawEvent) ?? activeShape.value
activeShape.value = getActiveTool()?.onDrawEnd?.(drawEvent.value) ?? activeShape.value
if (activeShape.value) {
history.value.push(activeShape.value)
activeShape.value = undefined
Expand Down

0 comments on commit 3ffff52

Please sign in to comment.