From 0d30df6ae4f845793f74d04b0ff01e145b762ca9 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 29 Sep 2010 11:21:16 -0700 Subject: [PATCH] Separated fill / stroke style --- src/context2d.cc | 42 +++++++++++++++++++++++++++++++++++++----- src/context2d.h | 8 ++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/context2d.cc b/src/context2d.cc index d1bb145..420c057 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -73,6 +73,7 @@ Context2d::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "closePath", ClosePath); NODE_SET_PROTOTYPE_METHOD(t, "arc", Arc); NODE_SET_PROTOTYPE_METHOD(t, "setFillRGBA", SetFillRGBA); + NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA); target->Set(String::NewSymbol("Context2d"), t->GetFunction()); } @@ -108,7 +109,7 @@ Context2d::~Context2d() { } /* - * Set fill RGBA, use internally for fillStyle= + * Set fill RGBA, used internally for fillStyle= */ Handle @@ -116,9 +117,26 @@ Context2d::SetFillRGBA(const Arguments &args) { HandleScope scope; RGBA_ARGS; Context2d *context = ObjectWrap::Unwrap(args.This()); + context->fill.r = r; + context->fill.g = g; + context->fill.b = b; + context->fill.a = a; + return Undefined(); +} - cairo_set_source_rgba(context->getContext(), r, g, b, a); - +/* + * Set stroke RGBA, used internally for strokeStyle= + */ + +Handle +Context2d::SetStrokeRGBA(const Arguments &args) { + HandleScope scope; + RGBA_ARGS; + Context2d *context = ObjectWrap::Unwrap(args.This()); + context->stroke.r = r; + context->stroke.g = g; + context->stroke.b = b; + context->stroke.a = a; return Undefined(); } @@ -187,7 +205,14 @@ Handle Context2d::Fill(const Arguments &args) { HandleScope scope; Context2d *context = ObjectWrap::Unwrap(args.This()); - cairo_fill(context->getContext()); + cairo_t *ctx = context->getContext(); + cairo_set_source_rgba( + ctx + , context->fill.r + , context->fill.g + , context->fill.b + , context->fill.a); + cairo_fill(ctx); return Undefined(); } @@ -199,7 +224,14 @@ Handle Context2d::Stroke(const Arguments &args) { HandleScope scope; Context2d *context = ObjectWrap::Unwrap(args.This()); - cairo_stroke(context->getContext()); + cairo_t *ctx = context->getContext(); + cairo_set_source_rgba( + ctx + , context->stroke.r + , context->stroke.g + , context->stroke.b + , context->stroke.a); + cairo_stroke(ctx); return Undefined(); } diff --git a/src/context2d.h b/src/context2d.h index 1a70d6b..fc73e57 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -10,8 +10,15 @@ #include "canvas.h" +typedef struct { + unsigned char r, g, b; + double a; +} rgba_t; + class Context2d: public node::ObjectWrap { public: + rgba_t fill; + rgba_t stroke; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle BeginPath(const Arguments &args); @@ -19,6 +26,7 @@ class Context2d: public node::ObjectWrap { static Handle Fill(const Arguments &args); static Handle Stroke(const Arguments &args); static Handle SetFillRGBA(const Arguments &args); + static Handle SetStrokeRGBA(const Arguments &args); static Handle BezierCurveTo(const Arguments &args); static Handle LineTo(const Arguments &args); static Handle MoveTo(const Arguments &args);