fix(tools): cross
This commit is contained in:
@@ -21,6 +21,7 @@ const CrosshairComponent = (
|
||||
const { scale } = useTopToolsStore()
|
||||
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null)
|
||||
const lastPointerRef = useRef<{ x: number; y: number } | null>(null)
|
||||
|
||||
const getFixed = (sparsity: number) => {
|
||||
const pointIdx = String(sparsity).indexOf(".")
|
||||
@@ -76,6 +77,7 @@ const CrosshairComponent = (
|
||||
ctx.beginPath()
|
||||
ctx.setLineDash([])
|
||||
ctx.strokeStyle = "#EF4444"
|
||||
ctx.fillStyle = "#EF4444"
|
||||
let carveLineWidth = 1
|
||||
ctx.lineWidth = carveLineWidth
|
||||
|
||||
@@ -100,6 +102,7 @@ const CrosshairComponent = (
|
||||
sparsity
|
||||
).toFixed(fixed)
|
||||
const textWidth = ctx.measureText(text).width
|
||||
ctx.fillStyle = "#EF4444"
|
||||
ctx.fillText(text, indexX - textWidth / 2, centerY - tickLength)
|
||||
} else {
|
||||
ctx.moveTo(indexX, centerY - tickLength / 2 - carveLineWidth)
|
||||
@@ -143,7 +146,11 @@ const CrosshairComponent = (
|
||||
canvas.width = window.innerWidth
|
||||
canvas.height = window.innerHeight
|
||||
const rect = canvas.getBoundingClientRect()
|
||||
drawCrosshair(rect.width / 2, rect.height / 2)
|
||||
const center = lastPointerRef.current || {
|
||||
x: rect.width / 2,
|
||||
y: rect.height / 2,
|
||||
}
|
||||
drawCrosshair(center.x, center.y)
|
||||
}
|
||||
}, [drawCrosshair])
|
||||
|
||||
@@ -153,6 +160,7 @@ const CrosshairComponent = (
|
||||
const rect = canvas.getBoundingClientRect()
|
||||
const centerX = event.clientX - rect.left
|
||||
const centerY = event.clientY - rect.top
|
||||
lastPointerRef.current = { x: centerX, y: centerY }
|
||||
drawCrosshair(centerX, centerY)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user