limit interpolated coordinates and use crosshair cursor

This commit is contained in:
Josh Hawkins 2024-04-18 11:40:30 -05:00
parent 083ca94c48
commit 565629871b
2 changed files with 25 additions and 2 deletions

View File

@ -222,6 +222,27 @@ export function PolygonCanvas({
} }
}; };
const handleStageMouseOver = (
e: Konva.KonvaEventObject<MouseEvent | TouchEvent>,
) => {
if (activePolygonIndex === undefined || !polygons) {
return;
}
const updatedPolygons = [...polygons];
const activePolygon = updatedPolygons[activePolygonIndex];
if (activePolygon.isFinished) return;
e.target.getStage()!.container().style.cursor = "crosshair";
};
const handleStageMouseOut = (
e: Konva.KonvaEventObject<MouseEvent | TouchEvent>,
) => {
if (!e.target) return;
e.target.getStage()!.container().style.cursor = "default";
};
return ( return (
<Stage <Stage
ref={stageRef} ref={stageRef}
@ -229,6 +250,8 @@ export function PolygonCanvas({
height={height} height={height}
onMouseDown={handleMouseDown} onMouseDown={handleMouseDown}
onTouchStart={handleMouseDown} onTouchStart={handleMouseDown}
onMouseOver={handleStageMouseOver}
onMouseOut={handleStageMouseOut}
> >
<Layer> <Layer>
<Image <Image

View File

@ -56,8 +56,8 @@ export const interpolatePoints = (
const newPoints: number[][] = []; const newPoints: number[][] = [];
for (const [x, y] of points) { for (const [x, y] of points) {
const newX = +((x * newWidth) / width).toFixed(3); const newX = Math.min(+((x * newWidth) / width).toFixed(3), newWidth);
const newY = +((y * newHeight) / height).toFixed(3); const newY = Math.min(+((y * newHeight) / height).toFixed(3), newHeight);
newPoints.push([newX, newY]); newPoints.push([newX, newY]);
} }