Browse Source

Added shadowColor accessor

v1.x
Tj Holowaychuk 14 years ago
parent
commit
0a12195647
  1. 34
      lib/canvas.js
  2. 14
      src/context2d.cc
  3. 2
      src/context2d.h

34
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] + ')';
});
});
/**
* 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] + ')';
});

14
src/context2d.cc

@ -94,6 +94,7 @@ Context2d::Initialize(Handle<Object> 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<Value>
Context2d::SetShadowRGBA(const Arguments &args) {
HandleScope scope;
RGBA_ARGS(0);
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
RGBA(context->shadow,r,g,b,a);
return Undefined();
}
/*
* Set fill RGBA, used internally for fillStyle=
*/

2
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<Value> SetSource(const Arguments &args);
static Handle<Value> SetFillRGBA(const Arguments &args);
static Handle<Value> SetStrokeRGBA(const Arguments &args);
static Handle<Value> SetShadowRGBA(const Arguments &args);
static Handle<Value> SetFillPattern(const Arguments &args);
static Handle<Value> SetStrokePattern(const Arguments &args);
static Handle<Value> BezierCurveTo(const Arguments &args);

Loading…
Cancel
Save