24 lines
679 B
JavaScript
24 lines
679 B
JavaScript
import { useRecoilValue } from 'recoil'
|
|
import { canvasState } from '@/store/canvasAtom'
|
|
import { calculateIntersection, getInterSectionLineNotOverCoordinate } from '@/util/canvas-util'
|
|
|
|
export function useMouse() {
|
|
const canvas = useRecoilValue(canvasState)
|
|
|
|
//가로선, 세로선의 교차점을 return
|
|
const getIntersectMousePoint = (e) => {
|
|
let pointer = canvas.getPointer(e.e)
|
|
const mouseLines = canvas.getObjects().filter((obj) => obj.name === 'mouseLine')
|
|
|
|
if (mouseLines.length < 2) {
|
|
return pointer
|
|
}
|
|
|
|
return getInterSectionLineNotOverCoordinate(mouseLines[0], mouseLines[1]) || pointer
|
|
}
|
|
|
|
return {
|
|
getIntersectMousePoint,
|
|
}
|
|
}
|