From 7c82ee4f217ea86ee4ebee80da29481f31e5019d Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Mon, 16 Apr 2012 16:03:29 -0700 Subject: re-enable some hit testing and change the code for obtaining 3D (stage world) point when there is no canvas yet --- js/lib/geom/sub-path.js | 55 +++------------------------------ js/tools/PenTool.js | 81 +++++++++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 87 deletions(-) (limited to 'js') diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index 31bf4632..62937461 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js @@ -614,13 +614,14 @@ GLSubpath.prototype.pickPath = function (pickX, pickY, pickZ, radius, testOnly) }//if is within bbox } + if (retCode!== this.SEL_NONE) + retCode = retCode | this.SEL_PATH; //ensure that path is also selected if anything else is selected + if (!testOnly){ - if (retCode!== this.SEL_NONE) - retCode = retCode | this.SEL_PATH; //ensure that path is also selected if anything else is selected this._selectMode = retCode; this._selectedAnchorIndex = selAnchorIndex; } - return [selAnchorIndex,retParam]; + return [selAnchorIndex,retParam, retCode]; }; //GLSubpath.pickPath function GLSubpath.prototype.getSelectedAnchorIndex = function () { @@ -693,54 +694,6 @@ GLSubpath.prototype.setStrokeWidth = function (w) { ElementMediator.setProperty(canvasArray, "height", [penCanvasNewHeight+"px"], "Changing", "penTool"); ElementMediator.setProperty(canvasArray, "left", [penCanvasNewLeft+"px"],"Changing", "penTool"); ElementMediator.setProperty(canvasArray, "top", [penCanvasNewTop+ "px"],"Changing", "penTool"); - - /* - //compute the current location of the canvas for this subpath - this.createSamples(); //this will also update the bounding box - var bboxMin = this.getBBoxMin(); - var bboxMax = this.getBBoxMax(); - var bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0]; //ignore the Z coord. for local coordinates - - //go from local coordinates to stage world - var ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; - var SnapManager = require("js/helper-classes/3D/snap-manager").SnapManager; - var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._canvas, true, true); - var bboxMidSW = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat); - bboxMidSW[0]+=SnapManager.getStageWidth()*0.5; - bboxMidSW[1]+=SnapManager.getStageHeight()*0.5; - - this._strokeWidth = Math.round(w); - this._dirty=true; - - // **** adjust the local coordinates to account for the change in stroke width **** - this.computeBoundingBox(); //this will take the new strokewidth into account - this.offsetPerBBoxMin(); //this will shift the local coordinates such that the bbox min point is at (0,0) - - // **** adjust the canvas position to account for the change in stroke width - var ElementMediator = require("js/mediators/element-mediator").ElementMediator; - //build the width and height of this canvas by looking at local coordinates - bboxMin = this.getBBoxMin(); - bboxMax = this.getBBoxMax(); - var width = Math.round(bboxMax[0] - bboxMin[0]); - var height = Math.round(bboxMax[1] - bboxMin[1]); - var left = Math.round(bboxMidSW[0] - 0.5 * width); - var top = Math.round(bboxMidSW[1] - 0.5 * height); - - var canvasArray=[this._canvas]; - ElementMediator.setProperty(canvasArray, "width", [width+"px"], "Changing", "penTool"); - ElementMediator.setProperty(canvasArray, "height", [height+"px"], "Changing", "penTool"); - - //check if the canvas was translated - var penCanvasCurrentLeft = parseInt(ElementMediator.getProperty(this._canvas, "left")); - var penCanvasCurrentTop = parseInt(ElementMediator.getProperty(this._canvas, "top")); - left = Math.round(penCanvasCurrentLeft - diffStrokeWidth*0.5); - top = Math.round(penCanvasCurrentTop - diffStrokeWidth*0.5); - - //left = Math.round(bboxMidSW[0] - 0.5 * width); - //top = Math.round(bboxMidSW[1] - 0.5 * height); - ElementMediator.setProperty(canvasArray, "left", [left+"px"],"Changing", "penTool"); - ElementMediator.setProperty(canvasArray, "top", [top+ "px"],"Changing", "penTool"); - */ }; GLSubpath.prototype.getStrokeColor = function () { diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 7e97a8a1..50fd97d7 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -98,6 +98,7 @@ exports.PenTool = Montage.create(ShapeTool, { //constants used for limiting size of the subpath canvas _MAX_CANVAS_DIMENSION: {value: 3000, writable: false}, + /* // get the stage world position corresponding to the (x,y) mouse event position by querying the snap manager // but temporarily turning off all snapping _getMouseEventPosition : { @@ -130,6 +131,7 @@ exports.PenTool = Montage.create(ShapeTool, { return [pos, dragPlane]; } }, + */ ShowToolProperties: { value: function () { @@ -146,15 +148,17 @@ exports.PenTool = Montage.create(ShapeTool, { // will use the plane of the selected path as the working plane if available, else use stage getHitRecord:{ value: function(x,y){ - var drawingCanvas = ViewUtils.getStageElement(); if (this._selectedSubpathCanvas){ - drawingCanvas = this._selectedSubpathCanvas; + var drawingCanvas = this._selectedSubpathCanvas; + var contentPlane = ViewUtils.getUnprojectedElementPlane(drawingCanvas); + snapManager.pushWorkingPlane(contentPlane); + } - var contentPlane = ViewUtils.getUnprojectedElementPlane(drawingCanvas); - snapManager.pushWorkingPlane(contentPlane); var tmpPoint = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); var hitRec = snapManager.snap(tmpPoint.x, tmpPoint.y, false); - snapManager.popWorkingPlane(); + if (this._selectedSubpathCanvas){ + snapManager.popWorkingPlane(); + } return hitRec; } }, @@ -281,8 +285,8 @@ exports.PenTool = Montage.create(ShapeTool, { //now perform the hit testing var prevSelectedAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex(); - var selAnchorAndParam = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, false); - var selParam = selAnchorAndParam[1]; + var selAnchorAndParamAndCode = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, false); + var selParam = selAnchorAndParamAndCode[1]; var whichPoint = this._selectedSubpath.getSelectedMode(); @@ -383,8 +387,7 @@ exports.PenTool = Montage.create(ShapeTool, { //clear the canvas before we draw anything else this.application.ninja.stage.clearDrawingCanvas(); this._hoveredAnchorIndex = -1; - return; - /* + //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet) if (this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0){ this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; @@ -395,11 +398,11 @@ exports.PenTool = Montage.create(ShapeTool, { "url('images/cursors/penCursors/Pen_newPath.png') 5 1, default"; } - var posInfo = this._getMouseEventPosition (event.pageX, event.pageY, true, false); - var currMousePos = posInfo[0]; + var hitRec = this.getHitRecord(event.pageX, event.pageY); if (this._isDrawing) { - if (currMousePos && this._selectedSubpath && (this._selectedSubpath.getSelectedAnchorIndex() >= 0 && this._selectedSubpath.getSelectedAnchorIndex() < this._selectedSubpath.getNumAnchors())) { + if (0){ + //if (currMousePos && this._selectedSubpath && (this._selectedSubpath.getSelectedAnchorIndex() >= 0 && this._selectedSubpath.getSelectedAnchorIndex() < this._selectedSubpath.getNumAnchors())) { // BEGIN NEW LOCAL COORD BLOCK //build the mouse position in local coordinates var drawingCanvas = this._selectedSubpath.getCanvas(); @@ -472,7 +475,7 @@ exports.PenTool = Montage.create(ShapeTool, { //this.doSnap(event); //this.DrawHandles(); - if (currMousePos && this._selectedSubpath ){ + if (this._selectedSubpath ){ //convert the mouse pos. to local space of the canvas //var widthAdjustment = -snapManager.getStageWidth()*0.5; @@ -483,36 +486,38 @@ exports.PenTool = Montage.create(ShapeTool, { if (!drawingCanvas){ drawingCanvas = ViewUtils.getStageElement(); } - posInfo = this._getMouseEventPosition (event.pageX, event.pageY, false, false); - var globalMousePos = posInfo[0]; + 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, true); - if (selAnchorRetCode[0] >=0) { - this._hoveredAnchorIndex = selAnchorRetCode[0]; - var lastAnchorIndex = this._selectedSubpath.getNumAnchors()-1; - var cursor = "url('images/cursors/penCursors/Pen_anchorSelect.png') 5 1, default"; - if (this._selectedSubpath.getIsClosed()===false){ - if (this._entryEditMode === this.ENTRY_SELECT_PATH && !this._isPickedEndPointInSelectPathMode && (this._hoveredAnchorIndex===0 || this._hoveredAnchorIndex===lastAnchorIndex)){ - //if we're in SELECT_PATH mode, have not yet clicked on the end anchors, AND we hovered over one of the end anchors - cursor = "url('images/cursors/penCursors/Pen_append.png') 5 1, default"; - } else if ( this._selectedSubpath.getSelectedAnchorIndex()===lastAnchorIndex && this._hoveredAnchorIndex===0) { - //if we've selected the last anchor and hover over the first anchor - cursor = "url('images/cursors/penCursors/Pen_closePath.png') 5 1, default"; - } - } //if path is not closed - this.application.ninja.stage.drawingCanvas.style.cursor = cursor; - } else { - //detect if the current mouse position will hit the path (such that clicking here will insert a new anchor) - var pathHitTestData = this._selectedSubpath.pathSamplesLocalHitTest(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS*0.5); - if (pathHitTestData[0]!==-1){ + //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); + if (selAnchorAndParamAndCode[0] >=0){ //something on the path was hit + if ((selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_ANCHOR) + || (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PREV) + || (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_NEXT)) + { //the anchor was hit + this._hoveredAnchorIndex = selAnchorAndParamAndCode[0]; + var lastAnchorIndex = this._selectedSubpath.getNumAnchors()-1; + var cursor = "url('images/cursors/penCursors/Pen_anchorSelect.png') 5 1, default"; + if (this._selectedSubpath.getIsClosed()===false){ + if (this._entryEditMode === this.ENTRY_SELECT_PATH && !this._isPickedEndPointInSelectPathMode && (this._hoveredAnchorIndex===0 || this._hoveredAnchorIndex===lastAnchorIndex)){ + //if we're in SELECT_PATH mode, have not yet clicked on the end anchors, AND we hovered over one of the end anchors + cursor = "url('images/cursors/penCursors/Pen_append.png') 5 1, default"; + } else if ( this._selectedSubpath.getSelectedAnchorIndex()===lastAnchorIndex && this._hoveredAnchorIndex===0) { + //if we've selected the last anchor and hover over the first anchor + cursor = "url('images/cursors/penCursors/Pen_closePath.png') 5 1, default"; + } + } //if path is not closed + 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; } - } + } //something on the path was hit } } //else of if (this._isDrawing) { @@ -520,7 +525,7 @@ exports.PenTool = Montage.create(ShapeTool, { if (this._selectedSubpath){ this.DrawSubpathAnchors(this._selectedSubpath); } - */ + }//value: function(event) },//HandleMouseMove @@ -769,6 +774,10 @@ exports.PenTool = Montage.create(ShapeTool, { this._selectedSubpathCanvasCenter[1]+= snapManager.getStageHeight()*0.5; } + //update the plane matrix of this subpath by querying the element mediator + if (this._selectedSubpathCanvas) { + this._selectedSubpathPlaneMat = ElementMediator.getMatrix(this._selectedSubpathCanvas); + } var planeMatInv = glmat4.inverse(this._selectedSubpathPlaneMat, []); // ***** compute local coordinates of the anchor points ***** -- cgit v1.2.3