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

Update AnnotationCreation.js and AnnotationDrawing.js

parent 24be05ba
No related branches found
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
Pipeline #1697 failed
...@@ -19,6 +19,7 @@ import StrokeColorIcon from '@mui/icons-material/BorderColor'; ...@@ -19,6 +19,7 @@ import StrokeColorIcon from '@mui/icons-material/BorderColor';
import LineWeightIcon from '@mui/icons-material/LineWeight'; import LineWeightIcon from '@mui/icons-material/LineWeight';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import FormatShapesIcon from '@mui/icons-material/FormatShapes'; import FormatShapesIcon from '@mui/icons-material/FormatShapes';
import TitleIcon from '@mui/icons-material/Title';
import { SketchPicker } from 'react-color'; import { SketchPicker } from 'react-color';
import { styled } from '@mui/material/styles'; import { styled } from '@mui/material/styles';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
...@@ -623,7 +624,7 @@ class AnnotationCreation extends Component { ...@@ -623,7 +624,7 @@ class AnnotationCreation extends Component {
<ToggleButton value="text" aria-label="select text"> <ToggleButton value="text" aria-label="select text">
<CursorIcon /> <TitleIcon />
</ToggleButton> </ToggleButton>
<ToggleButton value="cursor" aria-label="select cursor"> <ToggleButton value="cursor" aria-label="select cursor">
<CursorIcon /> <CursorIcon />
......
...@@ -146,10 +146,10 @@ class AnnotationDrawing extends Component { ...@@ -146,10 +146,10 @@ class AnnotationDrawing extends Component {
this.paper = paper; this.paper = paper;
} }
handleMouseDown = (e) => { handleMouseDown = (e) => {
console.log('mouse down', this.props.activeTool); console.log('mouse down', this.props);
const pos = e.target.getStage().getPointerPosition(); const pos = e.target.getStage().getPointerPosition();
console.log('pos', pos);
let shape = null; let shape = null;
switch (this.props.activeTool) { switch (this.props.activeTool) {
case 'rectangle': case 'rectangle':
...@@ -161,6 +161,10 @@ class AnnotationDrawing extends Component { ...@@ -161,6 +161,10 @@ class AnnotationDrawing extends Component {
fill: this.props.fillColor, fill: this.props.fillColor,
id: uuidv4(), id: uuidv4(),
}; };
this.setState({
newShape: shape,
currentShape: shape,
});
break; break;
...@@ -199,7 +203,7 @@ class AnnotationDrawing extends Component { ...@@ -199,7 +203,7 @@ class AnnotationDrawing extends Component {
this.setState({ newShape: shape }, () => { this.setState({ newShape: shape }, () => {
// Add global key press event listener // Add global key press event listener
window.addEventListener('keypress', this.handleKeyPress); window.addEventListener('keydown', this.handleKeyPress);
}); });
this.setState({ this.setState({
newShape: shape, newShape: shape,
...@@ -226,6 +230,7 @@ class AnnotationDrawing extends Component { ...@@ -226,6 +230,7 @@ class AnnotationDrawing extends Component {
if (newShape) { if (newShape) {
this.setState({ this.setState({
shapes: [...shapes, newShape], shapes: [...shapes, newShape],
currentShape: newShape,
newShape: null, newShape: null,
}); });
...@@ -311,8 +316,24 @@ class AnnotationDrawing extends Component { ...@@ -311,8 +316,24 @@ class AnnotationDrawing extends Component {
handleKeyPress = (e) => { handleKeyPress = (e) => {
const { currentShape,shapes } = this.state; const { currentShape,shapes } = this.state;
console.log('key press',currentShape, e.key); console.log('key press',e, e.key);
if (currentShape) { if (currentShape) {
console.log('current shape', currentShape);
// if supr remove shape
if (e.key === 'Delete') {
const index = shapes.findIndex((gshape) => shape.id === currentShape.id);
console.log('index', index);
const newShapes = [...shapes];
newShapes.splice(index, 1);
this.setState({
shapes: newShapes,
currentShape: null,
});
}
if (e.key === 'Backspace') { if (e.key === 'Backspace') {
// Remove the last character // Remove the last character
...@@ -324,6 +345,7 @@ class AnnotationDrawing extends Component { ...@@ -324,6 +345,7 @@ class AnnotationDrawing extends Component {
...currentShape, ...currentShape,
text: currentShape.text.slice(0, -1), text: currentShape.text.slice(0, -1),
}, },
}); });
const index = shapes.findIndex((shape) => shape.id === currentShape.id); const index = shapes.findIndex((shape) => shape.id === currentShape.id);
...@@ -372,16 +394,11 @@ class AnnotationDrawing extends Component { ...@@ -372,16 +394,11 @@ class AnnotationDrawing extends Component {
} }
} }
drawKonvas() { drawKonvas() {
console.log('rendering konva');
console.log(this.props)
const { activeTool, toolState } = this.props;
console.log('active tool', activeTool);
console.log('tool state', toolState);
const { shapes, newShape, currentShape } = this.state; const { shapes, newShape, currentShape } = this.state;
console.log('shapes', shapes);
...@@ -519,6 +536,14 @@ class AnnotationDrawing extends Component { ...@@ -519,6 +536,14 @@ class AnnotationDrawing extends Component {
shape.id === id ? { ...shape, x: shapeNode.x(), y: shapeNode.y() } : shape shape.id === id ? { ...shape, x: shapeNode.x(), y: shapeNode.y() } : shape
); );
this.setState({ shapes: updatedShapes }); this.setState({ shapes: updatedShapes });
// update the current shape
const { currentShape } = this.state;
if (currentShape && currentShape.id === id) {
this.setState({ currentShape: { ...currentShape, x: shapeNode.x(), y: shapeNode.y() } });
}
}; };
/** */ /** */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment