Browse Source

Added rotate() / translate()

v1.x
Tj Holowaychuk 15 years ago
parent
commit
a37b6eac6a
  1. 40
      src/context2d.cc
  2. 2
      src/context2d.h

40
src/context2d.cc

@ -86,6 +86,8 @@ Context2d::Initialize(Handle<Object> target) {
Local<ObjectTemplate> 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<Value>
Context2d::Rotate(const Arguments &args) {
HandleScope scope;
if (!args[0]->IsNumber())
return ThrowException(Exception::TypeError(String::New("angle required")));
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_rotate(context->getContext(), args[0]->NumberValue());
return Undefined();
}
/*
* Translate transformation.
*/
Handle<Value>
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<Context2d>(args.This());
cairo_translate(context->getContext()
, args[0]->NumberValue()
, args[1]->NumberValue());
return Undefined();
}
/*
* Fill the shape.
*/

2
src/context2d.h

@ -23,6 +23,8 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> New(const Arguments &args);
static Handle<Value> Save(const Arguments &args);
static Handle<Value> Restore(const Arguments &args);
static Handle<Value> Rotate(const Arguments &args);
static Handle<Value> Translate(const Arguments &args);
static Handle<Value> BeginPath(const Arguments &args);
static Handle<Value> ClosePath(const Arguments &args);
static Handle<Value> Fill(const Arguments &args);

Loading…
Cancel
Save