aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-30 14:49:49 -0700
committerValerio Virgillito2012-04-30 14:49:49 -0700
commit6b1a6994d98a18b45016b97ac8d81483109a586c (patch)
treecda8a39f8813fb5c0f9b4fb1d37007e6ec971128 /js/tools
parentc8fac64d4ad8ac18744a17a5e0f0d17204355fd6 (diff)
parent48e442977ef1630e0f664265a7142320b55d7d20 (diff)
downloadninja-6b1a6994d98a18b45016b97ac8d81483109a586c.tar.gz
Merge pull request #182 from ericmueller/Canvas-interaction
Canvas interaction
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/OvalTool.js2
-rwxr-xr-xjs/tools/PanTool.js20
-rwxr-xr-xjs/tools/SelectionTool.js2
-rwxr-xr-xjs/tools/ShapeTool.js40
-rwxr-xr-xjs/tools/drawing-tool-base.js14
5 files changed, 62 insertions, 16 deletions
diff --git a/js/tools/OvalTool.js b/js/tools/OvalTool.js
index e8e88d1d..6edec811 100755
--- a/js/tools/OvalTool.js
+++ b/js/tools/OvalTool.js
@@ -66,7 +66,7 @@ exports.OvalTool = Montage.create(ShapeTool, {
66 var world = this.getGLWorld(canvas, this.options.use3D); 66 var world = this.getGLWorld(canvas, this.options.use3D);
67 67
68 var xOffset = ((left - canvas.offsetLeft + w/2) - canvas.width/2); 68 var xOffset = ((left - canvas.offsetLeft + w/2) - canvas.width/2);
69 var yOffset = (canvas.height/2 - (top - canvas.offsetTop + h/2)); 69 var yOffset = -(canvas.height/2 - (top - canvas.offsetTop + h/2));
70 70
71 var oval = new Circle(); //GLCircle(); 71 var oval = new Circle(); //GLCircle();
72 oval.init(world, xOffset, yOffset, w, h, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle); 72 oval.init(world, xOffset, yOffset, w, h, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle);
diff --git a/js/tools/PanTool.js b/js/tools/PanTool.js
index 0537a27b..ce7606a1 100755
--- a/js/tools/PanTool.js
+++ b/js/tools/PanTool.js
@@ -331,10 +331,26 @@ exports.PanTool = Montage.create(toolBase,
331 331
332 if (!this._altKeyDown) 332 if (!this._altKeyDown)
333 delta[2] = 0; 333 delta[2] = 0;
334 var transMat = Matrix.Translation( delta ); 334
335 this._worldPt = wPt; 335 // limit the change
336 var ucMat = viewUtils.getMatrixFromElement(this.application.ninja.currentDocument.documentRoot);
337 var tooMuch = false
338 if ((ucMat[12] > 12000) && (delta[0] > 0)) tooMuch = true;
339 if ((ucMat[12] < -12000) && (delta[0] < 0)) tooMuch = true;
340 if ((ucMat[13] > 12000) && (delta[1] > 0)) tooMuch = true;
341 if ((ucMat[13] < -12000) && (delta[1] < 0)) tooMuch = true;
342 if ((ucMat[14] > 12000) && (delta[2] > 0)) tooMuch = true;
343 if ((ucMat[14] < -12000) && (delta[2] < 0)) tooMuch = true;
344 if (tooMuch)
345 {
346 this._isDrawing = false;
347 delta = [0,0,0];
348 }
349 else
350 this._worldPt = wPt;
336 351
337 // update everything 352 // update everything
353 var transMat = Matrix.Translation( delta );
338 this.applyDeltaMat( transMat ); 354 this.applyDeltaMat( transMat );
339 } 355 }
340 } 356 }
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js
index 7033ee3d..9c9aee93 100755
--- a/js/tools/SelectionTool.js
+++ b/js/tools/SelectionTool.js
@@ -222,8 +222,10 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
222 value: function(event) { 222 value: function(event) {
223 if(this.application.ninja.selectedElements.length > 0) { 223 if(this.application.ninja.selectedElements.length > 0) {
224 this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]; 224 this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0];
225 console.log( "setting container to selected element" );
225 } else { 226 } else {
226 this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot; 227 this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot;
228 console.log( "setting container to stage" );
227 } 229 }
228 } 230 }
229 }, 231 },
diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js
index 21a5a025..c0681200 100755
--- a/js/tools/ShapeTool.js
+++ b/js/tools/ShapeTool.js
@@ -54,9 +54,9 @@ exports.ShapeTool = Montage.create(DrawingTool, {
54 }, 54 },
55 55
56 HandleLeftButtonUp: 56 HandleLeftButtonUp:
57 { 57 {
58 value: function (event) 58 value: function (event)
59 { 59 {
60 var drawData; 60 var drawData;
61 61
62 drawData = this.getDrawingData(); 62 drawData = this.getDrawingData();
@@ -64,29 +64,34 @@ exports.ShapeTool = Montage.create(DrawingTool, {
64 if(drawData) { 64 if(drawData) {
65 var canvas; 65 var canvas;
66 if(!this._useExistingCanvas()) { 66 if(!this._useExistingCanvas()) {
67 console.log( "creating a new canvas" );
67 canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); 68 canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
68 var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height, 69 var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height,
69 drawData.planeMat, drawData.midPt, canvas, true); 70 drawData.planeMat, drawData.midPt, canvas, true);
70 71
71 canvas.elementModel.isShape = true; 72 canvas.elementModel.isShape = true;
72 this.application.ninja.elementMediator.addElements(canvas, elementModel.data); 73 this.application.ninja.elementMediator.addElements(canvas, elementModel.data);
73 } else { 74 } else {
75 console.log( "inserting shape into container" );
74 canvas = this._targetedElement; 76 canvas = this._targetedElement;
77 if (!canvas.getAttribute( "data-RDGE-id" ))
78 canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() );
75 canvas.elementModel.controller = ShapesController; 79 canvas.elementModel.controller = ShapesController;
76 if(!canvas.elementModel.shapeModel) { 80 if(!canvas.elementModel.shapeModel) {
77 canvas.elementModel.shapeModel = Montage.create(ShapeModel); 81 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
78 } 82 }
83 this.application.ninja.elementMediator.addElements(canvas, canvas.elementModel.data);
79 } 84 }
80 } 85 }
81 86
82 this.endDraw(event); 87 this.endDraw(event);
83 88
84 this._isDrawing = false; 89 this._isDrawing = false;
85 this._hasDraw=false; 90 this._hasDraw=false;
86 91
87 this.DrawHandles(); 92 this.DrawHandles();
88 } 93 }
89 }, 94 },
90 95
91 onAddElements: { 96 onAddElements: {
92 value: function(el) { 97 value: function(el) {
@@ -211,7 +216,20 @@ exports.ShapeTool = Montage.create(DrawingTool, {
211 _useExistingCanvas: { 216 _useExistingCanvas: {
212 value: function() 217 value: function()
213 { 218 {
214 return (this._targetedElement && !ShapesController.isElementAShape(this._targetedElement)); 219 var target;
220 if (this._targetedElement && (this._targetedElement.nodeName === "CANVAS") && !ShapesController.isElementAShape(this._targetedElement))
221 target = this._targetedElement;
222 else
223 {
224 var container = this.application.ninja.currentSelectedContainer;
225 if (container && (container.nodeName === "CANVAS"))
226 {
227 target = container;
228 this._targetedElement = target;
229 }
230 }
231
232 return target;
215 } 233 }
216 } 234 }
217 235
diff --git a/js/tools/drawing-tool-base.js b/js/tools/drawing-tool-base.js
index 2283dfab..2e652d42 100755
--- a/js/tools/drawing-tool-base.js
+++ b/js/tools/drawing-tool-base.js
@@ -41,11 +41,21 @@ exports.DrawingToolBase = Montage.create(Montage, {
41 41
42 // do the snap 42 // do the snap
43 var hitRec = snapManager.snap(x, y, true); 43 var hitRec = snapManager.snap(x, y, true);
44 var dragPlane;
44 if (hitRec) { 45 if (hitRec) {
45 // set up the working plane and convert the hit record to be working plane relative 46 // set up the working plane and convert the hit record to be working plane relative
46 var dragPlane = snapManager.setupDragPlanes( hitRec ); 47 if (hitRec.getElement() === snapManager.application.ninja.currentSelectedContainer)
47 var wpHitRec = hitRec.convertToWorkingPlane( dragPlane ); 48 {
49 dragPlane = viewUtils.getUnprojectedElementPlane( hitRec.getElement() );
50 snapManager.setupDragPlaneFromPlane( dragPlane );
51 }
52 else
53 {
54 dragPlane = snapManager.setupDragPlanes( hitRec );
55 }
56 console.log( "drag plane: " + dragPlane );
48 57
58 var wpHitRec = hitRec.convertToWorkingPlane( dragPlane );
49 var pt = hitRec.getScreenPoint(); 59 var pt = hitRec.getScreenPoint();
50 60
51 return( [wpHitRec, pt[0], pt[1]] ); 61 return( [wpHitRec, pt[0], pt[1]] );