aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorPushkar Joshi2012-03-23 17:37:19 -0700
committerPushkar Joshi2012-03-23 17:37:19 -0700
commit591812255e0e85e52825b1269f29f86fbd0f6182 (patch)
tree0f6a0e9f25ec83f4fcd504815ee0ce1c51c67992 /js
parent9b7dac9215fbd7c0fe7a80d3e8f1ff378332fec3 (diff)
downloadninja-591812255e0e85e52825b1269f29f86fbd0f6182.tar.gz
correctly update the brush stroke canvas size and position when the stroke size is changed (does not yet work when smoothing is applied) AND select the newly created brush stroke by default
Diffstat (limited to 'js')
-rwxr-xr-xjs/lib/geom/brush-stroke.js42
-rw-r--r--js/tools/BrushTool.js5
2 files changed, 37 insertions, 10 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index a3a5ed9a..f0925ba5 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -486,13 +486,23 @@ var BrushStroke = function GLBrushStroke() {
486 this._doSmoothing(); 486 this._doSmoothing();
487 487
488 // **** recompute the bounding box **** 488 // **** recompute the bounding box ****
489 this._updateBoundingBox(); 489 var deltaWH = this._updateBoundingBox();
490
491 // **** offset the local coords to account for the change in bbox ****
492 this._offsetLocalCoord(deltaWH[0]*0.5, deltaWH[1]*0.5);
490 493
491 // **** turn off the dirty flag **** 494 // **** turn off the dirty flag ****
492 this._isDirty = false; 495 this._isDirty = false;
493 } 496 }
494 }; 497 };
495 498
499 this._offsetLocalCoord = function(deltaW, deltaH){
500 var numPoints = this._LocalPoints.length;
501 for (var i=0;i<numPoints;i++) {
502 this._LocalPoints[i][0]+= deltaW;
503 this._LocalPoints[i][1]+= deltaH;
504 }
505 };
496 this._doSmoothing = function() { 506 this._doSmoothing = function() {
497 var numPoints = this._LocalPoints.length; 507 var numPoints = this._LocalPoints.length;
498 if (this._strokeDoSmoothing && numPoints>1) { 508 if (this._strokeDoSmoothing && numPoints>1) {
@@ -516,6 +526,9 @@ var BrushStroke = function GLBrushStroke() {
516 // *** compute the bounding box ********* 526 // *** compute the bounding box *********
517 var points = this._LocalPoints; 527 var points = this._LocalPoints;
518 var numPoints = points.length; 528 var numPoints = points.length;
529 var oldWidth = this._BBoxMax[0]-this._BBoxMin[0];
530 var oldHeight = this._BBoxMax[1]-this._BBoxMin[1];
531
519 this._BBoxMin = [Infinity, Infinity, Infinity]; 532 this._BBoxMin = [Infinity, Infinity, Infinity];
520 this._BBoxMax = [-Infinity, -Infinity, -Infinity]; 533 this._BBoxMax = [-Infinity, -Infinity, -Infinity];
521 if (numPoints === 0) { 534 if (numPoints === 0) {
@@ -553,6 +566,11 @@ var BrushStroke = function GLBrushStroke() {
553 this._BBoxMax[d]+= bboxPadding; 566 this._BBoxMax[d]+= bboxPadding;
554 }//for every dimension d from 0 to 2 567 }//for every dimension d from 0 to 2
555 } 568 }
569
570 //return the difference between the current and old bbox width and height
571 var newWidth = this._BBoxMax[0]-this._BBoxMin[0];
572 var newHeight = this._BBoxMax[1]-this._BBoxMin[1];
573 return [(newWidth-oldWidth), (newHeight-oldHeight)];
556 }; 574 };
557 575
558 this.buildBuffers = function () { 576 this.buildBuffers = function () {
@@ -584,19 +602,27 @@ var BrushStroke = function GLBrushStroke() {
584 if (this._canvas) { 602 if (this._canvas) {
585 // this seems to produce drift as the stroke size is changed smoothly...bug due to floating point round off? 603 // this seems to produce drift as the stroke size is changed smoothly...bug due to floating point round off?
586 //get the old left, top, width, and height 604 //get the old left, top, width, and height
587 var oldLeft = parseInt(CanvasController.getProperty(this._canvas, "left")); 605 /*var oldLeft = parseInt(CanvasController.getProperty(this._canvas, "left"));
588 var oldTop = parseInt(CanvasController.getProperty(this._canvas, "top")); 606 var oldTop = parseInt(CanvasController.getProperty(this._canvas, "top"));
589 var oldWidth = parseInt(CanvasController.getProperty(this._canvas, "width")); 607 var oldWidth = parseInt(CanvasController.getProperty(this._canvas, "width"));
590 var oldHeight = parseInt(CanvasController.getProperty(this._canvas, "height")); 608 var oldHeight = parseInt(CanvasController.getProperty(this._canvas, "height"));
591 var newLeft = oldLeft - ((bboxWidth-oldWidth)*0.5); 609 var newLeft = oldLeft - ((bboxWidth-oldWidth)*0.5);
592 var newTop = oldTop - ((bboxHeight-oldHeight)*0.5); 610 var newTop = oldTop - ((bboxHeight-oldHeight)*0.5);*/
593 611
612 //update the stageWorldCenter as a function of the new bounding box in plane space
613 var bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])];
614 var newStageWorldCenter = MathUtils.transformPoint(bboxMid, this._planeMat);
615 var wh = ViewUtils.getStageDimension();
616 newStageWorldCenter[0]+= wh[0]*0.5; newStageWorldCenter[1]+= wh[1]*0.5;
617
618 var newLeft = Math.round(this._stageWorldCenter[0] - 0.5 * bboxWidth);
619 var newTop = Math.round(this._stageWorldCenter[1] - 0.5 * bboxHeight);
594 //assign the new width and height as the canvas dimensions through the canvas controller 620 //assign the new width and height as the canvas dimensions through the canvas controller
595 //CanvasController.setProperty(this._canvas, "left", newLeft+"px"); 621 CanvasController.setProperty(this._canvas, "left", newLeft+"px");
596 //CanvasController.setProperty(this._canvas, "top", newTop+"px"); 622 CanvasController.setProperty(this._canvas, "top", newTop+"px");
597 623
598 //CanvasController.setProperty(this._canvas, "width", bboxWidth+"px"); 624 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
599 //CanvasController.setProperty(this._canvas, "height", bboxHeight+"px"); 625 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
600 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas); 626 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
601 } 627 }
602 628
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js
index f3c6773d..f7f0e4bf 100644
--- a/js/tools/BrushTool.js
+++ b/js/tools/BrushTool.js
@@ -349,9 +349,10 @@ exports.BrushTool = Montage.create(ShapeTool, {
349 // TODO - update the shape's info only. shapeModel will likely need an array of shapes. 349 // TODO - update the shape's info only. shapeModel will likely need an array of shapes.
350 } 350 }
351 351
352 if(newCanvas.elementModel.isShape) 352 //if(newCanvas.elementModel.isShape)
353 if (true)
353 { 354 {
354 this.application.ninja.selectionController.selectElement(canvas); 355 this.application.ninja.selectionController.selectElement(newCanvas);
355 } 356 }
356 } 357 }
357 } //if (!canvas) { 358 } //if (!canvas) {