Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 101 lines (83 sloc) 1.926 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

//
// 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();
  NODE_SET_PROTOTYPE_METHOD(t, "inspect", Inspect);
  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();
}

/*
* Custom inspect.
*/

Handle<Value>
Image::Inspect(const Arguments &args) {
  HandleScope scope;
  Image *img = ObjectWrap::Unwrap<Image>(args.This());
  Local<String> str = String::New("[Image");
  if (img->loaded()) {
    str = String::Concat(str, String::New(" "));
    str = String::Concat(str, String::New(img->filename()));
  }
  str = String::Concat(str, String::New("]"));
  return scope.Close(str);
}

/*
* Get src path.
*/

Handle<Value>
Image::GetSrc(Local<String>, const AccessorInfo &info) {
  Image *img = ObjectWrap::Unwrap<Image>(info.This());
  return String::New(img->filename());
}

/*
* Set src path.
*/

void
Image::SetSrc(Local<String>, Local<Value> val, const AccessorInfo &info) {
  if (val->IsString()) {
    String::AsciiValue src(val);
    Image *img = ObjectWrap::Unwrap<Image>(info.This());
    img->load(*src);
  }
}

/*
* Initialize a new Image.
*/

Image::Image() {
  _filename = NULL;
  _surface = NULL;
}

/*
* Destroy image and associated surface.
*/

Image::~Image() {
  cairo_surface_destroy(_surface);
}

void
Image::load(char *path) {
  _filename = path;
  // TODO: implement
}
Something went wrong with that request. Please try again.