- enhancedcamera settings and region painter.
- Can send to the back end
This commit is contained in:
@@ -3,12 +3,14 @@ import { Stage, Layer, Image, Shape } from "react-konva";
|
||||
import type { KonvaEventObject } from "konva/lib/Node";
|
||||
import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots";
|
||||
|
||||
import Card from "../../../../ui/Card";
|
||||
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
|
||||
|
||||
const rows = 40;
|
||||
const BACKEND_WIDTH = 640;
|
||||
const BACKEND_HEIGHT = 360;
|
||||
const BACKEND_CELL_SIZE = 16;
|
||||
|
||||
const rows = 22.5;
|
||||
const cols = 40;
|
||||
const size = 20;
|
||||
const gap = 0;
|
||||
|
||||
const VideoFeedGridPainter = () => {
|
||||
@@ -19,9 +21,12 @@ const VideoFeedGridPainter = () => {
|
||||
const selectedRegionIndex = state.selectedRegionIndex;
|
||||
const mode = state.modeByCamera[cameraFeedID];
|
||||
const { latestBitmapRef, isloading } = useCreateVideoSnapshot();
|
||||
const [stageSize, setStageSize] = useState({ width: 740, height: 460 });
|
||||
const [stageSize, setStageSize] = useState({ width: BACKEND_WIDTH, height: BACKEND_HEIGHT });
|
||||
const isDrawingRef = useRef(false);
|
||||
|
||||
const currentScale = stageSize.width / BACKEND_WIDTH;
|
||||
const size = BACKEND_CELL_SIZE * currentScale;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const paintLayerRef = useRef<any>(null);
|
||||
|
||||
@@ -60,7 +65,7 @@ const VideoFeedGridPainter = () => {
|
||||
|
||||
if (existing && existing.colour === currentColour) return;
|
||||
|
||||
map.set(key, { colour: currentColour });
|
||||
map.set(key, { colour: currentColour, region: activeRegion });
|
||||
|
||||
paintLayerRef.current?.batchDraw();
|
||||
};
|
||||
@@ -87,25 +92,25 @@ const VideoFeedGridPainter = () => {
|
||||
const handleResize = () => {
|
||||
const width = window.innerWidth;
|
||||
|
||||
const aspectRatio = 740 / 460;
|
||||
const aspectRatio = BACKEND_WIDTH / BACKEND_HEIGHT;
|
||||
const newWidth = width * 0.39;
|
||||
const newHeight = newWidth / aspectRatio;
|
||||
setStageSize({ width: newWidth, height: newHeight });
|
||||
};
|
||||
|
||||
handleResize();
|
||||
window.addEventListener("resize", handleResize);
|
||||
|
||||
return () => window.removeEventListener("resize", handleResize);
|
||||
}, []);
|
||||
|
||||
if (image === null || isloading)
|
||||
return (
|
||||
<Card className="row-span-3 col-span-2 rounded-lg p-4 w-full">
|
||||
<span className="text-slate-500">Loading Video feed…</span>
|
||||
</Card>
|
||||
);
|
||||
if (image === null || isloading) return <span className="text-slate-500">Loading Video feed…</span>;
|
||||
return (
|
||||
<div className="mt-4.5 row-span-1 col-span-2">
|
||||
<div
|
||||
className={`mt-4.5 row-span-1 col-span-2 ${mode === "painter" ? "hover:cursor-crosshair" : ""} ${
|
||||
mode === "eraser" ? "hover:cursor-pointer" : ""
|
||||
}`}
|
||||
>
|
||||
<Stage
|
||||
width={stageSize.width}
|
||||
height={stageSize.height}
|
||||
|
||||
Reference in New Issue
Block a user