Merge pull request #1338 from opencv/bs/fixed_escale_in_draw

React UI: Fixed escape in draw
main
Dmitry Kalinin 6 years ago committed by GitHub
commit 075ee50c85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- -
### Fixed ### Fixed
- - New shape is added when press ``esc`` when drawing instead of cancellation
### Security ### Security
- -

@ -50,6 +50,7 @@ export class DrawHandlerImpl implements DrawHandler {
// so, methods like draw() just undefined for SVG.Shape, but nevertheless they exist // so, methods like draw() just undefined for SVG.Shape, but nevertheless they exist
private drawInstance: any; private drawInstance: any;
private initialized: boolean; private initialized: boolean;
private canceled: boolean;
private pointsGroup: SVG.G | null; private pointsGroup: SVG.G | null;
private shapeSizeElement: ShapeSizeElement; private shapeSizeElement: ShapeSizeElement;
@ -149,6 +150,7 @@ export class DrawHandlerImpl implements DrawHandler {
// Clear drawing // Clear drawing
this.drawInstance.draw('stop'); this.drawInstance.draw('stop');
} }
this.drawInstance.off(); this.drawInstance.off();
this.drawInstance.remove(); this.drawInstance.remove();
this.drawInstance = null; this.drawInstance = null;
@ -161,6 +163,10 @@ export class DrawHandlerImpl implements DrawHandler {
if (this.crosshair) { if (this.crosshair) {
this.removeCrosshair(); this.removeCrosshair();
} }
if (!this.drawData.initialState) {
this.onDrawDone(null);
}
} }
private initDrawing(): void { private initDrawing(): void {
@ -175,8 +181,9 @@ export class DrawHandlerImpl implements DrawHandler {
const bbox = (e.target as SVGRectElement).getBBox(); const bbox = (e.target as SVGRectElement).getBBox();
const [xtl, ytl, xbr, ybr] = this.getFinalRectCoordinates(bbox); const [xtl, ytl, xbr, ybr] = this.getFinalRectCoordinates(bbox);
const { shapeType } = this.drawData; const { shapeType } = this.drawData;
this.cancel(); this.release();
if (this.canceled) return;
if ((xbr - xtl) * (ybr - ytl) >= consts.AREA_THRESHOLD) { if ((xbr - xtl) * (ybr - ytl) >= consts.AREA_THRESHOLD) {
this.onDrawDone({ this.onDrawDone({
shapeType, shapeType,
@ -290,11 +297,11 @@ export class DrawHandlerImpl implements DrawHandler {
this.drawInstance.on('drawdone', (e: CustomEvent): void => { this.drawInstance.on('drawdone', (e: CustomEvent): void => {
const targetPoints = pointsToArray((e.target as SVGElement).getAttribute('points')); const targetPoints = pointsToArray((e.target as SVGElement).getAttribute('points'));
const { points, box } = this.getFinalPolyshapeCoordinates(targetPoints); const { points, box } = this.getFinalPolyshapeCoordinates(targetPoints);
const { shapeType } = this.drawData; const { shapeType } = this.drawData;
this.cancel(); this.release();
if (this.canceled) return;
if (shapeType === 'polygon' if (shapeType === 'polygon'
&& ((box.xbr - box.xtl) * (box.ybr - box.ytl) >= consts.AREA_THRESHOLD) && ((box.xbr - box.xtl) * (box.ybr - box.ytl) >= consts.AREA_THRESHOLD)
&& points.length >= 3 * 2) { && points.length >= 3 * 2) {
@ -598,6 +605,7 @@ export class DrawHandlerImpl implements DrawHandler {
this.canvas = canvas; this.canvas = canvas;
this.text = text; this.text = text;
this.initialized = false; this.initialized = false;
this.canceled = false;
this.drawData = null; this.drawData = null;
this.geometry = null; this.geometry = null;
this.crosshair = null; this.crosshair = null;
@ -671,17 +679,18 @@ export class DrawHandlerImpl implements DrawHandler {
this.geometry = geometry; this.geometry = geometry;
if (drawData.enabled) { if (drawData.enabled) {
this.canceled = false;
this.drawData = drawData; this.drawData = drawData;
this.initDrawing(); this.initDrawing();
this.startDraw(); this.startDraw();
} else { } else {
this.cancel(); this.release();
this.drawData = drawData; this.drawData = drawData;
} }
} }
public cancel(): void { public cancel(): void {
this.canceled = true;
this.release(); this.release();
this.onDrawDone(null);
} }
} }

Loading…
Cancel
Save