From 8cf26690d358ff9d7d28866bc4fcef72450d2442 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Thu, 30 Sep 2010 13:11:30 -0700 Subject: [PATCH] Started Gradient --- src/canvas.cc | 2 +- src/canvas.h | 2 -- src/gradient.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gradient.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/gradient.cc create mode 100644 src/gradient.h diff --git a/src/canvas.cc b/src/canvas.cc index 9068a8e..ea7bd48 100644 --- a/src/canvas.cc +++ b/src/canvas.cc @@ -37,7 +37,7 @@ Canvas::New(const Arguments &args) { if (!args[1]->IsNumber()) return ThrowException(Exception::TypeError(String::New("height required"))); - Canvas *canvas = new Canvas(args[0]->Uint32Value(), args[1]->Uint32Value()); + Canvas *canvas = new Canvas(args[0]->Int32Value(), args[1]->Int32Value()); canvas->Wrap(args.This()); return args.This(); } diff --git a/src/canvas.h b/src/canvas.h index 57138c1..104080e 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -21,8 +21,6 @@ class Canvas: public node::ObjectWrap { static Handle New(const Arguments &args); static Handle SavePNG(const Arguments &args); inline cairo_surface_t *getSurface(){ return _surface; } - - protected: Canvas(int width, int height); private: diff --git a/src/gradient.cc b/src/gradient.cc new file mode 100644 index 0000000..dfe1538 --- /dev/null +++ b/src/gradient.cc @@ -0,0 +1,48 @@ + +// +// gradient.cc +// +// Copyright (c) 2010 LearnBoost +// + +#include "canvas.h" +#include "gradient.h" + +void +Gradient::Initialize(Handle target) { + HandleScope scope; + Local t = FunctionTemplate::New(Gradient::New); + t->InstanceTemplate()->SetInternalFieldCount(1); + t->SetClassName(String::NewSymbol("CanvasGradient")); + + target->Set(String::NewSymbol("CanvasGradient"), t->GetFunction()); +} + +Handle +Gradient::New(const Arguments &args) { + HandleScope scope; + + // Linear + if (4 == args.Length()) { + Gradient *grad = new Gradient( + args[0]->NumberValue() + , args[1]->NumberValue() + , args[2]->NumberValue() + , args[3]->NumberValue()); + } + + // Radial + if (6 == args.Length()) { + Gradient *grad = new Gradient( + args[0]->NumberValue() + , args[1]->NumberValue() + , args[2]->NumberValue() + , args[3]->NumberValue() + , args[4]->NumberValue() + , args[5]->NumberValue()); + grad->Wrap(args.This()); + return args.This(); + } + + return ThrowException(Exception::TypeError(String::New("invalid arguments"))); +} \ No newline at end of file diff --git a/src/gradient.h b/src/gradient.h new file mode 100644 index 0000000..48a08a3 --- /dev/null +++ b/src/gradient.h @@ -0,0 +1,28 @@ + +// +// gradient.h +// +// Copyright (c) 2010 LearnBoost +// + +#ifndef __NODE_GRADIENT_H__ +#define __NODE_GRADIENT_H__ + +#include "canvas.h" + +using namespace v8; + +class Gradient: public node::ObjectWrap { + public: + static void Initialize(Handle target); + static Handle New(const Arguments &args); + Gradient(double x0, double y0, double x1, double y1): + _x0(x0), _y0(y0), _x1(x1), _y1(y1) {}; + 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) {}; + + private: + double _x0, _y0, _x1, _y1, _r0, _r1; +}; + +#endif \ No newline at end of file