crop-area.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. crop.factory('cropArea', ['cropCanvas', function(CropCanvas) {
  3. var CropArea = function(ctx, events) {
  4. this._ctx=ctx;
  5. this._events=events;
  6. this._minSize=80;
  7. this._cropCanvas=new CropCanvas(ctx);
  8. this._image=new Image();
  9. this._x = 0;
  10. this._y = 0;
  11. this._size = 200;
  12. };
  13. /* GETTERS/SETTERS */
  14. CropArea.prototype.getImage = function () {
  15. return this._image;
  16. };
  17. CropArea.prototype.setImage = function (image) {
  18. this._image = image;
  19. };
  20. CropArea.prototype.getX = function () {
  21. return this._x;
  22. };
  23. CropArea.prototype.setX = function (x) {
  24. this._x = x;
  25. this._dontDragOutside();
  26. };
  27. CropArea.prototype.getY = function () {
  28. return this._y;
  29. };
  30. CropArea.prototype.setY = function (y) {
  31. this._y = y;
  32. this._dontDragOutside();
  33. };
  34. CropArea.prototype.getSize = function () {
  35. return this._size;
  36. };
  37. CropArea.prototype.setSize = function (size) {
  38. this._size = Math.max(this._minSize, size);
  39. this._dontDragOutside();
  40. };
  41. CropArea.prototype.getMinSize = function () {
  42. return this._minSize;
  43. };
  44. CropArea.prototype.setMinSize = function (size) {
  45. this._minSize = size;
  46. this._size = Math.max(this._minSize, this._size);
  47. this._dontDragOutside();
  48. };
  49. /* FUNCTIONS */
  50. CropArea.prototype._dontDragOutside=function() {
  51. var h=this._ctx.canvas.height,
  52. w=this._ctx.canvas.width;
  53. if(this._size>w) { this._size=w; }
  54. if(this._size>h) { this._size=h; }
  55. if(this._x<this._size/2) { this._x=this._size/2; }
  56. if(this._x>w-this._size/2) { this._x=w-this._size/2; }
  57. if(this._y<this._size/2) { this._y=this._size/2; }
  58. if(this._y>h-this._size/2) { this._y=h-this._size/2; }
  59. };
  60. CropArea.prototype._drawArea=function() {};
  61. CropArea.prototype.draw=function() {
  62. // draw crop area
  63. this._cropCanvas.drawCropArea(this._image,[this._x,this._y],this._size,this._drawArea);
  64. };
  65. CropArea.prototype.processMouseMove=function() {};
  66. CropArea.prototype.processMouseDown=function() {};
  67. CropArea.prototype.processMouseUp=function() {};
  68. return CropArea;
  69. }]);