aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/controllers/document-controller.js6
-rwxr-xr-xjs/data/tools-data.js2
-rwxr-xr-xjs/document/html-document.js5
-rwxr-xr-xjs/helper-classes/RDGE/GLBrushStroke.js175
-rw-r--r--js/mediators/io-mediator.js17
-rw-r--r--js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js27
-rw-r--r--js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js1
-rw-r--r--[-rwxr-xr-x]js/tools/BrushTool.js194
8 files changed, 307 insertions, 120 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 02031922..64ff2c7e 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -195,7 +195,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
195 value:function(doc){ 195 value:function(doc){
196 var response = doc || null;//default just for testing 196 var response = doc || null;//default just for testing
197 if(!!response && response.success && (response.status!== 500) && !!response.uri){ 197 if(!!response && response.success && (response.status!== 500) && !!response.uri){
198
199 this.isNewFilePath = true;//path identifier flag
198 this.creatingNewFile = true;//flag for timeline to identify new file flow 200 this.creatingNewFile = true;//flag for timeline to identify new file flow
201
199 this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); 202 this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this));
200 }else if(!!response && !response.success){ 203 }else if(!!response && !response.success){
201 //Todo: restrict directory path to the sandbox, in the dialog itself 204 //Todo: restrict directory path to the sandbox, in the dialog itself
@@ -224,9 +227,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
224 //TODO: Add UI to handle error codes, shouldn't be alert windows 227 //TODO: Add UI to handle error codes, shouldn't be alert windows
225 if(!!response && (response.status === 204)) { 228 if(!!response && (response.status === 204)) {
226 229
227 if((typeof this.creatingNewFile === 'undefined') || (this.creatingNewFile !== true)){//not from new file flow 230 if((typeof this.isNewFilePath === 'undefined') || (this.isNewFilePath !== true)){//not from new file flow
228 this.creatingNewFile = false; 231 this.creatingNewFile = false;
229 } 232 }
233 this.isNewFilePath = false;//reset path identifier flag
230 234
231 //Sending full response object 235 //Sending full response object
232 this.openDocument(response); 236 this.openDocument(response);
diff --git a/js/data/tools-data.js b/js/data/tools-data.js
index a3a30b57..faf3336f 100755
--- a/js/data/tools-data.js
+++ b/js/data/tools-data.js
@@ -141,7 +141,7 @@ exports.ToolsData = Montage.create(Montage, {
141 "spriteSheet": true, 141 "spriteSheet": true,
142 "action": "BrushTool", 142 "action": "BrushTool",
143 "toolTip": "Brush Tool", 143 "toolTip": "Brush Tool",
144 "cursor": "url('images/tools/brush_down.png'), default", 144 "cursor": "url('images/tools/brush_down.png') 9 17, default",
145 "lastInGroup": false, 145 "lastInGroup": false,
146 "container": false, 146 "container": false,
147 "selected": false 147 "selected": false
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 826a59c0..5d507476 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -647,9 +647,10 @@ exports.HTMLDocument = Montage.create(TextDocument, {
647 enumerable: false, 647 enumerable: false,
648 value: function () { 648 value: function () {
649 //TODO: Add logic to handle save before preview 649 //TODO: Add logic to handle save before preview
650 this.saveAll(); 650 this.application.ninja.documentController.handleExecuteSaveAll(null);
651 //Launching 'blank' tab for testing movie 651 //Launching 'blank' tab for testing movie
652 chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]}); 652 window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);
653 //chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]});
653 } 654 }
654 }, 655 },
655 //////////////////////////////////////////////////////////////////// 656 ////////////////////////////////////////////////////////////////////
diff --git a/js/helper-classes/RDGE/GLBrushStroke.js b/js/helper-classes/RDGE/GLBrushStroke.js
index fdf1595c..5d773c2d 100755
--- a/js/helper-classes/RDGE/GLBrushStroke.js
+++ b/js/helper-classes/RDGE/GLBrushStroke.js
@@ -34,6 +34,13 @@ function GLBrushStroke() {
34 this._strokeMaterial; 34 this._strokeMaterial;
35 this._strokeStyle = "Solid"; 35 this._strokeStyle = "Solid";
36 36
37 //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed to not depend on stroke width entirely
38 //smaller value means more samples for the path
39 this._WETNESS_FACTOR = 0.25;
40
41 //prevent extremely long paths that can take a long time to render
42 this._MAX_ALLOWED_SAMPLES = 500;
43
37 //drawing context 44 //drawing context
38 this._world = null; 45 this._world = null;
39 46
@@ -67,7 +74,25 @@ function GLBrushStroke() {
67 74
68 this.getNumPoints = function () { return this._Points.length; } 75 this.getNumPoints = function () { return this._Points.length; }
69 this.getPoint = function (index) { return this._Points[index]; } 76 this.getPoint = function (index) { return this._Points[index]; }
70 this.addPoint = function (anchorPt) { this._Points.push(anchorPt); this._dirty=true; } 77 this.addPoint = function (pt)
78 {
79 //add the point only if it is some epsilon away from the previous point
80 var numPoints = this._Points.length;
81 if (numPoints>0) {
82 var threshold = this._WETNESS_FACTOR*this._strokeWidth;
83 var prevPt = this._Points[numPoints-1];
84 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]];
85 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]);
86 if (diffPtMag>threshold){
87 this._Points.push(pt);
88 this._dirty=true;
89 }
90 }else{
91 this._Points.push(pt);
92 this._dirty=true;
93 }
94 }
95
71 this.insertPoint = function(pt, index){ this._Points.splice(index, 0, pt); this._dirty=true;} 96 this.insertPoint = function(pt, index){ this._Points.splice(index, 0, pt); this._dirty=true;}
72 this.isDirty = function(){return this._dirty;} 97 this.isDirty = function(){return this._dirty;}
73 this.makeDirty = function(){this._dirty=true;} 98 this.makeDirty = function(){this._dirty=true;}
@@ -111,10 +136,45 @@ function GLBrushStroke() {
111 136
112 this.computeMetaGeometry = function(){ 137 this.computeMetaGeometry = function(){
113 if (this._dirty){ 138 if (this._dirty){
139 var numPoints = this._Points.length;
140
141 //**** add samples to the path if needed...linear interpolation for now
142 if (numPoints>1) {
143 var threshold = this._WETNESS_FACTOR*this._strokeWidth;
144 var prevPt = this._Points[0];
145 var prevIndex = 0;
146 for (var i=1;i<numPoints;i++){
147 var pt = this._Points[i];
148 var diff = [pt[0]-prevPt[0], pt[1]-prevPt[1]];
149 var distance = Math.sqrt(diff[0]*diff[0]+diff[1]*diff[1]);
150 if (distance>threshold){
151 //insert points along the prev. to current point
152 var numNewPoints = Math.floor(distance/threshold);
153 for (var j=0;j<numNewPoints;j++){
154 var param = (j+1)/(numNewPoints+1);
155 var newpt = [prevPt[0]+ diff[0]*param, prevPt[1]+ diff[1]*param];
156 //insert new point before point i
157 this._Points.splice(i, 0, [newpt[0], newpt[1], 0]);
158 i++;
159 }
160 this._dirty=true;
161 }
162 prevPt=pt;
163 //update numPoints to match the new length
164 numPoints = this._Points.length;
165
166 //end this function if the numPoints has gone above the max. size specified
167 if (numPoints> this._MAX_ALLOWED_SAMPLES){
168 console.log("leaving the resampling because numPoints is greater than limit:"+this._MAX_ALLOWED_SAMPLES);
169 break;
170 }
171 }
172 }
173
114 // *** compute the bounding box ********* 174 // *** compute the bounding box *********
115 this._BBoxMin = [Infinity, Infinity, Infinity]; 175 this._BBoxMin = [Infinity, Infinity, Infinity];
116 this._BBoxMax = [-Infinity, -Infinity, -Infinity]; 176 this._BBoxMax = [-Infinity, -Infinity, -Infinity];
117 var numPoints = this._Points.length; 177 numPoints = this._Points.length;
118 if (numPoints === 0) { 178 if (numPoints === 0) {
119 this._BBoxMin = [0, 0, 0]; 179 this._BBoxMin = [0, 0, 0];
120 this._BBoxMax = [0, 0, 0]; 180 this._BBoxMax = [0, 0, 0];
@@ -167,7 +227,8 @@ function GLBrushStroke() {
167 var bboxWidth = bboxMax[0] - bboxMin[0]; 227 var bboxWidth = bboxMax[0] - bboxMin[0];
168 var bboxHeight = bboxMax[1] - bboxMin[1]; 228 var bboxHeight = bboxMax[1] - bboxMin[1];
169 ctx.clearRect(0, 0, bboxWidth, bboxHeight); 229 ctx.clearRect(0, 0, bboxWidth, bboxHeight);
170/* 230
231 /*
171 ctx.lineWidth = this._strokeWidth; 232 ctx.lineWidth = this._strokeWidth;
172 ctx.strokeStyle = "black"; 233 ctx.strokeStyle = "black";
173 if (this._strokeColor) 234 if (this._strokeColor)
@@ -185,30 +246,120 @@ function GLBrushStroke() {
185 ctx.lineTo(pt[0]-bboxMin[0], pt[1]-bboxMin[1]); 246 ctx.lineTo(pt[0]-bboxMin[0], pt[1]-bboxMin[1]);
186 } 247 }
187 ctx.stroke(); 248 ctx.stroke();
188 */ 249 */
250
251 /*
252 var isDebug = false;
253 var prevPt = this._Points[0];
254 var prevX = prevPt[0]-bboxMin[0];
255 var prevY = prevPt[1]-bboxMin[1];
256 prevPt = [prevX,prevY];
257 for (var i = 1; i < numPoints; i++) {
258 var pt = this._Points[i];
259 ctx.globalCompositeOperation = 'source-over';
260 var x = pt[0]-bboxMin[0];
261 var y = pt[1]-bboxMin[1];
262 pt = [x,y];
263
264 //vector from prev to current pt
265 var seg = VecUtils.vecSubtract(2, pt, prevPt);
266 var segDir = VecUtils.vecNormalize(2, seg, 1.0);
267
268 var segMidPt = VecUtils.vecInterpolate(2, pt, prevPt, 0.5);
269 var w2 = this._strokeWidth*0.5;
270 var segDirOrtho = [w2*segDir[1], -w2*segDir[0]];
271
272 //add half the strokewidth to the segMidPt
273 var lgStart = VecUtils.vecAdd(2, segMidPt, segDirOrtho);
274 var lgEnd = VecUtils.vecSubtract(2, segMidPt, segDirOrtho);
275
276 ctx.save();