aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-07 15:22:11 -0800
committerPushkar Joshi2012-02-07 15:22:11 -0800
commit9b6b228524f14bf65ba60aaf3d0993c8ec5bff2d (patch)
tree37bb26044958e8e991d08e271a1f67337a2029d4 /js/tools
parent4bbe42e6d01fd0f81d13357a75b40eae9925dda3 (diff)
downloadninja-9b6b228524f14bf65ba60aaf3d0993c8ec5bff2d.tar.gz
some minor bug fixes and code cleanup
Diffstat (limited to 'js/tools')
-rw-r--r--js/tools/PenTool.js44
1 files changed, 15 insertions, 29 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index cb2ea85a..5b48d3c9 100644
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -142,15 +142,12 @@ exports.PenTool = Montage.create(ShapeTool, {
142 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) 142 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
143 return; 143 return;
144 } 144 }
145 //BEGIN ShapeTool code
146 if (this._canDraw) { 145 if (this._canDraw) {
147 this._isDrawing = true; 146 this._isDrawing = true;
148 } 147 }
149 148
150 //this._targetedCanvas = stageManagerModule.stageManager.GetObjectFromPoint(event.layerX, event.layerY, this._canOperateOnStage);
151 149
152 this.startDraw(event); 150 this.startDraw(event);
153 //END ShapeTool code
154 151
155 //assume we are not starting a new path as we will set this to true if we create a new GLSubpath() 152 //assume we are not starting a new path as we will set this to true if we create a new GLSubpath()
156 this._isNewPath = false; 153 this._isNewPath = false;
@@ -269,6 +266,8 @@ exports.PenTool = Montage.create(ShapeTool, {
269 if (!g_DoPenToolMouseMove){ 266 if (!g_DoPenToolMouseMove){
270 NJevent("enableStageMove"); 267 NJevent("enableStageMove");
271 } 268 }
269
270 this._hoveredAnchorIndex = -1;
272 } //value: function (event) { 271 } //value: function (event) {
273 }, //HandleLeftButtonDown 272 }, //HandleLeftButtonDown
274 273
@@ -370,7 +369,7 @@ exports.PenTool = Montage.create(ShapeTool, {
370 } 369 }
371 370
372 }//value: function(event) 371 }//value: function(event)
373 }, 372 },//HandleMouseMove
374 373
375 //TODO Optimize! This function is probably no longer needed 374 //TODO Optimize! This function is probably no longer needed
376 TranslateSelectedSubpathPerPenCanvas:{ 375 TranslateSelectedSubpathPerPenCanvas:{
@@ -499,6 +498,7 @@ exports.PenTool = Montage.create(ShapeTool, {
499 if (!g_DoPenToolMouseMove){ 498 if (!g_DoPenToolMouseMove){
500 NJevent("disableStageMove"); 499 NJevent("disableStageMove");
501 } 500 }
501 this._hoveredAnchorIndex = -1;
502 } 502 }
503 }, 503 },
504 504
@@ -664,15 +664,17 @@ exports.PenTool = Montage.create(ShapeTool, {
664 }, //BuildSecondCtrlPoint:{ 664 }, //BuildSecondCtrlPoint:{
665 665
666 666
667 /*
667 deleteSelection: { 668 deleteSelection: {
668 value: function() { 669 value: function() {
669 //clear the selected subpath...the only new additions to this function w.r.t. ToolBase 670 //clear the selected subpath...the only new additions to this function w.r.t. ToolBase
670 if (this._selectedSubpath){ 671 if (this._selectedSubpath){
671 if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ 672 if (this._selectedSubpath.getSelectedAnchorIndex()>=0){
672 this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 673 this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex());
674 this._selectedSubpath.createSamples();
673 //clear the canvas 675 //clear the canvas
674 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); 676 this.application.ninja.stage.clearDrawingCanvas();
675 this.DrawSubpathAnchors(this._selectedSubpath); 677 this.DrawSubpathAnchors(this._selectedSubpath);
676 this.ShowSelectedSubpath(); 678 this.ShowSelectedSubpath();
677 } 679 }
678 else { 680 else {
@@ -681,28 +683,14 @@ exports.PenTool = Montage.create(ShapeTool, {
681 this._selectedSubpath.createSamples(); 683 this._selectedSubpath.createSamples();
682 this._selectedSubpath = null; 684 this._selectedSubpath = null;
683 //clear the canvas 685 //clear the canvas
684 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); 686 this.application.ninja.stage.clearDrawingCanvas();
685
686 //TODO begin code block taken from ToolBase...figure out how to override it correctly
687 var item;
688 /*
689 if(!selectionManagerModule.selectionManager.isDocument) {
690 for(var i=0; item = selectionManagerModule.selectionManager.selectedItems[i]; i++) {
691 drawUtils.removeElement(item._element); // TODO This was called twice - After the event.
692 window.snapManager.removeElementFrom2DCache( item._element ); // TODO Check with Nivesh about it.
693 DocumentControllerModule.DocumentController.RemoveElement(item._element);
694 }
695
696 NJevent( "deleteSelection" );
697 }
698 */
699 //end code block taken from ToolBase
700
701 this._penCanvas = null; 687 this._penCanvas = null;
702 } 688 }
703 } 689 }
704 } 690 }
705 }, 691 },
692 */
693
706 694
707 HandleDoubleClick: { 695 HandleDoubleClick: {
708 value: function () { 696 value: function () {
@@ -710,9 +698,6 @@ exports.PenTool = Montage.create(ShapeTool, {
710 if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) { 698 if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) {
711 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 699 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
712 var pos = Vector.create([selAnchor.getPosX(), selAnchor.getPosY(), selAnchor.getPosZ()]); 700 var pos = Vector.create([selAnchor.getPosX(), selAnchor.getPosY(), selAnchor.getPosZ()]);
713 //var prev = Vector.create([selAnchor.getPrevX(), selAnchor.getPrevY(), selAnchor.getPrevZ()]);
714 //var next = Vector.create([selAnchor.getNextX(), selAnchor.getNextY(), selAnchor.getNextZ()]);
715
716 var distToPrev = selAnchor.getPrevDistanceSq(pos[0], pos[1], pos[2]); 701 var distToPrev = selAnchor.getPrevDistanceSq(pos[0], pos[1], pos[2]);
717 var distToNext = selAnchor.getNextDistanceSq(pos[0], pos[1], pos[2]); 702 var distToNext = selAnchor.getNextDistanceSq(pos[0], pos[1], pos[2]);
718 var threshSq = 0; // 4 * this._PICK_POINT_RADIUS * this._PICK_POINT_RADIUS; 703 var threshSq = 0; // 4 * this._PICK_POINT_RADIUS * this._PICK_POINT_RADIUS;
@@ -820,8 +805,8 @@ exports.PenTool = Montage.create(ShapeTool, {
820 if (ctx.lineWidth == subpath.getStrokeWidth()) 805 if (ctx.lineWidth == subpath.getStrokeWidth())
821 ctx.lineWidth = 3; 806 ctx.lineWidth = 3;
822 ctx.strokeStyle = "black"; 807 ctx.strokeStyle = "black";
823 if (subpath.getStrokeColor()) 808 //if (subpath.getStrokeColor())
824 ctx.strokeStyle = MathUtils.colorToHex( subpath.getStrokeColor() ); 809 // ctx.strokeStyle = MathUtils.colorToHex( subpath.getStrokeColor() );
825 ctx.beginPath(); 810 ctx.beginPath();
826 var p0x = subpath.getAnchor(0).getPosX()+ horizontalOffset; 811 var p0x = subpath.getAnchor(0).getPosX()+ horizontalOffset;
827 var p0y = subpath.getAnchor(0).getPosY()+ verticalOffset; 812 var p0y = subpath.getAnchor(0).getPosY()+ verticalOffset;
@@ -884,7 +869,7 @@ exports.PenTool = Montage.create(ShapeTool, {
884 //display the hovered over anchor point 869 //display the hovered over anchor point
885 ctx.lineWidth = 2; 870 ctx.lineWidth = 2;
886 ctx.strokeStyle = "black"; 871 ctx.strokeStyle = "black";
887 if (this._hoveredAnchorIndex>=0) { 872 if (this._hoveredAnchorIndex && this._hoveredAnchorIndex>=0) {
888 var px = subpath.getAnchor(this._hoveredAnchorIndex).getPosX(); 873 var px = subpath.getAnchor(this._hoveredAnchorIndex).getPosX();
889 var py = subpath.getAnchor(this._hoveredAnchorIndex).getPosY(); 874 var py = subpath.getAnchor(this._hoveredAnchorIndex).getPosY();
890 ctx.beginPath(); 875 ctx.beginPath();
@@ -1061,6 +1046,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1061 //clear the selected subpath...the only new additions to this function w.r.t. ToolBase 1046 //clear the selected subpath...the only new additions to this function w.r.t. ToolBase
1062 if (this._selectedSubpath){ 1047 if (this._selectedSubpath){
1063 if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ 1048 if (this._selectedSubpath.getSelectedAnchorIndex()>=0){
1049 this._hoveredAnchorIndex=-1;
1064 this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 1050 this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex());
1065 this._selectedSubpath.createSamples(); 1051 this._selectedSubpath.createSamples();
1066 //clear the canvas 1052 //clear the canvas