From 923e760bf4a16baa82e81da6d38e671620664e8f Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 25 Jul 2012 14:34:59 -0700 Subject: Support line shape drawing inside existing canvases. Signed-off-by: Nivesh Rajbhandari --- js/tools/LineTool.js | 56 ++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'js/tools') diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js index f0d96c3c..4ec327b5 100755 --- a/js/tools/LineTool.js +++ b/js/tools/LineTool.js @@ -97,34 +97,38 @@ exports.LineTool = Montage.create(ShapeTool, { if(this.drawData) { w = Math.floor(this.drawData.width); h = Math.floor(this.drawData.height); + // set the dimensions + if(slope === "horizontal") { + h = Math.max(this._strokeSize, 1); + w = Math.max(w, 1); + } else if(slope === "vertical") { + w = Math.max(this._strokeSize, 1); + h = Math.max(h, 1); + } else { + // else make the line's stroke fit inside the canvas by growing the canvas + var theta = Math.atan(slope); + xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); + yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); + + w += ~~(xAdj*2); + h += ~~(yAdj*2); + } + if(!this._useExistingCanvas()) { - // set the dimensions - if(slope === "horizontal") { - h = Math.max(this._strokeSize, 1); - w = Math.max(w, 1); - } else if(slope === "vertical") { - w = Math.max(this._strokeSize, 1); - h = Math.max(h, 1); - } else { - // else make the line's stroke fit inside the canvas by growing the canvas - var theta = Math.atan(slope); - xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); - yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); - - w += ~~(xAdj*2); - h += ~~(yAdj*2); - } - - canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); - - var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData); - this.application.ninja.elementMediator.addElements(canvas, styles); - } else { - canvas = this._targetedElement; - canvas.elementModel.controller = ShapesController; - if(!canvas.elementModel.shapeModel) { - canvas.elementModel.shapeModel = Montage.create(ShapeModel); + + canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); + + var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData); + this.application.ninja.elementMediator.addElements(canvas, styles); + } else { + canvas = this._targetedElement; + if (!canvas.getAttribute( "data-RDGE-id" )) + canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); + canvas.elementModel.controller = ShapesController; + if(!canvas.elementModel.shapeModel) { + canvas.elementModel.shapeModel = Montage.create(ShapeModel); } + this.RenderShape(w, h, this.drawData.planeMat, this.drawData.midPt, canvas, slope, xAdj, yAdj); } } } -- cgit v1.2.3 From 74cda8443e4f3c6f3e29b5bf99c3615339a982a3 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 8 Aug 2012 15:02:19 -0700 Subject: IKNinja_1892 - [3D] Multiple objects fly off screen when translating in Z-axis. Signed-off-by: Nivesh Rajbhandari --- js/tools/Translate3DToolBase.js | 4 ++-- js/tools/TranslateObject3DTool.js | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'js/tools') diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index b5008666..fd275a8a 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -166,7 +166,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var len = selectedElements.length, self = this, - target = selectedElements[0], + target = this.clickedObject, curMat = viewUtils.getMatrixFromElement( target ), matInv = glmat4.inverse(this._startMat, []), nMat = glmat4.multiply(transMat, this._startMat, [] ); @@ -180,7 +180,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, var shouldUpdateStartMat = true; - if(this._clickedOnStage || ((this._handleMode === 2) && (len > 1))) + if(this._clickedOnStage || ((this._handleMode !== null) && (len > 1))) { shouldUpdateStartMat = false; } diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js index a3ece1f9..5dfd2029 100755 --- a/js/tools/TranslateObject3DTool.js +++ b/js/tools/TranslateObject3DTool.js @@ -77,15 +77,12 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { else { this._delta = null; - //if(this._handleMode === 2) { - this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target, this._handleMode, this._inLocalMode); - //console.log( "dragPlane: " + this._dragPlane ); - snapManager.setupDragPlaneFromPlane(this._dragPlane); - do3DSnap = false; - - snapManager.enableElementSnap ( false ); - snapManager.enableGridSnap ( false ); - //} + this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target, this._handleMode, (this._inLocalMode && (this.application.ninja.selectedElements.length === 1))); + snapManager.setupDragPlaneFromPlane(this._dragPlane); + do3DSnap = false; + + snapManager.enableElementSnap ( false ); + snapManager.enableGridSnap ( false ); } if(this.application.ninja.selectedElements.length) { @@ -95,7 +92,7 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { // a snap on the mouse down var hitRec = snapManager.snap(point.x, point.y, do3DSnap); - if(this._handleMode === 2) + if(this._handleMode !== null) { // translate z doesn't snap to element so hitRec's element will always be different // from what the browser says we clicked on. So, skip this check. @@ -135,7 +132,7 @@ exports.TranslateObject3DTool = Montage.create(Translate3DToolBase, { snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); } - if(this._handleMode === 2) + if(this._handleMode !== null) this.clickedObject = this._target; // parameterize the snap point on the target -- cgit v1.2.3