P5-1499. 3D view selects wrong part of the image after resizing and going into 3D mode without re-cropping

This commit is contained in:
EricaWind
2017-07-18 19:52:59 +03:00
parent ee3627914f
commit 765bc78095
6 changed files with 28 additions and 7 deletions
+3 -1
View File
@@ -35,7 +35,7 @@ var Canvas = fabric.util.createClass(fabric.Canvas, {
// Eventhandler for mouseup events on the whole canvas. // Eventhandler for mouseup events on the whole canvas.
// This should be rewritten a bit to not have that many events after the image has been cropped. // This should be rewritten a bit to not have that many events after the image has been cropped.
this.on('mouse:up', function () { this.on('mouse:up', function () {
if (this.getImage().__cropped && !this.get3dHandler().isEnabled()) { if (this.getImage().__dragged && !this.get3dHandler().isEnabled()) {
this.getApertures().setTransparent(false); this.getApertures().setTransparent(false);
this.getImageData().setCropData(); this.getImageData().setCropData();
@@ -196,6 +196,8 @@ var Canvas = fabric.util.createClass(fabric.Canvas, {
setImage: function (img) { setImage: function (img) {
this.removeImage(); this.removeImage();
this.__image = img; this.__image = img;
this.__image.__dragged = false;
this.__image.__cropped = false;
this.__image.addTo(this).center().on('mousedown', function () { this.__image.addTo(this).center().on('mousedown', function () {
img.canvas.getApertures().setTransparent(true); img.canvas.getApertures().setTransparent(true);
}).setCoords(); }).setCoords();
+1 -1
View File
@@ -13,7 +13,7 @@ function Draggable(img, boundingRect) {
* Triggers when object is moved * Triggers when object is moved
*/ */
function onMove() { function onMove() {
this.__cropped = true; this.__dragged = true;
this.canvas.disableScroll(); this.canvas.disableScroll();
+14 -1
View File
@@ -81,9 +81,22 @@ function ImageEditor(canvasId, args) {
* @return {ImageEditor} * @return {ImageEditor}
*/ */
this.crop = function (width, height, units) { this.crop = function (width, height, units) {
_canvas.getImage().__cropped = false;
_canvas.getImageData().removeCropData(); _canvas.getImageData().removeCropData();
_canvas.getViewport().set(width, height, units); _canvas.getViewport().set(width, height, units);
var shouldBeCropped = util.isAspectChanged(_canvas.getImage().width, _canvas.getImage().height, width, height);
if (shouldBeCropped) {
_canvas.getImage().__dragged = false;
_canvas.getImage().__cropped = true;
_canvas.getImageData().setCropData();
}
else {
_canvas.getImage().__cropped = false;
}
return this; return this;
}; };
+2 -3
View File
@@ -135,7 +135,7 @@ function Viewport(canvas) {
_data = util.calcCrop(canvas.getImage(), width, height, units); _data = util.calcCrop(canvas.getImage(), width, height, units);
var keepCropping = (oldData && (Math.abs(oldData.dim.width / oldData.dim.height - width / height) <= 0.01)); var keepCropping = (oldData && !util.isAspectChanged(oldData.dim.width, oldData.dim.height, width, height));
if (keepCropping) { if (keepCropping) {
canvas.getImageData().setCropData(); canvas.getImageData().setCropData();
} }
@@ -144,9 +144,8 @@ function Viewport(canvas) {
this.getGores().reset(); this.getGores().reset();
this.getRulers().reset(); this.getRulers().reset();
if (!canvas.getImage().__cropped && !keepCropping) { if (canvas.getImage().__cropped && !keepCropping) {
canvas.getApertures().setTransparent(true); canvas.getApertures().setTransparent(true);
canvas.getImageData().removeCropData();
// Trigger event to tell the image needs to be dragged. // Trigger event to tell the image needs to be dragged.
$(document).trigger('PIE:needs-dragging', { axis: _data.axis }); $(document).trigger('PIE:needs-dragging', { axis: _data.axis });
+1 -1
View File
@@ -12,5 +12,5 @@ module.exports = {
MouseMetrics: require('./utils/mouse-metrics'), MouseMetrics: require('./utils/mouse-metrics'),
supportsFullscreen: require('./utils/supports-fullscreen'), supportsFullscreen: require('./utils/supports-fullscreen'),
isFullscreen: require('./utils/is-fullscreen'), isFullscreen: require('./utils/is-fullscreen'),
isAspectChanged: require('./utils/is-aspect-changed'),
}; };
@@ -0,0 +1,7 @@
'use strict';
function isAspectChanged(x1, y1, x2, y2) {
return (Math.abs(x1 / y1 - x2 / y2) > 0.01);
}
module.exports = isAspectChanged;