Skip to content

Commit

Permalink
Add reference points to update
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jul 17, 2024
1 parent eada900 commit b583efd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
25 changes: 17 additions & 8 deletions src/tools/drawShapeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,17 @@ export class DrawShapeEditor {
* @param {Konva.Ellipse} anchor The anchor to set on.
*/
#setAnchorOn(anchor) {
let originaMathShape;
let originalProps;

// drag start listener
anchor.on('dragstart.edit', (event) => {
// prevent bubbling upwards
event.cancelBubble = true;
// store original math shape
originaMathShape = this.#annotation.mathShape;
// store original properties
originalProps = {
mathShape: this.#annotation.mathShape,
referencePoints: this.#annotation.referencePoints
};
});
// drag move listener
anchor.on('dragmove.edit', (event) => {
Expand Down Expand Up @@ -327,11 +330,14 @@ export class DrawShapeEditor {
// drag end listener
anchor.on('dragend.edit', (event) => {
// update annotation command
const newMathShape = this.#annotation.mathShape;
const newProps = {
mathShape: this.#annotation.mathShape,
referencePoints: this.#annotation.referencePoints
};
const command = new UpdateAnnotationCommand(
this.#annotation,
{mathShape: originaMathShape},
{mathShape: newMathShape},
originalProps,
newProps,
this.#drawLayer.getDrawController()
);
// add command to undo stack
Expand All @@ -341,8 +347,11 @@ export class DrawShapeEditor {
type: 'annotationupdate',
data: this.#annotation
});
// update original shape
originaMathShape = newMathShape;
// update original properties
originalProps = {
mathShape: newProps.mathShape,
referencePoints: newProps.referencePoints
}

Check failure on line 354 in src/tools/drawShapeEditor.js

View workflow job for this annotation

GitHub Actions / build

Missing semicolon

// prevent bubbling upwards
event.cancelBubble = true;
Expand Down
26 changes: 18 additions & 8 deletions src/tools/drawShapeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class DrawShapeHandler {
// cache vars
let dragStartPos;
let previousPos;
let originaMathShape;
let originalProps;
let colour;

// shape listeners ------------------------------------------
Expand All @@ -286,8 +286,11 @@ export class DrawShapeHandler {
x: event.target.x(),
y: event.target.y()
};
// store the original math shape
originaMathShape = annotation.mathShape;
// store original properties
originalProps = {
mathShape: annotation.mathShape,
referencePoints: annotation.referencePoints
};

// display trash
this.#trash.activate(drawLayer);
Expand Down Expand Up @@ -369,7 +372,8 @@ export class DrawShapeHandler {
this.#shapeEditor.reset();
this.#trash.changeGroupChildrenColour(shapeGroup, colour);
// reset math shape (for undo)
annotation.mathShape = originaMathShape;
annotation.mathShape = originalProps.mathShape;
annotation.referencePoints = originalProps.referencePoints;

// create remove annotation command
const command = new RemoveAnnotationCommand(
Expand All @@ -390,11 +394,14 @@ export class DrawShapeHandler {
};
if (translation.x !== 0 || translation.y !== 0) {
// update annotation command
const newMathShape = annotation.mathShape;
const newProps = {
mathShape: annotation.mathShape,
referencePoints: annotation.referencePoints
};
const command = new UpdateAnnotationCommand(
annotation,
{mathShape: originaMathShape},
{mathShape: newMathShape},
originalProps,
newProps,
drawLayer.getDrawController()
);
// add command to undo stack
Expand All @@ -405,7 +412,10 @@ export class DrawShapeHandler {
data: annotation
});
// update original shape
originaMathShape = newMathShape;
originalProps = {
mathShape: newProps.mathShape,
referencePoints: newProps.referencePoints
};
}
// reset anchors
this.#shapeEditor.setAnchorsActive(true);
Expand Down

0 comments on commit b583efd

Please sign in to comment.