From 76db3eb0aa4ffe9e75812db570c793e9f852f853 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Mon, 11 Jun 2012 14:06:09 -0700 Subject: fix the brush tool runtime: update the brush coordinates to account for change in bounding box due to smoothing --- assets/canvas-runtime.js | 35 ++++++++++++++++++++++++++++++++++- js/io/system/ninjalibrary.json | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index fe5f839c..c2ab0bd8 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -2107,7 +2107,40 @@ NinjaCvsRt.RuntimeBrushStroke = Object.create(NinjaCvsRt.RuntimeGeomObj, { } this._LocalPoints = newPoints.slice(0); } - } + + // *** compute the bounding box ********* + var BBoxMin = [Infinity, Infinity, Infinity]; + var BBoxMax = [-Infinity, -Infinity, -Infinity]; + if (numPoints === 0) { + BBoxMin = [0, 0, 0]; + BBoxMax = [0, 0, 0]; + } else { + for (var i=0;i pt[d]) { + BBoxMin[d] = pt[d]; + } + if (BBoxMax[d] < pt[d]) { + BBoxMax[d] = pt[d]; + } + }//for every dimension d from 0 to 2 + } + } + + //increase the bbox given the stroke width and the angle (in case of calligraphic brush) + var bboxPadding = this._strokeWidth*0.5; + for (var d = 0; d < 3; d++) { + BBoxMin[d]-= bboxPadding; + BBoxMax[d]+= bboxPadding; + }//for every dimension d from 0 to 2 + + //******* update the local coords so that the bbox min is at the origin ****** + for (var i=0;i=0){ @@ -853,9 +866,9 @@ exports.PenTool = Montage.create(ShapeTool, { this._editMode = this.EDIT_NONE; //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 - if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){ - this._selectedSubpath = null; - } + //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 -- cgit v1.2.3 From 0dd995834865202de1c51b1b4635f6515f54b1ea Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 12 Jun 2012 09:57:13 -0700 Subject: correct mouse cursor on mousemove --- js/tools/PenTool.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 52af294a..33ca5c71 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -539,7 +539,9 @@ exports.PenTool = Montage.create(ShapeTool, { //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){ + if ((this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0 && !this._selectedSubpath.getIsClosed()) + || + this._entryEditMode === this.ENTRY_SELECT_PATH){ this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; "url('images/cursors/penCursors/Pen_.png') 5 1, default"; } -- cgit v1.2.3 From 4d9b676db06a3d4ff5f4cf0f35e8fc998e0000c5 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 12 Jun 2012 10:16:20 -0700 Subject: ignore hardness for calligraphic brushes if stroke width is 1 --- js/lib/geom/brush-stroke.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 var disp = [brushStamp[t][0], brushStamp[t][1]]; var alphaVal = 1.0; var distFromOpaqueRegion = Math.abs(t-halfNumTraces) - opaqueRegionHalfWidth; - if (distFromOpaqueRegion>0) { + if (numTraces === 1){ + distFromOpaqueRegion = 0; + } + else if (distFromOpaqueRegion>0) { var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values alphaVal *= 0.5; //factor that accounts for lineWidth == 2 -- cgit v1.2.3 From c7135de92b25b380bebcafac541821a3696cfdfa Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 12 Jun 2012 10:21:03 -0700 Subject: change the brush runtime to ignore hardness in case of strokewidth of 1 --- assets/canvas-runtime.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index c2ab0bd8..feb35187 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -2264,7 +2264,10 @@ NinjaCvsRt.RuntimeBrushStroke = Object.create(NinjaCvsRt.RuntimeGeomObj, { var disp = [brushStamp[t][0], brushStamp[t][1]]; var alphaVal = 1.0; var distFromOpaqueRegion = Math.abs(t-halfNumTraces) - opaqueRegionHalfWidth; - if (distFromOpaqueRegion>0) { + if (numTraces === 1){ + distFromOpaqueRegion = 0; + } + else if (distFromOpaqueRegion>0) { var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values alphaVal *= 0.5; //factor that accounts for lineWidth == 2 -- cgit v1.2.3