Skip to content

Commit

Permalink
crop update - on CTRL key, it will keep global ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
viliusle committed Jul 29, 2018
1 parent dd3b488 commit b7448b0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/js/tools/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ class Crop_class extends Base_tools_class {

var width = mouse.x - mouse.click_x;
var height = mouse.y - mouse.click_y;

if(event.ctrlKey == true || event.metaKey){
//ctrl is pressed - crop will be calculated based on global width and height ratio
var ratio = config.WIDTH / config.HEIGHT;
var width_new = Math.round(height * config.WIDTH / config.HEIGHT);
var height_new = Math.round(width * config.HEIGHT / config.WIDTH);

if(Math.abs(width * 100 / width_new) > Math.abs(height * 100 / height_new)){
if (width * 100 / width_new > 0)
height = height_new;
else
height = -height_new;
}
else{
if (height * 100 / height_new > 0)
width = width_new;
else
width = -width_new;
}
}

this.Base_selection.set_selection(null, null, width, height);
}
Expand Down

0 comments on commit b7448b0

Please sign in to comment.