From a37b6eac6a8018c04ea0a039d3a04e5cdf3a6299 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 29 Sep 2010 15:11:33 -0700 Subject: [PATCH] Added rotate() / translate() --- src/context2d.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/context2d.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/src/context2d.cc b/src/context2d.cc index 02f7f59..dac61b2 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -86,6 +86,8 @@ Context2d::Initialize(Handle target) { Local proto = t->PrototypeTemplate(); NODE_SET_PROTOTYPE_METHOD(t, "save", Save); NODE_SET_PROTOTYPE_METHOD(t, "restore", Restore); + NODE_SET_PROTOTYPE_METHOD(t, "rotate", Rotate); + NODE_SET_PROTOTYPE_METHOD(t, "translate", Translate); NODE_SET_PROTOTYPE_METHOD(t, "fill", Fill); NODE_SET_PROTOTYPE_METHOD(t, "stroke", Stroke); NODE_SET_PROTOTYPE_METHOD(t, "fillRect", FillRect); @@ -356,6 +358,44 @@ Context2d::ClosePath(const Arguments &args) { return Undefined(); } +/* + * Rotate transformation. + */ + +Handle +Context2d::Rotate(const Arguments &args) { + HandleScope scope; + + if (!args[0]->IsNumber()) + return ThrowException(Exception::TypeError(String::New("angle required"))); + + Context2d *context = ObjectWrap::Unwrap(args.This()); + cairo_rotate(context->getContext(), args[0]->NumberValue()); + + return Undefined(); +} + +/* + * Translate transformation. + */ + +Handle +Context2d::Translate(const Arguments &args) { + HandleScope scope; + + if (!args[0]->IsNumber()) + return ThrowException(Exception::TypeError(String::New("tx required"))); + if (!args[1]->IsNumber()) + return ThrowException(Exception::TypeError(String::New("ty required"))); + + Context2d *context = ObjectWrap::Unwrap(args.This()); + cairo_translate(context->getContext() + , args[0]->NumberValue() + , args[1]->NumberValue()); + + return Undefined(); +} + /* * Fill the shape. */ diff --git a/src/context2d.h b/src/context2d.h index 65aa269..fed4688 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -23,6 +23,8 @@ class Context2d: public node::ObjectWrap { static Handle New(const Arguments &args); static Handle Save(const Arguments &args); static Handle Restore(const Arguments &args); + static Handle Rotate(const Arguments &args); + static Handle Translate(const Arguments &args); static Handle BeginPath(const Arguments &args); static Handle ClosePath(const Arguments &args); static Handle Fill(const Arguments &args);