Blame view
app/scripts/controllers/tshirtdesign.js
4.82 KB
6f105dbd5
|
1 2 |
define(['app'], function (app) { 'use strict'; |
422e7837d
|
3 |
app.controller('TshirtdesignCtrl', function ($scope, $rootScope, $illustration) { |
6f105dbd5
|
4 5 6 7 8 9 10 |
var canvas = new fabric.Canvas('main-design-container'); fabric.Object.prototype.transparentCorners = false; canvas.on('after:render', function() { }); canvas.on({ |
aff3eb043
|
11 |
'object:added': onIllustrationAdded, |
6f105dbd5
|
12 13 14 15 |
'object:moving': onIllustrationChange, 'object:scaling': onIllustrationChange, 'object:rotating': onIllustrationChange, 'object:selected': onllustrationSelected, |
aff3eb043
|
16 |
'object:modified': onllustrationModifield |
6f105dbd5
|
17 |
}); |
aff3eb043
|
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
var currentObj; var listObj = []; var stateObj = []; var indexCurr = 0; var indexCurr2 = 0; var actionObj = false; var refreshObj = true; function onIllustrationAdded(options){ var object = options.target; console.log('object:added'); if (actionObj === true) { stateObj = [stateObj[indexCurr2]]; listObj = [listObj[indexCurr2]]; actionObj = false; console.log(stateObj); indexCurr = 1; } object.saveState(); console.log(object.originalState); stateObj[indexCurr] = JSON.stringify(object.originalState); listObj[indexCurr] = object; indexCurr++; indexCurr2 = indexCurr - 1; refreshObj = true; } function onllustrationModifield(options){ var objOffset = canvas.getActiveObject().getBoundingRect(); var cH = canvas.height, cW = canvas.width, H0 = 50, W0 = 50; console.log(objOffset,canvas.height,canvas.width); if (objOffset.left<W0-objOffset.width || objOffset.left>cW-W0 || objOffset.top<H0-objOffset.height || objOffset.top>cH-H0){ if (confirm('削除してもよろしいですか')){ canvas.getActiveObject().remove(); }else{ undoCanvas(); return; } } var object = options.target; console.log('object:modified'); if (actionObj === true) { stateObj = [stateObj[indexCurr2]]; listObj = [listObj[indexCurr2]]; actionObj = false; console.log(stateObj); indexCurr = 1; } object.saveState(); stateObj[indexCurr] = JSON.stringify(object.originalState); listObj[indexCurr] = object; indexCurr++; indexCurr2 = indexCurr - 1; console.log(stateObj); refreshObj = true; } |
6f105dbd5
|
83 |
function onIllustrationChange(options) { |
d75c45c56
|
84 85 86 87 88 |
// options.target.setCoords(); // canvas.forEachObject(function(obj) { // if (obj === options.target) return; // obj.setOpacity(options.target.intersectsWithObject(obj) ? 0.5 : 1); // }); |
6f105dbd5
|
89 |
} |
6f105dbd5
|
90 |
function onllustrationSelected(options){ |
aff3eb043
|
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
//console.log(canvas.getActiveObject()); } function undoCanvas() { if (indexCurr <= 0) { indexCurr = 0; return; } if (refreshObj === true) { indexCurr--; refreshObj = false; } console.log('undo'); indexCurr2 = indexCurr - 1; currentObj = listObj[indexCurr2]; if (currentObj){ currentObj.setOptions(JSON.parse(indexCurr[indexCurr2])); } indexCurr--; currentObj.setCoords(); canvas.renderAll(); actionObj = true; } function redoCanvas() { actionObj = true; if (indexCurr >= stateObj.length - 1) { return; } console.log('redo'); indexCurr2 = indexCurr + 1; currentObj = listObj[indexCurr2]; currentObj.setOptions(JSON.parse(indexCurr[indexCurr2])); indexCurr++; currentObj.setCoords(); canvas.renderAll(); |
6f105dbd5
|
134 135 136 137 138 139 |
} // Illustration process $scope.changeIllustrationCategory = function(currentIllustration){ $scope.currentIllustrationCate = $illustration.getList(currentIllustration); console.log($scope.currentIllustrationCate); |
422e7837d
|
140 |
}; |
6f105dbd5
|
141 142 143 144 |
$scope.insertSvg = function(item){ fabric.loadSVGFromURL(item.path, function(objects, options) { var shape = fabric.util.groupSVGElements(objects, options); |
d75c45c56
|
145 |
// shape.setFill('green'); |
6f105dbd5
|
146 147 148 149 150 |
canvas.add(shape.scale(0.6)); shape.set({ left: 150, top: 200 }).setCoords(); canvas.renderAll(); canvas.setActiveObject(shape); }); |
422e7837d
|
151 |
}; |
6f105dbd5
|
152 153 154 |
// color pattern $scope.changeColorPattern = function(color){ |
aff3eb043
|
155 156 157 158 |
if (canvas.getActiveObject()){ canvas.getActiveObject().set("fill", color); canvas.renderAll(); } |
422e7837d
|
159 |
}; |
6f105dbd5
|
160 |
$scope.listColorPatterns = [ |
aff3eb043
|
161 162 163 164 |
'#000000','#ffff00','#ff6600','#ff0000','#ff6262','#ffa19c','#ff9933','#c45d01','#5d2b03','#ffffcc', '#ffff99','#ffd500','#c0db50','#21a52a','#00663f','#abfcab','#36ffaa','#89eaea','#00938c','#005450', '#0badff','#006cff','#839aff','#0410a0','#ffb2ff','#f93fff','#6600ca','#ff6699','#999999','#666666', '#333333' |
422e7837d
|
165 |
]; |
98acd3acd
|
166 167 168 169 170 171 172 173 |
//Design text $scope.inputText = function(e) { var text = e; var iText = new fabric.IText(text); canvas.add(iText); canvas.renderAll(); canvas.setActiveObject(iText); } |
6f105dbd5
|
174 175 |
}); }); |