Skip to content
Snippets Groups Projects
Commit dc5af89b authored by Samuel Jugnet's avatar Samuel Jugnet
Browse files

polygon + get latest shape after delete

parent ede3d6f5
Branches
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
Pipeline #1761 failed
...@@ -100,9 +100,12 @@ function AnnotationDrawing(props) { ...@@ -100,9 +100,12 @@ function AnnotationDrawing(props) {
const newShapes = shapes.filter((shape) => shape.id !== currentShape.id); const newShapes = shapes.filter((shape) => shape.id !== currentShape.id);
setShapes(newShapes); setShapes(newShapes);
setCurrentShape(null); // get latest shape in the list
const newCurrentShape = newShapes[newShapes.length - 1];
setCurrentShape(newShapes.length > 0 ? newCurrentShape : null);
window.removeEventListener('keydown', handleKeyPress);
// window.removeEventListener('keydown', handleKeyPress);
return; return;
} }
...@@ -220,20 +223,21 @@ function AnnotationDrawing(props) { ...@@ -220,20 +223,21 @@ function AnnotationDrawing(props) {
// window.addEventListener('keydown', handleKeyPress); // window.addEventListener('keydown', handleKeyPress);
break; break;
case 'freehand': case 'polygon':
setIsDrawing(true); setIsDrawing(true);
// eslint-disable-next-line no-case-declarations // eslint-disable-next-line no-case-declarations
const tool = 'pen';
shape = { shape = {
fill: props.fillColor, fill: props.fillColor,
height: 10, stroke: props.strokeColor,
id: uuidv4(), id: uuidv4(),
lines: [pos.x, pos.y],
points: [0, 0, 0, 0, 0, 0], points: [pos.x, pos.y],
type: 'freehand', type: 'polygon',
width: 10,
x: pos.x, x: 0,
y: pos.y, y: 0,
}; };
// shape = { // shape = {
// fill: props.fillColor, // fill: props.fillColor,
...@@ -341,18 +345,16 @@ function AnnotationDrawing(props) { ...@@ -341,18 +345,16 @@ function AnnotationDrawing(props) {
updateCurrentShapeInShapes(); updateCurrentShapeInShapes();
break; break;
case 'freehand': case 'polygon':
const freehandShape = {...currentShape} const polygonShape = {...currentShape}
freehandShape.points.push(pos.x ); polygonShape.points[2] = pos.x;
freehandShape.points.push(pos.y ); polygonShape.points[3] = pos.y;
setCurrentShape(polygonShape);
setCurrentShape(freehandShape);
// setShapes(shapes.map((shape) => (shape.id === currentShape.id
// ? { ...shape, points: [...shape.points, e.evt.clientX, e.evt.clientY] }
// : shape)));
updateCurrentShapeInShapes(); updateCurrentShapeInShapes();
......
...@@ -2,12 +2,13 @@ import React, { useState, useEffect } from 'react'; ...@@ -2,12 +2,13 @@ import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Layer } from 'react-konva'; import { Layer } from 'react-konva';
import FreeHand from './FreeHand';
import Rectangle from './Rectangle'; import Rectangle from './Rectangle';
import EllipseNode from './EllipseNode'; import EllipseNode from './EllipseNode';
import TextNode from './TextNode'; import TextNode from './TextNode';
import LineNode from './LineNode'; import LineNode from './LineNode';
import ArrowNode from './ArrowNode'; import ArrowNode from './ArrowNode';
import Polygon from './Polygon';
/** Loads Konva and display in function of their type */ /** Loads Konva and display in function of their type */
...@@ -80,9 +81,9 @@ function ParentComponent({ ...@@ -80,9 +81,9 @@ function ParentComponent({
key={i} key={i}
/> />
); );
case 'line': case 'polygon':
return ( return (
<LineNode <Polygon
{...{ {...{
...shape, activeTool, isSelected, onShapeClick: handleShapeClick, shape, ...shape, activeTool, isSelected, onShapeClick: handleShapeClick, shape,
}} }}
......
...@@ -25,12 +25,13 @@ function FreeHand({ ...@@ -25,12 +25,13 @@ function FreeHand({
}; };
return ( return (
console.log("FreeHand shape", shape),
<> <>
<Line <Line
ref={shapeRef} ref={shapeRef}
id={shape.id} id={shape.id}
points={shape.lines} points={shape.points}
stroke="#df4b26" stroke={shape.stroke || 'black'}
strokeWidth={5} strokeWidth={5}
tension={0.5} tension={0.5}
lineCap="round" lineCap="round"
...@@ -38,6 +39,7 @@ function FreeHand({ ...@@ -38,6 +39,7 @@ function FreeHand({
closed={false} closed={false}
onClick={handleClick} onClick={handleClick}
fill={fill || 'red'} fill={fill || 'red'}
draggable={activeTool === 'cursor' || activeTool === 'edit'}
globalCompositeOperation="source-over" globalCompositeOperation="source-over"
/> />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment