From d41dee0c552a30724a146965ae4272a268777fc5 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 2 Feb 2012 14:53:14 -0800 Subject: Integrating Pan and Zoom tool and snap manager fixes. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/canvas-controller.js | 14 ++++---- js/helper-classes/3D/draw-utils.js | 3 +- js/helper-classes/3D/snap-manager.js | 11 +++++- js/stage/stage.reel/stage.js | 51 +++++++++++++++++++--------- js/tools/PanTool.js | 33 +++++++----------- js/tools/ZoomTool.js | 39 ++++++--------------- 6 files changed, 77 insertions(+), 74 deletions(-) (limited to 'js') diff --git a/js/controllers/elements/canvas-controller.js b/js/controllers/elements/canvas-controller.js index 21de9879..b5df3911 100644 --- a/js/controllers/elements/canvas-controller.js +++ b/js/controllers/elements/canvas-controller.js @@ -34,12 +34,12 @@ exports.CanvasController = Montage.create(ElementController, { } } }, - - setProperties: { - value: function(el, props, index) { - for(var p in props) { - el.elementModel.controller.setProperty(el, p, props[p][index]); - } - } + + setProperties: { + value: function(el, props, index) { + for(var p in props) { + el.elementModel.controller.setProperty(el, p, props[p][index]); + } + } } }); \ No newline at end of file diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index c26a5cd1..fd96af4d 100644 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -1089,7 +1089,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { var resMat = glmat4.multiply( tMat, mat, [] ); var origin = [0,0,0,1]; - var arrowSize = 50; + var zoomFactor = this.application.ninja.documentBar.zoomFactor/100.0; + var arrowSize = 50 / zoomFactor; var xAxis = [arrowSize,0,0,1]; //var rO = resMat.multiply(origin); var rO = glmat4.multiplyVec3( resMat, origin, []); diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 3ed96082..8819f637 100644 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1780,7 +1780,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var mergedSnap = this.mergeHitRecords( hitRecs ); if (mergedSnap) { - while (hitRecs.length > 0) hitRecs.pop(); + while (hitRecs.length > 0) hitRecs.pop(); hitRecs.push( mergedSnap ); //console.log( "merged snaps" ); } @@ -1836,6 +1836,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { hSnap.setLocalPoint( localPt ); hSnap.setScreenPoint( scrPt ); hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); + hSnap.setElement( stage ); + hSnap.setPlane( [0,0,1,0] ); + hSnap.setPlaneMatrix( Matrix.I(4) ); if (vSnap.hasAssociatedScreenPoint() ) hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); if (vSnap.hasAssociatedScreenPoint2() ) @@ -1882,6 +1885,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { hSnap.setLocalPoint( localPt ); hSnap.setScreenPoint( scrPt ); hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); + hSnap.setElement( stage ); + hSnap.setPlane( [0,0,1,0] ); + hSnap.setPlaneMatrix( Matrix.I(4) ); if (vSnap.hasAssociatedScreenPoint() ) hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); if (vSnap.hasAssociatedScreenPoint2() ) @@ -1934,6 +1940,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { hSnap.setLocalPoint( localPt ); hSnap.setScreenPoint( scrPt ); hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); + hSnap.setElement( stage ); + hSnap.setPlane( [0,0,1,0] ); + hSnap.setPlaneMatrix( Matrix.I(4) ); if (vSnap.hasAssociatedScreenPoint() ) hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); if (vSnap.hasAssociatedScreenPoint2() ) diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 8c4efd58..9e2df5a2 100644 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -787,14 +787,9 @@ exports.Stage = Montage.create(Component, { var userContent = this.application.ninja.currentDocument.documentRoot; if (userContent) { - var w = userContent.offsetWidth, - h = userContent.offsetHeight; - if(userContent.width) - w = userContent.width; - if(userContent.height) - h = userContent.height; - var localPt = [ w/2, h/2, 0]; - var globalPt = this.stageDeps.viewUtils.localToGlobal( localPt, userContent ); + var w = this._canvas.width, + h = this._canvas.height; + var globalPt = [w/2, h/2, 0]; this.stageDeps.viewUtils.setStageZoom( globalPt, value/100 ); @@ -811,6 +806,36 @@ exports.Stage = Montage.create(Component, { } }, + getPlaneForView: + { + value: function( side ) + { + var plane = [0,0,1,0]; + switch(side) + { + case "top": + plane = [0,1,0,0]; + plane[3] = this.application.ninja.currentDocument.documentRoot.offsetHeight / 2.0; + break; + + case "side": + plane = [1,0,0,0]; + plane[3] = this.application.ninja.currentDocument.documentRoot.offsetWidth / 2.0; + break; + + case "front": + plane = [0,0,1,0]; + break; + + default: + console.log( "unrecognized view in snapManager.getPlaneForView: " + side ); + break; + } + + return plane; + } + }, + setStageView: { value: function(side) { var mat, @@ -821,32 +846,26 @@ exports.Stage = Montage.create(Component, { currentDoc.elementModel.props3D.ResetRotationValues(); - switch(side) { + switch(side){ case "top": mat = Matrix.RotationX(Math.PI * 270.0/180.0); - drawUtils.drawXY = drawUtils.drawYZ = false; drawUtils.drawXZ = isDrawingGrid; - workingPlane = [0,1,0,0]; break; case "side": mat = Matrix.RotationY(Math.PI * 270/180); - drawUtils.drawXY = drawUtils.drawXZ = false; drawUtils.drawYZ = isDrawingGrid; - workingPlane = [1,0,0,0]; break; case "front": mat = Matrix.I(4); - drawUtils.drawYZ = drawUtils.drawXZ = false; drawUtils.drawXY = isDrawingGrid; - workingPlane = [0,0,1,0]; break; } - + workingPlane = this.getPlaneForView( side ); this.stageDeps.viewUtils.setMatrixForElement(currentDoc, mat, false); diff --git a/js/tools/PanTool.js b/js/tools/PanTool.js index ba40b020..71301d46 100644 --- a/js/tools/PanTool.js +++ b/js/tools/PanTool.js @@ -19,6 +19,7 @@ exports.PanTool = Montage.create(toolBase, _globalPt :{value: [0,0] , writable:true}, _globalToUCWorld :{value: [] , writable:true}, _lastGPt :{value: [0,0], writable:true}, + _lastY :{value: 0, writable:true}, Configure: { value: function ( doActivate ) @@ -43,6 +44,7 @@ exports.PanTool = Montage.create(toolBase, HandleLeftButtonDown: { value : function ( event ) { this._isDrawing = true; + this.isDrawing = true; this.mouseDown( event ); } @@ -68,6 +70,7 @@ exports.PanTool = Montage.create(toolBase, this.application.ninja.stage.clearDrawingCanvas(); this._hasDraw = false; this._isDrawing = false; + this.isDrawing = false; } } }, @@ -77,7 +80,6 @@ exports.PanTool = Montage.create(toolBase, if(event.altKey) { this._altKeyDown = true; - //console.log( "altKeyDown" ); } } }, @@ -87,7 +89,6 @@ exports.PanTool = Montage.create(toolBase, if(event.keyCode === Keyboard.ALT) { this._altKeyDown = false; - console.log( "altKeyUp" ); } } }, @@ -220,6 +221,7 @@ exports.PanTool = Montage.create(toolBase, var tmpLocal = MathUtils.transformAndDivideHomogeneousPoint( this._globalPt, globalToLocalMat ); this._lastGPt = this._globalPt.slice(); + this._lastY = this._lastGPt[1]; // set up the matrices we will be needing var eltToStageWorldMat = glmat4.multiply( ucMat, viewUtils.getObjToStageWorldMatrix(elt, true), []); @@ -275,14 +277,19 @@ exports.PanTool = Montage.create(toolBase, { if (this._isDrawing) { - //console.log( "PanTool.mouseMove (drag)" ); - // get the global screen point var gPt = [point.x, point.y, this._globalPt[2]]; + if (this._altKeyDown) + { + var dy = 5*(point.y - this._lastY); + this._globalPt[2] += dy; + gPt = [this._lastGPt[0], this._lastGPt[1], this._globalPt[2]]; + } // update the scrollbars var deltaGPt = VecUtils.vecSubtract(2, gPt, this._lastGPt); this._lastGPt = gPt.slice(); + this._lastY = point.y; var oldLeft = this.application.ninja.stage._iframeContainer.scrollLeft, oldTop = this.application.ninja.stage._iframeContainer.scrollTop; @@ -297,27 +304,13 @@ exports.PanTool = Montage.create(toolBase, this.updateGlobalToUCWorldMatrix(); var wPt = MathUtils.transformAndDivideHomogeneousPoint( gPt, this._globalToUCWorld ); - //console.log( "wPt: " + wPt ); var delta = vecUtils.vecSubtract( 3, wPt, this._worldPt ); - if (this._altKeyDown) - { - //console.log( "moveZ" ); - var dist = vecUtils.vecMag(2, delta); - delta[0] = 0; delta[1] = 0; delta[2] = dist; - var dy = point.y - this._globalPt[1]; - if (dy < 0) delta[2] = -delta[2]; - } - else - { - console.log( "NOT MOVING Z" ); + + if (!this._altKeyDown) delta[2] = 0; - } var transMat = Matrix.Translation( delta ); this._worldPt = wPt; - if (this._altKeyDown) - this._globalPt[1] = point.y; - // update everything this.applyDeltaMat( transMat ); } diff --git a/js/tools/ZoomTool.js b/js/tools/ZoomTool.js index cabf3a3d..4b6705c1 100644 --- a/js/tools/ZoomTool.js +++ b/js/tools/ZoomTool.js @@ -74,10 +74,12 @@ exports.ZoomTool = Montage.create(DrawingTool, { if(wasSelected) { this.AddCustomFeedback(); this.eventManager.addEventListener( "toolDoubleClick", this, false); + this.application.ninja.stage.drawingCanvas.addEventListener("mousewheel", this, false); } else { this.RemoveCustomFeedback(); this.eventManager.removeEventListener( "toolDoubleClick", this, false); + this.application.ninja.stage.drawingCanvas.removeEventListener("mousewheel", this, false); } } }, @@ -138,9 +140,11 @@ exports.ZoomTool = Montage.create(DrawingTool, { { value : function (event) { - // check for some reasonable amount of mouse movement - var dx = Math.abs(event.layerX - this.downPoint.x), - dy = Math.abs(event.layerY - this.downPoint.y); + var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, + new WebKitPoint(event.pageX, event.pageY)); + // check for some reasonable amount of mouse movement + var dx = Math.abs(point.x - this.downPoint.x), + dy = Math.abs(point.y - this.downPoint.y); if ((dx >= 4) || (dy >= 4)) { @@ -238,19 +242,6 @@ exports.ZoomTool = Montage.create(DrawingTool, { var p1 = [this._layerX, this._layerY, 0]; globalPt = vecUtils.vecAdd(3, p0, p1); vecUtils.vecScale(3, globalPt, 0.5); - - var hitRec = snapManager.snap( globalPt[0], globalPt[1], true ); - if (hitRec) - { - var elt = hitRec.getElement(); - if (elt) - { -// console.log( "hit: " + hitRec.getElement().id ); - var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt ); - var localPt = hitRec.calculateElementPreTransformScreenPoint(); - globalPt = MathUtils.transformAndDivideHomogeneousPoint( localPt, localToGlobalMat ); - } - } } else if (this._mode === "doubleClickReset") { @@ -270,19 +261,9 @@ exports.ZoomTool = Montage.create(DrawingTool, { } else if (this._mode === "mouseWheelZoom") { - if (userContent) - { - var w = userContent.offsetWidth, - h = userContent.offsetHeight; - if(userContent.width) - w = userContent.width; - if(userContent.height) - h = userContent.height; - var localPt = [ w/2, h/2, 0]; - globalPt = viewUtils.localToGlobal( localPt, userContent ); - } - else - globalPt = [0,0,0]; + var w = this.application.ninja.stage._canvas.width, + h = this.application.ninja.stage._canvas.height; + globalPt = [w/2, h/2, 0]; } else { -- cgit v1.2.3