diff --git a/lib/canvas.js b/lib/canvas.js index 3e6a070..f035db2 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -269,4 +269,36 @@ Context2d.prototype.__defineSetter__('strokeStyle', function(val){ Context2d.prototype.__defineGetter__('strokeStyle', function(){ var rgba = this.lastStrokeStyle; return 'rgba(' + rgba[0] + ',' + rgba[1] + ',' + rgba[2] + ',' + rgba[3] + ')'; -}); \ No newline at end of file +}); + +/** + * Set the shadow color with the given css color string. + * + * @see exports.parseColor() + * @api public + */ + +Context2d.prototype.__defineSetter__('shadowColor', function(val){ + if ('string' == typeof val) { + var rgba; + if (rgba = parseColor(val)) { + this.lastShadowColor = rgba; + this.setShadowRGBA( + rgba[0] + , rgba[1] + , rgba[2] + , rgba[3]); + } + } +}); + +/** + * Get the current shadow color string. + * + * @api public + */ + +Context2d.prototype.__defineGetter__('shadowColor', function(){ + var rgba = this.lastShadowColor; + return 'rgba(' + rgba[0] + ',' + rgba[1] + ',' + rgba[2] + ',' + rgba[3] + ')'; +}); diff --git a/src/context2d.cc b/src/context2d.cc index 3109786..b81baf1 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -94,6 +94,7 @@ Context2d::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "beginPath", BeginPath); NODE_SET_PROTOTYPE_METHOD(t, "closePath", ClosePath); NODE_SET_PROTOTYPE_METHOD(t, "arc", Arc); + NODE_SET_PROTOTYPE_METHOD(t, "setShadowRGBA", SetShadowRGBA); NODE_SET_PROTOTYPE_METHOD(t, "setFillRGBA", SetFillRGBA); NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA); NODE_SET_PROTOTYPE_METHOD(t, "setFillPattern", SetFillPattern); @@ -390,6 +391,19 @@ Context2d::SetStrokePattern(const Arguments &args) { return Undefined(); } +/* + * Set shadow RGBA, used internally for shadowColor= + */ + +Handle +Context2d::SetShadowRGBA(const Arguments &args) { + HandleScope scope; + RGBA_ARGS(0); + Context2d *context = ObjectWrap::Unwrap(args.This()); + RGBA(context->shadow,r,g,b,a); + return Undefined(); +} + /* * Set fill RGBA, used internally for fillStyle= */ diff --git a/src/context2d.h b/src/context2d.h index fd21f8b..44e55a9 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -23,6 +23,7 @@ class Context2d: public node::ObjectWrap { public: rgba_t fill; rgba_t stroke; + rgba_t shadow; cairo_pattern_t *fillPattern; cairo_pattern_t *strokePattern; float globalAlpha; @@ -44,6 +45,7 @@ class Context2d: public node::ObjectWrap { static Handle SetSource(const Arguments &args); static Handle SetFillRGBA(const Arguments &args); static Handle SetStrokeRGBA(const Arguments &args); + static Handle SetShadowRGBA(const Arguments &args); static Handle SetFillPattern(const Arguments &args); static Handle SetStrokePattern(const Arguments &args); static Handle BezierCurveTo(const Arguments &args);