Browse Source

Added rgba_to_string()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
ddeb6f3566
  1. 2
      src/CanvasRenderingContext2d.cc
  2. 23
      src/color.cc
  3. 3
      src/color.h

2
src/CanvasRenderingContext2d.cc

@ -1010,7 +1010,7 @@ Context2d::SetShadowColor(Local<String> prop, Local<Value> val, const AccessorIn
Handle<Value>
Context2d::GetShadowColor(Local<String> prop, const AccessorInfo &info) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
return Null();
return String::New(rgba_to_string(context->state->shadow));
}
/*

23
src/color.cc

@ -6,6 +6,7 @@
//
#include "color.h"
#include <stdlib.h>
/*
* Consume whitespace.
@ -234,6 +235,28 @@ rgba_create(uint32_t rgba) {
return color;
}
/*
* Return a string representation of the color.
*/
char *
rgba_to_string(rgba_t rgba) {
char *buf = (char *) malloc(64);
if (1 == rgba.a) {
sprintf(buf, "#%.2X%.2X%.2X"
, (int) (rgba.r * 255)
, (int) (rgba.g * 255)
, (int) (rgba.b * 255));
} else {
sprintf(buf, "rgba(%d, %d, %d, %.2f)"
, (int) (rgba.r * 255)
, (int) (rgba.g * 255)
, (int) (rgba.b * 255)
, rgba.a);
}
return buf;
}
/*
* Return rgba from (r,g,b,a).
*/

3
src/color.h

@ -30,6 +30,9 @@ rgba_create(uint32_t rgba);
int32_t
rgba_from_string(const char *str, short *ok);
char *
rgba_to_string(rgba_t rgba);
void
rgba_inspect(int32_t rgba);

Loading…
Cancel
Save