From 2dca8a0aa69981bc2a81c4a68f9061aef861f0ea Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Wed, 6 Jun 2012 15:01:10 -0700 Subject: enable gradients for brush stroke (in authoring as well as runtime) --- assets/canvas-runtime.js | 62 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'assets') diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index 524cdfeb..76332bcb 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -2137,15 +2137,59 @@ NinjaCvsRt.RuntimeBrushStroke = Object.create(NinjaCvsRt.RuntimeGeomObj, { } }, + //buildColor returns the fillStyle or strokeStyle for the Canvas 2D context + buildColor: { + value: function(ctx, //the 2D rendering context (for creating gradients if necessary) + ipColor, //color string, also encodes whether there's a gradient and of what type + w, //width of the region of color + h, //height of the region of color + lw) //linewidth (i.e. stroke width/size) + { + if (ipColor.gradientMode){ + var position, gradient, cs, inset; //vars used in gradient calculations + inset = Math.ceil( lw ) - 0.5; + + if(ipColor.gradientMode === "radial") { + var ww = w - 2*lw, hh = h - 2*lw; + gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(ww, hh)/2); + } else { + gradient = ctx.createLinearGradient(inset, h/2, w-inset, h/2); + } + var colors = ipColor.color; + + var len = colors.length; + for(n=0; n