Skip to content
Snippets Groups Projects
Commit 153d518f authored by Anthony's avatar Anthony
Browse files

Fix bug on freehand

parent 56b062f7
No related branches found
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
...@@ -12,7 +12,7 @@ import { v4 as uuidv4 } from 'uuid'; ...@@ -12,7 +12,7 @@ import { v4 as uuidv4 } from 'uuid';
import { OSDReferences } from 'mirador/dist/es/src/plugins/OSDReferences'; import { OSDReferences } from 'mirador/dist/es/src/plugins/OSDReferences';
// eslint-disable-next-line import/no-extraneous-dependencies // eslint-disable-next-line import/no-extraneous-dependencies
import { VideosReferences } from 'mirador/dist/es/src/plugins/VideosReferences'; import { VideosReferences } from 'mirador/dist/es/src/plugins/VideosReferences';
import ParentComponent from './shapes/ParentComponent'; import ParentComponent from './KonvaDrawing/shapes/ParentComponent';
/** All the stuff to draw on the canvas */ /** All the stuff to draw on the canvas */
...@@ -225,10 +225,8 @@ function AnnotationDrawing(props) { ...@@ -225,10 +225,8 @@ function AnnotationDrawing(props) {
setShapes([...shapes, shape]); setShapes([...shapes, shape]);
setCurrentShape(shape); setCurrentShape(shape);
break; break;
case 'freehand': case 'freehand':
// Not totally functionnal // Not totally functionnal
// TODO Not sure for this one
setIsDrawing(true); setIsDrawing(true);
shape = { shape = {
fill: props.fillColor, fill: props.fillColor,
...@@ -245,6 +243,8 @@ function AnnotationDrawing(props) { ...@@ -245,6 +243,8 @@ function AnnotationDrawing(props) {
rotation: 0, rotation: 0,
scaleX: 1, scaleX: 1,
scaleY: 1, scaleY: 1,
stroke: props.strokeColor,
strokeWidth: props.strokeWidth,
type: 'freehand', type: 'freehand',
x: 0, x: 0,
y: 0, y: 0,
...@@ -272,7 +272,7 @@ function AnnotationDrawing(props) { ...@@ -272,7 +272,7 @@ function AnnotationDrawing(props) {
case 'arrow': case 'arrow':
setIsDrawing(true); setIsDrawing(true);
shape = { shape = {
fill: props.fillColor || 'red', fill: props.fillColor,
id: uuidv4(), id: uuidv4(),
pointerLength: 20, pointerLength: 20,
pointerWidth: 20, pointerWidth: 20,
...@@ -280,10 +280,9 @@ function AnnotationDrawing(props) { ...@@ -280,10 +280,9 @@ function AnnotationDrawing(props) {
rotation: 0, rotation: 0,
scaleX: 1, scaleX: 1,
scaleY: 1, scaleY: 1,
stroke: props.fillColor || 'red', stroke: props.strokeColor,
type: 'arrow', type: 'arrow',
}; };
setShapes([...shapes, shape]); setShapes([...shapes, shape]);
setCurrentShape(shape); setCurrentShape(shape);
case 'debug': case 'debug':
...@@ -459,7 +458,7 @@ AnnotationDrawing.propTypes = { ...@@ -459,7 +458,7 @@ AnnotationDrawing.propTypes = {
AnnotationDrawing.defaultProps = { AnnotationDrawing.defaultProps = {
activeTool: null, activeTool: null,
closed: true, closed: true,
fillColor: null, fillColor: 'red',
selectedShapeId: null, selectedShapeId: null,
strokeColor: '#00BFFF', strokeColor: '#00BFFF',
strokeWidth: 1, strokeWidth: 1,
......
import React, { useEffect, useRef } from 'react'; import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import { Transformer, Line, Group } from 'react-konva';
Transformer, Shape, Line,
Layer, Group
} from 'react-konva';
/** FreeHand shape displaying */ /** FreeHand shape displaying */
function Freehand({ function Freehand({
activeTool, fill, height, onShapeClick, points, isSelected, shape, stroke, strokeWidth, width, x, y,onTransformEnd, handleDragEnd activeTool, fill, height, onShapeClick, points, isSelected, shape, stroke, strokeWidth, width, x, y, onTransformEnd, handleDragEnd,
}) { }) {
// TODO check if selectedShapeId is needed // TODO check if selectedShapeId is needed
const shapeRef = useRef(); const shapeRef = useRef();
...@@ -20,22 +17,15 @@ function Freehand({ ...@@ -20,22 +17,15 @@ function Freehand({
} }
}, [isSelected, shape]); }, [isSelected, shape]);
/** */ /** */
const handleClick = () => { const handleClick = () => {
onShapeClick(shape); onShapeClick(shape);
}; };
return ( return (
<> <>
<Group <Group
ref={shapeRef} ref={shapeRef}
// x={ 0}
// y={ 0}
onClick={handleClick} onClick={handleClick}
onTransformEnd={onTransformEnd} onTransformEnd={onTransformEnd}
scaleX={shape.scaleX} scaleX={shape.scaleX}
...@@ -46,22 +36,19 @@ function Freehand({ ...@@ -46,22 +36,19 @@ function Freehand({
width={shape.width || 1920} width={shape.width || 1920}
height={shape.height || 1080} height={shape.height || 1080}
onDragEnd={handleDragEnd} onDragEnd={handleDragEnd}
> >
{shape.lines.map((line, i) => ( {shape.lines.map((line, i) => (
<Line <Line
key={i} key={i}
fill={shape.fill || 'black'}
points={line.points} points={line.points}
stroke={line.stroke || 'black'} stroke={shape.stroke || 'black'}
strokeWidth={15} strokeWidth={15}
tension={0.5} tension={0.5}
lineCap="round" lineCap="round"
lineJoin="round" lineJoin="round"
/> />
))} ))}
</Group> </Group>
<Transformer <Transformer
ref={trRef} ref={trRef}
......
...@@ -15,7 +15,7 @@ import ImageShape from './Image'; ...@@ -15,7 +15,7 @@ import ImageShape from './Image';
function ParentComponent({ function ParentComponent({
shapes, onShapeClick, selectedShapeId, activeTool, shapes, onShapeClick, selectedShapeId, activeTool,
scale, width, height,onTransformEnd,handleDragEnd scale, width, height, onTransformEnd, handleDragEnd,
}) { }) {
// TODO Simplify these state // TODO Simplify these state
const [selectedShape, setSelectedShape] = useState(null); const [selectedShape, setSelectedShape] = useState(null);
...@@ -37,8 +37,6 @@ function ParentComponent({ ...@@ -37,8 +37,6 @@ function ParentComponent({
const handleShapeClick = (shape) => { const handleShapeClick = (shape) => {
onShapeClick(shape); onShapeClick(shape);
setSelectedShape(shape); setSelectedShape(shape);
}; };
return ( return (
...@@ -47,18 +45,21 @@ function ParentComponent({ ...@@ -47,18 +45,21 @@ function ParentComponent({
height={height} height={height}
scaleX={scale} scaleX={scale}
scaleY={scale} scaleY={scale}
> >
{shapes.map((shape, i) => { {shapes.map((shape, i) => {
const isSelected = selectedShapeId === shape.id; const isSelected = selectedShapeId === shape.id;
switch (shape.type) { switch (shape.type) {
case 'rectangle': case 'rectangle':
return ( return (
<Rectangle <Rectangle
{...{ {...{
...shape, activeTool, isSelected, onShapeClick: handleShapeClick, shape, ...shape,
onTransformEnd,handleDragEnd activeTool,
isSelected,
onShapeClick: handleShapeClick,
shape,
onTransformEnd,
handleDragEnd,
}} }}
key={i} key={i}
/> />
...@@ -67,8 +68,13 @@ function ParentComponent({ ...@@ -67,8 +68,13 @@ function ParentComponent({
return ( return (
<TextNode <TextNode
{...{ {...{
...shape, activeTool, isSelected, onShapeClick: handleShapeClick, shape, ...shape,
onTransformEnd,handleDragEnd activeTool,
isSelected,
onShapeClick: handleShapeClick,
shape,
onTransformEnd,
handleDragEnd,
}} }}
key={i} key={i}
/> />
...@@ -77,8 +83,13 @@ function ParentComponent({ ...@@ -77,8 +83,13 @@ function ParentComponent({
return ( return (
<EllipseNode <EllipseNode
{...{ {...{
...shape, activeTool, isSelected, onShapeClick: handleShapeClick, shape, ...shape,
onTransformEnd,handleDragEnd activeTool,
isSelected,
onShapeClick: handleShapeClick,
shape,
onTransformEnd,
handleDragEnd,
}} }}
key={i} key={i}
/> />
...@@ -87,8 +98,13 @@ function ParentComponent({ ...@@ -87,8 +98,13 @@ function ParentComponent({
return ( return (
<Freehand <Freehand
{...{ {...{
...shape, activeTool, isSelected, onShapeClick: handleShapeClick, shape, ...shape,
onTransformEnd,handleDragEnd activeTool,
isSelected,
onShapeClick: handleShapeClick,
shape,
onTransformEnd,
handleDragEnd,
}} }}
key={i} key={i}
/> />
...@@ -97,13 +113,17 @@ function ParentComponent({ ...@@ -97,13 +113,17 @@ function ParentComponent({
return ( return (
<Polygon <Polygon
{...{ {...{
...shape, activeTool, isSelected, onShapeClick: handleShapeClick, shape, ...shape,
onTransformEnd,handleDragEnd activeTool,
isSelected,
onShapeClick: handleShapeClick,
shape,
onTransformEnd,
handleDragEnd,
}} }}
key={i} key={i}
/> />
); );
case 'arrow': case 'arrow':
return ( return (
<ArrowNode <ArrowNode
...@@ -113,19 +133,23 @@ function ParentComponent({ ...@@ -113,19 +133,23 @@ function ParentComponent({
isSelected, isSelected,
onShapeClick: handleShapeClick, onShapeClick: handleShapeClick,
shape, shape,
onTransformEnd,handleDragEnd onTransformEnd,
handleDragEnd,
}} }}
key={i} key={i}
/> />
); );
case 'image': case 'image':
return ( return (
<ImageShape <ImageShape
{...{ {...{
...shape, activeTool, isSelected, onShapeClick: handleShapeClick, shape, ...shape,
onTransformEnd,handleDragEnd, activeTool,
isSelected,
onShapeClick: handleShapeClick,
shape,
onTransformEnd,
handleDragEnd,
src: shape.src, src: shape.src,
}} }}
key={i} key={i}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment