From d45b72b0e683d307ce3e798769f19627416015db Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Wed, 25 Apr 2012 10:01:57 -0700 Subject: render the calligraphic brush stroke in realtime on a rotated canvas --- js/lib/geom/brush-stroke.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index 89ef79fb..1fae0c1d 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js @@ -568,11 +568,11 @@ var BrushStroke = function GLBrushStroke() { } ctx.save(); ctx.clearRect(0, 0, bboxWidth, bboxHeight); - this.drawToContext(ctx, 0, 0, false); + this.drawToContext(ctx, false); ctx.restore(); } //this.render() - this.drawToContext = function(ctx, deltaX, deltaY, drawStageWorldPts, stageWorldToScreenMat){ + this.drawToContext = function(ctx, drawStageWorldPts, stageWorldDeltaX, stageWorldDeltaY, stageWorldToScreenMat){ var points = this._LocalPoints; if (drawStageWorldPts){ //this is usually true when we're drawing the brush stroke on the stage (no canvas yet) points = this._Points; @@ -623,9 +623,23 @@ var BrushStroke = function GLBrushStroke() { //ctx.strokeStyle="rgba("+parseInt(255*currStrokeColor[0])+","+parseInt(255*currStrokeColor[1])+","+parseInt(255*currStrokeColor[2])+","+alphaVal+")"; ctx.translate(disp[0],disp[1]); ctx.beginPath(); - ctx.moveTo(points[0][0]-deltaX, points[0][1]-deltaY); + if (drawStageWorldPts) { + tempP = points[0].slice(0); + tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; + p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); + } else { + p = points[0]; + } + ctx.moveTo(p[0],p[1]); for (var i=0;i