Browse Source

Merge branch 'globals'

v1.x
Tj Holowaychuk 15 years ago
parent
commit
4fa6ca2103
  1. 24
      src/context2d.cc
  2. 3
      src/context2d.h
  3. 21
      test/canvas.test.js

24
src/context2d.cc

@ -32,7 +32,7 @@ using namespace node;
, C.r \ , C.r \
, C.g \ , C.g \
, C.b \ , C.b \
, C.a); , context->globalAlpha == -1 ? C.a : context->globalAlpha);
/* /*
* Rectangle arg assertions. * Rectangle arg assertions.
@ -100,6 +100,7 @@ Context2d::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "arc", Arc); NODE_SET_PROTOTYPE_METHOD(t, "arc", Arc);
NODE_SET_PROTOTYPE_METHOD(t, "setFillRGBA", SetFillRGBA); NODE_SET_PROTOTYPE_METHOD(t, "setFillRGBA", SetFillRGBA);
NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA); NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA);
proto->SetAccessor(String::NewSymbol("globalAlpha"), GetGlobalAlpha, SetGlobalAlpha);
proto->SetAccessor(String::NewSymbol("miterLimit"), GetMiterLimit, SetMiterLimit); proto->SetAccessor(String::NewSymbol("miterLimit"), GetMiterLimit, SetMiterLimit);
proto->SetAccessor(String::NewSymbol("lineWidth"), GetLineWidth, SetLineWidth); proto->SetAccessor(String::NewSymbol("lineWidth"), GetLineWidth, SetLineWidth);
proto->SetAccessor(String::NewSymbol("lineCap"), GetLineCap, SetLineCap); proto->SetAccessor(String::NewSymbol("lineCap"), GetLineCap, SetLineCap);
@ -128,6 +129,7 @@ Context2d::Context2d(Canvas *canvas): ObjectWrap() {
_canvas = canvas; _canvas = canvas;
_context = cairo_create(canvas->getSurface()); _context = cairo_create(canvas->getSurface());
cairo_set_line_width(_context, 1); cairo_set_line_width(_context, 1);
globalAlpha = -1;
RGBA(fill,0,0,0,1); RGBA(fill,0,0,0,1);
RGBA(stroke,0,0,0,1); RGBA(stroke,0,0,0,1);
} }
@ -140,6 +142,26 @@ Context2d::~Context2d() {
cairo_destroy(_context); cairo_destroy(_context);
} }
/*
* Get global alpha.
*/
Handle<Value>
Context2d::GetGlobalAlpha(Local<String> prop, const AccessorInfo &info) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
return Number::New(context->globalAlpha);
}
/*
* Set global alpha.
*/
void
Context2d::SetGlobalAlpha(Local<String> prop, Local<Value> val, const AccessorInfo &info) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
context->globalAlpha = val->NumberValue();
}
/* /*
* Get miter limit. * Get miter limit.
*/ */

3
src/context2d.h

@ -18,6 +18,7 @@ class Context2d: public node::ObjectWrap {
public: public:
rgba_t fill; rgba_t fill;
rgba_t stroke; rgba_t stroke;
float globalAlpha;
static void Initialize(Handle<Object> target); static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args); static Handle<Value> New(const Arguments &args);
static Handle<Value> Save(const Arguments &args); static Handle<Value> Save(const Arguments &args);
@ -40,10 +41,12 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> ClearRect(const Arguments &args); static Handle<Value> ClearRect(const Arguments &args);
static Handle<Value> Rect(const Arguments &args); static Handle<Value> Rect(const Arguments &args);
static Handle<Value> Arc(const Arguments &args); static Handle<Value> Arc(const Arguments &args);
static Handle<Value> GetGlobalAlpha(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetMiterLimit(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> GetLineCap(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetLineJoin(Local<String> prop, const AccessorInfo &info); static Handle<Value> GetLineJoin(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetLineWidth(Local<String> prop, const AccessorInfo &info); static Handle<Value> GetLineWidth(Local<String> prop, const AccessorInfo &info);
static void SetGlobalAlpha(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetMiterLimit(Local<String> prop, Local<Value> val, const AccessorInfo &info); static void SetMiterLimit(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetLineCap(Local<String> prop, Local<Value> val, const AccessorInfo &info); static void SetLineCap(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetLineJoin(Local<String> prop, Local<Value> val, const AccessorInfo &info); static void SetLineJoin(Local<String> prop, Local<Value> val, const AccessorInfo &info);

21
test/canvas.test.js

@ -339,5 +339,26 @@ module.exports = {
, path , path
, 'fc8bbf2cf6ae2d85fcf526103200e844' , 'fc8bbf2cf6ae2d85fcf526103200e844'
, 'Context2d#save() / resetore() failed'); , 'Context2d#save() / resetore() failed');
},
'test Context2d#globalAlpha=': function(assert){
var canvas = new Canvas(200, 200)
, ctx = canvas.getContext('2d')
, path = __dirname + '/images/globalAlpha.png';
ctx.fillRect(0,0,50,50);
ctx.translate(15,15);
ctx.globalAlpha = 0.6;
assert.equal(0.6, ctx.globalAlpha.toFixed(1));
ctx.fillStyle = 'red';
ctx.fillRect(0,0,20,20);
ctx.fillStyle = 'yellow';
ctx.fillRect(0,0,10,10);
assertChecksum(
canvas
, path
, 'd8365233f2beb420ba18ff78dc6d7405'
, 'Context2d#globalAlpha= failed');
} }
} }
Loading…
Cancel
Save