aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-04 15:52:41 -0700
committerPushkar Joshi2012-04-04 15:52:41 -0700
commitf4eccf3e7cb76a14a3546a646575162dbd831538 (patch)
tree8beabf96fc3dcc08d1fdb5a6a016be8992260b58 /js/tools
parent12f988a32da12731ab35104128e396a6f388aeae (diff)
downloadninja-f4eccf3e7cb76a14a3546a646575162dbd831538.tar.gz
draw the path overlay (and anchor points) taking into account the transformation applied to the element canvas and the stage canvas. Still quite buggy.
Diffstat (limited to 'js/tools')
-rw-r--r--js/tools/BrushTool.js1
-rwxr-xr-xjs/tools/PenTool.js82
-rwxr-xr-xjs/tools/drawing-tool-base.js2
3 files changed, 65 insertions, 20 deletions
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js
index f7f0e4bf..78d1e7e6 100644
--- a/js/tools/BrushTool.js
+++ b/js/tools/BrushTool.js
@@ -134,7 +134,6 @@ exports.BrushTool = Montage.create(ShapeTool, {
134 snapManager.enableSnapAlign(false); 134 snapManager.enableSnapAlign(false);
135 135
136 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); 136 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y));
137 //todo fix this function to allow us to get the correct location (in 3D) for the mouse position
138 var unsnappedpos = DrawingToolBase.getHitRecPos(snapManager.snap(point.x, point.y, false)); 137 var unsnappedpos = DrawingToolBase.getHitRecPos(snapManager.snap(point.x, point.y, false));
139 this._draggingPlane = snapManager.getDragPlane(); 138 this._draggingPlane = snapManager.getDragPlane();
140 139
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 2eae6adc..f1c79153 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -14,7 +14,7 @@ var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
14var TagTool = require("js/tools/TagTool").TagTool; 14var TagTool = require("js/tools/TagTool").TagTool;
15var ElementController = require("js/controllers/elements/element-controller").ElementController; 15var ElementController = require("js/controllers/elements/element-controller").ElementController;
16var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; 16var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager;
17 17var ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
18var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint; 18var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint;
19var SubPath = require("js/lib/geom/sub-path").SubPath; 19var SubPath = require("js/lib/geom/sub-path").SubPath;
20 20
@@ -108,7 +108,6 @@ exports.PenTool = Montage.create(ShapeTool, {
108 snapManager.enableSnapAlign(false); 108 snapManager.enableSnapAlign(false);
109 109
110 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); 110 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y));
111 //todo fix this function to allow us to get the correct location (in 3D) for the mouse position
112 var unsnappedpos = DrawingToolBase.getHitRecPos(snapManager.snap(point.x, point.y, false)); 111 var unsnappedpos = DrawingToolBase.getHitRecPos(snapManager.snap(point.x, point.y, false));
113 this._dragPlane = snapManager.getDragPlane(); 112 this._dragPlane = snapManager.getDragPlane();
114 113
@@ -830,14 +829,12 @@ exports.PenTool = Montage.create(ShapeTool, {
830 //display the subpath as a sequence of cubic beziers 829 //display the subpath as a sequence of cubic beziers
831 ctx.lineWidth = 1;//TODO replace hardcoded stroke width with some programmatically set value (should not be same as stroke width) 830 ctx.lineWidth = 1;//TODO replace hardcoded stroke width with some programmatically set value (should not be same as stroke width)
832 ctx.strokeStyle = "green"; 831 ctx.strokeStyle = "green";
833 //if (subpath.getStrokeColor()) 832 var i=0;
834 // ctx.strokeStyle = MathUtils.colorToHex( subpath.getStrokeColor() );
835
836 ctx.beginPath(); 833 ctx.beginPath();
837 var p0x = subpath.getAnchor(0).getPosX()+ horizontalOffset; 834 var p0x = subpath.getAnchor(0).getPosX()+ horizontalOffset;
838 var p0y = subpath.getAnchor(0).getPosY()+ verticalOffset; 835 var p0y = subpath.getAnchor(0).getPosY()+ verticalOffset;
839 ctx.moveTo(p0x, p0y); 836 ctx.moveTo(p0x, p0y);
840 for (var i = 1; i < numAnchors; i++) { 837 for (i = 1; i < numAnchors; i++) {
841 var p1x = subpath.getAnchor(i - 1).getNextX()+ horizontalOffset; 838 var p1x = subpath.getAnchor(i - 1).getNextX()+ horizontalOffset;
842 var p1y = subpath.getAnchor(i - 1).getNextY()+ verticalOffset; 839 var p1y = subpath.getAnchor(i - 1).getNextY()+ verticalOffset;
843 var p2x = subpath.getAnchor(i).getPrevX()+ horizontalOffset; 840 var p2x = subpath.getAnchor(i).getPrevX()+ horizontalOffset;
@@ -858,6 +855,34 @@ exports.PenTool = Montage.create(ShapeTool, {
858 } 855 }
859 ctx.stroke(); 856 ctx.stroke();
860 857
858
859 //draw the stage world points by projecting them to screen space
860 //get the screen coords of this anchor from its stage world coord
861 ctx.beginPath();
862 ctx.strokeStyle = "red";
863 var localToGlobalMat = ViewUtils.getLocalToGlobalMatrix(subpath.getCanvas());
864 var currentLTWH = subpath.computeLeftTopWidthHeight();
865 var deltaX = currentLTWH[0] - parseInt(ElementMediator.getProperty(subpath.getCanvas(), "left"));
866 var deltaY = currentLTWH[1] - parseInt(ElementMediator.getProperty(subpath.getCanvas(), "top"));
867
868 var localCoord = subpath.getAnchorLocalCoord(0);
869 var sp = MathUtils.transformAndDivideHomogeneousPoint(localCoord,localToGlobalMat);
870 //add the difference between the current left and top and the canvas left and top
871 sp[0]+=deltaX; sp[1]+=deltaY;
872
873 ctx.moveTo(sp[0],sp[1]);
874 for (i = 1; i < numAnchors; i++) {
875 localCoord = subpath.getAnchorLocalCoord(i);
876 sp = MathUtils.transformAndDivideHomogeneousPoint(localCoord,localToGlobalMat);
877 //add the difference between the current left and top and the canvas left and top
878 sp[0]+=deltaX; sp[1]+=deltaY;
879 ctx.lineTo(sp[0],sp[1]);
880 }
881 if (subpath.getIsClosed()){
882 ctx.closePath();
883 }
884 ctx.stroke();
885
861 ctx.restore(); 886 ctx.restore();
862 } //function (subpath) 887 } //function (subpath)
863 }, //DrawSubpathSVG 888 }, //DrawSubpathSVG
@@ -879,37 +904,56 @@ exports.PenTool = Montage.create(ShapeTool, {
879 var horizontalOffset = this.application.ninja.stage.userContentLeft;//stageManagerModule.stageManager.userContentLeft; 904 var horizontalOffset = this.application.ninja.stage.userContentLeft;//stageManagerModule.stageManager.userContentLeft;
880 var verticalOffset = this.application.ninja.stage.userContentTop;//stageManagerModule.stageManager.userContentTop; 905 var verticalOffset = this.application.ninja.stage.userContentTop;//stageManagerModule.stageManager.userContentTop;
881 906
882 //display circles and squares near all control points 907 var localToGlobalMat = ViewUtils.getLocalToGlobalMatrix(subpath.getCanvas());
908
909 var currentLTWH = subpath.computeLeftTopWidthHeight();
910 var deltaX = currentLTWH[0] - parseInt(ElementMediator.getProperty(subpath.getCanvas(), "left"));
911 var deltaY = currentLTWH[1] - parseInt(ElementMediator.getProperty(subpath.getCanvas(), "top"));
912
913 //display circles and squares near all control points
883 ctx.fillStyle = "#FFFFFF"; 914 ctx.fillStyle = "#FFFFFF";
884 ctx.lineWidth = 1; 915 ctx.lineWidth = 1;
885 ctx.strokeStyle = "green"; 916 ctx.strokeStyle = "green";
886 var anchorDelta = 2; 917 var anchorDelta = 2;
887 var selAnchorDelta = 4; 918 var selAnchorDelta = 4;
888 for (var i = 0; i < numAnchors; i++) { 919 for (var i = 0; i < numAnchors; i++) {
889 var px = subpath.getAnchor(i).getPosX(); 920 var px = subpath.getAnchor(i).getPosX()+horizontalOffset;
890 var py = subpath.getAnchor(i).getPosY(); 921 var py = subpath.getAnchor(i).getPosY()+verticalOffset;
922 var localCoord = subpath.getAnchorLocalCoord(i);
923 if (localCoord) {
924 var sp = MathUtils.transformAndDivideHomogeneousPoint(localCoord,localToGlobalMat);
925 px = sp[0]; py=sp[1];
926 sp[0]+=deltaX; sp[1]+=deltaY;
927 }
891 ctx.beginPath(); 928 ctx.beginPath();
892 //ctx.arc(px + horizontalOffset, py + verticalOffset, this._DISPLAY_ANCHOR_RADIUS, 0, 2 * Math.PI, false); 929 //ctx.arc(px + horizontalOffset, py + verticalOffset, this._DISPLAY_ANCHOR_RADIUS, 0, 2 * Math.PI, false);
893 ctx.moveTo(px-anchorDelta+horizontalOffset, py-anchorDelta+verticalOffset); 930 ctx.moveTo(px-anchorDelta, py-anchorDelta);
894 ctx.lineTo(px+anchorDelta+horizontalOffset, py-anchorDelta+verticalOffset); 931 ctx.lineTo(px+anchorDelta, py-anchorDelta);
895 ctx.lineTo(px+anchorDelta+horizontalOffset, py+anchorDelta+verticalOffset); 932 ctx.lineTo(px+anchorDelta, py+anchorDelta);
896 ctx.lineTo(px-anchorDelta+horizontalOffset, py+anchorDelta+verticalOffset); 933 ctx.lineTo(px-anchorDelta, py+anchorDelta);
897 ctx.closePath(); 934 ctx.closePath();
898 ctx.fill(); 935 ctx.fill();
899 ctx.stroke(); 936 ctx.stroke();
937
900 } 938 }
901 939
902 //display the hovered over anchor point 940 //display the hovered over anchor point
903 ctx.lineWidth = 2; 941 ctx.lineWidth = 2;
904 if (this._hoveredAnchorIndex>=0 && this._hoveredAnchorIndex<numAnchors) { 942 if (this._hoveredAnchorIndex>=0 && this._hoveredAnchorIndex<numAnchors) {
905 var px = subpath.getAnchor(this._hoveredAnchorIndex).getPosX(); 943 var px = subpath.getAnchor(this._hoveredAnchorIndex).getPosX() +horizontalOffset;
906 var py = subpath.getAnchor(this._hoveredAnchorIndex).getPosY(); 944 var py = subpath.getAnchor(this._hoveredAnchorIndex).getPosY() +verticalOffset;
945 var localCoord = subpath.getAnchorLocalCoord(this._hoveredAnchorIndex);
946 if (localCoord) {
947 var sp = MathUtils.transformAndDivideHomogeneousPoint(localCoord,localToGlobalMat);
948 px = sp[0]; py=sp[1];
949 sp[0]+=deltaX; sp[1]+=deltaY;
950 }
907 ctx.beginPath(); 951 ctx.beginPath();
908 //ctx.arc(px + horizontalOffset, py + verticalOffset, this._DISPLAY_ANCHOR_RADIUS*1.5, 0, 2 * Math.PI, false); 952 //ctx.arc(px + horizontalOffset, py + verticalOffset, this._DISPLAY_ANCHOR_RADIUS*1.5, 0, 2 * Math.PI, false);
909 ctx.moveTo(px-selAnchorDelta+horizontalOffset, py-selAnchorDelta+verticalOffset); 953 ctx.moveTo(px-selAnchorDelta, py-selAnchorDelta);
910 ctx.lineTo(px+selAnchorDelta+horizontalOffset, py-selAnchorDelta+verticalOffset); 954 ctx.lineTo(px+selAnchorDelta, py-selAnchorDelta);
911 ctx.lineTo(px+selAnchorDelta+horizontalOffset, py+selAnchorDelta+verticalOffset); 955 ctx.lineTo(px+selAnchorDelta, py+selAnchorDelta);
912 ctx.lineTo(px-selAnchorDelta+horizontalOffset, py+selAnchorDelta+verticalOffset); 956 ctx.lineTo(px-selAnchorDelta, py+selAnchorDelta);
913 ctx.closePath(); 957 ctx.closePath();
914 ctx.stroke(); 958 ctx.stroke();
915 } 959 }
diff --git a/js/tools/drawing-tool-base.js b/js/tools/drawing-tool-base.js
index 8d87605c..991a2f1c 100755
--- a/js/tools/drawing-tool-base.js
+++ b/js/tools/drawing-tool-base.js
@@ -158,6 +158,8 @@ exports.DrawingToolBase = Montage.create(Montage, {
158 // get the center of the circle in stage world space 158 // get the center of the circle in stage world space
159 var swPos = viewUtils.postViewToStageWorld(MathUtils.transformPoint(psPos, hitRec.getPlaneMatrix()), hitRec.getElt()); 159 var swPos = viewUtils.postViewToStageWorld(MathUtils.transformPoint(psPos, hitRec.getPlaneMatrix()), hitRec.getElt());
160 160
161 //var swPos = hitRec.calculateStageWorldPoint(); todo figure out why we cannot just use this function instead of the above
162
161 // the stage world space point is now relative to the center of the 3D space. To 163 // the stage world space point is now relative to the center of the 3D space. To
162 // calculate the left and top offsets, this must be offset by the stage dimensions 164 // calculate the left and top offsets, this must be offset by the stage dimensions
163 swPos[0] += snapManager.getStageWidth() / 2.0; 165 swPos[0] += snapManager.getStageWidth() / 2.0;