Skip to content
Snippets Groups Projects
Commit 01994146 authored by Laurent Knoll's avatar Laurent Knoll
Browse files

RAZ de l'état du bouton "Fini !" du contour de masque. Closes #10

parent 391a97f3
No related branches found
No related tags found
No related merge requests found
...@@ -19,14 +19,17 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume ...@@ -19,14 +19,17 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume
/** /**
* Appelé lorsque le tracé est fermé * Appelé lorsque le tracé est fermé
*/ */
public onClose : () => void = () => {}; public onClose: () => void = () => {
};
/** /**
* Appelé lorsque le tracé s'ouvre * Appelé lorsque le tracé s'ouvre
*/ */
public onOpen : () => void = () => {}; public onOpen: () => void = () => {
};
public constructor(protected lab : Lab, coords : PathCoords) {
public constructor(protected lab: Lab, coords: PathCoords) {
super(lab, coords, [ super(lab, coords, [
new Handle("startHandle", true), new Handle("startHandle", true),
]) ])
...@@ -43,16 +46,16 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume ...@@ -43,16 +46,16 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume
refresh() { refresh() {
super.refresh(); super.refresh();
let isClosed = this.coords.isClosed(); let isClosed = this.coords.isClosed();
if(!this.wasClosed && isClosed) { if (!this.wasClosed && isClosed) {
this.onClose(); this.onClose();
} else if(this.wasClosed && !isClosed) { } else if (this.wasClosed && !isClosed) {
this.onOpen(); this.onOpen();
} }
this.wasClosed = isClosed; this.wasClosed = isClosed;
if(DEBUG_MODE) { // Traces les contours convexes et fitted ellipse if (DEBUG_MODE) { // Traces les contours convexes et fitted ellipse
if(this.drawGroup.bounds.area > 10) { if (this.drawGroup.bounds.area > 10) {
let fittedEllipse = new ToEllipseFitter().transform(this.coords).toRemovedPath(); let fittedEllipse = new ToEllipseFitter().transform(this.coords).toRemovedPath();
fittedEllipse.strokeColor = new paper.Color("red"); fittedEllipse.strokeColor = new paper.Color("red");
fittedEllipse.strokeWidth = PaperUtils.absoluteDimension(2); fittedEllipse.strokeWidth = PaperUtils.absoluteDimension(2);
...@@ -75,8 +78,8 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume ...@@ -75,8 +78,8 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume
} }
locateHandle(coords: PathCoords, handle: Handle): paper.Point { locateHandle(coords: PathCoords, handle: Handle): paper.Point {
if(handle.name == "startHandle") { if (handle.name == "startHandle") {
if(coords.points.length == 0) { if (coords.points.length == 0) {
return null; return null;
} else { } else {
return coords.points[0]; return coords.points[0];
...@@ -89,7 +92,7 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume ...@@ -89,7 +92,7 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume
* Attacher le handler lors de l'activation * Attacher le handler lors de l'activation
*/ */
public onActivation() { public onActivation() {
if(!this.lab.raster.data.blobMaskAttached) { if (!this.lab.raster.data.blobMaskAttached) {
this.lab.raster.on("mousedown", this.onMouseDown.bind(this)); this.lab.raster.on("mousedown", this.onMouseDown.bind(this));
this.lab.raster.on("mousedrag", this.onMouseDrag.bind(this)); this.lab.raster.on("mousedrag", this.onMouseDrag.bind(this));
this.lab.raster.data.blobMaskAttached = true; this.lab.raster.data.blobMaskAttached = true;
...@@ -99,19 +102,19 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume ...@@ -99,19 +102,19 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume
/** /**
* Lorsque quelque chose est déplacé de la règle * Lorsque quelque chose est déplacé de la règle
*/ */
private addMousePoint(point : paper.Point) { private addMousePoint(point: paper.Point) {
if(!this.coords.isClosed()) { // Une fois la boucle fermée, on ne peut plus ajouter de if (!this.coords.isClosed()) { // Une fois la boucle fermée, on ne peut plus ajouter de
this.coords.points.push(point) this.coords.points.push(point)
this.refresh(); this.refresh();
} }
return true; return true;
} }
private onMouseDown(event : paper.MouseEvent) : boolean { private onMouseDown(event: paper.MouseEvent): boolean {
if(!this.active) { if (!this.active) {
return true; return true;
} }
if(event.modifiers.control) { if (event.modifiers.control) {
return true; // On ne fait si CONTROL est pressé en dessinant return true; // On ne fait si CONTROL est pressé en dessinant
} }
this.addMousePoint(event.point); this.addMousePoint(event.point);
...@@ -121,11 +124,11 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume ...@@ -121,11 +124,11 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume
/** /**
* Déplacement de la souris * Déplacement de la souris
*/ */
private onMouseDrag(event : paper.MouseEvent) : boolean { private onMouseDrag(event: paper.MouseEvent): boolean {
if(!this.active) { if (!this.active) {
return true; return true;
} }
if(event.modifiers.control) { if (event.modifiers.control) {
return true; // On ne fait si CONTROL est pressé en dessinant return true; // On ne fait si CONTROL est pressé en dessinant
} }
this.addMousePoint(event.point); this.addMousePoint(event.point);
...@@ -133,8 +136,8 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume ...@@ -133,8 +136,8 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume
} }
protected override fillColor(active: boolean, coords : PathCoords): paper.Color | null { protected override fillColor(active: boolean, coords: PathCoords): paper.Color | null {
if(coords.isClosed()) { if (coords.isClosed()) {
let fillColor = active ? new paper.Color("yellow") : new paper.Color("olive"); let fillColor = active ? new paper.Color("yellow") : new paper.Color("olive");
fillColor.alpha = 0.5; fillColor.alpha = 0.5;
return fillColor; return fillColor;
...@@ -143,6 +146,13 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume ...@@ -143,6 +146,13 @@ export class BlobMask extends AbstractInstrument<PathCoords> implements Instrume
} }
} }
/**
* Appelé lorsque le tracé est fermé
*/
public isClosed() : boolean {
return this.coords.isClosed();
}
/** /**
* Supprime quelques derniers points * Supprime quelques derniers points
*/ */
......
...@@ -28,6 +28,7 @@ export class DrawBlobMaskStep extends Step<DrawBlobMaskStepState> { ...@@ -28,6 +28,7 @@ export class DrawBlobMaskStep extends Step<DrawBlobMaskStepState> {
onActivation(): void { onActivation(): void {
this.props.lab.blobMask.activate(); this.props.lab.blobMask.activate();
this.setState({closed: this.props.lab.blobMask.isClosed() });
this.props.lab.blobMask.onClose = () => { this.props.lab.blobMask.onClose = () => {
this.setState({closed: true }); this.setState({closed: true });
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment