Tj Holowaychuk 15 years ago
parent
commit
b0b4729b82
  1. 6
      src/context2d.h
  2. 22
      src/gradient.cc

6
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 {

22
src/gradient.cc

@ -8,6 +8,10 @@
#include "canvas.h"
#include "gradient.h"
/*
* Initialie CanvasGradient.
*/
void
Gradient::Initialize(Handle<Object> target) {
HandleScope scope;
@ -19,10 +23,16 @@ Gradient::Initialize(Handle<Object> target) {
target->Set(String::NewSymbol("CanvasGradient"), t->GetFunction());
}
/*
* Initialize a new CanvasGradient.
*/
Handle<Value>
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<Value>
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);

Loading…
Cancel
Save