diff options
-rw-r--r-- | assets/canvas-runtime.js | 40 | ||||
-rw-r--r-- | js/io/system/ninjalibrary.json | 2 | ||||
-rwxr-xr-x | js/lib/geom/brush-stroke.js | 5 | ||||
-rwxr-xr-x | js/tools/PenTool.js | 49 |
4 files changed, 75 insertions, 21 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index fe5f839c..feb35187 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -2107,7 +2107,40 @@ NinjaCvsRt.RuntimeBrushStroke = Object.create(NinjaCvsRt.RuntimeGeomObj, { | |||
2107 | } | 2107 | } |
2108 | this._LocalPoints = newPoints.slice(0); | 2108 | this._LocalPoints = newPoints.slice(0); |
2109 | } | 2109 | } |
2110 | } | 2110 | |
2111 | // *** compute the bounding box ********* | ||
2112 | var BBoxMin = [Infinity, Infinity, Infinity]; | ||
2113 | var BBoxMax = [-Infinity, -Infinity, -Infinity]; | ||
2114 | if (numPoints === 0) { | ||
2115 | BBoxMin = [0, 0, 0]; | ||
2116 | BBoxMax = [0, 0, 0]; | ||
2117 | } else { | ||
2118 | for (var i=0;i<numPoints;i++){ | ||
2119 | var pt = this._LocalPoints[i]; | ||
2120 | for (var d = 0; d < 3; d++) { | ||
2121 | if (BBoxMin[d] > pt[d]) { | ||
2122 | BBoxMin[d] = pt[d]; | ||
2123 | } | ||
2124 | if (BBoxMax[d] < pt[d]) { | ||
2125 | BBoxMax[d] = pt[d]; | ||
2126 | } | ||
2127 | }//for every dimension d from 0 to 2 | ||
2128 | } | ||
2129 | } | ||
2130 | |||
2131 | //increase the bbox given the stroke width and the angle (in case of calligraphic brush) | ||
2132 | var bboxPadding = this._strokeWidth*0.5; | ||
2133 | for (var d = 0; d < 3; d++) { | ||
2134 | BBoxMin[d]-= bboxPadding; | ||
2135 | BBoxMax[d]+= bboxPadding; | ||
2136 | }//for every dimension d from 0 to 2 | ||
2137 | |||
2138 | //******* update the local coords so that the bbox min is at the origin ****** | ||
2139 | for (var i=0;i<numPoints;i++) { | ||
2140 | this._LocalPoints[i][0]-= BBoxMin[0]; | ||
2141 | this._LocalPoints[i][1]-= BBoxMin[1]; | ||
2142 | } | ||
2143 | }//if we need to do smoothing | ||
2111 | } | 2144 | } |
2112 | }, | 2145 | }, |
2113 | 2146 | ||
@@ -2231,7 +2264,10 @@ NinjaCvsRt.RuntimeBrushStroke = Object.create(NinjaCvsRt.RuntimeGeomObj, { | |||
2231 | var disp = [brushStamp[t][0], brushStamp[t][1]]; | 2264 | var disp = [brushStamp[t][0], brushStamp[t][1]]; |
2232 | var alphaVal = 1.0; | 2265 | var alphaVal = 1.0; |
2233 | var distFromOpaqueRegion = Math.abs(t-halfNumTraces) - opaqueRegionHalfWidth; | 2266 | var distFromOpaqueRegion = Math.abs(t-halfNumTraces) - opaqueRegionHalfWidth; |
2234 | if (distFromOpaqueRegion>0) { | 2267 | if (numTraces === 1){ |
2268 | distFromOpaqueRegion = 0; | ||
2269 | } | ||
2270 | else if (distFromOpaqueRegion>0) { | ||
2235 | var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; | 2271 | var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; |
2236 | alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values | 2272 | alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values |
2237 | alphaVal *= 0.5; //factor that accounts for lineWidth == 2 | 2273 | alphaVal *= 0.5; //factor that accounts for lineWidth == 2 |
diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json index e9df5e58..03753da9 100644 --- a/js/io/system/ninjalibrary.json +++ b/js/io/system/ninjalibrary.json | |||
@@ -1,6 +1,6 @@ | |||
1 | { | 1 | { |
2 | "libraries": [ | 2 | "libraries": [ |
3 | {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.10.0.0"}, | 3 | {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.10.0.0"}, |
4 | {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.9.0"} | 4 | {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.6.0.0"} |
5 | ] | 5 | ] |
6 | } \ No newline at end of file | 6 | } \ No newline at end of file |
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index d9c2ab53..0e0406dd 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js | |||
@@ -719,7 +719,10 @@ BrushStroke.prototype.drawToContext = function(ctx, drawStageWorldPts, stageWorl | |||
719 | var disp = [brushStamp[t][0], brushStamp[t][1]]; | 719 | var disp = [brushStamp[t][0], brushStamp[t][1]]; |
720 | var alphaVal = 1.0; | 720 | var alphaVal = 1.0; |
721 | var distFromOpaqueRegion = Math.abs(t-halfNumTraces) - opaqueRegionHalfWidth; | 721 | var distFromOpaqueRegion = Math.abs(t-halfNumTraces) - opaqueRegionHalfWidth; |
722 | if (distFromOpaqueRegion>0) { | 722 | if (numTraces === 1){ |
723 | distFromOpaqueRegion = 0; | ||
724 | } | ||
725 | else if (distFromOpaqueRegion>0) { | ||
723 | var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; | 726 | var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; |
724 | alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values | 727 | alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values |
725 | alphaVal *= 0.5; //factor that accounts for lineWidth == 2 | 728 | alphaVal *= 0.5; //factor that accounts for lineWidth == 2 |
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index e296d0e5..33ca5c71 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -288,16 +288,35 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
288 | 288 | ||
289 | //assume we are not starting a new path as we will set this to true if we create a new Subpath() | 289 | //assume we are not starting a new path as we will set this to true if we create a new Subpath() |
290 | this._isNewPath = false; | 290 | this._isNewPath = false; |
291 | |||
292 | //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath | ||
293 | if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths) { | ||
294 | this._selectedSubpath = null; | ||
295 | } | ||
296 | 291 | ||
297 | if (this._subtool !== this.SUBTOOL_NONE && this._selectedSubpath===null) { | 292 | if (this._subtool !== this.SUBTOOL_NONE && this._selectedSubpath===null) { |
298 | //do nothing because the pen plus and pen minus subtools need a selected subpath | 293 | //do nothing because the pen plus and pen minus subtools need a selected subpath |
299 | return; | 294 | return; |
300 | } | 295 | } |
296 | |||
297 | //build the hit record for the current mouse position (on the stage or the plane of the path canvas) | ||
298 | var hitRec = this.getHitRecord(event.pageX, event.pageY, false); | ||
299 | var globalMousePos=null, localMousePos=null, stageWorldMousePos = null, drawingCanvas=null; | ||
300 | if (this._selectedSubpathCanvas){ | ||
301 | globalMousePos = hitRec.getScreenPoint(); | ||
302 | localMousePos = ViewUtils.globalToLocal(globalMousePos, this._selectedSubpathCanvas); | ||
303 | } | ||
304 | |||
305 | //if we have a selected subpath and canvas, check if the current click location hits the path | ||
306 | // todo optimize this...currently pickPath is called twice (see later in this function) | ||
307 | var hitPath = false; | ||
308 | if (this._selectedSubpath && this._selectedSubpathCanvas ) { | ||
309 | var tempSelAnchorAndParamAndCode = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, true); | ||
310 | if (tempSelAnchorAndParamAndCode[2] !== this._selectedSubpath.SEL_NONE){ // ******* if we hit the path anywhere ********* | ||
311 | hitPath = true; | ||
312 | } | ||
313 | } | ||
314 | |||
315 | //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath | ||
316 | if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths && !hitPath) { | ||
317 | this._selectedSubpath = null; | ||
318 | } | ||
319 | |||
301 | if (this._selectedSubpath === null) { | 320 | if (this._selectedSubpath === null) { |
302 | this._selectedSubpath = new SubPath(); | 321 | this._selectedSubpath = new SubPath(); |
303 | this._selectedSubpathCanvas = null; | 322 | this._selectedSubpathCanvas = null; |
@@ -335,9 +354,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
335 | this._selectedSubpath.setFillColor(colorArray); | 354 | this._selectedSubpath.setFillColor(colorArray); |
336 | } //if the selectedSubpath was null and needed to be constructed | 355 | } //if the selectedSubpath was null and needed to be constructed |
337 | 356 | ||
338 | //build the hit record for the current mouse position (on the stage or the plane of the path canvas) | 357 | //build the current mouse position in stage world space in case we don't already have a canvas |
339 | var hitRec = this.getHitRecord(event.pageX, event.pageY, false); | ||
340 | var globalMousePos=null, localMousePos=null, stageWorldMousePos = null, drawingCanvas=null; | ||
341 | if (!this._selectedSubpathCanvas){ | 358 | if (!this._selectedSubpathCanvas){ |
342 | drawingCanvas = this.application.ninja.currentDocument.model.documentRoot;//ViewUtils.getStageElement(); | 359 | drawingCanvas = this.application.ninja.currentDocument.model.documentRoot;//ViewUtils.getStageElement(); |
343 | stageWorldMousePos = hitRec.calculateStageWorldPoint(); | 360 | stageWorldMousePos = hitRec.calculateStageWorldPoint(); |
@@ -345,10 +362,7 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
345 | stageWorldMousePos[1]+= snapManager.getStageHeight()*0.5; | 362 | stageWorldMousePos[1]+= snapManager.getStageHeight()*0.5; |
346 | localMousePos = stageWorldMousePos; //since the subpath points are in stage world space, set the 'localMousePos' to be stage world as well | 363 | localMousePos = stageWorldMousePos; //since the subpath points are in stage world space, set the 'localMousePos' to be stage world as well |
347 | } | 364 | } |
348 | else { | 365 | |
349 | globalMousePos = hitRec.getScreenPoint(); | ||
350 | localMousePos = ViewUtils.globalToLocal(globalMousePos, this._selectedSubpathCanvas); | ||
351 | } | ||
352 | 366 | ||
353 | if (this._selectedSubpathCanvas === null && this._subtool===this.SUBTOOL_NONE){ | 367 | if (this._selectedSubpathCanvas === null && this._subtool===this.SUBTOOL_NONE){ |
354 | //IF this is the first anchor point of the selected subpath | 368 | //IF this is the first anchor point of the selected subpath |
@@ -358,7 +372,6 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
358 | if (this._selectedSubpath.getNumAnchors()===0) { | 372 | if (this._selectedSubpath.getNumAnchors()===0) { |
359 | this._selectedSubpathPlaneMat = hitRec.getPlaneMatrix(); | 373 | this._selectedSubpathPlaneMat = hitRec.getPlaneMatrix(); |
360 | } | 374 | } |
361 | |||
362 | //check if the mouse click location is close to the existing anchor | 375 | //check if the mouse click location is close to the existing anchor |
363 | var indexAndCode = this._selectedSubpath.pickAnchor(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2], this._PICK_POINT_RADIUS); | 376 | var indexAndCode = this._selectedSubpath.pickAnchor(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2], this._PICK_POINT_RADIUS); |
364 | if (indexAndCode[0]>=0){ | 377 | if (indexAndCode[0]>=0){ |
@@ -526,7 +539,9 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
526 | 539 | ||
527 | //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet) | 540 | //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet) |
528 | if (this._subtool===this.SUBTOOL_NONE){ | 541 | if (this._subtool===this.SUBTOOL_NONE){ |
529 | if (this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0){ | 542 | if ((this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0 && !this._selectedSubpath.getIsClosed()) |
543 | || | ||
544 | this._entryEditMode === this.ENTRY_SELECT_PATH){ | ||
530 | this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; | 545 | this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; |
531 | "url('images/cursors/penCursors/Pen_.png') 5 1, default"; | 546 | "url('images/cursors/penCursors/Pen_.png') 5 1, default"; |
532 | } | 547 | } |
@@ -853,9 +868,9 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
853 | this._editMode = this.EDIT_NONE; | 868 | this._editMode = this.EDIT_NONE; |
854 | 869 | ||
855 | //if we're not in edit_path mode and we closed the selected subpath, then we are going to start a new subpath, so we nullify the selected subpath | 870 | //if we're not in edit_path mode and we closed the selected subpath, then we are going to start a new subpath, so we nullify the selected subpath |
856 | if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){ | 871 | //if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){ |
857 | this._selectedSubpath = null; | 872 | // this._selectedSubpath = null; |
858 | } | 873 | //} |
859 | 874 | ||
860 | if (this._selectedSubpath){ | 875 | if (this._selectedSubpath){ |
861 | this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas | 876 | this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas |