diff --git a/src/context2d.h b/src/context2d.h index e46e9e3..fd21f8b 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -11,8 +11,12 @@ #include "canvas.h" #include "gradient.h" +/* + * RGBA struct used to retain values of fill/stroke. + */ + typedef struct { - float r, g, b, a; + double r, g, b, a; } rgba_t; class Context2d: public node::ObjectWrap { diff --git a/src/gradient.cc b/src/gradient.cc index 8423694..432cd0f 100644 --- a/src/gradient.cc +++ b/src/gradient.cc @@ -8,6 +8,10 @@ #include "canvas.h" #include "gradient.h" +/* + * Initialie CanvasGradient. + */ + void Gradient::Initialize(Handle target) { HandleScope scope; @@ -19,10 +23,16 @@ Gradient::Initialize(Handle target) { target->Set(String::NewSymbol("CanvasGradient"), t->GetFunction()); } +/* + * Initialize a new CanvasGradient. + */ + Handle Gradient::New(const Arguments &args) { HandleScope scope; + // TODO: separate concerns / validate args + // Linear if (4 == args.Length()) { Gradient *grad = new Gradient( @@ -50,6 +60,10 @@ Gradient::New(const Arguments &args) { return ThrowException(Exception::TypeError(String::New("invalid arguments"))); } +/* + * Add RGBA color stop. + */ + Handle Gradient::AddColorStopRGBA(const Arguments &args) { HandleScope scope; @@ -67,11 +81,19 @@ Gradient::AddColorStopRGBA(const Arguments &args) { return Undefined(); } +/* + * Initialize linear gradient. + */ + Gradient::Gradient(double x0, double y0, double x1, double y1): _x0(x0), _y0(y0), _x1(x1), _y1(y1) { _pattern = cairo_pattern_create_linear(x0, y0, x1, y1); } +/* + * Initialize radial gradient. + */ + Gradient::Gradient(double x0, double y0, double r0, double x1, double y1, double r1): _x0(x0), _y0(y0), _x1(x1), _y1(y1), _r0(r0), _r1(r1) { _pattern = cairo_pattern_create_radial(x0, y0, r0, x1, y1, r1);