Browse Source

Added Context2d::Get{Fill,Stroke}Color()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
85ae1c931f
  1. 23
      lib/context2d.js
  2. 26
      src/CanvasRenderingContext2d.cc
  3. 2
      src/CanvasRenderingContext2d.h

23
lib/context2d.js

@ -138,6 +138,17 @@ Context2d.prototype.__defineSetter__('fillStyle', function(val){
}
});
/**
* Get previous fill style.
*
* @return {CanvasGradient|String}
* @api public
*/
Context2d.prototype.__defineGetter__('fillStyle', function(){
return this.lastFillStyle || this.fillColor;
});
/**
* Set the stroke style with the given css color string.
*
@ -153,6 +164,18 @@ Context2d.prototype.__defineSetter__('strokeStyle', function(val){
}
});
/**
* Get previous stroke style.
*
* @return {CanvasGradient|String}
* @api public
*/
Context2d.prototype.__defineGetter__('strokeStyle', function(){
return this.lastStrokeStyle || this.strokeColor;
});
/**
* Set font.
*

26
src/CanvasRenderingContext2d.cc

@ -97,6 +97,8 @@ Context2d::Initialize(Handle<Object> target) {
proto->SetAccessor(String::NewSymbol("globalCompositeOperation"), GetGlobalCompositeOperation, SetGlobalCompositeOperation);
proto->SetAccessor(String::NewSymbol("globalAlpha"), GetGlobalAlpha, SetGlobalAlpha);
proto->SetAccessor(String::NewSymbol("shadowColor"), GetShadowColor, SetShadowColor);
proto->SetAccessor(String::NewSymbol("fillColor"), GetFillColor);
proto->SetAccessor(String::NewSymbol("strokeColor"), GetStrokeColor);
proto->SetAccessor(String::NewSymbol("miterLimit"), GetMiterLimit, SetMiterLimit);
proto->SetAccessor(String::NewSymbol("lineWidth"), GetLineWidth, SetLineWidth);
proto->SetAccessor(String::NewSymbol("lineCap"), GetLineCap, SetLineCap);
@ -1033,6 +1035,18 @@ Context2d::SetFillColor(const Arguments &args) {
return Undefined();
}
/*
* Get fill color.
*/
Handle<Value>
Context2d::GetFillColor(Local<String> prop, const AccessorInfo &info) {
char buf[64];
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
rgba_to_string(context->state->fill, buf);
return String::New(buf);
}
/*
* Set stroke color, used internally for strokeStyle=
*/
@ -1051,6 +1065,18 @@ Context2d::SetStrokeColor(const Arguments &args) {
return Undefined();
}
/*
* Get stroke color.
*/
Handle<Value>
Context2d::GetStrokeColor(Local<String> prop, const AccessorInfo &info) {
char buf[64];
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
rgba_to_string(context->state->stroke, buf);
return String::New(buf);
}
/*
* Bezier curve.
*/

2
src/CanvasRenderingContext2d.h

@ -80,6 +80,8 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> GetGlobalCompositeOperation(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetGlobalAlpha(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetShadowColor(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetFillColor(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetStrokeColor(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetMiterLimit(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetLineCap(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetLineJoin(Local<String> prop, const AccessorInfo &info);

Loading…
Cancel
Save