2 changed files with 84 additions and 0 deletions
@ -0,0 +1,53 @@ |
|||||
|
|
||||
|
//
|
||||
|
// Image.cc
|
||||
|
//
|
||||
|
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
|
||||
|
//
|
||||
|
|
||||
|
#include "canvas.h" |
||||
|
#include "image.h" |
||||
|
|
||||
|
/*
|
||||
|
* Initialize Image. |
||||
|
*/ |
||||
|
|
||||
|
void |
||||
|
Image::Initialize(Handle<Object> target) { |
||||
|
HandleScope scope; |
||||
|
Local<FunctionTemplate> t = FunctionTemplate::New(Image::New); |
||||
|
t->InstanceTemplate()->SetInternalFieldCount(1); |
||||
|
t->SetClassName(String::NewSymbol("Image")); |
||||
|
|
||||
|
Local<ObjectTemplate> proto = t->PrototypeTemplate(); |
||||
|
proto->SetAccessor(String::NewSymbol("src"), GetSrc, SetSrc); |
||||
|
target->Set(String::NewSymbol("Image"), t->GetFunction()); |
||||
|
} |
||||
|
|
||||
|
/*
|
||||
|
* Initialize a new Image. |
||||
|
*/ |
||||
|
|
||||
|
Handle<Value> |
||||
|
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); |
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
|
||||
|
//
|
||||
|
// Image.h
|
||||
|
//
|
||||
|
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
|
||||
|
//
|
||||
|
|
||||
|
#ifndef __NODE_IMAGE_H__ |
||||
|
#define __NODE_IMAGE_H__ |
||||
|
|
||||
|
#include "canvas.h" |
||||
|
|
||||
|
using namespace v8; |
||||
|
|
||||
|
class Image: public node::ObjectWrap { |
||||
|
public: |
||||
|
static void Initialize(Handle<Object> target); |
||||
|
static Handle<Value> New(const Arguments &args); |
||||
|
static Handle<Value> GetSrc(Local<String> prop, const AccessorInfo &info); |
||||
|
static void SetSrc(Local<String> prop, Local<Value> 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 |
Loading…
Reference in new issue