aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/sub-path.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-19 09:40:39 -0700
committerPushkar Joshi2012-04-19 09:40:39 -0700
commitb1013db1b1a44d5fcd2e1a244d3c21c013d23e6e (patch)
treef00e8bb5f9dd3f7887dc8bdd18ff3e6fd5b0f662 /js/lib/geom/sub-path.js
parenta8123f065e7be7566a0588dd87ccac1cd59a0b8e (diff)
downloadninja-b1013db1b1a44d5fcd2e1a244d3c21c013d23e6e.tar.gz
store the canvas center (in local space) per each subpath, instead of tracking it by the pen tool. This fixes the bug where the canvas transform was incorrectly applied when the stroke width was changed
Diffstat (limited to 'js/lib/geom/sub-path.js')
-rwxr-xr-xjs/lib/geom/sub-path.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index 2ecafa1c..60335990 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -34,6 +34,8 @@ var GLSubpath = function GLSubpath() {
34 this._Anchors = []; 34 this._Anchors = [];
35 this._BBoxMin = [0, 0, 0]; 35 this._BBoxMin = [0, 0, 0];
36 this._BBoxMax = [0, 0, 0]; 36 this._BBoxMax = [0, 0, 0];
37 this._canvasCenterLocalCoord = [0,0,0];
38
37 this._isClosed = false; 39 this._isClosed = false;
38 40
39 this._Samples = []; //polyline representation of this curve in canvas space 41 this._Samples = []; //polyline representation of this curve in canvas space
@@ -274,6 +276,14 @@ GLSubpath.prototype.setIsClosed = function (isClosed) {
274 } 276 }
275}; 277};
276 278
279GLSubpath.prototype.setCanvasCenterLocalCoord = function(center){
280 this._canvasCenterLocalCoord = center;
281};
282
283GLSubpath.prototype.getCanvasCenterLocalCoord = function(){
284 return this._canvasCenterLocalCoord;
285};
286
277GLSubpath.prototype.getNumAnchors = function () { 287GLSubpath.prototype.getNumAnchors = function () {
278 return this._Anchors.length; 288 return this._Anchors.length;
279}; 289};
@@ -681,13 +691,16 @@ GLSubpath.prototype.setStrokeWidth = function (w) {
681 if (this._dirty){ 691 if (this._dirty){
682 this.createSamples(false); //this will also update the bounding box 692 this.createSamples(false); //this will also update the bounding box
683 } else{ 693 } else{
684 this.computeBoundingBox(false); 694 this.computeBoundingBox(true,false);
685 } 695 }
686 this.offsetPerBBoxMin(); //this will shift the local coordinates such that the bbox min point is at (0,0) 696 this.offsetPerBBoxMin(); //this will shift the local coordinates such that the bbox min point is at (0,0)
687 697
688 //figure out the adjustment to the canvas position and size 698 //figure out the adjustment to the canvas position and size
689 var delta = Math.round(diffStrokeWidth*0.5); 699 var delta = Math.round(diffStrokeWidth*0.5);
690 700
701 //update the canvas center (it's simply the center of the new bbox in this case)
702 this._canvasCenterLocalCoord = [0.5*(this._BBoxMax[0]+this._BBoxMin[0]),0.5*(this._BBoxMax[1]+this._BBoxMin[1]),0.5*(this._BBoxMax[2]+this._BBoxMin[2])];
703
691 //update the width, height, left and top 704 //update the width, height, left and top
692 var ElementMediator = require("js/mediators/element-mediator").ElementMediator; 705 var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
693 var penCanvasCurrentWidth = parseInt(ElementMediator.getProperty(this._canvas, "width")); 706 var penCanvasCurrentWidth = parseInt(ElementMediator.getProperty(this._canvas, "width"));