Browse Source

Separated fill / stroke style

v1.x
Tj Holowaychuk 15 years ago
parent
commit
0d30df6ae4
  1. 42
      src/context2d.cc
  2. 8
      src/context2d.h

42
src/context2d.cc

@ -73,6 +73,7 @@ Context2d::Initialize(Handle<Object> 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<Value>
@ -116,9 +117,26 @@ Context2d::SetFillRGBA(const Arguments &args) {
HandleScope scope;
RGBA_ARGS;
Context2d *context = ObjectWrap::Unwrap<Context2d>(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<Value>
Context2d::SetStrokeRGBA(const Arguments &args) {
HandleScope scope;
RGBA_ARGS;
Context2d *context = ObjectWrap::Unwrap<Context2d>(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<Value>
Context2d::Fill(const Arguments &args) {
HandleScope scope;
Context2d *context = ObjectWrap::Unwrap<Context2d>(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<Value>
Context2d::Stroke(const Arguments &args) {
HandleScope scope;
Context2d *context = ObjectWrap::Unwrap<Context2d>(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();
}

8
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<Object> target);
static Handle<Value> New(const Arguments &args);
static Handle<Value> BeginPath(const Arguments &args);
@ -19,6 +26,7 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> Fill(const Arguments &args);
static Handle<Value> Stroke(const Arguments &args);
static Handle<Value> SetFillRGBA(const Arguments &args);
static Handle<Value> SetStrokeRGBA(const Arguments &args);
static Handle<Value> BezierCurveTo(const Arguments &args);
static Handle<Value> LineTo(const Arguments &args);
static Handle<Value> MoveTo(const Arguments &args);

Loading…
Cancel
Save