aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/controllers/elements/shapes-controller.js12
-rwxr-xr-xjs/data/pi/pi-data.js4
-rwxr-xr-xjs/lib/geom/brush-stroke.js52
-rw-r--r--js/tools/BrushTool.js2
4 files changed, 43 insertions, 27 deletions
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js
index b5e63514..46e337b7 100755
--- a/js/controllers/elements/shapes-controller.js
+++ b/js/controllers/elements/shapes-controller.js
@@ -122,7 +122,7 @@ exports.ShapesController = Montage.create(CanvasController, {
122 break; 122 break;
123 case "strokeAngle": 123 case "strokeAngle":
124 this.setShapeProperty(el, "strokeAngle", value); 124 this.setShapeProperty(el, "strokeAngle", value);
125 el.elementModel.shapeModel.GLGeomObj.setStrokeAngle(Math.PI * -val/180); 125 el.elementModel.shapeModel.GLGeomObj.setStrokeAngle(Math.PI * val/180);
126 el.elementModel.shapeModel.GLWorld.render(); 126 el.elementModel.shapeModel.GLWorld.render();
127 break; 127 break;
128 default: 128 default:
@@ -146,35 +146,35 @@ exports.ShapesController = Montage.create(CanvasController, {
146 return this.getShapeProperty(el, p); 146 return this.getShapeProperty(el, p);
147 case "strokeHardness": 147 case "strokeHardness":
148 if (el.elementModel && el.elementModel.shapeModel){ 148 if (el.elementModel && el.elementModel.shapeModel){
149 return el.elementModel.shapeModel.GLGeomObj.getStrokeHardness();; 149 return el.elementModel.shapeModel.GLGeomObj.getStrokeHardness();
150 } else { 150 } else {
151 return null; 151 return null;
152 } 152 }
153 break; 153 break;
154 case "doSmoothing": 154 case "doSmoothing":
155 if (el.elementModel && el.elementModel.shapeModel){ 155 if (el.elementModel && el.elementModel.shapeModel){
156 return el.elementModel.shapeModel.GLGeomObj.getDoSmoothing();; 156 return el.elementModel.shapeModel.GLGeomObj.getDoSmoothing();
157 } else { 157 } else {
158 return null; 158 return null;
159 } 159 }
160 break; 160 break;
161 case "strokeSmoothing": 161 case "strokeSmoothing":
162 if (el.elementModel && el.elementModel.shapeModel){ 162 if (el.elementModel && el.elementModel.shapeModel){
163 return el.elementModel.shapeModel.GLGeomObj.getSmoothingAmount();; 163 return el.elementModel.shapeModel.GLGeomObj.getSmoothingAmount();
164 } else { 164 } else {
165 return null; 165 return null;
166 } 166 }
167 break; 167 break;
168 case "isCalligraphic": 168 case "isCalligraphic":
169 if (el.elementModel && el.elementModel.shapeModel){ 169 if (el.elementModel && el.elementModel.shapeModel){
170 return el.elementModel.shapeModel.GLGeomObj.getStrokeUseCalligraphic();; 170 return el.elementModel.shapeModel.GLGeomObj.getStrokeUseCalligraphic();
171 } else { 171 } else {
172 return null; 172 return null;
173 } 173 }
174 break; 174 break;
175 case "strokeAngle": 175 case "strokeAngle":
176 if (el.elementModel && el.elementModel.shapeModel){ 176 if (el.elementModel && el.elementModel.shapeModel){
177 return el.elementModel.shapeModel.GLGeomObj.getStrokeAngle();; 177 return 180*el.elementModel.shapeModel.GLGeomObj.getStrokeAngle()/Math.PI;
178 } else { 178 } else {
179 return null; 179 return null;
180 } 180 }
diff --git a/js/data/pi/pi-data.js b/js/data/pi/pi-data.js
index 9d90aa3d..ad2f3088 100755
--- a/js/data/pi/pi-data.js
+++ b/js/data/pi/pi-data.js
@@ -649,7 +649,7 @@ exports.PiData = Montage.create( Montage, {
649 id : "strokeSize", 649 id : "strokeSize",
650 prop : "strokeSize", 650 prop : "strokeSize",
651 label : "Stroke", 651 label : "Stroke",
652 valueMutator: parseFloat, 652 valueMutator: parseInt,
653 min : 1, 653 min : 1,
654 max : 100, 654 max : 100,
655 value : 1, 655 value : 1,
@@ -661,7 +661,7 @@ exports.PiData = Montage.create( Montage, {
661 id : "strokeHardness", 661 id : "strokeHardness",
662 prop : "strokeHardness", 662 prop : "strokeHardness",
663 label : "Hardness", 663 label : "Hardness",
664 valueMutator: parseFloat, 664 valueMutator: parseInt,
665 min : 0, 665 min : 0,
666 max : 100, 666 max : 100,
667 value : 100, 667 value : 100,
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 68b9110f..afeaf6e6 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -24,6 +24,7 @@ var BrushStroke = function GLBrushStroke() {
24 this._BBoxMin = [0, 0, 0]; 24 this._BBoxMin = [0, 0, 0];
25 this._BBoxMax = [0, 0, 0]; 25 this._BBoxMax = [0, 0, 0];
26 this._dirty = true; 26 this._dirty = true;
27 this._isInit = false;
27 this._addedSamples = false; 28 this._addedSamples = false;
28 this._storedOrigPoints = false; 29 this._storedOrigPoints = false;
29 30
@@ -286,7 +287,7 @@ var BrushStroke = function GLBrushStroke() {
286 287
287 this.computeMetaGeometry = function() { 288 this.computeMetaGeometry = function() {
288 var numPoints = this._Points.length; 289 var numPoints = this._Points.length;
289 if (this._addedSamples === false){ 290 if (this._isInit === false){
290 //**** add samples to the long sections of the path --- Catmull-Rom spline interpolation ***** 291 //**** add samples to the long sections of the path --- Catmull-Rom spline interpolation *****
291 // instead of the following, may use 4-point subdivision iterations over continuous regions of 'long' segments 292 // instead of the following, may use 4-point subdivision iterations over continuous regions of 'long' segments
292 // look at http://www.gvu.gatech.edu/~jarek/Split&Tweak/ for formula 293 // look at http://www.gvu.gatech.edu/~jarek/Split&Tweak/ for formula
@@ -325,16 +326,12 @@ var BrushStroke = function GLBrushStroke() {
325 } 326 }
326 this._Points = newSampledPoints.slice(0); 327 this._Points = newSampledPoints.slice(0);
327 newSampledPoints = []; 328 newSampledPoints = [];
328 console.log("Inserted "+numInsertedPoints+" additional CatmullRom points");
329 this._addedSamples = true;
330 this._dirty=true; 329 this._dirty=true;
331 } //if we need to add samples to this curve (done only once)
332 330
333 //build a copy of the original points...this should be done only once 331 //store the original points
334 if (this._storedOrigPoints === false) {
335 this._OrigPoints = this._Points.slice(0); 332 this._OrigPoints = this._Points.slice(0);
336 this._storedOrigPoints = true; 333 this._isInit = true;
337 } //if we need to store a copy of the original points (done only once) 334 } //if have not initialized this brush stroke yet
338 335
339 if (this._dirty) { 336 if (this._dirty) {
340 this._Points = this._OrigPoints.slice(0); 337 this._Points = this._OrigPoints.slice(0);
@@ -377,7 +374,9 @@ var BrushStroke = function GLBrushStroke() {
377 374
378 //increase the bbox given the stroke width and the angle (in case of calligraphic brush) 375 //increase the bbox given the stroke width and the angle (in case of calligraphic brush)
379 var bboxPadding = this._strokeWidth/2; 376 var bboxPadding = this._strokeWidth/2;
380 if (this.__strokeUseCalligraphic) { 377 //if (this._strokeUseCalligraphic) {
378 //todo re-enable this if check once we are able to change the left and top of the brush canvas
379 if (false){
381 this._BBoxMin[0]-= bboxPadding*Math.cos(this._strokeAngle); 380 this._BBoxMin[0]-= bboxPadding*Math.cos(this._strokeAngle);
382 this._BBoxMin[1]-= bboxPadding*Math.sin(this._strokeAngle); 381 this._BBoxMin[1]-= bboxPadding*Math.sin(this._strokeAngle);
383 this._BBoxMax[0]+= bboxPadding*Math.cos(this._strokeAngle); 382 this._BBoxMax[0]+= bboxPadding*Math.cos(this._strokeAngle);
@@ -388,9 +387,9 @@ var BrushStroke = function GLBrushStroke() {
388 this._BBoxMax[d]+= bboxPadding; 387 this._BBoxMax[d]+= bboxPadding;
389 }//for every dimension d from 0 to 2 388 }//for every dimension d from 0 to 2
390 } 389 }
391
392 } //if this was dirty 390 } //if this was dirty
393 this._dirty = false; 391 this._dirty = false;
392
394 }; 393 };
395 394
396 this.buildBuffers = function () { 395 this.buildBuffers = function () {
@@ -402,32 +401,47 @@ var BrushStroke = function GLBrushStroke() {
402 this.render = function () { 401 this.render = function () {
403 // get the world 402 // get the world
404 var world = this.getWorld(); 403 var world = this.getWorld();
405 if (!world) throw( "null world in brushstroke render" ); 404 if (!world){
406 405 throw( "null world in brushstroke render" );
407 // get the context 406 }
408 var ctx = world.get2DContext();
409 if (!ctx) throw ("null context in brushstroke render");
410 407
411 var numPoints = this.getNumPoints(); 408 var numPoints = this.getNumPoints();
412 if (numPoints === 0) { 409 if (numPoints === 0) {
413 return; //nothing to do for empty paths 410 return; //nothing to do for empty paths
414 } 411 }
415 412
416 ctx.save();
417
418 this.computeMetaGeometry(); 413 this.computeMetaGeometry();
419 var bboxMin = this.getBBoxMin(); 414 var bboxMin = this.getBBoxMin();
420 var bboxMax = this.getBBoxMax(); 415 var bboxMax = this.getBBoxMax();
421 var bboxWidth = bboxMax[0] - bboxMin[0]; 416 var bboxWidth = bboxMax[0] - bboxMin[0];
422 var bboxHeight = bboxMax[1] - bboxMin[1]; 417 var bboxHeight = bboxMax[1] - bboxMin[1];
423 418
424 //assign the new width and height as the canvas dimensions through the canvas controller 419
425 if (this._canvas) { 420 if (this._canvas) {
421 // this seems to produce drift as the stroke size is changed smoothly...bug due to floating point round off
422 //get the old left, top, width, and height
423// var oldLeft = parseInt(CanvasController.getProperty(this._canvas, "left"));
424// var oldTop = parseInt(CanvasController.getProperty(this._canvas, "top"));
425// var oldWidth = parseInt(CanvasController.getProperty(this._canvas, "width"));
426// var oldHeight = parseInt(CanvasController.getProperty(this._canvas, "height"));
427// var newLeft = oldLeft - parseInt((bboxWidth-oldWidth)*0.5);
428// var newTop = oldTop - parseInt((bboxHeight-oldHeight)*0.5);
429//
430// //assign the new width and height as the canvas dimensions through the canvas controller
431// CanvasController.setProperty(this._canvas, "left", newLeft+"px");
432// CanvasController.setProperty(this._canvas, "top", newTop+"px");*/
426 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); 433 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
427 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); 434 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
428 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); 435 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
436