From 036cf034e124dbc1f4893e90f7c6d240904a3faf Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 17 Apr 2012 14:43:37 -0700 Subject: Snapshot for pen tool before merging with master....can draw polylines (no prev, next) handles and hit testing in 3D. Update of the canvas with a transformation on it will modify the canvas incorrectly, and will be completed after merging with master --- js/lib/geom/sub-path.js | 21 ++++++++------ js/tools/PenTool.js | 76 +++++++++++++++++++++++++++++-------------------- 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index 62937461..7e11bb33 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js @@ -413,19 +413,21 @@ GLSubpath.prototype._checkIntersectionWithSamples = function(startIndex, endInde //will assume that the BBox test is performed outside this function if (endIndex1 && !this._selectedSubpath.getIsClosed() && this._selectedSubpath.getSelectedAnchorIndex()===0 && prevSelectedAnchorIndex === numAnchors-1){ - //setting the selection mode to NONE will effectively add a new anchor point at the click location and also give us snapping - whichPoint = this._selectedSubpath.SEL_NONE; + //insert an anchor temporarily that will get removed in the mouse up handler + this._selectedSubpath.addAnchor(new AnchorPoint()); + var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); + newAnchor.setPos(localMousePos[0], localMousePos[1], localMousePos[2]); + newAnchor.setPrevPos(localMousePos[0], localMousePos[1], localMousePos[2]); + newAnchor.setNextPos(localMousePos[0], localMousePos[1], localMousePos[2]); + //set the snap target in case the mouse move handler doesn't get called this._snapTargetIndex = 0; } @@ -489,7 +501,6 @@ exports.PenTool = Montage.create(ShapeTool, { var globalMousePos = hitRec.getScreenPoint(); var localMousePos = ViewUtils.globalToLocal(globalMousePos, drawingCanvas); - //var selAnchorRetCode = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS, false); //var selAnchorRetCode = this._selectedSubpath.pickAnchor(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS); var selAnchorAndParamAndCode = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, true); @@ -513,7 +524,6 @@ exports.PenTool = Montage.create(ShapeTool, { this.application.ninja.stage.drawingCanvas.style.cursor = cursor; } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) { //change the cursor - STOPPED HERE...why is this case not being hit? var cursor = "url('images/cursors/penCursors/Pen_plus.png') 5 1, default"; this.application.ninja.stage.drawingCanvas.style.cursor = cursor; } @@ -723,20 +733,28 @@ exports.PenTool = Montage.create(ShapeTool, { value: function(){ var i=0,d=0; var currAnchor = null; - var localPos = [[0,0,0],[0,0,0],[0,0,0]]; - //if there is already is a subpath canvas, it means the anchor points are in local space + var xAdjustment = snapManager.getStageWidth()*0.5; + var yAdjustment = snapManager.getStageHeight()*0.5; + var localPos = [[0,0,0,0],[0,0,0,0],[0,0,0,0]]; + //if there already is a subpath canvas, it means the anchor points are in local space // so convert them to stage world space var numAnchors = this._selectedSubpath.getNumAnchors(); if (this._selectedSubpathCanvas) { - var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, true, true); + //this transformation will take the path points from local space to stage world space + // *without* taking into account the transformation applied to this canvas + // (this is because we use the center of the bbox to find a place for the canvas) + var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, true, false); for (i=0;ithis._MAX_CANVAS_DIMENSION){ - needToRemoveLastPoint = true; + console.log("PEN: Warning! Ignoring last added point because canvas size too large"); + this._selectedSubpath.removeAnchor(numAnchors-1); + numAnchors--; + //recompute the bbox of this subpath + this._selectedSubpath.createSamples(true); + bboxMin = this._selectedSubpath.getBBoxMin(); + bboxMax = this._selectedSubpath.getBBoxMax(); + break; } } - if (needToRemoveLastPoint){ - console.log("PEN: Warning! Ignoring last added point because canvas size too large") - this._selectedSubpath.removeAnchor(numAnchors-1); - numAnchors--; - //recompute the bbox of this subpath - this._selectedSubpath.createSamples(true); - bboxMin = this._selectedSubpath.getBBoxMin(); - bboxMax = this._selectedSubpath.getBBoxMax(); - } + this._selectedSubpathCanvasCenter = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); - if (this._selectedSubpathCanvas) { - //if the canvas does not yet exist, the stage world point already have this stage dimension offset below - this._selectedSubpathCanvasCenter[0]+= snapManager.getStageWidth()*0.5; - this._selectedSubpathCanvasCenter[1]+= snapManager.getStageHeight()*0.5; - } //update the plane matrix of this subpath by querying the element mediator if (this._selectedSubpathCanvas) { @@ -784,9 +795,9 @@ exports.PenTool = Montage.create(ShapeTool, { for (i=0;i