From 7bee50379c1df86bb571e0e8d6c08e24d25231f5 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Mon, 9 Jul 2012 16:38:08 -0700 Subject: BSD License --- js/tools/PenTool.js | 67 +++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'js/tools/PenTool.js') diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 25423f76..1b9c4a5d 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -1,24 +1,25 @@ /* -Copyright (c) 2012, Motorola Mobility, Inc +Copyright (c) 2012, Motorola Mobility LLC. All Rights Reserved. -BSD License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Motorola Mobility nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of Motorola Mobility LLC nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS @@ -148,7 +149,7 @@ exports.PenTool = Montage.create(ShapeTool, { var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); var pos; if (getStageWorld){ - pos = (snapManager.snap(point.x, point.y, false)).calculateStageWorldPoint(); + pos = (snapManager.snap(point.x, point.y, false)).calculateStageWorldPoint(); } else { pos = (snapManager.snap(point.x, point.y, false)).getScreenPoint(); } @@ -306,7 +307,7 @@ exports.PenTool = Montage.create(ShapeTool, { //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) return; } - + //set the drawing flags (see the drawing-tool.js base class) if (this._canDraw) { this._isDrawing = true; @@ -423,7 +424,7 @@ exports.PenTool = Montage.create(ShapeTool, { console.log("WARNING picked anchor point with incorrect mode"); break; } - + } else { this._selectedSubpath.addAnchor(new AnchorPoint()); var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); @@ -568,7 +569,7 @@ exports.PenTool = Montage.create(ShapeTool, { //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) return; } - + //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet) if (this._subtool===this.SUBTOOL_NONE){ if ((this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0 && !this._selectedSubpath.getIsClosed()) @@ -618,7 +619,7 @@ exports.PenTool = Montage.create(ShapeTool, { var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); var selAnchorPos = selAnchor.getAllPos(); var localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[1]); - + if (this._editMode & this.EDIT_ANCHOR) { selAnchor.translateAll(localTranslation[0], localTranslation[1], localTranslation[2]); } @@ -691,7 +692,7 @@ exports.PenTool = Montage.create(ShapeTool, { } //if path is not closed } else if (this._subtool === this.SUBTOOL_PENMINUS && selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_ANCHOR){ cursor = "url('images/cursors/penCursors/Pen_minus.png') 5 1, default"; - } + } this.application.ninja.stage.drawingCanvas.style.cursor = cursor; } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) { //change the cursor only if we're not in pen-minus subtool @@ -825,7 +826,7 @@ exports.PenTool = Montage.create(ShapeTool, { //TODO this will not work if there are multiple shapes in the same canvas canvas.elementModel.shapeModel.GLGeomObj = subpath; - if(canvas.elementModel.isShape) + if(canvas.elementModel.isShape) { this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the canvas this.application.ninja.selectionController.selectElement(canvas); @@ -841,7 +842,7 @@ exports.PenTool = Montage.create(ShapeTool, { // Check if the selected anchor point of the selected subpath should be snapped to another anchor point // (also sets open subpaths closed if appropriate) // IF the selected subpath does not have a canvas - // + // // Draw the selected subpath anchors and the selected subpath itself in the stage's context // ********************************************************************************************************** HandleLeftButtonUp: { @@ -851,7 +852,7 @@ exports.PenTool = Montage.create(ShapeTool, { if (this._subtool===this.SUBTOOL_PENMINUS){ return; } - + // ******************** snapping *********************** // if there was a snapTarget and a selected anchor, move the anchor to the snap target if (this._snapTargetIndex !== -1 && this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) { @@ -903,7 +904,7 @@ exports.PenTool = Montage.create(ShapeTool, { //if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){ // this._selectedSubpath = null; //} - + if (this._selectedSubpath){ this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas }else{ @@ -937,7 +938,7 @@ exports.PenTool = Montage.create(ShapeTool, { return;//nothing to do } this._selectedSubpath.makeDirty(); - + var bboxMin=null, bboxMax=null; if (this._selectedSubpathCanvas) { //if there already is a subpath canvas, it means the anchor points are in local space @@ -980,7 +981,7 @@ exports.PenTool = Montage.create(ShapeTool, { glmat4.multiply( newMat, tMat, newMat); this._selectedSubpathPlaneMat = newMat; ViewUtils.setMatrixForElement(this._selectedSubpathCanvas, newMat, true); - + //now set the center of the canvas as the center of the bounding box expressed in stage world coordinates var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, false, false); this._selectedSubpathCanvasCenter = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat); @@ -1009,7 +1010,7 @@ exports.PenTool = Montage.create(ShapeTool, { currAnchor.setNextPos(localNext[0],localNext[1],localNext[2]); } } - + this._selectedSubpath.makeDirty(); this._selectedSubpath.createSamples(false); this._selectedSubpath.offsetPerBBoxMin(); @@ -1104,10 +1105,10 @@ exports.PenTool = Montage.create(ShapeTool, { handleScroll: { value: function(event) { this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); - this.DrawSubpathAnchors(this._selectedSubpath); + this.DrawSubpathAnchors(this._selectedSubpath); } }, - + BuildSecondCtrlPoint:{ value: function(p0, p2, p3) { var baselineOrig = VecUtils.vecSubtract(3, p3, p0); @@ -1199,7 +1200,7 @@ exports.PenTool = Montage.create(ShapeTool, { this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); this.DrawSubpathAnchors(this._selectedSubpath); - } //if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) + } //if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) } //value: function () { }, //HandleDoubleClick: { @@ -1503,7 +1504,7 @@ exports.PenTool = Montage.create(ShapeTool, { /*if (this.application.ninja.selectedElements.length === 0){ this._entryEditMode = this.ENTRY_SELECT_NONE; } - + else{ for (var i=0;i