Blame view
app/scripts/controllers/tshirtdesign.js
2.93 KB
6f105dbd5
|
1 |
define(['app'], function (app) { |
c8bfdfd96
|
2 |
//'use strict'; |
6f105dbd5
|
3 |
|
422e7837d
|
4 |
app.controller('TshirtdesignCtrl', function ($scope, $rootScope, $illustration) { |
6f105dbd5
|
5 6 7 8 9 10 11 12 13 |
var canvas = new fabric.Canvas('main-design-container'); fabric.Object.prototype.transparentCorners = false; canvas.on('after:render', function() { }); canvas.on({ 'object:moving': onIllustrationChange, 'object:scaling': onIllustrationChange, 'object:rotating': onIllustrationChange, |
c8bfdfd96
|
14 15 16 17 |
'object:selected': onIllustrationSelected, 'selected:deselected' : onIllustrationOut, //'selected:out' : onIllustrationOut, //'mouse:up' : onIllustrationOut, |
6f105dbd5
|
18 19 |
}); function onIllustrationChange(options) { |
d75c45c56
|
20 21 22 23 24 |
// options.target.setCoords(); // canvas.forEachObject(function(obj) { // if (obj === options.target) return; // obj.setOpacity(options.target.intersectsWithObject(obj) ? 0.5 : 1); // }); |
c8bfdfd96
|
25 26 27 28 29 |
} function onIllustrationOut() { console.log('out object'); |
6f105dbd5
|
30 31 32 |
} $scope.currentObject = null; |
c8bfdfd96
|
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
function onIllustrationSelected(options) { var object = options.target; $scope.typeObject = object.type; switch ($scope.typeObject) { case 'i-text' : $('#input-design-text').focus(); $rootScope.isShowLeftPanel = 'text'; break; case 'path-group' : $rootScope.isShowLeftPanel = 'illustration'; break; default : $rootScope.isShowLeftPanel = 'default'; break; } $rootScope.safeApply(); |
6f105dbd5
|
51 52 53 54 55 |
} // Illustration process $scope.changeIllustrationCategory = function(currentIllustration){ $scope.currentIllustrationCate = $illustration.getList(currentIllustration); |
c8bfdfd96
|
56 |
//console.log($scope.currentIllustrationCate); |
422e7837d
|
57 |
}; |
6f105dbd5
|
58 59 60 61 |
$scope.insertSvg = function(item){ fabric.loadSVGFromURL(item.path, function(objects, options) { var shape = fabric.util.groupSVGElements(objects, options); |
d75c45c56
|
62 |
// shape.setFill('green'); |
6f105dbd5
|
63 64 65 66 67 |
canvas.add(shape.scale(0.6)); shape.set({ left: 150, top: 200 }).setCoords(); canvas.renderAll(); canvas.setActiveObject(shape); }); |
422e7837d
|
68 |
}; |
6f105dbd5
|
69 70 71 72 73 |
// color pattern $scope.changeColorPattern = function(color){ canvas.getActiveObject().set("fill", color); canvas.renderAll(); |
422e7837d
|
74 |
}; |
6f105dbd5
|
75 76 77 78 79 80 81 82 83 84 85 |
$scope.listColorPatterns = [ '#000000', '#ffff00', '#ff6600', '#ff0000', '#ff6262', '#ffa19c', '#ff9933', '#c45d01', '#5d2b03', '#ffffcc', |
6f105dbd5
|
86 87 88 89 90 91 92 93 94 95 |
'#000000', '#ffff00', '#ff6600', '#ff0000', '#ff6262', '#ffa19c', '#ff9933', '#c45d01', '#5d2b03', '#ffffcc', |
6f105dbd5
|
96 97 98 99 100 101 102 103 104 105 |
'#000000', '#ffff00', '#ff6600', '#ff0000', '#ff6262', '#ffa19c', '#ff9933', '#c45d01', '#5d2b03', '#ffffcc', |
6f105dbd5
|
106 |
'#ffffcc' |
422e7837d
|
107 |
]; |
c8bfdfd96
|
108 109 110 111 |
$scope.focusInputText = function() { if($scope.typeObject != 'i-text') $scope.iText = new fabric.IText(''); }; |
422e7837d
|
112 |
|
98acd3acd
|
113 114 |
//Design text $scope.inputText = function(e) { |
c8bfdfd96
|
115 116 |
var iText = $scope.iText; iText.text = e; |
98acd3acd
|
117 118 119 |
canvas.add(iText); canvas.renderAll(); canvas.setActiveObject(iText); |
c8bfdfd96
|
120 |
}; |
98acd3acd
|
121 |
|
c8bfdfd96
|
122 123 |
//init //$scope.showIllustration('default'); |
6f105dbd5
|
124 125 |
}); }); |