Browse Source

Started Context2d#drawImage()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
b92797961e
  1. 55
      src/CanvasRenderingContext2d.cc
  2. 1
      src/CanvasRenderingContext2d.h

55
src/CanvasRenderingContext2d.cc

@ -9,6 +9,7 @@
#include <string.h>
#include <stdlib.h>
#include "Canvas.h"
#include "Image.h"
#include "CanvasRenderingContext2d.h"
#include "CanvasGradient.h"
@ -66,6 +67,7 @@ Context2d::Initialize(Handle<Object> target) {
// Prototype
Local<ObjectTemplate> proto = t->PrototypeTemplate();
NODE_SET_PROTOTYPE_METHOD(t, "drawImage", DrawImage);
NODE_SET_PROTOTYPE_METHOD(t, "save", Save);
NODE_SET_PROTOTYPE_METHOD(t, "restore", Restore);
NODE_SET_PROTOTYPE_METHOD(t, "rotate", Rotate);
@ -112,19 +114,6 @@ Context2d::Initialize(Handle<Object> target) {
target->Set(String::NewSymbol("CanvasRenderingContext2d"), t->GetFunction());
}
/*
* Initialize a new Context2d with the given canvas.
*/
Handle<Value>
Context2d::New(const Arguments &args) {
HandleScope scope;
Canvas *canvas = ObjectWrap::Unwrap<Canvas>(args[0]->ToObject());
Context2d *context = new Context2d(canvas);
context->Wrap(args.This());
return args.This();
}
/*
* Create a cairo context.
*/
@ -382,6 +371,46 @@ Context2d::blur(cairo_surface_t *surface, int radius) {
free( precalc );
}
/*
* Initialize a new Context2d with the given canvas.
*/
Handle<Value>
Context2d::New(const Arguments &args) {
HandleScope scope;
Canvas *canvas = ObjectWrap::Unwrap<Canvas>(args[0]->ToObject());
Context2d *context = new Context2d(canvas);
context->Wrap(args.This());
return args.This();
}
/*
* Draw image.
*/
Handle<Value>
Context2d::DrawImage(const Arguments &args) {
HandleScope scope;
if (!args[1]->IsNumber()
|| !args[2]->IsNumber()) return Undefined();
// TODO: instanceof
Image *img = ObjectWrap::Unwrap<Image>(args[0]->ToObject());
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
double x = args[1]->NumberValue();
double y = args[2]->NumberValue();
cairo_t *ctx = context->context();
cairo_save(ctx);
cairo_set_source_surface(ctx, img->surface(), x, y);
cairo_paint(ctx);
cairo_restore(ctx);
return Undefined();
}
/*
* Get global alpha.
*/

1
src/CanvasRenderingContext2d.h

@ -47,6 +47,7 @@ class Context2d: public node::ObjectWrap {
canvas_state_t *state;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
static Handle<Value> DrawImage(const Arguments &args);
static Handle<Value> Save(const Arguments &args);
static Handle<Value> Restore(const Arguments &args);
static Handle<Value> Rotate(const Arguments &args);

Loading…
Cancel
Save