-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save crop position #1
Changes from 4 commits
c4d1c81
3235987
e136e9d
0897bfb
8cb3a5c
0285e09
660ad1e
d56525a
fbe5f4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ crop.factory('cropAreaCircle', ['cropArea', function(CropArea) { | |
this._cropCanvas.drawIconResizeBoxNESW(this._calcResizeIconCenterCoords(), this._boxResizeBaseSize, this._boxResizeIsHover?this._boxResizeHoverRatio:this._boxResizeNormalRatio); | ||
}; | ||
|
||
CropAreaCircle.prototype.processMouseMove=function(mouseCurX, mouseCurY) { | ||
CropAreaCircle.prototype.processMouseMove=function(mouseCurX, mouseCurY, position) { | ||
var cursor='default'; | ||
var res=false; | ||
|
||
|
@@ -73,6 +73,10 @@ crop.factory('cropAreaCircle', ['cropArea', function(CropArea) { | |
if (this._areaIsDragging) { | ||
this._x = mouseCurX - this._posDragStartX; | ||
this._y = mouseCurY - this._posDragStartY; | ||
if (position) { | ||
position.x = this._x | ||
position.y = this._y | ||
} | ||
this._areaIsHover = true; | ||
cursor='move'; | ||
res=true; | ||
|
@@ -89,6 +93,10 @@ crop.factory('cropAreaCircle', ['cropArea', function(CropArea) { | |
} | ||
|
||
this._size = Math.max(this._minSize, iFR); | ||
if(position) { | ||
position.size = this._size | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно сетить без условий |
||
this._boxResizeIsHover = true; | ||
res=true; | ||
this._events.trigger('area-resize'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ crop.factory('cropAreaSquare', ['cropArea', function(CropArea) { | |
} | ||
}; | ||
|
||
CropAreaSquare.prototype.processMouseMove=function(mouseCurX, mouseCurY) { | ||
CropAreaSquare.prototype.processMouseMove=function(mouseCurX, mouseCurY, position) { | ||
var cursor='default'; | ||
var res=false; | ||
|
||
|
@@ -95,6 +95,10 @@ crop.factory('cropAreaSquare', ['cropArea', function(CropArea) { | |
if (this._areaIsDragging) { | ||
this._x = mouseCurX - this._posDragStartX; | ||
this._y = mouseCurY - this._posDragStartY; | ||
if (position) { | ||
position.x = this._x | ||
position.y = this._y | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Давай обновлять эти параметры всегда, в независимости, есть ли у нас position There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если не будет position будет exception |
||
this._areaIsHover = true; | ||
cursor='move'; | ||
res=true; | ||
|
@@ -136,6 +140,11 @@ crop.factory('cropAreaSquare', ['cropArea', function(CropArea) { | |
var posModifier=(this._size-wasSize)/2; | ||
this._x+=posModifier*xMulti; | ||
this._y+=posModifier*yMulti; | ||
if(position) { | ||
position.size = this._size | ||
position.x = this._x | ||
position.y = this._y | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут можно сетить при любых условиях There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. проверка на position тут нужна для того чтобы директива работала полноценно без всяких дополнений и не выпрыгивал exception (x of undefined etc.) |
||
this._resizeCtrlIsHover = this._resizeCtrlIsDragging; | ||
res=true; | ||
this._events.trigger('area-resize'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop | |
return { top: Math.round(top), left: Math.round(left) }; | ||
}; | ||
|
||
return function(elCanvas, opts, events){ | ||
return function(elCanvas, opts, events, position){ | ||
/* PRIVATE VARIABLES */ | ||
|
||
// Object Pointers | ||
|
@@ -91,10 +91,17 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop | |
} | ||
elCanvas.prop('width',canvasDims[0]).prop('height',canvasDims[1]).css({'margin-left': -canvasDims[0]/2+'px', 'margin-top': -canvasDims[1]/2+'px'}); | ||
|
||
theArea.setX(ctx.canvas.width/2); | ||
theArea.setY(ctx.canvas.height/2); | ||
theArea.setSize(Math.min(200, ctx.canvas.width/2, ctx.canvas.height/2)); | ||
} else { | ||
if(position) { | ||
theArea.setX(position.x); | ||
theArea.setY(position.y); | ||
theArea.setSize(position.size); | ||
}else{ | ||
theArea.setX(ctx.canvas.width/2); | ||
theArea.setY(ctx.canvas.height/2); | ||
theArea.setSize(Math.min(200, ctx.canvas.width/2, ctx.canvas.height/2)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно сделать проверку под каждый параметр - так будет безопасней There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Для корректного сохранения позиции кропа нам нужны все 3 правильно подвязанные параметра поэтому устанавливать только какой-то определенный можно только если кидать какой то exception |
||
} | ||
|
||
} else { | ||
elCanvas.prop('width',0).prop('height',0).css({'margin-top': 0}); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. У нас тут упало форматирование |
||
|
@@ -124,7 +131,7 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop | |
pageX=e.pageX; | ||
pageY=e.pageY; | ||
} | ||
theArea.processMouseMove(pageX-offset.left, pageY-offset.top); | ||
theArea.processMouseMove(pageX-offset.left, pageY-offset.top, position); | ||
drawScene(); | ||
} | ||
}; | ||
|
@@ -158,7 +165,7 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop | |
pageX=e.pageX; | ||
pageY=e.pageY; | ||
} | ||
theArea.processMouseUp(pageX-offset.left, pageY-offset.top); | ||
theArea.processMouseUp(pageX-offset.left, pageY-offset.top, position); | ||
drawScene(); | ||
} | ||
}; | ||
|
@@ -274,6 +281,11 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop | |
theArea.setX(theArea.getX()*ratioNewCurWidth); | ||
theArea.setY(theArea.getY()*ratioNewCurHeight); | ||
theArea.setSize(theArea.getSize()*ratioMin); | ||
if(position) { | ||
position.x = theArea.getX() | ||
position.y = theArea.getY() | ||
position.size = theArea.getSize() | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Андрей, мы эти параметры можем сетить в любом случае, в независимости есть ли у нас |
||
elCanvas.prop('width',0).prop('height',0).css({'margin-top': 0}); | ||
} | ||
|
@@ -320,9 +332,16 @@ crop.factory('cropHost', ['$document', 'cropAreaCircle', 'cropAreaSquare', 'crop | |
} | ||
theArea = new AreaClass(ctx, events); | ||
theArea.setMinSize(curMinSize); | ||
theArea.setSize(curSize); | ||
theArea.setX(curX); | ||
theArea.setY(curY); | ||
if(position) { | ||
theArea.setSize(position.size); | ||
theArea.setX(position.x); | ||
theArea.setY(position.y); | ||
}else{ | ||
theArea.setSize(curSize); | ||
theArea.setX(curX); | ||
theArea.setY(curY); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можем сделать проверку под каждый параметр - так будет безопасней |
||
|
||
// resetCropHost(); | ||
if(image!==null) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ crop.directive('imgCrop', ['$timeout', 'cropHost', 'cropPubSub', function($timeo | |
scope: { | ||
image: '=', | ||
resultImage: '=', | ||
position: '=', | ||
|
||
|
||
changeOnFly: '=', | ||
areaType: '@', | ||
|
@@ -28,7 +30,7 @@ crop.directive('imgCrop', ['$timeout', 'cropHost', 'cropPubSub', function($timeo | |
var events = scope.events; | ||
|
||
// Init Crop Host | ||
var cropHost=new CropHost(element.find('canvas'), {}, events); | ||
var cropHost=new CropHost(element.find('canvas'), {}, events, scope.position); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В случае если
|
||
// Store Result Image to check if it's changed | ||
var storedResultImage; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут тоже можно сетить без условий
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тогда будет исключение