Browse Source

new Canvas() constructor allowing width/height

v1.x
Tj Holowaychuk 14 years ago
parent
commit
bc6e3c1fa1
  1. 28
      src/canvas.cc
  2. 7
      src/canvas.h

28
src/canvas.cc

@ -43,15 +43,13 @@ Canvas::Initialize(Handle<Object> target) {
Handle<Value>
Canvas::New(const Arguments &args) {
HandleScope scope;
int width = 0
, height = 0;
if (!args[0]->IsNumber())
return ThrowException(Exception::TypeError(String::New("width required")));
if (!args[1]->IsNumber())
return ThrowException(Exception::TypeError(String::New("height required")));
if (args[0]->IsNumber()) width = args[0]->Uint32Value();
if (args[1]->IsNumber()) height = args[1]->Uint32Value();
Canvas *canvas = new Canvas(args[0]->Int32Value(), args[1]->Int32Value());
args.This()->Set(String::NewSymbol("width"), args[0]);
args.This()->Set(String::NewSymbol("height"), args[1]);
Canvas *canvas = new Canvas(width, height);
canvas->Wrap(args.This());
return args.This();
}
@ -104,8 +102,10 @@ Canvas::StreamPNGSync(const Arguments &args) {
* Initialize cairo surface.
*/
Canvas::Canvas(int width, int height): ObjectWrap() {
_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
Canvas::Canvas(int w, int h): ObjectWrap() {
width = w;
height = h;
_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
}
/*
@ -116,6 +116,16 @@ Canvas::~Canvas() {
cairo_surface_destroy(_surface);
}
/*
* Re-alloc the surface, destroying the previous.
*/
void
Canvas::resetSurface() {
cairo_surface_destroy(_surface);
_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
}
/*
* Construct an Error from the given cairo status.
*/

7
src/canvas.h

@ -48,8 +48,14 @@ using namespace v8;
class Canvas: public node::ObjectWrap {
public:
int width;
int height;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
static Handle<Value> SetHeight(const Arguments &args);
static Handle<Value> GetHeight(const Arguments &args);
static Handle<Value> SetWidth(const Arguments &args);
static Handle<Value> GetWidth(const Arguments &args);
static Handle<Value> SavePNG(const Arguments &args);
static Handle<Value> StreamPNGSync(const Arguments &args);
static Handle<Value> Error(cairo_status_t status);
@ -59,6 +65,7 @@ class Canvas: public node::ObjectWrap {
private:
~Canvas();
void resetSurface();
cairo_surface_t *_surface;
};

Loading…
Cancel
Save