Skip to content
Snippets Groups Projects
Select Git revision
  • 60487ff328a4cf0798ee27350264ed84823c840b
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

AnnotationItem.js

Blame
  • AnnotationDrawing.js 15.86 KiB
    /* eslint-disable require-jsdoc */
    import React, {
      useEffect, useState, useLayoutEffect,
    } from 'react';
    import ReactDOM from 'react-dom';
    import PropTypes, { object } from 'prop-types';
    import { Stage } from 'react-konva';
    import { v4 as uuidv4 } from 'uuid';
    // eslint-disable-next-line import/no-extraneous-dependencies
    import { OSDReferences } from 'mirador/dist/es/src/plugins/OSDReferences';
    // eslint-disable-next-line import/no-extraneous-dependencies
    import { VideosReferences } from 'mirador/dist/es/src/plugins/VideosReferences';
    import ParentComponent from './AnnotationFormOverlay/KonvaDrawing/shapes/ParentComponent';
    import { SHAPES_TOOL } from '../AnnotationCreationUtils';
    /** All the stuff to draw on the canvas */
    function AnnotationDrawing({ drawingState, setDrawingState, ...props }) {
      const { height, width } = props.mediaVideo ? props.mediaVideo.ref.current : 0;
    
      useEffect(() => {
        const overlay = props.mediaVideo ? props.mediaVideo.ref.current : null;
        if (overlay) {
          props.updateScale(overlay.containerWidth / overlay.canvasWidth);
        }
      }, [{ height, width }]);
    
      useEffect(() => {
        // TODO clean
        if (!props.imageEvent) return;
        if (!props.imageEvent.id) return;
        const shape = {
          id: uuidv4(),
          rotation: 0,
          scaleX: 1,
          scaleY: 1,
          type: 'image',
          url: props.imageEvent.id,
          x: 0,
          y: 0,
        };
    
        setDrawingState({
          ...drawingState,
          currentShape: shape,
          shapes: [...drawingState.shapes, shape],
        });
      }, [props.imageEvent]);
    
      const { fillColor, strokeColor, strokeWidth } = props;
    
      /** */
      /*  useEffect(() => {
        /!*if (!isDrawing) {
          const newCurrentShape = shapes[shapes.length - 1];
          // get latest shape in the list
          if (newCurrentShape) {
            setCurrentShape(newCurrentShape);
          }
        }
        props.updateShapes([...shapes]);*!/
      }, [shapes]); */
    
      useEffect(() => {
        // Perform an action when fillColor, strokeColor, or strokeWidth change
        // update current shape
        if (drawingState.currentShape) {
          drawingState.currentShape.fill = fillColor;
          drawingState.currentShape.stroke = strokeColor;
          drawingState.currentShape.strokeWidth = strokeWidth;
          updateCurrentShapeInShapes(drawingState.currentShape);
        }