[mutter] gradient: Port from GdkColor to GdkRGBA
- From: Florian MÃllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] gradient: Port from GdkColor to GdkRGBA
- Date: Fri, 8 Jul 2011 19:41:39 +0000 (UTC)
commit 8199699e7c1e9fa72bd4775db7ada08da44deb1a
Author: Florian MÃllner <fmuellner gnome org>
Date: Thu May 12 16:47:45 2011 +0200
gradient: Port from GdkColor to GdkRGBA
GdkColor is about to be deprecated, so move to GdkRGBA instead.
It might be worth considering using cairo patterns for the gradients
rather than using custom code to render gradients to a pixbuf which
is then drawn with cairo, but for now this is just a straight port
of the existing code.
https://bugzilla.gnome.org/show_bug.cgi?id=650586
src/meta/gradient.h | 10 ++--
src/ui/gradient.c | 130 ++++++++++++++++++++++++------------------------
src/ui/testgradient.c | 50 ++++++++++---------
src/ui/theme.c | 11 +++-
4 files changed, 104 insertions(+), 97 deletions(-)
---
diff --git a/src/meta/gradient.h b/src/meta/gradient.h
index c8e7049..5e9db8a 100644
--- a/src/meta/gradient.h
+++ b/src/meta/gradient.h
@@ -37,19 +37,19 @@ typedef enum
GdkPixbuf* meta_gradient_create_simple (int width,
int height,
- const GdkColor *from,
- const GdkColor *to,
+ const GdkRGBA *from,
+ const GdkRGBA *to,
MetaGradientType style);
GdkPixbuf* meta_gradient_create_multi (int width,
int height,
- const GdkColor *colors,
+ const GdkRGBA *colors,
int n_colors,
MetaGradientType style);
GdkPixbuf* meta_gradient_create_interwoven (int width,
int height,
- const GdkColor colors1[2],
+ const GdkRGBA colors1[2],
int thickness1,
- const GdkColor colors2[2],
+ const GdkRGBA colors2[2],
int thickness2);
diff --git a/src/ui/gradient.c b/src/ui/gradient.c
index ef1f061..21ae422 100644
--- a/src/ui/gradient.c
+++ b/src/ui/gradient.c
@@ -31,27 +31,27 @@
*/
static GdkPixbuf* meta_gradient_create_horizontal (int width,
int height,
- const GdkColor *from,
- const GdkColor *to);
+ const GdkRGBA *from,
+ const GdkRGBA *to);
static GdkPixbuf* meta_gradient_create_vertical (int width,
int height,
- const GdkColor *from,
- const GdkColor *to);
+ const GdkRGBA *from,
+ const GdkRGBA *to);
static GdkPixbuf* meta_gradient_create_diagonal (int width,
int height,
- const GdkColor *from,
- const GdkColor *to);
+ const GdkRGBA *from,
+ const GdkRGBA *to);
static GdkPixbuf* meta_gradient_create_multi_horizontal (int width,
int height,
- const GdkColor *colors,
+ const GdkRGBA *colors,
int count);
static GdkPixbuf* meta_gradient_create_multi_vertical (int width,
int height,
- const GdkColor *colors,
+ const GdkRGBA *colors,
int count);
static GdkPixbuf* meta_gradient_create_multi_diagonal (int width,
int height,
- const GdkColor *colors,
+ const GdkRGBA *colors,
int count);
@@ -100,8 +100,8 @@ blank_pixbuf (int width, int height, gboolean no_padding)
GdkPixbuf*
meta_gradient_create_simple (int width,
int height,
- const GdkColor *from,
- const GdkColor *to,
+ const GdkRGBA *from,
+ const GdkRGBA *to,
MetaGradientType style)
{
switch (style)
@@ -136,7 +136,7 @@ meta_gradient_create_simple (int width,
GdkPixbuf*
meta_gradient_create_multi (int width,
int height,
- const GdkColor *colors,
+ const GdkRGBA *colors,
int n_colors,
MetaGradientType style)
{
@@ -181,9 +181,9 @@ meta_gradient_create_multi (int width,
GdkPixbuf*
meta_gradient_create_interwoven (int width,
int height,
- const GdkColor colors1[2],
+ const GdkRGBA colors1[2],
int thickness1,
- const GdkColor colors2[2],
+ const GdkRGBA colors2[2],
int thickness2)
{
@@ -202,21 +202,21 @@ meta_gradient_create_interwoven (int width,
pixels = gdk_pixbuf_get_pixels (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
- r1 = colors1[0].red<<8;
- g1 = colors1[0].green<<8;
- b1 = colors1[0].blue<<8;
+ r1 = (long)(colors1[0].red*0xffffff);
+ g1 = (long)(colors1[0].green*0xffffff);
+ b1 = (long)(colors1[0].blue*0xffffff);
- r2 = colors2[0].red<<8;
- g2 = colors2[0].green<<8;
- b2 = colors2[0].blue<<8;
+ r2 = (long)(colors2[0].red*0xffffff);
+ g2 = (long)(colors2[0].green*0xffffff);
+ b2 = (long)(colors2[0].blue*0xffffff);
- dr1 = ((colors1[1].red-colors1[0].red)<<8)/(int)height;
- dg1 = ((colors1[1].green-colors1[0].green)<<8)/(int)height;
- db1 = ((colors1[1].blue-colors1[0].blue)<<8)/(int)height;
+ dr1 = ((colors1[1].red-colors1[0].red)*0xffffff)/(int)height;
+ dg1 = ((colors1[1].green-colors1[0].green)*0xffffff)/(int)height;
+ db1 = ((colors1[1].blue-colors1[0].blue)*0xffffff)/(int)height;
- dr2 = ((colors2[1].red-colors2[0].red)<<8)/(int)height;
- dg2 = ((colors2[1].green-colors2[0].green)<<8)/(int)height;
- db2 = ((colors2[1].blue-colors2[0].blue)<<8)/(int)height;
+ dr2 = ((colors2[1].red-colors2[0].red)*0xffffff)/(int)height;
+ dg2 = ((colors2[1].green-colors2[0].green)*0xffffff)/(int)height;
+ db2 = ((colors2[1].blue-colors2[0].blue)*0xffffff)/(int)height;
for (i=0,k=0,l=0,ll=thickness1; i<height; i++)
{
@@ -280,8 +280,8 @@ meta_gradient_create_interwoven (int width,
*/
static GdkPixbuf*
meta_gradient_create_horizontal (int width, int height,
- const GdkColor *from,
- const GdkColor *to)
+ const GdkRGBA *from,
+ const GdkRGBA *to)
{
int i;
long r, g, b, dr, dg, db;
@@ -300,12 +300,12 @@ meta_gradient_create_horizontal (int width, int height,
ptr = pixels;
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
- r0 = (guchar) (from->red / 256.0);
- g0 = (guchar) (from->green / 256.0);
- b0 = (guchar) (from->blue / 256.0);
- rf = (guchar) (to->red / 256.0);
- gf = (guchar) (to->green / 256.0);
- bf = (guchar) (to->blue / 256.0);
+ r0 = (guchar) (from->red * 0xff);
+ g0 = (guchar) (from->green * 0xff);
+ b0 = (guchar) (from->blue * 0xff);
+ rf = (guchar) (to->red * 0xff);
+ gf = (guchar) (to->green * 0xff);
+ bf = (guchar) (to->blue * 0xff);
r = r0 << 16;
g = g0 << 16;
@@ -348,8 +348,8 @@ meta_gradient_create_horizontal (int width, int height,
*/
static GdkPixbuf*
meta_gradient_create_vertical (int width, int height,
- const GdkColor *from,
- const GdkColor *to)
+ const GdkRGBA *from,
+ const GdkRGBA *to)
{
int i, j;
long r, g, b, dr, dg, db;
@@ -367,12 +367,12 @@ meta_gradient_create_vertical (int width, int height,
pixels = gdk_pixbuf_get_pixels (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
- r0 = (guchar) (from->red / 256.0);
- g0 = (guchar) (from->green / 256.0);
- b0 = (guchar) (from->blue / 256.0);
- rf = (guchar) (to->red / 256.0);
- gf = (guchar) (to->green / 256.0);
- bf = (guchar) (to->blue / 256.0);
+ r0 = (guchar) (from->red * 0xff);
+ g0 = (guchar) (from->green * 0xff);
+ b0 = (guchar) (from->blue * 0xff);
+ rf = (guchar) (to->red * 0xff);
+ gf = (guchar) (to->green * 0xff);
+ bf = (guchar) (to->blue * 0xff);
r = r0<<16;
g = g0<<16;
@@ -419,8 +419,8 @@ meta_gradient_create_vertical (int width, int height,
static GdkPixbuf*
meta_gradient_create_diagonal (int width, int height,
- const GdkColor *from,
- const GdkColor *to)
+ const GdkRGBA *from,
+ const GdkRGBA *to)
{
GdkPixbuf *pixbuf, *tmp;
int j;
@@ -467,7 +467,7 @@ meta_gradient_create_diagonal (int width, int height,
static GdkPixbuf*
meta_gradient_create_multi_horizontal (int width, int height,
- const GdkColor *colors,
+ const GdkRGBA *colors,
int count)
{
int i, j, k;
@@ -498,16 +498,16 @@ meta_gradient_create_multi_horizontal (int width, int height,
k = 0;
- r = colors[0].red << 8;
- g = colors[0].green << 8;
- b = colors[0].blue << 8;
+ r = (long)(colors[0].red * 0xffffff);
+ g = (long)(colors[0].green * 0xffffff);
+ b = (long)(colors[0].blue * 0xffffff);
/* render the first line */
for (i=1; i<count; i++)
{
- dr = ((int)(colors[i].red - colors[i-1].red) <<8)/(int)width2;
- dg = ((int)(colors[i].green - colors[i-1].green)<<8)/(int)width2;
- db = ((int)(colors[i].blue - colors[i-1].blue) <<8)/(int)width2;
+ dr = (int)((colors[i].red - colors[i-1].red) *0xffffff)/(int)width2;
+ dg = (int)((colors[i].green - colors[i-1].green)*0xffffff)/(int)width2;
+ db = (int)((colors[i].blue - colors[i-1].blue) *0xffffff)/(int)width2;
for (j=0; j<width2; j++)
{
*ptr++ = (unsigned char)(r>>16);
@@ -518,9 +518,9 @@ meta_gradient_create_multi_horizontal (int width, int height,
b += db;
k++;
}
- r = colors[i].red << 8;
- g = colors[i].green << 8;
- b = colors[i].blue << 8;
+ r = (long)(colors[i].red * 0xffffff);
+ g = (long)(colors[i].green * 0xffffff);
+ b = (long)(colors[i].blue * 0xffffff);
}
for (j=k; j<width; j++)
{
@@ -539,7 +539,7 @@ meta_gradient_create_multi_horizontal (int width, int height,
static GdkPixbuf*
meta_gradient_create_multi_vertical (int width, int height,
- const GdkColor *colors,
+ const GdkRGBA *colors,
int count)
{
int i, j, k;
@@ -570,15 +570,15 @@ meta_gradient_create_multi_vertical (int width, int height,
k = 0;
- r = colors[0].red << 8;
- g = colors[0].green << 8;
- b = colors[0].blue << 8;
+ r = (long)(colors[0].red * 0xffffff);
+ g = (long)(colors[0].green * 0xffffff);
+ b = (long)(colors[0].blue * 0xffffff);
for (i=1; i<count; i++)
{
- dr = ((int)(colors[i].red - colors[i-1].red) <<8)/(int)height2;
- dg = ((int)(colors[i].green - colors[i-1].green)<<8)/(int)height2;
- db = ((int)(colors[i].blue - colors[i-1].blue) <<8)/(int)height2;
+ dr = (int)((colors[i].red - colors[i-1].red) *0xffffff)/(int)height2;
+ dg = (int)((colors[i].green - colors[i-1].green)*0xffffff)/(int)height2;
+ db = (int)((colors[i].blue - colors[i-1].blue) *0xffffff)/(int)height2;
for (j=0; j<height2; j++)
{
@@ -597,9 +597,9 @@ meta_gradient_create_multi_vertical (int width, int height,
b += db;
k++;
}
- r = colors[i].red << 8;
- g = colors[i].green << 8;
- b = colors[i].blue << 8;
+ r = (long)(colors[i].red * 0xffffff);
+ g = (long)(colors[i].green * 0xffffff);
+ b = (long)(colors[i].blue * 0xffffff);
}
if (k<height)
@@ -629,7 +629,7 @@ meta_gradient_create_multi_vertical (int width, int height,
static GdkPixbuf*
meta_gradient_create_multi_diagonal (int width, int height,
- const GdkColor *colors,
+ const GdkRGBA *colors,
int count)
{
GdkPixbuf *pixbuf, *tmp;
diff --git a/src/ui/testgradient.c b/src/ui/testgradient.c
index 29c3acb..c66c9e5 100644
--- a/src/ui/testgradient.c
+++ b/src/ui/testgradient.c
@@ -33,18 +33,20 @@ draw_checkerboard (cairo_t *cr,
int height)
{
gint i, j, xcount, ycount;
- GdkColor color1, color2;
+ GdkRGBA color1, color2;
#define CHECK_SIZE 10
#define SPACING 2
- color1.red = 30000;
- color1.green = 30000;
- color1.blue = 30000;
+ color1.red = 30000. / 65535.;
+ color1.green = 30000. / 65535.;
+ color1.blue = 30000. / 65535.;
+ color1.alpha = 1.0;
- color2.red = 50000;
- color2.green = 50000;
- color2.blue = 50000;
+ color2.red = 50000. / 65535.;
+ color2.green = 50000. / 65535.;
+ color2.blue = 50000. / 65535.;
+ color2.alpha = 1.0;
xcount = 0;
i = SPACING;
@@ -55,9 +57,9 @@ draw_checkerboard (cairo_t *cr,
while (j < height)
{
if (ycount % 2)
- gdk_cairo_set_source_color (cr, &color1);
+ gdk_cairo_set_source_rgba (cr, &color1);
else
- gdk_cairo_set_source_color (cr, &color2);
+ gdk_cairo_set_source_rgba (cr, &color2);
/* If we're outside event->area, this will do nothing.
* It might be mildly more efficient if we handled
@@ -82,10 +84,10 @@ render_simple (cairo_t *cr,
gboolean with_alpha)
{
GdkPixbuf *pixbuf;
- GdkColor from, to;
+ GdkRGBA from, to;
- gdk_color_parse ("blue", &from);
- gdk_color_parse ("green", &to);
+ gdk_rgba_parse (&from, "blue");
+ gdk_rgba_parse (&to, "green");
pixbuf = meta_gradient_create_simple (width, height,
&from, &to,
@@ -153,13 +155,13 @@ render_multi (cairo_t *cr,
{
GdkPixbuf *pixbuf;
#define N_COLORS 5
- GdkColor colors[N_COLORS];
+ GdkRGBA colors[N_COLORS];
- gdk_color_parse ("red", &colors[0]);
- gdk_color_parse ("blue", &colors[1]);
- gdk_color_parse ("orange", &colors[2]);
- gdk_color_parse ("pink", &colors[3]);
- gdk_color_parse ("green", &colors[4]);
+ gdk_rgba_parse (&colors[0], "red");
+ gdk_rgba_parse (&colors[1], "blue");
+ gdk_rgba_parse (&colors[2], "orange");
+ gdk_rgba_parse (&colors[3], "pink");
+ gdk_rgba_parse (&colors[4], "green");
pixbuf = meta_gradient_create_multi (width, height,
colors, N_COLORS,
@@ -200,12 +202,12 @@ render_interwoven_func (cairo_t *cr,
{
GdkPixbuf *pixbuf;
#define N_COLORS 4
- GdkColor colors[N_COLORS];
+ GdkRGBA colors[N_COLORS];
- gdk_color_parse ("red", &colors[0]);
- gdk_color_parse ("blue", &colors[1]);
- gdk_color_parse ("pink", &colors[2]);
- gdk_color_parse ("green", &colors[3]);
+ gdk_rgba_parse (&colors[0], "red");
+ gdk_rgba_parse (&colors[1], "blue");
+ gdk_rgba_parse (&colors[2], "pink");
+ gdk_rgba_parse (&colors[3], "green");
pixbuf = meta_gradient_create_interwoven (width, height,
colors, height / 10,
@@ -234,7 +236,7 @@ draw_callback (GtkWidget *widget,
gtk_style_context_lookup_color (style, "foreground-color", &color);
gtk_style_context_restore (style);
- cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);
+ gdk_cairo_set_source_rgba (cr, &color);
(* func) (cr,
gtk_widget_get_allocated_width (widget),
diff --git a/src/ui/theme.c b/src/ui/theme.c
index 873f13b..86b2b29 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -1020,7 +1020,7 @@ meta_gradient_spec_render (const MetaGradientSpec *spec,
int height)
{
int n_colors;
- GdkColor *colors;
+ GdkRGBA *colors;
GSList *tmp;
int i;
GdkPixbuf *pixbuf;
@@ -1030,13 +1030,18 @@ meta_gradient_spec_render (const MetaGradientSpec *spec,
if (n_colors == 0)
return NULL;
- colors = g_new (GdkColor, n_colors);
+ colors = g_new (GdkRGBA, n_colors);
i = 0;
tmp = spec->color_specs;
while (tmp != NULL)
{
- meta_color_spec_render (tmp->data, style, &colors[i]);
+ GdkColor gdk_color;
+ meta_color_spec_render (tmp->data, style, &gdk_color);
+
+ colors[i].red = gdk_color.red / 65535.;
+ colors[i].green = gdk_color.green / 65535.;
+ colors[i].blue = gdk_color.blue / 65535.;
tmp = tmp->next;
++i;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]