Skip to content

Commit

Permalink
allow size of square-like areas (width equals height) to be set with …
Browse files Browse the repository at this point in the history
…a single numeric size value
  • Loading branch information
chirgwin committed Jul 29, 2014
1 parent 680558e commit f377700
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 1 addition & 3 deletions source/js/classes/crop-area-circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ crop.factory('cropAreaCircle', ['cropArea', function(CropArea) {
iFR = this._posResizeStartSize.w + iFX*2;
}

var diameter = Math.max(this._minSize.h, iFR);

var prevCenter = this.getCenterPoint();

this.setSize({w: diameter, h: diameter});
this.setSize(Math.max(this._minSize.h, iFR));

//recenter
this.setCenterPoint(prevCenter);
Expand Down
3 changes: 1 addition & 2 deletions source/js/classes/crop-area-square.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ crop.factory('cropAreaSquare', ['cropArea', function(CropArea) {
}
var prevCenter = this.getCenterPoint();

var width = Math.max(this._minSize.w, iFR);
this.setSize({w: width, h: width});
this.setSize(Math.max(this._minSize.w, iFR));

//recenter
this.setCenterPoint(prevCenter);
Expand Down
25 changes: 17 additions & 8 deletions source/js/classes/crop-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ crop.factory('cropArea', ['cropCanvas', function(CropCanvas) {

CropArea.prototype.setSize = function (size) {

//make this polymorphic to accept a single floating point number n , size.w = n, size.h = n
this._size = {x: Math.max(this._minSize.x, size.x) || this._minSize.x,
y: Math.max(this._minSize.y, size.y) || this._minSize.y,
w: Math.max(this._minSize.w, size.w) || this._minSize.w,
h: Math.max(this._minSize.h, size.h) || this._minSize.h};

this._size = this._processSize(size);
this._dontDragOutside();
};

Expand All @@ -58,8 +53,8 @@ crop.factory('cropArea', ['cropCanvas', function(CropCanvas) {
};

CropArea.prototype.setMinSize = function (size) {
this._minSize = size;
this.setSize(size);
this._minSize = this._processSize(size);
this.setSize(this._minSize);
this._dontDragOutside();
};

Expand Down Expand Up @@ -91,6 +86,20 @@ crop.factory('cropArea', ['cropCanvas', function(CropCanvas) {

CropArea.prototype._drawArea=function() {};

CropArea.prototype._processSize=function(size)
{
// make this polymorphic to accept a single floating point number
// for square-like sizes (including circle)
if (typeof size == "number")
{
size = {w: size, h: size};
}
return {x: Math.max(this._minSize.x, size.x) || this._minSize.x,
y: Math.max(this._minSize.y, size.y) || this._minSize.y,
w: Math.max(this._minSize.w, size.w) || this._minSize.w,
h: Math.max(this._minSize.h, size.h) || this._minSize.h};
}

CropArea.prototype.draw=function() {
// draw crop area
this._cropCanvas.drawCropArea(this._image,this.getCenterPoint(),this._size,this._drawArea);
Expand Down

0 comments on commit f377700

Please sign in to comment.