Browse Source

Started Gradient

v1.x
Tj Holowaychuk 14 years ago
parent
commit
8cf26690d3
  1. 2
      src/canvas.cc
  2. 2
      src/canvas.h
  3. 48
      src/gradient.cc
  4. 28
      src/gradient.h

2
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();
}

2
src/canvas.h

@ -21,8 +21,6 @@ class Canvas: public node::ObjectWrap {
static Handle<Value> New(const Arguments &args);
static Handle<Value> SavePNG(const Arguments &args);
inline cairo_surface_t *getSurface(){ return _surface; }
protected:
Canvas(int width, int height);
private:

48
src/gradient.cc

@ -0,0 +1,48 @@
//
// gradient.cc
//
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
//
#include "canvas.h"
#include "gradient.h"
void
Gradient::Initialize(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(Gradient::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("CanvasGradient"));
target->Set(String::NewSymbol("CanvasGradient"), t->GetFunction());
}
Handle<Value>
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")));
}

28
src/gradient.h

@ -0,0 +1,28 @@
//
// gradient.h
//
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
//
#ifndef __NODE_GRADIENT_H__
#define __NODE_GRADIENT_H__
#include "canvas.h"
using namespace v8;
class Gradient: public node::ObjectWrap {
public:
static void Initialize(Handle<Object> target);
static Handle<Value> 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
Loading…
Cancel
Save