From f466473bfb4ca275258bd74d0bef3dcc5af039f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 19 Jul 2013 17:48:29 -0700 Subject: [PATCH] Add support for shadows. Closes #36. --- src/item/Item.js | 12 ++++++++-- src/style/Style.js | 55 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 993c5c50..9ae568b0 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -2887,8 +2887,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ limit = style.getMiterLimit(), fillColor = style.getFillColor(), strokeColor = style.getStrokeColor(), - dashArray = style.getDashArray(), - dashOffset = style.getDashOffset(); + shadowColor = style.getShadowColor(); if (width != null) ctx.lineWidth = width; if (join) @@ -2901,6 +2900,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{ ctx.fillStyle = fillColor.toCanvasStyle(ctx); if (strokeColor) { ctx.strokeStyle = strokeColor.toCanvasStyle(ctx); + var dashArray = style.getDashArray(), + dashOffset = style.getDashOffset(); if (paper.support.nativeDash && dashArray && dashArray.length) { if ('setLineDash' in ctx) { ctx.setLineDash(dashArray); @@ -2911,6 +2912,13 @@ var Item = Base.extend(Callback, /** @lends Item# */{ } } } + if (shadowColor) { + ctx.shadowColor = shadowColor.toCanvasStyle(ctx); + ctx.shadowBlur = style.getShadowBlur(); + var offset = this.getShadowOffset(); + ctx.shadowOffsetX = offset.x; + ctx.shadowOffsetY = offset.y; + } }, // TODO: Implement View into the drawing. diff --git a/src/style/Style.js b/src/style/Style.js index 2973c2e9..cf958d14 100644 --- a/src/style/Style.js +++ b/src/style/Style.js @@ -69,21 +69,26 @@ var Style = Base.extend(new function() { // windingRule / resolution / fillOverprint / strokeOverprint are currently // not supported. var defaults = { - // path styles + // Paths fillColor: undefined, strokeColor: undefined, - selectedColor: undefined, strokeWidth: 1, strokeCap: 'butt', strokeJoin: 'miter', miterLimit: 10, dashOffset: 0, dashArray: [], - // character styles + // Shadows + shadowColor: undefined, + shadowBlur: 0, + shadowOffset: new Point(), + // Selection + selectedColor: undefined, + // Characters font: 'sans-serif', fontSize: 12, leading: null, - // paragraph styles + // Paragraphs justification: 'left' }; @@ -415,6 +420,48 @@ var Style = Base.extend(new function() { * circle.fillColor = new Color(1, 0, 0); */ + /** + * {@grouptitle Shadow Style} + * + * The shadow color. + * + * @property + * @name Style#shadowColor + * @type Color + * + * @example {@paperscript} + * // Setting the shadow color of a path to black: + * + * // Create a circle shaped path at { x: 80, y: 50 } + * // with a radius of 35: + * var circle = new Path.Circle(new Point(80, 50), 35); + * + * // Set the shadow color of the circle to RGB black: + * circle.shadowColor = new Color(0, 0, 0); + * + * // Set the shadow blur, offset to { x: 10, y: 10 } + * circle.shadowBlur = 10; + * circle.shadowOffset = new Poit(10, 10); + */ + + /** + * The shadow's blur radius. + * + * @property + * @default 0 + * @name Style#shadowBlur + * @type Number + */ + + /** + * The shadow's offset. + * + * @property + * @default 0 + * @name Style#shadowOffset + * @type Point + */ + /** * {@grouptitle Selection Style} *