From 596b5c1255826a9a0fac226a7629200a349293e8 Mon Sep 17 00:00:00 2001 From: ivmartel Date: Mon, 11 Jun 2018 21:19:58 +0200 Subject: [PATCH] Stop using hard coded values for trash position. Fixes #517. (cherry picked from commit 0cb9e637a8345a63a6952effcc8ca89ba0060b04) --- src/tools/draw.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/tools/draw.js b/src/tools/draw.js index bb4ff40966..042d70580f 100644 --- a/src/tools/draw.js +++ b/src/tools/draw.js @@ -115,6 +115,8 @@ dwv.tool.Draw = function (app, shapeFactoryList) points: [10, -10, -10, 10 ], stroke: 'red' }); + trash.width(20); + trash.height(20); trash.add(trashLine1); trash.add(trashLine2); @@ -432,8 +434,8 @@ dwv.tool.Draw = function (app, shapeFactoryList) var stage = app.getDrawStage(); var scale = stage.scale(); var invscale = {'x': 1/scale.x, 'y': 1/scale.y}; - trash.x( stage.offset().x + ( 256 / scale.x ) ); - trash.y( stage.offset().y + ( 20 / scale.y ) ); + trash.x( stage.offset().x + ( stage.width() / (2 * scale.x) ) ); + trash.y( stage.offset().y + ( stage.height() / (15 * scale.y) ) ); trash.scale( invscale ); drawLayer.add( trash ); // deactivate anchors to avoid events on null shape @@ -446,8 +448,10 @@ dwv.tool.Draw = function (app, shapeFactoryList) // highlight trash when on it var offset = dwv.html.getEventOffset( event.evt )[0]; var eventPos = getRealPosition( offset ); - if ( Math.abs( eventPos.x - trash.x() ) < 10 && - Math.abs( eventPos.y - trash.y() ) < 10 ) { + var trashHalfWidth = trash.width() * trash.scaleX() / 2; + var trashHalfHeight = trash.height() * trash.scaleY() / 2; + if ( Math.abs( eventPos.x - trash.x() ) < trashHalfWidth && + Math.abs( eventPos.y - trash.y() ) < trashHalfHeight ) { trash.getChildren().each( function (tshape){ tshape.stroke('orange'); }); // change the group shapes colour shapeGroup.getChildren( dwv.draw.canNodeChangeColour ).forEach( @@ -470,8 +474,10 @@ dwv.tool.Draw = function (app, shapeFactoryList) // delete case var offset = dwv.html.getEventOffset( event.evt )[0]; var eventPos = getRealPosition( offset ); - if ( Math.abs( eventPos.x - trash.x() ) < 10 && - Math.abs( eventPos.y - trash.y() ) < 10 ) { + var trashHalfWidth = trash.width() * trash.scaleX() / 2; + var trashHalfHeight = trash.height() * trash.scaleY() / 2; + if ( Math.abs( eventPos.x - trash.x() ) < trashHalfWidth && + Math.abs( eventPos.y - trash.y() ) < trashHalfHeight ) { // compensate for the drag translation this.x( dragStartPos.x ); this.y( dragStartPos.y );