Skip to content

Commit

Permalink
fix: improve the smoothness of crop box resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Jun 1, 2018
1 parent cc35974 commit 2b606c9
Showing 1 changed file with 61 additions and 41 deletions.
102 changes: 61 additions & 41 deletions src/js/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ export default {
check(ACTION_EAST);
width += range.x;

if (aspectRatio) {
height = width / aspectRatio;
top -= (range.x / aspectRatio) / 2;
}

if (width < 0) {
action = ACTION_WEST;
width = 0;
width = -width;
left -= width;
}

if (aspectRatio) {
height = width / aspectRatio;
top += (cropBoxData.height - height) / 2;
}

break;
Expand All @@ -145,14 +146,15 @@ export default {
height -= range.y;
top += range.y;

if (aspectRatio) {
width = height * aspectRatio;
left += (range.y * aspectRatio) / 2;
}

if (height < 0) {
action = ACTION_SOUTH;
height = 0;
height = -height;
top -= height;
}

if (aspectRatio) {
width = height * aspectRatio;
left += (cropBoxData.width - width) / 2;
}

break;
Expand All @@ -168,14 +170,15 @@ export default {
width -= range.x;
left += range.x;

if (aspectRatio) {
height = width / aspectRatio;
top += (range.x / aspectRatio) / 2;
}

if (width < 0) {
action = ACTION_EAST;
width = 0;
width = -width;
left -= width;
}

if (aspectRatio) {
height = width / aspectRatio;
top += (cropBoxData.height - height) / 2;
}

break;
Expand All @@ -190,14 +193,15 @@ export default {
check(ACTION_SOUTH);
height += range.y;

if (aspectRatio) {
width = height * aspectRatio;
left -= (range.y * aspectRatio) / 2;
}

if (height < 0) {
action = ACTION_NORTH;
height = 0;
height = -height;
top -= height;
}

if (aspectRatio) {
width = height * aspectRatio;
left += (cropBoxData.width - width) / 2;
}

break;
Expand Down Expand Up @@ -240,14 +244,18 @@ export default {

if (width < 0 && height < 0) {
action = ACTION_SOUTH_WEST;
height = 0;
width = 0;
height = -height;
width = -width;
top -= height;
left -= width;
} else if (width < 0) {
action = ACTION_NORTH_WEST;
width = 0;
width = -width;
left -= width;
} else if (height < 0) {
action = ACTION_SOUTH_EAST;
height = 0;
height = -height;
top -= height;
}

break;
Expand All @@ -263,7 +271,7 @@ export default {
height -= range.y;
top += range.y;
width = height * aspectRatio;
left += range.y * aspectRatio;
left += cropBoxData.width - width;
} else {
check(ACTION_NORTH);
check(ACTION_WEST);
Expand Down Expand Up @@ -293,14 +301,18 @@ export default {

if (width < 0 && height < 0) {
action = ACTION_SOUTH_EAST;
height = 0;
width = 0;
height = -height;
width = -width;
top -= height;
left -= width;
} else if (width < 0) {
action = ACTION_NORTH_EAST;
width = 0;
width = -width;
left -= width;
} else if (height < 0) {
action = ACTION_SOUTH_WEST;
height = 0;
height = -height;
top -= height;
}

break;
Expand Down Expand Up @@ -343,14 +355,18 @@ export default {

if (width < 0 && height < 0) {
action = ACTION_NORTH_EAST;
height = 0;
width = 0;
height = -height;
width = -width;
top -= height;
left -= width;
} else if (width < 0) {
action = ACTION_SOUTH_EAST;
width = 0;
width = -width;
left -= width;
} else if (height < 0) {
action = ACTION_NORTH_WEST;
height = 0;
height = -height;
top -= height;
}

break;
Expand Down Expand Up @@ -390,14 +406,18 @@ export default {

if (width < 0 && height < 0) {
action = ACTION_NORTH_WEST;
height = 0;
width = 0;
height = -height;
width = -width;
top -= height;
left -= width;
} else if (width < 0) {
action = ACTION_SOUTH_WEST;
width = 0;
width = -width;
left -= width;
} else if (height < 0) {
action = ACTION_NORTH_EAST;
height = 0;
height = -height;
top -= height;
}

break;
Expand Down

0 comments on commit 2b606c9

Please sign in to comment.