theme: Port from GdkColor to GdkRGBA

GdkColor is about to be deprecated, so move to GdkRGBA instead.

https://bugzilla.gnome.org/show_bug.cgi?id=650586
This commit is contained in:
Florian Müllner 2011-05-17 20:50:40 +02:00
parent 8199699e7c
commit ce1369609f
3 changed files with 57 additions and 90 deletions

View File

@ -2612,7 +2612,7 @@ meta_frames_set_window_background (MetaFrames *frames,
if (frame_exists && style->window_background_color != NULL) if (frame_exists && style->window_background_color != NULL)
{ {
GdkColor color; GdkRGBA color;
GdkVisual *visual; GdkVisual *visual;
meta_color_spec_render (style->window_background_color, meta_color_spec_render (style->window_background_color,
@ -2624,11 +2624,10 @@ meta_frames_set_window_background (MetaFrames *frames,
visual = gtk_widget_get_visual (GTK_WIDGET (frames)); visual = gtk_widget_get_visual (GTK_WIDGET (frames));
if (gdk_visual_get_depth (visual) == 32) /* we have ARGB */ if (gdk_visual_get_depth (visual) == 32) /* we have ARGB */
{ {
color.pixel = (color.pixel & 0xffffff) & color.alpha = style->window_background_alpha / 255.0;
style->window_background_alpha << 24;
} }
gdk_window_set_background (frame->window, &color); gdk_window_set_background_rgba (frame->window, &color);
} }
else else
{ {

View File

@ -304,7 +304,7 @@ struct _MetaColorSpec
union union
{ {
struct { struct {
GdkColor color; GdkRGBA color;
} basic; } basic;
struct { struct {
MetaGtkColorComponent component; MetaGtkColorComponent component;
@ -315,13 +315,13 @@ struct _MetaColorSpec
MetaColorSpec *background; MetaColorSpec *background;
double alpha; double alpha;
GdkColor color; GdkRGBA color;
} blend; } blend;
struct { struct {
MetaColorSpec *base; MetaColorSpec *base;
double factor; double factor;
GdkColor color; GdkRGBA color;
} shade; } shade;
} data; } data;
}; };
@ -962,7 +962,7 @@ MetaColorSpec* meta_color_spec_new_gtk (MetaGtkColorComponent component,
void meta_color_spec_free (MetaColorSpec *spec); void meta_color_spec_free (MetaColorSpec *spec);
void meta_color_spec_render (MetaColorSpec *spec, void meta_color_spec_render (MetaColorSpec *spec,
GtkStyleContext *style_gtk, GtkStyleContext *style_gtk,
GdkColor *color); GdkRGBA *color);
MetaDrawOp* meta_draw_op_new (MetaDrawType type); MetaDrawOp* meta_draw_op_new (MetaDrawType type);

View File

@ -63,14 +63,14 @@
#define GDK_COLOR_RGBA(color) \ #define GDK_COLOR_RGBA(color) \
((guint32) (0xff | \ ((guint32) (0xff | \
(((color).red / 256) << 24) | \ ((int)((color).red * 255) << 24) | \
(((color).green / 256) << 16) | \ ((int)((color).green * 255) << 16) | \
(((color).blue / 256) << 8))) ((int)((color).blue * 255) << 8)))
#define GDK_COLOR_RGB(color) \ #define GDK_COLOR_RGB(color) \
((guint32) ((((color).red / 256) << 16) | \ ((guint32) (((int)((color).red * 255) << 16) | \
(((color).green / 256) << 8) | \ ((int)((color).green * 255) << 8) | \
(((color).blue / 256)))) ((int)((color).blue * 255))))
#define ALPHA_TO_UCHAR(d) ((unsigned char) ((d) * 255)) #define ALPHA_TO_UCHAR(d) ((unsigned char) ((d) * 255))
@ -78,8 +78,8 @@
#define CLAMP_UCHAR(v) ((guchar) (CLAMP (((int)v), (int)0, (int)255))) #define CLAMP_UCHAR(v) ((guchar) (CLAMP (((int)v), (int)0, (int)255)))
#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
static void gtk_style_shade (GdkColor *a, static void gtk_style_shade (GdkRGBA *a,
GdkColor *b, GdkRGBA *b,
gdouble k); gdouble k);
static void rgb_to_hls (gdouble *r, static void rgb_to_hls (gdouble *r,
gdouble *g, gdouble *g,
@ -95,7 +95,7 @@ static MetaTheme *meta_current_theme = NULL;
static GdkPixbuf * static GdkPixbuf *
colorize_pixbuf (GdkPixbuf *orig, colorize_pixbuf (GdkPixbuf *orig,
GdkColor *new_color) GdkRGBA *new_color)
{ {
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
double intensity; double intensity;
@ -138,16 +138,16 @@ colorize_pixbuf (GdkPixbuf *orig,
if (intensity <= 0.5) if (intensity <= 0.5)
{ {
/* Go from black at intensity = 0.0 to new_color at intensity = 0.5 */ /* Go from black at intensity = 0.0 to new_color at intensity = 0.5 */
dr = (new_color->red * intensity * 2.0) / 65535.0; dr = new_color->red * intensity * 2.0;
dg = (new_color->green * intensity * 2.0) / 65535.0; dg = new_color->green * intensity * 2.0;
db = (new_color->blue * intensity * 2.0) / 65535.0; db = new_color->blue * intensity * 2.0;
} }
else else
{ {
/* Go from new_color at intensity = 0.5 to white at intensity = 1.0 */ /* Go from new_color at intensity = 0.5 to white at intensity = 1.0 */
dr = (new_color->red + (65535 - new_color->red) * (intensity - 0.5) * 2.0) / 65535.0; dr = new_color->red + (1.0 - new_color->red) * (intensity - 0.5) * 2.0;
dg = (new_color->green + (65535 - new_color->green) * (intensity - 0.5) * 2.0) / 65535.0; dg = new_color->green + (1.0 - new_color->green) * (intensity - 0.5) * 2.0;
db = (new_color->blue + (65535 - new_color->blue) * (intensity - 0.5) * 2.0) / 65535.0; db = new_color->blue + (1.0 - new_color->blue) * (intensity - 0.5) * 2.0;
} }
dest[0] = CLAMP_UCHAR (255 * dr); dest[0] = CLAMP_UCHAR (255 * dr);
@ -172,18 +172,15 @@ colorize_pixbuf (GdkPixbuf *orig,
} }
static void static void
color_composite (const GdkColor *bg, color_composite (const GdkRGBA *bg,
const GdkColor *fg, const GdkRGBA *fg,
double alpha_d, double alpha,
GdkColor *color) GdkRGBA *color)
{ {
guint16 alpha;
*color = *bg; *color = *bg;
alpha = alpha_d * 0xffff; color->red = color->red + (fg->red - color->red) * alpha;
color->red = color->red + (((fg->red - color->red) * alpha + 0x8000) >> 16); color->green = color->green + (fg->green - color->green) * alpha;
color->green = color->green + (((fg->green - color->green) * alpha + 0x8000) >> 16); color->blue = color->blue + (fg->blue - color->blue) * alpha;
color->blue = color->blue + (((fg->blue - color->blue) * alpha + 0x8000) >> 16);
} }
/** /**
@ -1036,12 +1033,7 @@ meta_gradient_spec_render (const MetaGradientSpec *spec,
tmp = spec->color_specs; tmp = spec->color_specs;
while (tmp != NULL) while (tmp != NULL)
{ {
GdkColor gdk_color; meta_color_spec_render (tmp->data, style, &colors[i]);
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; tmp = tmp->next;
++i; ++i;
@ -1386,7 +1378,7 @@ meta_color_spec_new_from_string (const char *str,
{ {
spec = meta_color_spec_new (META_COLOR_SPEC_BASIC); spec = meta_color_spec_new (META_COLOR_SPEC_BASIC);
if (!gdk_color_parse (str, &spec->data.basic.color)) if (!gdk_rgba_parse (&spec->data.basic.color, str))
{ {
g_set_error (err, META_THEME_ERROR, g_set_error (err, META_THEME_ERROR,
META_THEME_ERROR_FAILED, META_THEME_ERROR_FAILED,
@ -1424,12 +1416,11 @@ meta_color_spec_new_gtk (MetaGtkColorComponent component,
#define LIGHTNESS_MULT 1.3 #define LIGHTNESS_MULT 1.3
#define DARKNESS_MULT 0.7 #define DARKNESS_MULT 0.7
static void static void
meta_set_color_from_style (GdkColor *color, meta_set_color_from_style (GdkRGBA *color,
GtkStyleContext *context, GtkStyleContext *context,
GtkStateType state, GtkStateType state,
MetaGtkColorComponent component) MetaGtkColorComponent component)
{ {
GdkRGBA *rgba_color = NULL;
GtkStateFlags flags; GtkStateFlags flags;
switch (state) switch (state)
@ -1457,48 +1448,25 @@ meta_set_color_from_style (GdkColor *color,
case META_GTK_COLOR_MID: case META_GTK_COLOR_MID:
case META_GTK_COLOR_LIGHT: case META_GTK_COLOR_LIGHT:
case META_GTK_COLOR_DARK: case META_GTK_COLOR_DARK:
gtk_style_context_get (context, flags, gtk_style_context_get_background_color (context, flags, color);
"background-color", &rgba_color,
NULL);
break; break;
case META_GTK_COLOR_FG: case META_GTK_COLOR_FG:
case META_GTK_COLOR_TEXT: case META_GTK_COLOR_TEXT:
case META_GTK_COLOR_TEXT_AA: case META_GTK_COLOR_TEXT_AA:
gtk_style_context_get (context, flags, gtk_style_context_get_color (context, flags, color);
"color", &rgba_color,
NULL);
break; break;
case META_GTK_COLOR_LAST: case META_GTK_COLOR_LAST:
g_assert_not_reached (); g_assert_not_reached ();
break; break;
} }
if (rgba_color)
{
color->pixel = 0;
color->red = CLAMP ((guint) (rgba_color->red * 65535), 0, 65535);
color->green = CLAMP ((guint) (rgba_color->green * 65535), 0, 65535);
color->blue = CLAMP ((guint) (rgba_color->blue * 65535), 0, 65535);
gdk_rgba_free (rgba_color);
}
else
{
meta_warning (_("Failed to retrieve color %s[%s] from GTK+ theme.\n"),
meta_color_component_to_string (component),
meta_gtk_state_to_string (state));
color->pixel = 0;
color->red = component == META_GTK_COLOR_TEXT ? 0 : 65535;
color->green = 0;
color->blue = component == META_GTK_COLOR_TEXT ? 0 : 65535;
}
if (component == META_GTK_COLOR_LIGHT) if (component == META_GTK_COLOR_LIGHT)
gtk_style_shade (color, color, LIGHTNESS_MULT); gtk_style_shade (color, color, LIGHTNESS_MULT);
else if (component == META_GTK_COLOR_DARK) else if (component == META_GTK_COLOR_DARK)
gtk_style_shade (color, color, DARKNESS_MULT); gtk_style_shade (color, color, DARKNESS_MULT);
else if (component == META_GTK_COLOR_MID) else if (component == META_GTK_COLOR_MID)
{ {
GdkColor light, dark; GdkRGBA light, dark;
gtk_style_shade (color, &light, LIGHTNESS_MULT); gtk_style_shade (color, &light, LIGHTNESS_MULT);
gtk_style_shade (color, &dark, DARKNESS_MULT); gtk_style_shade (color, &dark, DARKNESS_MULT);
@ -1509,7 +1477,7 @@ meta_set_color_from_style (GdkColor *color,
} }
else if (component == META_GTK_COLOR_TEXT_AA) else if (component == META_GTK_COLOR_TEXT_AA)
{ {
GdkColor base; GdkRGBA base;
meta_set_color_from_style (&base, context, state, META_GTK_COLOR_BASE); meta_set_color_from_style (&base, context, state, META_GTK_COLOR_BASE);
color->red = (color->red + base.red) / 2; color->red = (color->red + base.red) / 2;
@ -1521,7 +1489,7 @@ meta_set_color_from_style (GdkColor *color,
void void
meta_color_spec_render (MetaColorSpec *spec, meta_color_spec_render (MetaColorSpec *spec,
GtkStyleContext *context, GtkStyleContext *context,
GdkColor *color) GdkRGBA *color)
{ {
g_return_if_fail (spec != NULL); g_return_if_fail (spec != NULL);
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
@ -1541,7 +1509,7 @@ meta_color_spec_render (MetaColorSpec *spec,
case META_COLOR_SPEC_BLEND: case META_COLOR_SPEC_BLEND:
{ {
GdkColor bg, fg; GdkRGBA bg, fg;
meta_color_spec_render (spec->data.blend.background, context, &bg); meta_color_spec_render (spec->data.blend.background, context, &bg);
meta_color_spec_render (spec->data.blend.foreground, context, &fg); meta_color_spec_render (spec->data.blend.foreground, context, &fg);
@ -3348,7 +3316,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
case META_DRAW_RECTANGLE: case META_DRAW_RECTANGLE:
if (op->data.rectangle.filled) if (op->data.rectangle.filled)
{ {
GdkColor color; GdkRGBA color;
meta_color_spec_render (op->data.rectangle.color_spec, meta_color_spec_render (op->data.rectangle.color_spec,
context, context,
@ -3370,7 +3338,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
case META_DRAW_TINT: case META_DRAW_TINT:
{ {
GdkColor color; GdkRGBA color;
guint32 rgba; guint32 rgba;
gboolean has_alpha; gboolean has_alpha;
@ -3431,7 +3399,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
{ {
if (op->data.image.colorize_spec) if (op->data.image.colorize_spec)
{ {
GdkColor color; GdkRGBA color;
meta_color_spec_render (op->data.image.colorize_spec, meta_color_spec_render (op->data.image.colorize_spec,
context, &color); context, &color);
@ -3590,7 +3558,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
MetaRectangle rect, MetaRectangle rect,
MetaPositionExprEnv *env) MetaPositionExprEnv *env)
{ {
GdkColor color; GdkRGBA color;
cairo_save (cr); cairo_save (cr);
gtk_style_context_save (style_gtk); gtk_style_context_save (style_gtk);
@ -3604,7 +3572,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
int x1, x2, y1, y2; int x1, x2, y1, y2;
meta_color_spec_render (op->data.line.color_spec, style_gtk, &color); meta_color_spec_render (op->data.line.color_spec, style_gtk, &color);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_rgba (cr, &color);
if (op->data.line.width > 0) if (op->data.line.width > 0)
cairo_set_line_width (cr, op->data.line.width); cairo_set_line_width (cr, op->data.line.width);
@ -3680,7 +3648,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
meta_color_spec_render (op->data.rectangle.color_spec, meta_color_spec_render (op->data.rectangle.color_spec,
style_gtk, &color); style_gtk, &color);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_rgba (cr, &color);
rx = parse_x_position_unchecked (op->data.rectangle.x, env); rx = parse_x_position_unchecked (op->data.rectangle.x, env);
ry = parse_y_position_unchecked (op->data.rectangle.y, env); ry = parse_y_position_unchecked (op->data.rectangle.y, env);
@ -3710,7 +3678,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
double center_x, center_y; double center_x, center_y;
meta_color_spec_render (op->data.arc.color_spec, style_gtk, &color); meta_color_spec_render (op->data.arc.color_spec, style_gtk, &color);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_rgba (cr, &color);
rx = parse_x_position_unchecked (op->data.arc.x, env); rx = parse_x_position_unchecked (op->data.arc.x, env);
ry = parse_y_position_unchecked (op->data.arc.y, env); ry = parse_y_position_unchecked (op->data.arc.y, env);
@ -3766,7 +3734,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
{ {
meta_color_spec_render (op->data.tint.color_spec, meta_color_spec_render (op->data.tint.color_spec,
style_gtk, &color); style_gtk, &color);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_rgba (cr, &color);
cairo_rectangle (cr, rx, ry, rwidth, rheight); cairo_rectangle (cr, rx, ry, rwidth, rheight);
cairo_fill (cr); cairo_fill (cr);
@ -3940,7 +3908,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
meta_color_spec_render (op->data.title.color_spec, meta_color_spec_render (op->data.title.color_spec,
style_gtk, &color); style_gtk, &color);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_rgba (cr, &color);
rx = parse_x_position_unchecked (op->data.title.x, env); rx = parse_x_position_unchecked (op->data.title.x, env);
ry = parse_y_position_unchecked (op->data.title.y, env); ry = parse_y_position_unchecked (op->data.title.y, env);
@ -6557,17 +6525,17 @@ meta_image_fill_type_to_string (MetaImageFillType fill_type)
* \param k amount to scale lightness and saturation by * \param k amount to scale lightness and saturation by
*/ */
static void static void
gtk_style_shade (GdkColor *a, gtk_style_shade (GdkRGBA *a,
GdkColor *b, GdkRGBA *b,
gdouble k) gdouble k)
{ {
gdouble red; gdouble red;
gdouble green; gdouble green;
gdouble blue; gdouble blue;
red = (gdouble) a->red / 65535.0; red = a->red;
green = (gdouble) a->green / 65535.0; green = a->green;
blue = (gdouble) a->blue / 65535.0; blue = a->blue;
rgb_to_hls (&red, &green, &blue); rgb_to_hls (&red, &green, &blue);
@ -6585,9 +6553,9 @@ gtk_style_shade (GdkColor *a,
hls_to_rgb (&red, &green, &blue); hls_to_rgb (&red, &green, &blue);
b->red = red * 65535.0; b->red = red;
b->green = green * 65535.0; b->green = green;
b->blue = blue * 65535.0; b->blue = blue;
} }
/** /**
@ -6774,7 +6742,7 @@ draw_bg_solid_composite (const MetaTextureSpec *bg,
int width, int width,
int height) int height)
{ {
GdkColor bg_color; GdkRGBA bg_color;
g_assert (bg->type == META_TEXTURE_SOLID); g_assert (bg->type == META_TEXTURE_SOLID);
g_assert (fg->type != META_TEXTURE_COMPOSITE); g_assert (fg->type != META_TEXTURE_COMPOSITE);
@ -6788,7 +6756,7 @@ draw_bg_solid_composite (const MetaTextureSpec *bg,
{ {
case META_TEXTURE_SOLID: case META_TEXTURE_SOLID:
{ {
GdkColor fg_color; GdkRGBA fg_color;
meta_color_spec_render (fg->data.solid.color_spec, meta_color_spec_render (fg->data.solid.color_spec,
widget, widget,