From 27c1ba250a7db26cf24dd456d20af9ff1649e638 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 23 Apr 2012 17:04:48 -0700 Subject: canvas interaction --- js/helper-classes/3D/snap-manager.js | 274 ++++++++++++++--------------------- 1 file changed, 108 insertions(+), 166 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index cd8cc102..2c975985 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1077,7 +1077,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); // see if we can snap to a contained geometry object - if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) + if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt)) { var localPt = hitRec.calculateElementWorldPoint(); if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) @@ -1320,193 +1320,135 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { } }, - snapToContainedElement : + doSnapToContainedElement: { value: function( eyePt, dir, glObj, hitRec, targetScrPt ) { var rtnVal = false; - var elt = hitRec.getElement(); + var elt = hitRec.getElt(); var world = glObj.getWorld(); - switch (glObj.geomType()) + + var nearVrt = glObj.getNearVertex( eyePt, dir ); + if (nearVrt) { - case glObj.GEOM_TYPE_RECTANGLE: - break; + var viewPt = this.GLToView(nearVrt, world ); + var mat = viewUtils.getMatrixFromElement( elt ); + var worldPt = MathUtils.transformPoint( viewPt, mat ); - case glObj.GEOM_TYPE_CIRCLE: + viewUtils.pushViewportObj( elt ); + var scrPt = viewUtils.viewToScreen( worldPt ); + var offset = viewUtils.getElementOffset( elt ); + MathUtils.makeDimension3( offset ); + var parentPt = vecUtils.vecAdd(3, scrPt, offset ); + var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); + + var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); + if (dist < this.ELEMENT_VERTEX_HIT_RAD) + { + console.log( "hit a vertex" ); + + // check if the distance is less than + // the distance on the current hit record + if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) { - var nearVrt = glObj.getNearVertex( eyePt, dir ); - if (nearVrt) - { - var viewPt = this.GLToView(nearVrt, world ); - var mat = viewUtils.getMatrixFromElement( elt ); - var worldPt = MathUtils.transformPoint( viewPt, mat ); - - viewUtils.pushViewportObj( elt ); - var scrPt = viewUtils.viewToScreen( worldPt ); - var offset = viewUtils.getElementOffset( elt ); - MathUtils.makeDimension3( offset ); - var parentPt = vecUtils.vecAdd(3, scrPt, offset ); - var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); - - var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); - if (dist < this.ELEMENT_VERTEX_HIT_RAD) - { - // check if the distance is less than - // the distance on the current hit record - if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) - { - hitRec.setScreenPoint( globalPt ); - //var localMatInv = hitRec.getPlaneMatrix().inverse(); - var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); - viewUtils.pushViewportObj( hitRec.getElement() ); - var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); - localPt = MathUtils.transformPoint( localPt, localMatInv ); - hitRec.setLocalPoint( localPt ); - hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - - rtnVal = true; - } - } - } // if (nearVrt) + console.log( "rejected - further than existing snap" ); + + hitRec.setScreenPoint( globalPt ); + //var localMatInv = hitRec.getPlaneMatrix().inverse(); + var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); + viewUtils.pushViewportObj( hitRec.getElement() ); + var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); + viewUtils.popViewportObj(); + localPt = MathUtils.transformPoint( localPt, localMatInv ); + hitRec.setLocalPoint( localPt ); + hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - if (!rtnVal) - { - var nearPt = glObj.getNearPoint( eyePt, dir ); - if (nearPt) - { - var viewPt = this.GLToView(nearPt, world ); - var mat = viewUtils.getMatrixFromElement( elt ); - var worldPt = MathUtils.transformPoint( viewPt, mat ); - - viewUtils.pushViewportObj( elt ); - var scrPt = viewUtils.viewToScreen( worldPt ); - var offset = viewUtils.getElementOffset( elt ); - MathUtils.makeDimension3( offset ); - var parentPt = vecUtils.vecAdd(3, scrPt, offset ); - var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); - - var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); - if (dist < this.ELEMENT_EDGE_HIT_RAD) - { - // check if the distance is less than - // the distance on the current hit record - //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ); - //if (dist <= dist2+1 ) - { - hitRec.setScreenPoint( globalPt ); - //var localMatInv = hitRec.getPlaneMatrix().inverse(); - var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); - viewUtils.pushViewportObj( hitRec.getElement() ); - var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); - localPt = MathUtils.transformPoint( localPt, localMatInv ); - hitRec.setLocalPoint( localPt ); - hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - - rtnVal = true; - } - } - } - } // if (!rtnVal) + rtnVal = true; + } + } + } - if (!rtnVal && glObj.containsPoint( eyePt, dir )) + if (!rtnVal) + { + var nearPt = glObj.getNearPoint( eyePt, dir ); + if (nearPt) + { + var viewPt = this.GLToView(nearPt, world ); + var mat = viewUtils.getMatrixFromElement( elt ); + var worldPt = MathUtils.transformPoint( viewPt, mat ); + + viewUtils.pushViewportObj( elt ); + var scrPt = viewUtils.viewToScreen( worldPt ); + var offset = viewUtils.getElementOffset( elt ); + MathUtils.makeDimension3( offset ); + var parentPt = vecUtils.vecAdd(3, scrPt, offset ); + var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); + + var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); + if (dist < this.ELEMENT_EDGE_HIT_RAD) + { + console.log( "hit an edge" ); + + // check if the distance is less than + // the distance on the current hit record + //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ); + //if (dist <= dist2+1 ) { + hitRec.setScreenPoint( globalPt ); + //var localMatInv = hitRec.getPlaneMatrix().inverse(); + var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); + viewUtils.pushViewportObj( hitRec.getElement() ); + var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); + viewUtils.popViewportObj(); + localPt = MathUtils.transformPoint( localPt, localMatInv ); + hitRec.setLocalPoint( localPt ); + hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); + rtnVal = true; } } + } + } // if (!rtnVal) + + if (!rtnVal && glObj.containsPoint( eyePt, dir )) + { + rtnVal = true; + } + + return rtnVal; + } + }, + + snapToContainedElement : + { + value: function( eyePt, dir, glObj, hitRec, targetScrPt ) + { + var rtnVal = false; + var elt = hitRec.getElement(); + + var world = glObj.getWorld(); + switch (glObj.geomType()) + { + case glObj.GEOM_TYPE_RECTANGLE: + if ((glObj.getWidth() != world.getViewportWidth()) || (glObj.getHeight() != world.getViewportHeight())) + rtnVal = this.doSnapToContainedElement( eyePt, dir, glObj, hitRec, targetScrPt ); + break; + + case glObj.GEOM_TYPE_CIRCLE: + rtnVal = this.doSnapToContainedElement( eyePt, dir, glObj, hitRec, targetScrPt ); break; case glObj.GEOM_TYPE_LINE: case glObj.GEOM_TYPE_PATH: // Snapping not implemented for these type, but don't throw an error... break; - case glObj.GEOM_TYPE_BRUSH_STROKE: + + case glObj.GEOM_TYPE_BRUSH_STROKE: break; //don't throw error because snapping not yet implemented - case glObj.GEOM_TYPE_CUBIC_BEZIER: - { - var nearVrt = glObj.getNearVertex( eyePt, dir ); - if (nearVrt) - { - var viewPt = this.GLToView(nearVrt, world ); - var mat = viewUtils.getMatrixFromElement( elt ); - var worldPt = MathUtils.transformPoint( viewPt, mat ); - - viewUtils.pushViewportObj( elt ); - var scrPt = viewUtils.viewToScreen( worldPt ); - var offset = viewUtils.getElementOffset( elt ); - MathUtils.makeDimension3( offset ); - var parentPt = vecUtils.vecAdd(3, scrPt, offset ); - var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); - - var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); - if (dist < this.ELEMENT_VERTEX_HIT_RAD) - { - // check if the distance is less than - // the distance on the current hit record - if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) - { - hitRec.setScreenPoint( globalPt ); - //var localMatInv = hitRec.getPlaneMatrix().inverse(); - var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); - viewUtils.pushViewportObj( hitRec.getElement() ); - var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); - localPt = MathUtils.transformPoint( localPt, localMatInv ); - hitRec.setLocalPoint( localPt ); - hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - - rtnVal = true; - } - } - } // if (nearVrt) - - if (!rtnVal) - { - var nearPt = glObj.getNearPoint( eyePt, dir ); - if (nearPt) - { - var viewPt = this.GLToView(nearPt, world ); - var mat = viewUtils.getMatrixFromElement( elt ); - var worldPt = MathUtils.transformPoint( viewPt, mat ); - - viewUtils.pushViewportObj( elt ); - var scrPt = viewUtils.viewToScreen( worldPt ); - var offset = viewUtils.getElementOffset( elt ); - MathUtils.makeDimension3( offset ); - var parentPt = vecUtils.vecAdd(3, scrPt, offset ); - var globalPt = viewUtils.localToGlobal( parentPt, elt.offsetParent ); - - var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); - if (dist < this.ELEMENT_EDGE_HIT_RAD) - { - // check if the distance is less than - // the distance on the current hit record - //var dist2 = vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() ); - //if (dist <= dist2+1 ) - { - hitRec.setScreenPoint( globalPt ); - //var localMatInv = hitRec.getPlaneMatrix().inverse(); - var localMatInv = glmat4.inverse( hitRec.getPlaneMatrix(), []); - viewUtils.pushViewportObj( hitRec.getElement() ); - var localPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); - localPt = MathUtils.transformPoint( localPt, localMatInv ); - hitRec.setLocalPoint( localPt ); - hitRec.setType( hitRec.SNAP_TYPE_CONTAINED_ELEMENT ); - - rtnVal = true; - } - } - } - } // if (!rtnVal) - - if (!rtnVal && glObj.containsPoint( eyePt, dir )) - { - rtnVal = true; - } - } + + case glObj.GEOM_TYPE_CUBIC_BEZIER: + rtnVal = this.doSnapToContainedElement( eyePt, dir, glObj, hitRec, targetScrPt ); break; default: throw new Error( "invalid GL geometry type: " + glObj.geomType() ); -- cgit v1.2.3 From 4b83774cdbfbf30add9a8fa2f11b1c4ff35179fa Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 26 Apr 2012 12:50:57 -0700 Subject: canvas interaction --- js/helper-classes/3D/snap-manager.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 2c975985..dcfd5ddc 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, { { // see if we can snap to a contained geometry object - if (hitRec && this.getGLWorld(elt) && !this.isARectangle(elt)) + if (hitRec && this.getGLWorld(elt)) // && !this.isARectangle(elt)) { var localPt = hitRec.calculateElementWorldPoint(); if (hitRec.getType() != hitRec.SNAP_TYPE_ELEMENT) @@ -1346,13 +1346,13 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); if (dist < this.ELEMENT_VERTEX_HIT_RAD) { - console.log( "hit a vertex" ); + //console.log( "hit a vertex" ); // check if the distance is less than // the distance on the current hit record - if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) + //if (dist <= vecUtils.vecDist(2, targetScrPt, hitRec.getScreenPoint() )) { - console.log( "rejected - further than existing snap" ); + //console.log( "rejected - further than existing snap" ); hitRec.setScreenPoint( globalPt ); //var localMatInv = hitRec.getPlaneMatrix().inverse(); @@ -1388,7 +1388,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var dist = vecUtils.vecDist(2, globalPt, targetScrPt ); if (dist < this.ELEMENT_EDGE_HIT_RAD) { - console.log( "hit an edge" ); + //console.log( "hit an edge" ); // check if the distance is less than // the distance on the current hit record -- cgit v1.2.3 From e73fba18b095f0c270f5d954e5993c155b488c73 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 27 Apr 2012 13:52:40 -0700 Subject: Creating shapes in a container --- js/helper-classes/3D/snap-manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index dcfd5ddc..7fc492a5 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1011,7 +1011,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { } // hit test the current object var hit; - if (depth > 0) // don't snap to the root + var snapToStage = ((depth === 0) && (elt === this.application.ninja.currentSelectedContainer) && (elt.nodeName === 'CANVAS')); + if ((depth > 0) || snapToStage) // don't snap to the root unles we are working inside a canvas { // if the element is in the 2D cache snapping is done there if (elt.elementModel && !elt.elementModel.isIn2DSnapCache) -- cgit v1.2.3