Browse Source

Added Context2d::SetSource()

v1.x
Tj Holowaychuk 15 years ago
parent
commit
97b6730052
  1. 20
      src/context2d.cc
  2. 1
      src/context2d.h
  3. 5
      src/gradient.cc

20
src/context2d.cc

@ -5,10 +5,11 @@
// Copyright (c) 2010 LearnBoost <tj@learnboost.com> // Copyright (c) 2010 LearnBoost <tj@learnboost.com>
// //
#include "canvas.h"
#include "context2d.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include "canvas.h"
#include "context2d.h"
#include "gradient.h"
using namespace v8; using namespace v8;
using namespace node; using namespace node;
@ -80,6 +81,7 @@ Context2d::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "beginPath", BeginPath); NODE_SET_PROTOTYPE_METHOD(t, "beginPath", BeginPath);
NODE_SET_PROTOTYPE_METHOD(t, "closePath", ClosePath); NODE_SET_PROTOTYPE_METHOD(t, "closePath", ClosePath);
NODE_SET_PROTOTYPE_METHOD(t, "arc", Arc); 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, "setFillRGBA", SetFillRGBA);
NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA); NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA);
proto->SetAccessor(String::NewSymbol("globalCompositeOperation"), GetGlobalCompositeOperation, SetGlobalCompositeOperation); proto->SetAccessor(String::NewSymbol("globalCompositeOperation"), GetGlobalCompositeOperation, SetGlobalCompositeOperation);
@ -319,6 +321,20 @@ Context2d::SetLineCap(Local<String> prop, Local<Value> val, const AccessorInfo &
} }
} }
/*
* Set source pattern, used internally for fillStyle=
*/
Handle<Value>
Context2d::SetSource(const Arguments &args) {
HandleScope scope;
// TODO: HasInstance / error handling
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
Gradient *grad = ObjectWrap::Unwrap<Gradient>(args[0]->ToObject());
cairo_set_source(context->getContext(), grad->getPattern());
return Undefined();
}
/* /*
* Set fill RGBA, used internally for fillStyle= * Set fill RGBA, used internally for fillStyle=
*/ */

1
src/context2d.h

@ -31,6 +31,7 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> ClosePath(const Arguments &args); static Handle<Value> ClosePath(const Arguments &args);
static Handle<Value> Fill(const Arguments &args); static Handle<Value> Fill(const Arguments &args);
static Handle<Value> Stroke(const Arguments &args); static Handle<Value> Stroke(const Arguments &args);
static Handle<Value> SetSource(const Arguments &args);
static Handle<Value> SetFillRGBA(const Arguments &args); static Handle<Value> SetFillRGBA(const Arguments &args);
static Handle<Value> SetStrokeRGBA(const Arguments &args); static Handle<Value> SetStrokeRGBA(const Arguments &args);
static Handle<Value> BezierCurveTo(const Arguments &args); static Handle<Value> BezierCurveTo(const Arguments &args);

5
src/gradient.cc

@ -60,7 +60,10 @@ Gradient::AddColorStopRGBA(const Arguments &args) {
cairo_pattern_add_color_stop_rgba( cairo_pattern_add_color_stop_rgba(
grad->getPattern() grad->getPattern()
, args[0]->NumberValue() , args[0]->NumberValue()
, r, g, b, a); , r / 255 * 1
, g / 255 * 1
, b / 255 * 1
, a);
return Undefined(); return Undefined();
} }

Loading…
Cancel
Save