From e224b70246ae9d0d0b52dfea2e08939938ffcf48 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 29 Sep 2010 10:59:52 -0700 Subject: [PATCH] Added RGBA_ARGS --- src/context2d.cc | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/context2d.cc b/src/context2d.cc index 521db65..d1bb145 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -30,6 +30,24 @@ using namespace node; int width = args[2]->Int32Value(); \ int height = args[3]->Int32Value(); +/* + * RGBA arg assertions. + */ + +#define RGBA_ARGS \ + if (!args[0]->IsNumber()) \ + return ThrowException(Exception::TypeError(String::New("r required"))); \ + if (!args[1]->IsNumber()) \ + return ThrowException(Exception::TypeError(String::New("g required"))); \ + if (!args[2]->IsNumber()) \ + return ThrowException(Exception::TypeError(String::New("b required"))); \ + if (!args[3]->IsNumber()) \ + return ThrowException(Exception::TypeError(String::New("alpha required"))); \ + int r = args[0]->Int32Value(); \ + int g = args[1]->Int32Value(); \ + int b = args[2]->Int32Value(); \ + int a = args[3]->NumberValue(); + /* * Initialize Context2d. */ @@ -96,23 +114,10 @@ Context2d::~Context2d() { Handle Context2d::SetFillRGBA(const Arguments &args) { HandleScope scope; - - if (!args[0]->IsNumber()) - return ThrowException(Exception::TypeError(String::New("r required"))); - if (!args[1]->IsNumber()) - return ThrowException(Exception::TypeError(String::New("g required"))); - if (!args[2]->IsNumber()) - return ThrowException(Exception::TypeError(String::New("b required"))); - if (!args[3]->IsNumber()) - return ThrowException(Exception::TypeError(String::New("alpha required"))); - + RGBA_ARGS; Context2d *context = ObjectWrap::Unwrap(args.This()); - cairo_set_source_rgba(context->getContext() - , args[0]->Int32Value() - , args[1]->Int32Value() - , args[2]->Int32Value() - , args[3]->NumberValue()); + cairo_set_source_rgba(context->getContext(), r, g, b, a); return Undefined(); }