Browse Source

AddColorStop() using new color parser

v1.x
Tj Holowaychuk 14 years ago
parent
commit
9fddb25eb5
  1. 18
      src/Canvas.h
  2. 25
      src/CanvasGradient.cc

18
src/Canvas.h

@ -25,24 +25,6 @@ using namespace node;
#define CANVAS_MAX_STATES 64
#endif
/*
* RGBA arg assertions.
*/
#define RGBA_ARGS(N) \
if (!args[N]->IsNumber()) \
return ThrowException(Exception::TypeError(String::New("r required"))); \
if (!args[N+1]->IsNumber()) \
return ThrowException(Exception::TypeError(String::New("g required"))); \
if (!args[N+2]->IsNumber()) \
return ThrowException(Exception::TypeError(String::New("b required"))); \
if (!args[N+3]->IsNumber()) \
return ThrowException(Exception::TypeError(String::New("alpha required"))); \
double r = args[N]->Int32Value(); \
double g = args[N+1]->Int32Value(); \
double b = args[N+2]->Int32Value(); \
double a = args[N+3]->NumberValue();
/*
* Canvas.
*/

25
src/CanvasGradient.cc

@ -5,6 +5,7 @@
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
//
#include "color.h"
#include "Canvas.h"
#include "CanvasGradient.h"
@ -74,15 +75,23 @@ Gradient::AddColorStop(const Arguments &args) {
return ThrowException(Exception::TypeError(String::New("offset required")));
if (!args[1]->IsString())
return ThrowException(Exception::TypeError(String::New("color string required")));
RGBA_ARGS(1);
Gradient *grad = ObjectWrap::Unwrap<Gradient>(args.This());
cairo_pattern_add_color_stop_rgba(
grad->pattern()
, args[0]->NumberValue()
, r / 255 * 1
, g / 255 * 1
, b / 255 * 1
, a);
short ok;
String::AsciiValue str(args[1]);
uint32_t rgba = rgba_from_string(*str, &ok);
if (ok) {
rgba_t color = rgba_create(rgba);
cairo_pattern_add_color_stop_rgba(
grad->pattern()
, args[0]->NumberValue()
, color.r
, color.g
, color.b
, color.a);
}
return Undefined();
}

Loading…
Cancel
Save