aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-05-01 20:13:58 -0700
committerNivesh Rajbhandari2012-05-01 20:13:58 -0700
commit355656cac2fa1a025ad97791ea095a54cebdff71 (patch)
treefeb28083c4540ea6298a8d6d3410ffa0e9c15527 /js/tools
parent0f16c5ea0d08a740f553284c436bb3e589fb1357 (diff)
downloadninja-355656cac2fa1a025ad97791ea095a54cebdff71.tar.gz
Support drawing in side and top view. Also, adding back support for drawing shapes inside canvas when double-clicked into canvas or when moused over canvas.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/ShapeTool.js3
-rwxr-xr-xjs/tools/drawing-tool-base.js63
-rwxr-xr-xjs/tools/drawing-tool.js3
3 files changed, 41 insertions, 28 deletions
diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js
index 8f45891d..d2337000 100755
--- a/js/tools/ShapeTool.js
+++ b/js/tools/ShapeTool.js
@@ -106,6 +106,9 @@ exports.ShapeTool = Montage.create(DrawingTool, {
106 if(wasSelected) { 106 if(wasSelected) {
107 this.AddCustomFeedback(); 107 this.AddCustomFeedback();
108 this.application.ninja.elementMediator.addDelegate = this; 108 this.application.ninja.elementMediator.addDelegate = this;
109 if(this.application.ninja.currentSelectedContainer.nodeName === "CANVAS") {
110 this._targetedElement = this.application.ninja.currentSelectedContainer;
111 }
109 } else { 112 } else {
110 this.RemoveCustomFeedback(); 113 this.RemoveCustomFeedback();
111 this.application.ninja.elementMediator.addDelegate = null; 114 this.application.ninja.elementMediator.addDelegate = null;
diff --git a/js/tools/drawing-tool-base.js b/js/tools/drawing-tool-base.js
index 0b51aa28..7d97f105 100755
--- a/js/tools/drawing-tool-base.js
+++ b/js/tools/drawing-tool-base.js
@@ -24,6 +24,9 @@ exports.DrawingToolBase = Montage.create(Montage, {
24 value: null 24 value: null
25 }, 25 },
26 26
27 dragPlane: {
28 value: null
29 },
27 /** 30 /**
28 * Used on the initial MouseDown for Drawing Tools 31 * Used on the initial MouseDown for Drawing Tools
29 * 32 *
@@ -33,28 +36,30 @@ exports.DrawingToolBase = Montage.create(Montage, {
33 * 2 - Y value converted to screen point 36 * 2 - Y value converted to screen point
34 */ 37 */
35 getInitialSnapPoint: { 38 getInitialSnapPoint: {
36 value: function(x,y) { 39 value: function(x, y, shapeCanvas) {
40 snapManager.clearDragPlane();
41
37 // update the snap settings 42 // update the snap settings
38 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); 43 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
39 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); 44 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() );
40 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); 45 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() );
41 46
42 // do the snap 47 // do the snap
43 var hitRec = snapManager.snap(x, y, true); 48 this.dragPlane = null;
44 var dragPlane; 49 var hitRec = snapManager.snap(x, y, true);
45 if (hitRec) { 50 if (hitRec) {
46 // set up the working plane and convert the hit record to be working plane relative 51 if (shapeCanvas)
47 if (hitRec.getElement() === snapManager.application.ninja.currentSelectedContainer)
48 { 52 {
49 dragPlane = viewUtils.getUnprojectedElementPlane( hitRec.getElement() ); 53 this.dragPlane = viewUtils.getUnprojectedElementPlane( shapeCanvas );
50 snapManager.setupDragPlaneFromPlane( dragPlane ); 54 snapManager.setupDragPlaneFromPlane( this.dragPlane );
51 } 55 }
52 else 56 else
53 { 57 {
54 dragPlane = snapManager.setupDragPlanes( hitRec ); 58 this.dragPlane = snapManager.setupDragPlanes( hitRec, true );
55 } 59 }
60// console.log( "drag plane: " + this.dragPlane );
56 61
57 var wpHitRec = hitRec.convertToWorkingPlane( dragPlane ); 62 var wpHitRec = hitRec.convertToWorkingPlane( this.dragPlane );
58 var pt = hitRec.getScreenPoint(); 63 var pt = hitRec.getScreenPoint();
59 64
60 return( [wpHitRec, pt[0], pt[1]] ); 65 return( [wpHitRec, pt[0], pt[1]] );
@@ -72,28 +77,32 @@ exports.DrawingToolBase = Montage.create(Montage, {
72 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); 77 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() );
73 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); 78 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() );
74 79
75
76 // do the first snap
77 var hitRec = snapManager.snap(x, y, snap3d ); 80 var hitRec = snapManager.snap(x, y, snap3d );
78 if (hitRec) { 81 if (hitRec) {
79 if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) { 82// if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) {
80 hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() ); 83// hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() );
81 } 84// }
82 85//
83 if(downHitRec !== null) { 86// if(downHitRec !== null) {
84 // if we are working off-plane, do a snap to the projected locations of the geometry 87// // if we are working off-plane, do a snap to the projected locations of the geometry
85 var thePlane = workingPlane; 88// var thePlane = workingPlane;
86 if (snapManager.hasDragPlane()) 89// if (snapManager.hasDragPlane())
87 { 90// {
88 thePlane = snapManager.getDragPlane(); 91// thePlane = snapManager.getDragPlane();
89 } 92// }
90 93//
91 // Return the up HitRec 94// // Return the up HitRec
92 return hitRec; 95// return hitRec;
93 } else { 96// } else {
94 return null; 97// return null;
98// }
99 if(downHitRec) {
100 hitRec = hitRec.convertToWorkingPlane(this.dragPlane);
101 } else if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) {
102 hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() );
95 } 103 }
96 } 104 }
105 return hitRec;
97 } 106 }
98 }, 107 },
99 108
diff --git a/js/tools/drawing-tool.js b/js/tools/drawing-tool.js
index dc5f7996..d906fdf9 100755
--- a/js/tools/drawing-tool.js
+++ b/js/tools/drawing-tool.js
@@ -72,10 +72,11 @@ exports.DrawingTool = Montage.create(ToolBase, {
72 var snapData, point; 72 var snapData, point;
73 73
74 this._isDrawing = true; 74 this._isDrawing = true;
75 this.mouseDownHitRec = null;
75 this.mouseUpHitRec = null; 76 this.mouseUpHitRec = null;
76 77
77 point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); 78 point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY));
78 snapData = DrawingToolBase.getInitialSnapPoint(point.x, point.y); //event.layerX, event.layerY); 79 snapData = DrawingToolBase.getInitialSnapPoint(point.x, point.y, this._targetedElement); //event.layerX, event.layerY);
79 this.mouseDownHitRec = snapData[0]; 80 this.mouseDownHitRec = snapData[0];
80 this.downPoint.x = snapData[1]; 81 this.downPoint.x = snapData[1];
81 this.downPoint.y = snapData[2]; 82 this.downPoint.y = snapData[2];