aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-03 11:13:07 -0700
committerPushkar Joshi2012-04-03 11:13:07 -0700
commit06970d710f7172ee5ab736ef082c7703c61bfd0c (patch)
treeac3daf4accc7b257c19b662ae6c0bfe0b97114ef /js/lib
parentc838f85d28acbf2fe208a4358aef9cac73b65fbc (diff)
downloadninja-06970d710f7172ee5ab736ef082c7703c61bfd0c.tar.gz
track the canvas top left position instead of the center position to figure out when to translate the subpath per canvas translation...this one seems to not drift (no floating point issues uncovered so far)
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/geom/sub-path.js45
1 files changed, 23 insertions, 22 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index 4ded360c..d8d74928 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -72,9 +72,9 @@ var GLSubpath = function GLSubpath() {
72 //the canvas that will draw this subpath 72 //the canvas that will draw this subpath
73 this._canvas = null; 73 this._canvas = null;
74 74
75 //the X and Y location of this subpath's canvas in stage world space of Ninja 75 //the top left location of this subpath's canvas in screen space
76 this._canvasX = 0; 76 this._canvasLeft = 0;
77 this._canvasY = 0; 77 this._canvasTop = 0;
78 78
79 //stroke information 79 //stroke information
80 this._strokeWidth = 1.0; 80 this._strokeWidth = 1.0;
@@ -362,20 +362,20 @@ GLSubpath.prototype.setPlaneCenter = function(pc){
362 this._planeCenter = pc; 362 this._planeCenter = pc;
363}; 363};
364 364
365GLSubpath.prototype.getCanvasX = function(){ 365GLSubpath.prototype.getCanvasLeft = function(){
366 return this._canvasX; 366 return this._canvasLeft;
367}; 367};
368 368
369GLSubpath.prototype.getCanvasY = function(){ 369GLSubpath.prototype.getCanvasTop = function(){
370 return this._canvasY; 370 return this._canvasTop;
371}; 371};
372 372
373GLSubpath.prototype.setCanvasX = function(cx){ 373GLSubpath.prototype.setCanvasLeft = function(cx){
374 this._canvasX=cx; 374 this._canvasLeft=cx;
375}; 375};
376 376
377GLSubpath.prototype.setCanvasY = function(cy){ 377GLSubpath.prototype.setCanvasTop = function(cy){
378 this._canvasY=cy; 378 this._canvasTop=cy;
379}; 379};
380 380
381GLSubpath.prototype.getIsClosed = function () { 381GLSubpath.prototype.getIsClosed = function () {
@@ -868,20 +868,17 @@ GLSubpath.prototype.getStrokeWidth = function () {
868 868
869GLSubpath.prototype.translateSubpathPerCanvas = function(elemMediator){ 869GLSubpath.prototype.translateSubpathPerCanvas = function(elemMediator){
870 //check if the canvas was translated 870 //check if the canvas was translated
871 var penCanvasLeft = parseInt(elemMediator.getProperty(this._canvas, "left"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "left")); 871 var penCanvasCurrentLeft = parseInt(elemMediator.getProperty(this._canvas, "left"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "left"));
872 var penCanvasTop = parseInt(elemMediator.getProperty(this._canvas, "top"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "top")); 872 var penCanvasCurrentTop = parseInt(elemMediator.getProperty(this._canvas, "top"));//parseFloat(DocumentControllerModule.DocumentController.GetElementStyle(this._penCanvas, "top"));
873 var penCanvasWidth = parseInt(elemMediator.getProperty(this._canvas, "width"));//this._penCanvas.width;
874 var penCanvasHeight = parseInt(elemMediator.getProperty(this._canvas, "height"));//this._penCanvas.height;
875 var penCanvasOldX = penCanvasLeft + 0.5 * penCanvasWidth;
876 var penCanvasOldY = penCanvasTop + 0.5 * penCanvasHeight;
877 873
878 var translateCanvasX = penCanvasOldX - this._canvasX; 874 var translateCanvasX = Math.round(penCanvasCurrentLeft - this._canvasLeft);
879 var translateCanvasY = penCanvasOldY - this._canvasY; 875 var translateCanvasY = Math.round(penCanvasCurrentTop - this._canvasTop);
880 876
881 //update the canvasX and canvasY parameters for this subpath and also translate the subpath points (since they're stored in stage world space) 877 //update the left and top parameters for this subpath and also translate the subpath points (since they're stored in stage world space)
882 if (Math.abs(translateCanvasX)>=1 || Math.abs(translateCanvasY)>=1){ 878 if (Math.abs(translateCanvasX)>=1 || Math.abs(translateCanvasY)>=1){
883 this.setCanvasX(translateCanvasX + this._canvasX); 879 this.setCanvasLeft(penCanvasCurrentLeft);
884 this.setCanvasY(translateCanvasY + this._canvasY); 880 this.setCanvasTop(penCanvasCurrentTop);
881 //todo does the canvas translation correspond to the translation in stage world space?
885 this.translateAnchors(translateCanvasX, translateCanvasY, 0); 882 this.translateAnchors(translateCanvasX, translateCanvasY, 0);
886 } 883 }
887 this._dirty=true; 884 this._dirty=true;
@@ -896,6 +893,8 @@ GLSubpath.prototype.setStrokeWidth = function (w) {
896 this._dirty=true; 893 this._dirty=true;
897 894
898 var ElementMediator = require("js/mediators/element-mediator").ElementMediator; 895 var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
896
897 //translate the subpath in case the actual canvas location does not match where subpath thinks the canvas should be
899 this.translateSubpathPerCanvas(ElementMediator); 898 this.translateSubpathPerCanvas(ElementMediator);
900 899
901 // **** adjust the left, top, width, and height to adjust for the change in stroke width **** 900 // **** adjust the left, top, width, and height to adjust for the change in stroke width ****
@@ -920,6 +919,8 @@ GLSubpath.prototype.setStrokeWidth = function (w) {
920 ElementMediator.setProperty(canvasArray, "height", [bboxHeight+"px"], "Changing", "penTool");//canvas.height = h; 919 ElementMediator.setProperty(canvasArray, "height", [bboxHeight+"px"], "Changing", "penTool");//canvas.height = h;
921 ElementMediator.setProperty(canvasArray, "left", [left+"px"],"Changing", "penTool");//DocumentControllerModule.DocumentController.SetElementStyle(canvas, "left", parseInt(left) + "px"); 920 ElementMediator.setProperty(canvasArray, "left", [left+"px"],"Changing", "penTool");//DocumentControllerModule.DocumentController.SetElementStyle(canvas, "left", parseInt(left) + "px");
922 ElementMediator.setProperty(canvasArray, "top", [top + "px"],"Changing", "penTool");//DocumentControllerModule.DocumentController.SetElementStyle(canvas, "top", parseInt(top) + "px"); 921 ElementMediator.setProperty(canvasArray, "top", [top + "px"],"Changing", "penTool");//DocumentControllerModule.DocumentController.SetElementStyle(canvas, "top", parseInt(top) + "px");
922 this.setCanvasLeft(left);
923 this.setCanvasTop(top);
923}; 924};
924 925
925GLSubpath.prototype.getStrokeMaterial = function () { 926GLSubpath.prototype.getStrokeMaterial = function () {