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

wip...

parent 11c1d7f1
No related branches found
No related tags found
No related merge requests found
Pipeline #1889 failed
...@@ -13,6 +13,7 @@ import { OSDReferences } from 'mirador/dist/es/src/plugins/OSDReferences'; ...@@ -13,6 +13,7 @@ import { OSDReferences } from 'mirador/dist/es/src/plugins/OSDReferences';
import { VideosReferences } from 'mirador/dist/es/src/plugins/VideosReferences'; import { VideosReferences } from 'mirador/dist/es/src/plugins/VideosReferences';
import ParentComponent from './AnnotationFormOverlay/KonvaDrawing/shapes/ParentComponent'; import ParentComponent from './AnnotationFormOverlay/KonvaDrawing/shapes/ParentComponent';
import { SHAPES_TOOL } from '../AnnotationCreationUtils'; import { SHAPES_TOOL } from '../AnnotationCreationUtils';
import Surface from './AnnotationFormOverlay/KonvaDrawing/Surface';
/** All the stuff to draw on the canvas */ /** All the stuff to draw on the canvas */
function AnnotationDrawing(props) { function AnnotationDrawing(props) {
const [shapes, setShapes] = useState([]); const [shapes, setShapes] = useState([]);
...@@ -127,22 +128,35 @@ function AnnotationDrawing(props) { ...@@ -127,22 +128,35 @@ function AnnotationDrawing(props) {
/** */ /** */
const onShapeClick = async (shp) => { const onShapeClick = async (shp) => {
// retrn if we are not in edit or cursor mode
if (props.activeTool !== 'edit' && props.activeTool !== 'cursor' && props.activeTool !== 'delete') {
return;
}
console.log('shape clicked', shp);
const shape = shapes.find((s) => s.id === shp.id); const shape = shapes.find((s) => s.id === shp.id);
console.log('shape', shape);
if (props.activeTool === 'delete') { if (props.activeTool === 'delete') {
const newShapes = shapes.filter((s) => s.id !== shape.id); const newShapes = shapes.filter((s) => s.id !== shape.id);
setShapes(newShapes); setShapes(newShapes);
return; return;
} }
setCurrentShape(shape); setCurrentShape({...shape});
console.log('currentShape', currentShape);
props.setShapeProperties(shape); // TODO Check that code ? props.setShapeProperties(shape); // TODO Check that code ?
props.setColorToolFromCurrentShape( // props.setColorToolFromCurrentShape(
{ // {
fillColor: shape.fill, // fillColor: shape.fill,
strokeColor: shape.stroke, // strokeColor: shape.stroke,
strokeWidth: shape.strokeWidth, // strokeWidth: shape.strokeWidth,
}, // },
); // );
}; };
const onTransform = (evt) => { const onTransform = (evt) => {
...@@ -344,6 +358,7 @@ function AnnotationDrawing(props) { ...@@ -344,6 +358,7 @@ function AnnotationDrawing(props) {
setCurrentShape(shape); setCurrentShape(shape);
break; break;
case SHAPES_TOOL.ARROW: case SHAPES_TOOL.ARROW:
setIsDrawing(true); setIsDrawing(true);
shape = { shape = {
fill: props.fillColor, fill: props.fillColor,
...@@ -351,6 +366,8 @@ function AnnotationDrawing(props) { ...@@ -351,6 +366,8 @@ function AnnotationDrawing(props) {
pointerLength: 20, pointerLength: 20,
pointerWidth: 20, pointerWidth: 20,
points: [pos.x, pos.y, pos.x, pos.y], points: [pos.x, pos.y, pos.x, pos.y],
x: 0,
y: 0,
rotation: 0, rotation: 0,
scaleX: 1, scaleX: 1,
scaleY: 1, scaleY: 1,
...@@ -371,6 +388,7 @@ function AnnotationDrawing(props) { ...@@ -371,6 +388,7 @@ function AnnotationDrawing(props) {
/** */ /** */
const handleMouseMove = (e) => { const handleMouseMove = (e) => {
try { try {
if (!isDrawing) { if (!isDrawing) {
return; return;
...@@ -445,6 +463,7 @@ function AnnotationDrawing(props) { ...@@ -445,6 +463,7 @@ function AnnotationDrawing(props) {
arrowShape.strokeWidth = props.strokeWidth; arrowShape.strokeWidth = props.strokeWidth;
setCurrentShape(arrowShape); setCurrentShape(arrowShape);
updateCurrentShapeInShapes(); updateCurrentShapeInShapes();
setIsDrawing(true);
break; break;
default: default:
break; break;
...@@ -456,18 +475,11 @@ function AnnotationDrawing(props) { ...@@ -456,18 +475,11 @@ function AnnotationDrawing(props) {
/** Stop drawing */ /** Stop drawing */
const handleMouseUp = (e) => { const handleMouseUp = (e) => {
const pos = e.target.getStage().getRelativePointerPosition();
pos.x /= props.scale;
pos.y /= props.scale;
try {
if (!currentShape) {
return;
}
// For these cases, the action is similar: stop drawing and add the shape
setIsDrawing(false); setIsDrawing(false);
} catch (error) {
console.error('error', error);
}
}; };
/** */ /** */
......
...@@ -17,9 +17,7 @@ function Surface({ ...@@ -17,9 +17,7 @@ function Surface({
} }
}, [tabView]); }, [tabView]);
// const handleClick = () => {
// onShapeClick(shape);
// };
return ( return (
<Layer <Layer
......
...@@ -34,6 +34,7 @@ function LineNode({ ...@@ -34,6 +34,7 @@ function LineNode({
closed={false} closed={false}
draggable={activeTool === 'cursor' || activeTool === 'edit'} draggable={activeTool === 'cursor' || activeTool === 'edit'}
onClick={handleClick} onClick={handleClick}
onMousedown={handleClick}
/> />
<Transformer <Transformer
......
...@@ -12,8 +12,9 @@ import ImageShape from './Image'; ...@@ -12,8 +12,9 @@ import ImageShape from './Image';
/** Loads Konva and display in function of their type */ /** Loads Konva and display in function of their type */
function ParentComponent({ function ParentComponent({
isMouseOverSave, isMouseOverSave,
scale, width, height, onTransform, handleDragEnd, scale, onTransform, handleDragEnd,
shapes, onShapeClick, selectedShapeId, activeTool, shapes, onShapeClick, selectedShapeId, activeTool,
trview,
}) { }) {
// TODO Simplify these state // TODO Simplify these state
const [selectedShape, setSelectedShape] = useState(null); const [selectedShape, setSelectedShape] = useState(null);
...@@ -44,6 +45,9 @@ function ParentComponent({ ...@@ -44,6 +45,9 @@ function ParentComponent({
scaleY={scale} scaleY={scale}
> >
{shapes.map((shape, i) => { {shapes.map((shape, i) => {
const isSelected = selectedShapeId === shape.id && isMouseOverSave === false && trview === true; const isSelected = selectedShapeId === shape.id && isMouseOverSave === false && trview === true;
switch (shape.type) { switch (shape.type) {
case 'rectangle': case 'rectangle':
...@@ -154,13 +158,12 @@ function ParentComponent({ ...@@ -154,13 +158,12 @@ function ParentComponent({
ParentComponent.propTypes = { ParentComponent.propTypes = {
activeTool: PropTypes.string.isRequired, activeTool: PropTypes.string.isRequired,
handleDragEnd: PropTypes.func.isRequired, handleDragEnd: PropTypes.func.isRequired,
height: PropTypes.number.isRequired,
isMouseOverSave: PropTypes.bool.isRequired, isMouseOverSave: PropTypes.bool.isRequired,
onShapeClick: PropTypes.func.isRequired, onShapeClick: PropTypes.func.isRequired,
onTransform: PropTypes.func.isRequired, onTransform: PropTypes.func.isRequired,
scale: PropTypes.number.isRequired, scale: PropTypes.number.isRequired,
selectedShapeId: PropTypes.string.isRequired, selectedShapeId: PropTypes.string,
shapes: PropTypes.arrayOf(PropTypes.object).isRequired, shapes: PropTypes.arrayOf(PropTypes.object).isRequired
width: PropTypes.number.isRequired,
}; };
export default ParentComponent; export default ParentComponent;
...@@ -37,8 +37,9 @@ function Polygon({ ...@@ -37,8 +37,9 @@ function Polygon({
lineCap="round" lineCap="round"
lineJoin="round" lineJoin="round"
closed={false} closed={false}
onClick={handleClick}
onMousedown={handleClick} onMousedown={handleClick}
onClick={handleClick}
fill={shape.fill} fill={shape.fill}
draggable={activeTool === 'cursor' || activeTool === 'edit'} 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