From fcab2a14f8de302948d38f55db41e2c1c92baa34 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Thu, 8 Mar 2012 16:03:17 -0800 Subject: brush stroke options for calligraphic brush style --- .../brush-properties.reel/brush-properties.html | 23 +++- .../brush-properties.reel/brush-properties.js | 8 +- js/lib/geom/brush-stroke.js | 147 ++++++++++++--------- js/tools/BrushTool.js | 18 ++- 4 files changed, 129 insertions(+), 67 deletions(-) (limited to 'js') diff --git a/js/components/tools-properties/brush-properties.reel/brush-properties.html b/js/components/tools-properties/brush-properties.reel/brush-properties.html index 6d4852e6..d96bd1ba 100755 --- a/js/components/tools-properties/brush-properties.reel/brush-properties.html +++ b/js/components/tools-properties/brush-properties.reel/brush-properties.html @@ -37,6 +37,19 @@ } }, + "strokeAngleHT": { + "module": "js/components/hottextunit.reel", + "name": "HotTextUnit", + "properties": { + "element": {"#": "strokeAngle"}, + "minValue": -90, + "maxValue": 90, + "value": 0, + "decimalPlace": 10, + "acceptableUnits" : ["px", "pt"] + } + }, + "owner": { "module": "js/components/tools-properties/brush-properties.reel", "name": "BrushProperties", @@ -44,7 +57,9 @@ "element": {"#": "brushProperties"}, "_strokeSize": {"@": "strokeSizeHT"}, "_strokeHardness": {"@": "strokeHardnessHT"}, - "_doSmoothing": {"@": "doSmoothing"} + "_doSmoothing": {"#": "doSmoothing"}, + "_useCalligraphic":{"#": "useCalligraphic"}, + "_strokeAngle": {"@": "strokeAngleHT"} } } } @@ -59,7 +74,11 @@
- + + + +
+ diff --git a/js/components/tools-properties/brush-properties.reel/brush-properties.js b/js/components/tools-properties/brush-properties.reel/brush-properties.js index 0ce685b5..e6faa0f0 100755 --- a/js/components/tools-properties/brush-properties.reel/brush-properties.js +++ b/js/components/tools-properties/brush-properties.reel/brush-properties.js @@ -16,6 +16,12 @@ exports.BrushProperties = Montage.create(ToolProperties, { get: function() { return this._strokeHardness; } }, doSmoothing:{ - get: function() {return this._doSmoothing; } + get: function() {return this._doSmoothing.checked; } + }, + useCalligraphic: { + get: function() {return this._useCalligraphic.checked;} + }, + strokeAngle: { + get: function() {return this._strokeAngle;} } }); diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index 3e64e730..a92657a4 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js @@ -37,6 +37,8 @@ var BrushStroke = function GLBrushStroke() { this._strokeMaterial = null; this._strokeStyle = "Solid"; this._strokeDoSmoothing = false; + this._strokeUseCalligraphic = false; + this._strokeAngle = 0; //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed to not depend on stroke width entirely //smaller value means more samples for the path @@ -117,7 +119,7 @@ var BrushStroke = function GLBrushStroke() { //add the point only if it is some epsilon away from the previous point var numPoints = this._Points.length; if (numPoints>0) { - var threshold = 1;//this._WETNESS_FACTOR*this._strokeWidth; + var threshold = 2;//this._WETNESS_FACTOR*this._strokeWidth; var prevPt = this._Points[numPoints-1]; var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); @@ -188,6 +190,14 @@ var BrushStroke = function GLBrushStroke() { this._strokeDoSmoothing = s; } + this.setStrokeUseCalligraphic = function(c){ + this._strokeUseCalligraphic = c; + } + + this.setStrokeAngle = function(a){ + this._strokeAngle = a; + } + this.getStrokeStyle = function () { return this._strokeStyle; }; @@ -266,6 +276,8 @@ var BrushStroke = function GLBrushStroke() { } } } + //todo 4-point subdivision iterations over continuous regions of 'long' segments + // look at http://www.gvu.gatech.edu/~jarek/Split&Tweak/ for formula //**** add samples to the long sections of the path --- Catmull-Rom spline interpolation if (this._strokeDoSmoothing && numPoints>1) { var numInsertedPoints = 0; @@ -496,75 +508,84 @@ var BrushStroke = function GLBrushStroke() { } */ - /* - //build the stamp for the brush stroke - //todo get this directly from the UI - var t=0; - var numTraces = this._strokeWidth; - var halfNumTraces = numTraces/2; - var startPos = [-this._strokeWidth/2,0]; - var brushStamp = []; - - //build an angled (calligraphic) brush stamp - var deltaDisplacement = [1,1];//[this._strokeWidth/numTraces, 0]; //a horizontal line brush - for (t=0;t0) { + alphaVal = 1.0 - distFromOpaqueRegion/maxTransparentRegionHalfWidth; + } + + ctx.save(); + ctx.lineWidth=this._strokeWidth/10;//todo figure out the correct formula for the line width + if (ctx.lineWidth<2) + ctx.lineWidth=2; + if (t===numTraces-1){ + ctx.lineWidth = 1; + } + ctx.lineJoin="bevel"; + ctx.lineCap="butt"; + ctx.globalAlpha = this._strokeColor[3]; + + //if (t