Browse Source

Added nvgRGBf and nvgRGBAf constructor functions.

shared-context
Doug Binks 11 years ago
parent
commit
a83913bc87
2 changed files with 20 additions and 1 deletions
  1. +11
    -0
      src/nanovg.c
  2. +9
    -1
      src/nanovg.h

+ 11
- 0
src/nanovg.c View File

@@ -283,12 +283,23 @@ struct NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b)
return nvgRGBA(r,g,b,255);
}

struct NVGcolor nvgRGBf(float r, float g, float b)
{
return nvgRGBA(r,g,b,1.0f);
}

struct NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
struct NVGcolor color = {r/255.0f, g/255.0f, b/255.0f, a/255.0f};
return color;
}

struct NVGcolor nvgRGBAf(float r, float g, float b, float a)
{
struct NVGcolor color = {r, g, b, a};
return color;
}

struct NVGcolor nvgTransRGBA(struct NVGcolor c, unsigned char a)
{
c.a = a / 255.0f;


+ 9
- 1
src/nanovg.h View File

@@ -113,12 +113,20 @@ void nvgEndFrame(struct NVGcontext* ctx);
//
// Colors in NanoVG are stored as unsigned ints in ABGR format.

// Returns a color value from red, green, blue values. Alpha will be set to 255.
// Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
struct NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);

// Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
struct NVGcolor nvgRGBf(float r, float g, float b);


// Returns a color value from red, green, blue and alpha values.
struct NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);

// Returns a color value from red, green, blue and alpha values.
struct NVGcolor nvgRGBAf(float r, float g, float b, float a);


// Linearly interpoaltes from color c0 to c1, and returns resulting color value.
struct NVGcolor nvgLerpRGBA(struct NVGcolor c0, struct NVGcolor c1, float u);



Loading…
Cancel
Save