diff --git a/src/context2d.cc b/src/context2d.cc index 45b0bb0..979a07b 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -5,10 +5,11 @@ // Copyright (c) 2010 LearnBoost // -#include "canvas.h" -#include "context2d.h" #include #include +#include "canvas.h" +#include "context2d.h" +#include "gradient.h" using namespace v8; using namespace node; @@ -80,6 +81,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, "setSource", SetSource); NODE_SET_PROTOTYPE_METHOD(t, "setFillRGBA", SetFillRGBA); NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA); proto->SetAccessor(String::NewSymbol("globalCompositeOperation"), GetGlobalCompositeOperation, SetGlobalCompositeOperation); @@ -319,6 +321,20 @@ Context2d::SetLineCap(Local prop, Local val, const AccessorInfo & } } +/* + * Set source pattern, used internally for fillStyle= + */ + +Handle +Context2d::SetSource(const Arguments &args) { + HandleScope scope; + // TODO: HasInstance / error handling + Context2d *context = ObjectWrap::Unwrap(args.This()); + Gradient *grad = ObjectWrap::Unwrap(args[0]->ToObject()); + cairo_set_source(context->getContext(), grad->getPattern()); + return Undefined(); +} + /* * Set fill RGBA, used internally for fillStyle= */ diff --git a/src/context2d.h b/src/context2d.h index e5fc5f9..dc9fcf2 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -31,6 +31,7 @@ class Context2d: public node::ObjectWrap { static Handle ClosePath(const Arguments &args); static Handle Fill(const Arguments &args); static Handle Stroke(const Arguments &args); + static Handle SetSource(const Arguments &args); static Handle SetFillRGBA(const Arguments &args); static Handle SetStrokeRGBA(const Arguments &args); static Handle BezierCurveTo(const Arguments &args); diff --git a/src/gradient.cc b/src/gradient.cc index af2e63b..8423694 100644 --- a/src/gradient.cc +++ b/src/gradient.cc @@ -60,7 +60,10 @@ Gradient::AddColorStopRGBA(const Arguments &args) { cairo_pattern_add_color_stop_rgba( grad->getPattern() , args[0]->NumberValue() - , r, g, b, a); + , r / 255 * 1 + , g / 255 * 1 + , b / 255 * 1 + , a); return Undefined(); }