diff --git a/src/Image.cc b/src/Image.cc new file mode 100644 index 0000000..208479e --- /dev/null +++ b/src/Image.cc @@ -0,0 +1,53 @@ + +// +// Image.cc +// +// Copyright (c) 2010 LearnBoost +// + +#include "canvas.h" +#include "image.h" + +/* + * Initialize Image. + */ + +void +Image::Initialize(Handle target) { + HandleScope scope; + Local t = FunctionTemplate::New(Image::New); + t->InstanceTemplate()->SetInternalFieldCount(1); + t->SetClassName(String::NewSymbol("Image")); + + Local proto = t->PrototypeTemplate(); + proto->SetAccessor(String::NewSymbol("src"), GetSrc, SetSrc); + target->Set(String::NewSymbol("Image"), t->GetFunction()); +} + +/* + * Initialize a new Image. + */ + +Handle +Image::New(const Arguments &args) { + HandleScope scope; + Image *img = new Image; + img->Wrap(args.This()); + return args.This(); +} + +/* + * Initialize a new Image. + */ + +Image::Image() { + _surface = NULL; +} + +/* + * Destroy image and associated surface. + */ + +Image::~Image() { + cairo_surface_destroy(_surface); +} \ No newline at end of file diff --git a/src/Image.h b/src/Image.h new file mode 100644 index 0000000..7a5acf0 --- /dev/null +++ b/src/Image.h @@ -0,0 +1,31 @@ + +// +// Image.h +// +// Copyright (c) 2010 LearnBoost +// + +#ifndef __NODE_IMAGE_H__ +#define __NODE_IMAGE_H__ + +#include "canvas.h" + +using namespace v8; + +class Image: public node::ObjectWrap { + public: + static void Initialize(Handle target); + static Handle New(const Arguments &args); + static Handle GetSrc(Local prop, const AccessorInfo &info); + static void SetSrc(Local prop, Local val, const AccessorInfo &info); + inline cairo_surface_t *surface(){ return _surface; } + inline char *filename(){ return _filename; } + Image(); + + private: + char *_filename; + cairo_surface_t *_surface; + ~Image(); +}; + +#endif \ No newline at end of file