Constrain boundary movement to image canvas.

This commit is contained in:
Aaron van Geffen 2020-11-23 20:46:13 +01:00
parent 5e0d4df2f7
commit 2a740d8cef
1 changed files with 10 additions and 7 deletions

View File

@ -255,14 +255,17 @@ class CropEditor {
let scaleFactor = this.getScaleFactor();
this.source_x.value = parseInt(this.source_x.value) + Math.ceil((this.dragEndX - this.dragStartX) * scaleFactor);
this.source_y.value = parseInt(this.source_y.value) + Math.ceil((this.dragEndY - this.dragStartY) * scaleFactor);
let x = parseInt(this.source_x.value) + Math.ceil((this.dragEndX - this.dragStartX) * scaleFactor);
if (x + parseInt(this.crop_width.value) > this.original_image.naturalWidth) {
x += this.original_image.naturalWidth - (x + parseInt(this.crop_width.value));
}
this.source_x.value = Math.max(x, 0);
// let width = Math.ceil(Math.abs(this.dragEndX - this.dragStartX) * scaleFactor);
// this.crop_width.value = Math.min(width, this.original_image.naturalWidth - this.source_x.value);
// let height = Math.ceil(Math.abs(this.dragEndY - this.dragStartY) * scaleFactor);
// this.crop_height.value = Math.min(height, this.original_image.naturalHeight - this.source_y.value);
let y = parseInt(this.source_y.value) + Math.ceil((this.dragEndY - this.dragStartY) * scaleFactor);
if (y + parseInt(this.crop_height.value) > this.original_image.naturalHeight) {
y += this.original_image.naturalHeight - (y + parseInt(this.crop_height.value));
}
this.source_y.value = Math.max(y, 0);
this.positionBoundary();
}