aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/html-document.js18
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js279
-rwxr-xr-xjs/lib/drawing/world.js11
-rwxr-xr-xjs/lib/geom/circle.js61
-rwxr-xr-xjs/lib/geom/geom-obj.js59
-rwxr-xr-xjs/lib/geom/rectangle.js40
-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
11 files changed, 331 insertions, 215 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 3dbf96ce..9d083dd8 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -207,16 +207,16 @@ exports.HTMLDocument = Montage.create(TextDocument, {
207 var elt = this.documentRoot; 207 var elt = this.documentRoot;
208 if (elt) 208 if (elt)
209 { 209 {
210 /*
211 // Use this code to test the runtime version of WebGL
212 var cdm = new NinjaCvsRt.CanvasDataManager();
213 cdm.loadGLData(elt, value, null );
214 */
215
216 // /*
210 var nWorlds= value.length; 217 var nWorlds= value.length;
211 for (var i=0; i<nWorlds; i++) 218 for (var i=0; i<nWorlds; i++)
212 { 219 {
213 /*
214 // Use this code to test the runtime version of WebGL
215 var cdm = new NinjaCvsRt.CanvasDataManager();
216 cdm.loadGLData(elt, value, null );
217 */
218
219 // /*
220 // get the data for the next canvas 220 // get the data for the next canvas
221 var importStr = value[i]; 221 var importStr = value[i];
222 222
@@ -228,7 +228,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
228 { 228 {
229 // JSON format. pull off the 229 // JSON format. pull off the
230 importStr = importStr.substr( index+1 ); 230 importStr = importStr.substr( index+1 );
231 jObj = jObj = JSON.parse( importStr ); 231 jObj = JSON.parse( importStr );
232 id = jObj.id; 232 id = jObj.id;
233 } 233 }
234 else 234 else
@@ -281,8 +281,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
281 } 281 }
282 } 282 }
283 } 283 }
284 // */
285 } 284 }
285 // */
286 } 286 }
287 } 287 }
288 }, 288 },
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index cd8cc102..7fc492a5 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -948,7 +948,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
948 { 948 {
949 949
950 // see if we can snap to a contained geometry object 950 // see if we can snap to a contained geometry object
951 if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) 951 if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt))
952 { 952 {
953 var localPt = hitRec.calculateElementWorldPoint(); 953 var localPt = hitRec.calculateElementWorldPoint();
954 if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) 954 if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT)
@@ -1011,7 +1011,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1011 } 1011 }
1012 // hit test the current object 1012 // hit test the current object
1013 var hit; 1013 var hit;
1014 if (depth > 0) // don't snap to the root 1014 var snapToStage = ((depth === 0) && (elt === this.application.ninja.currentSelectedContainer) && (elt.nodeName === 'CANVAS'));
1015 if ((depth > 0) || snapToStage) // don't snap to the root unles we are working inside a canvas
1015 { 1016 {
1016 // if the element is in the 2D cache snapping is done there 1017 // if the element is in the 2D cache snapping is done there
1017 if (elt.elementModel && !elt.elementModel.isIn2DSnapCache) 1018 if (elt.elementModel && !elt.elementModel.isIn2DSnapCache)
@@ -1077,7 +1078,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1077 var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); 1078 var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D );
1078 1079
1079 // see if we can snap to a contained geometry object 1080 // see if we can snap to a contained geometry object
1080 if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) 1081 if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt))
1081 { 1082 {
1082 var localPt = hitRec.calculateElementWorldPoint(); 1083 var localPt = hitRec.calculateElementWorldPoint();
1083 if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) 1084 if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT)
@@ -1320,193 +1321,135 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1320 } 1321 }
1321 }, 1322 },
1322 1323
1323 snapToContainedElement : 1324 doSnapToContainedElement:
1324 { 1325 {
1325 value: function( eyePt, dir, glObj, hitRec, targetScrPt ) 1326 value: function( eyePt, dir, glObj, hitRec, targetScrPt )
1326 { 1327 {
1327 var rtnVal = false; 1328 var rtnVal = false;
1328 var elt = hitRec.getElement();
1329 1329
1330 var elt = hitRec.getElt();
1330 var world = glObj.getWorld(); 1331 var world = glObj.getWorld();
1331 switch (glObj.geomType()) 1332
1333 var nearVrt = glObj.getNearVertex( eyePt, dir );
1334 if (nearVrt)
1332 { 1335 {
1333 case glObj.GEOM_TYPE_RECTANGLE: 1336 var viewPt = this.GLToView(nearVrt, world );
1334 break; 1337 var mat = viewUtils.getMatrixFromElement( elt );
1338 var worldPt = MathUtils.transformPoint( viewPt, mat );
1335 1339
1336 case glObj.GEOM_TYPE_CIRCLE: 1340 viewUtils.pushViewportObj( elt );
1341 var scrPt = viewUtils.viewToScreen( worldPt );
1342 var offset = viewUtils.getElementOffset( elt );
1343 MathUtils.makeDimension3( offset );
1344 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1345 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1346
1347 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1348 if (dist < this.ELEMENT_VERTEX_HIT_RAD)
1349 {
1350 //console.log( "hit a vertex" );
1351
1352 // check if the distance is less than
1353 // the distance on the current hit record
1354 //if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ))
1337 { 1355 {
1338 var nearVrt = glObj.getNearVertex( eyePt, dir ); 1356 //console.log( "rejected - further than existing snap" );
1339 if (nearVrt) 1357
1340 { 1358 hitRec.setScreenPoint( globalPt );
1341 var viewPt = this.GLToView(nearVrt, world ); 1359 //var localMatInv = hitRec.getPlaneMatrix().inverse();
1342 var mat = viewUtils.getMatrixFromElement( elt ); 1360 var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []);
1343 var worldPt = MathUtils.transformPoint( viewPt, mat ); 1361 viewUtils.pushViewportObj( hitRec.getElement() );
1344 1362 var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] );
1345 viewUtils.pushViewportObj( elt ); 1363 viewUtils.popViewportObj();
1346 var scrPt = viewUtils.viewToScreen( worldPt ); 1364 localPt = MathUtils.transformPoint( localPt, localMatInv );
1347 var offset = viewUtils.getElementOffset( elt ); 1365 hitRec.setLocalPoint( localPt );
1348 MathUtils.makeDimension3( offset ); 1366 hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT );
1349 var parentPt = vecUtils.vecAdd(3, scrPt, offset );
1350 var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent );
1351
1352 var dist = vecUtils.vecDist(2, globalPt, targetScrPt );
1353 if (dist < this.ELEMENT_VERTEX_HIT_RAD)
1354 {
1355 // check if the distance is less than
1356 // the distance on the current hit record
1357 if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ))
1358 {
1359 hitRec.setScreenPoint( globalPt );
1360 //var localMatInv = hitRec.getPlaneMatrix().inverse();
1361 var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []);
1362 viewUtils.pushViewportObj( hitRec.getElement() );
1363 var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] );
1364 viewUtils.popViewportObj();
1365 localPt = MathUtils.transformPoint( localPt, localMatInv );
1366 hitRec.setLocalPoint( localPt );
1367 hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT );
1368
1369 rtnVal = true;
1370 }
1371 }
1372 } // if (nearVrt)
1373 1367
1374 if (!rtnVal) 1368 rtnVal = true;
1375 { 1369 }
1376 var nearPt = glObj.getNearPoint( eyePt, dir ); 1370 }
1377 if (nearPt) 1371 }
1378 {
1379 var viewPt = this.GLToView(nearPt, world );
1380 var mat = viewUtils.getMatrixFromElement( elt );
1381