Skip to content

Commit

Permalink
Stop using hard coded values for trash position. Fixes #517.
Browse files Browse the repository at this point in the history
(cherry picked from commit 0cb9e63)
  • Loading branch information
ivmartel committed Jun 12, 2018
1 parent 93a223f commit 596b5c1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/tools/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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 );
Expand Down

0 comments on commit 596b5c1

Please sign in to comment.