From e562ac20dffde1989c1c66d00e92a52e1d1d293f Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Sun, 6 Jun 2010 23:03:26 +0100 Subject: [PATCH] cogl-color: Provide setters for all the channels We only had getters for the red, green, blue and alpha channels of a color. This meant that, if you wanted to change, say, the alpha component of a color, one would need to query the red, green and blue channels and use set_from_4ub() or set_from_4f(). Instead of this, just provide some setters for CoglColor, using the same naming scheme than the existing getters. --- clutter/cogl/cogl/cogl-color.c | 84 +++++++++++++++++++ clutter/cogl/cogl/cogl-color.h | 156 +++++++++++++++++++++++++++++++++++ doc/reference/cogl/cogl-sections.txt | 18 ++++ 3 files changed, 258 insertions(+) diff --git a/clutter/cogl/cogl/cogl-color.c b/clutter/cogl/cogl/cogl-color.c index 544d874..5051bf1 100644 --- a/clutter/cogl/cogl/cogl-color.c +++ b/clutter/cogl/cogl/cogl-color.c @@ -156,6 +156,90 @@ cogl_color_get_alpha (const CoglColor *color) } void +cogl_color_set_red_byte (CoglColor *color, + unsigned char red) +{ + color->red = red; +} + +void +cogl_color_set_red_float (CoglColor *color, + float red) +{ + color->red = red * 255.0; +} + +void +cogl_color_set_red (CoglColor *color, + float red) +{ + color->red = red * 255.0; +} + +void +cogl_color_set_green_byte (CoglColor *color, + unsigned char green) +{ + color->green = green; +} + +void +cogl_color_set_green_float (CoglColor *color, + float green) +{ + color->green = green * 255.0; +} + +void +cogl_color_set_green (CoglColor *color, + float green) +{ + color->green = green * 255.0; +} + +void +cogl_color_set_blue_byte (CoglColor *color, + unsigned char blue) +{ + color->blue = blue; +} + +void +cogl_color_set_blue_float (CoglColor *color, + float blue) +{ + color->blue = blue * 255.0; +} + +void +cogl_color_set_blue (CoglColor *color, + float blue) +{ + color->blue = blue * 255.0; +} + +void +cogl_color_set_alpha_byte (CoglColor *color, + unsigned char alpha) +{ + color->alpha = alpha; +} + +void +cogl_color_set_alpha_float (CoglColor *color, + float alpha) +{ + color->alpha = alpha * 255.0; +} + +void +cogl_color_set_alpha (CoglColor *color, + float alpha) +{ + color->alpha = alpha * 255.0; +} + +void cogl_color_premultiply (CoglColor *color) { color->red = (color->red * color->alpha + 128) / 255; diff --git a/clutter/cogl/cogl/cogl-color.h b/clutter/cogl/cogl/cogl-color.h index 1e1a14d..b179944 100644 --- a/clutter/cogl/cogl/cogl-color.h +++ b/clutter/cogl/cogl/cogl-color.h @@ -287,6 +287,162 @@ float cogl_color_get_alpha (const CoglColor *color); /** + * cogl_color_set_red_byte: + * @color: a #CoglColor + * @red: a byte value between 0 and 255 + * + * Sets the red channel of @color to @red. + * + * Since: 1.4 + */ +void +cogl_color_set_red_byte (CoglColor *color, + unsigned char red); + +/** + * cogl_color_set_green_byte: + * @color: a #CoglColor + * @green: a byte value between 0 and 255 + * + * Sets the green channel of @color to @green. + * + * Since: 1.4 + */ +void +cogl_color_set_green_byte (CoglColor *color, + unsigned char green); + +/** + * cogl_color_set_blue_byte: + * @color: a #CoglColor + * @blue: a byte value between 0 and 255 + * + * Sets the blue channel of @color to @blue. + * + * Since: 1.4 + */ +void +cogl_color_set_blue_byte (CoglColor *color, + unsigned char blue); + +/** + * cogl_color_set_alpha_byte: + * @color: a #CoglColor + * @alpha: a byte value between 0 and 255 + * + * Sets the alpha channel of @color to @alpha. + * + * Since: 1.4 + */ +void +cogl_color_set_alpha_byte (CoglColor *color, + unsigned char alpha); + +/** + * cogl_color_set_red_float: + * @color: a #CoglColor + * @red: a float value between 0.0f and 1.0f + * + * Sets the red channel of @color to @red. + * + * since: 1.4 + */ +void +cogl_color_set_red_float (CoglColor *color, + float red); + +/** + * cogl_color_set_green_float: + * @color: a #CoglColor + * @green: a float value between 0.0f and 1.0f + * + * Sets the green channel of @color to @green. + * + * since: 1.4 + */ +void +cogl_color_set_green_float (CoglColor *color, + float green); + +/** + * cogl_color_set_blue_float: + * @color: a #CoglColor + * @blue: a float value between 0.0f and 1.0f + * + * Sets the blue channel of @color to @blue. + * + * since: 1.4 + */ +void +cogl_color_set_blue_float (CoglColor *color, + float blue); + +/** + * cogl_color_set_alpha_float: + * @color: a #CoglColor + * @alpha: a float value between 0.0f and 1.0f + * + * Sets the alpha channel of @color to @alpha. + * + * since: 1.4 + */ +void +cogl_color_set_alpha_float (CoglColor *color, + float alpha); + +/** + * cogl_color_set_red: + * @color: a #CoglColor + * @red: a float value between 0.0f and 1.0f + * + * Sets the red channel of @color to @red. + * + * Since: 1.4 + */ +void +cogl_color_set_red (CoglColor *color, + float red); + +/** + * cogl_color_set_green: + * @color: a #CoglColor + * @green: a float value between 0.0f and 1.0f + * + * Sets the green channel of @color to @green. + * + * Since: 1.4 + */ +void +cogl_color_set_green (CoglColor *color, + float green); + +/** + * cogl_color_set_blue: + * @color: a #CoglColor + * @blue: a float value between 0.0f and 1.0f + * + * Sets the blue channel of @color to @blue. + * + * Since: 1.4 + */ +void +cogl_color_set_blue (CoglColor *color, + float blue); + +/** + * cogl_color_set_alpha: + * @color: a #CoglColor + * @alpha: a float value between 0.0f and 1.0f + * + * Sets the alpha channel of @color to @alpha. + * + * Since: 1.4 + */ +void +cogl_color_set_alpha (CoglColor *color, + float alpha); + +/** * cogl_color_premultiply: * @color: the color to premultiply * diff --git a/doc/reference/cogl/cogl-sections.txt b/doc/reference/cogl/cogl-sections.txt index f23a7b1..6a4b7e4 100644 --- a/doc/reference/cogl/cogl-sections.txt +++ b/doc/reference/cogl/cogl-sections.txt @@ -383,6 +383,24 @@ cogl_color_get_blue_float cogl_color_get_alpha_float +cogl_color_set_red +cogl_color_set_green +cogl_color_set_blue +cogl_color_set_alpha + + +cogl_color_set_red_byte +cogl_color_set_green_byte +cogl_color_set_blue_byte +cogl_color_set_alpha_byte + + +cogl_color_set_red_float +cogl_color_set_green_float +cogl_color_set_blue_float +cogl_color_set_alpha_float + + cogl_color_premultiply cogl_color_unpremultiply cogl_color_equal -- 2.7.4