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