- improved ui for region selector and camera settings

This commit is contained in:
2025-11-25 14:57:18 +00:00
parent 6ecb005417
commit 18124924f7
7 changed files with 133 additions and 58 deletions

View File

@@ -2,7 +2,7 @@ import { useEffect, useRef, useState, type RefObject } from "react";
import { Stage, Layer, Image, Shape } from "react-konva";
import type { KonvaEventObject } from "konva/lib/Node";
import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots";
import type { Region } from "../../../../types/types";
import type { PaintedCell, Region } from "../../../../types/types";
import Card from "../../../../ui/Card";
const rows = 40;
@@ -14,17 +14,14 @@ type VideoFeedGridPainterProps = {
regions: Region[];
selectedRegionIndex: number;
mode: string;
paintedCells: RefObject<Map<string, PaintedCell>>;
};
type PaintedCell = {
colour: string;
};
const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode }: VideoFeedGridPainterProps) => {
const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode, paintedCells }: VideoFeedGridPainterProps) => {
const { latestBitmapRef, isloading } = useCreateVideoSnapshot();
const [stageSize, setStageSize] = useState({ width: 740, height: 460 });
const isDrawingRef = useRef(false);
const paintedCellsRef = useRef<Map<string, PaintedCell>>(new Map());
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const paintLayerRef = useRef<any>(null);
@@ -50,7 +47,7 @@ const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode }: VideoFeedG
const key = `${row}-${col}`;
const currentColour = regions[selectedRegionIndex].brushColour;
const map = paintedCellsRef.current;
const map = paintedCells.current;
const existing = map.get(key);
if (mode === "eraser") {
@@ -103,12 +100,12 @@ const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode }: VideoFeedG
if (image === null || isloading)
return (
<Card className="row-span-1 col-span-2 rounded-lg p-4 w-full">
<Card className="row-span-3 col-span-2 rounded-lg p-4 w-full">
<span className="text-slate-500">Loading Video feed</span>
</Card>
);
return (
<div className="row-span-1 col-span-2 rounded-lg">
<div className="mt-4.5 row-span-1 col-span-2">
<Stage
width={stageSize.width}
height={stageSize.height}
@@ -124,7 +121,7 @@ const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode }: VideoFeedG
<Layer ref={paintLayerRef} opacity={0.6}>
<Shape
sceneFunc={(ctx, shape) => {
const cells = paintedCellsRef.current;
const cells = paintedCells.current;
cells.forEach((cell, key) => {
const [rowStr, colStr] = key.split("-");
const row = Number(rowStr);