Commit 4e02218f authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

Use GdkRGBA all around in GtkStyleContext.

parent 3a455ed8
......@@ -279,7 +279,7 @@
* <row>
* <entry>background-color</entry>
* <entry morerows="3"><programlisting>color</programlisting></entry>
* <entry morerows="3">#GdkColor</entry>
* <entry morerows="3">#GdkRGBA</entry>
* <entry morerows="3">
* <programlisting>
* background-color: &num;fff;
......@@ -1532,21 +1532,30 @@ symbolic_color_parse_str (const gchar *string,
str = (gchar *) string;
if (str[0] == '#')
if (str[0] == '#' || str[0] == 'r')
{
GdkColor color;
GdkRGBA color;
gchar *color_str;
const gchar *end;
end = str + 1;
while (g_ascii_isxdigit (*end))
end++;
if (str[0] == '#')
while (g_ascii_isxdigit (*end))
end++;
else
{
while (*end != ')' && *end != '\0')
end++;
if (*end == ')')
end++;
}
color_str = g_strndup (str, end - str);
*end_ptr = (gchar *) end;
if (!gdk_color_parse (color_str, &color))
if (!gdk_rgba_parse (&color, color_str))
{
g_free (color_str);
return NULL;
......@@ -2205,11 +2214,11 @@ css_provider_parse_value (GtkCssProvider *css_provider,
type = G_VALUE_TYPE (value);
if (type == GDK_TYPE_COLOR)
if (type == GDK_TYPE_RGBA)
{
GdkColor color;
GdkRGBA color;
if (gdk_color_parse (value_str, &color) == TRUE)
if (gdk_rgba_parse (&color, value_str) == TRUE)
g_value_set_boxed (value, &color);
else
{
......
......@@ -1278,7 +1278,7 @@ gtk_settings_get_style (GtkStyleProvider *provider,
{
GtkSymbolicColor *color;
gchar *name, *pos;
GdkColor col;
GdkRGBA col;
if (!*colors[i])
continue;
......@@ -1297,7 +1297,7 @@ gtk_settings_get_style (GtkStyleProvider *provider,
while (*pos == ' ')
pos++;
if (!*pos || !gdk_color_parse (pos, &col))
if (!*pos || !gdk_rgba_parse (&col, pos))
continue;
color = gtk_symbolic_color_new_literal (&col);
......
......@@ -642,7 +642,8 @@ set_color (GtkStyle *style,
GtkStateType state,
GtkRcFlags prop)
{
GdkColor *color = NULL;
GdkRGBA *color = NULL;
GdkColor *dest = { 0 }; /* Shut up gcc */
switch (prop)
{
......@@ -650,34 +651,36 @@ set_color (GtkStyle *style,
gtk_style_context_get (context, state,
"background-color", &color,
NULL);
if (color)
style->bg[state] = *color;
dest = &style->bg[state];
break;
case GTK_RC_FG:
gtk_style_context_get (context, state,
"foreground-color", &color,
NULL);
if (color)
style->fg[state] = *color;
dest = &style->fg[state];
break;
case GTK_RC_TEXT:
gtk_style_context_get (context, state,
"text-color", &color,
NULL);
if (color)
style->text[state] = *color;
dest = &style->text[state];
break;
case GTK_RC_BASE:
gtk_style_context_get (context, state,
"base-color", &color,
NULL);
if (color)
style->base[state] = *color;
dest = &style->base[state];
break;
}
if (color)
gdk_color_free (color);
{
dest->pixel = 0;
dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
gdk_rgba_free (color);
}
}
static void
......@@ -973,6 +976,8 @@ gtk_style_lookup_color (GtkStyle *style,
GdkColor *color)
{
GtkStylePrivate *priv;
gboolean result;
GdkRGBA rgba;
g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
g_return_val_if_fail (color_name != NULL, FALSE);
......@@ -983,7 +988,17 @@ gtk_style_lookup_color (GtkStyle *style,
if (!priv->context)
return FALSE;
return gtk_style_context_lookup_color (priv->context, color_name, color);
result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
if (color)
{
color->red = (guint16) (rgba.red * 65535);
color->green = (guint16) (rgba.green * 65535);
color->blue = (guint16) (rgba.blue * 65535);
color->pixel = 0;
}
return result;
}
/**
......
......@@ -2376,7 +2376,7 @@ gtk_style_context_get_junction_sides (GtkStyleContext *context)
gboolean
gtk_style_context_lookup_color (GtkStyleContext *context,
const gchar *color_name,
GdkColor *color)
GdkRGBA *color)
{
GtkStyleContextPrivate *priv;
GtkSymbolicColor *sym_color;
......
......@@ -137,7 +137,7 @@ GtkJunctionSides gtk_style_context_get_junction_sides (GtkStyleContext *context
gboolean gtk_style_context_lookup_color (GtkStyleContext *context,
const gchar *color_name,
GdkColor *color);
GdkRGBA *color);
void gtk_style_context_notify_state_change (GtkStyleContext *context,
GdkWindow *window,
......
......@@ -81,10 +81,10 @@ gtk_style_set_class_init (GtkStyleSetClass *klass)
object_class->finalize = gtk_style_set_finalize;
/* Initialize default property set */
gtk_style_set_register_property ("foreground-color", GDK_TYPE_COLOR, NULL, NULL);
gtk_style_set_register_property ("background-color", GDK_TYPE_COLOR, NULL, NULL);
gtk_style_set_register_property ("text-color", GDK_TYPE_COLOR, NULL, NULL);
gtk_style_set_register_property ("base-color", GDK_TYPE_COLOR, NULL, NULL);
gtk_style_set_register_property ("foreground-color", GDK_TYPE_RGBA, NULL, NULL);
gtk_style_set_register_property ("background-color", GDK_TYPE_RGBA, NULL, NULL);
gtk_style_set_register_property ("text-color", GDK_TYPE_RGBA, NULL, NULL);
gtk_style_set_register_property ("base-color", GDK_TYPE_RGBA, NULL, NULL);
gtk_style_set_register_property ("font", PANGO_TYPE_FONT_DESCRIPTION, NULL, NULL);
......@@ -94,7 +94,7 @@ gtk_style_set_class_init (GtkStyleSetClass *klass)
gtk_style_set_register_property ("border-width", G_TYPE_INT, NULL, NULL);
gtk_style_set_register_property ("border-radius", G_TYPE_INT, NULL, NULL);
gtk_style_set_register_property ("border-style", GTK_TYPE_BORDER_STYLE, NULL, NULL);
gtk_style_set_register_property ("border-color", GDK_TYPE_COLOR, NULL, NULL);
gtk_style_set_register_property ("border-color", GDK_TYPE_RGBA, NULL, NULL);
gtk_style_set_register_property ("background-image", CAIRO_GOBJECT_TYPE_PATTERN, NULL, NULL);
gtk_style_set_register_property ("border-image", GTK_TYPE_9SLICE, NULL, NULL);
......@@ -572,10 +572,10 @@ gtk_style_set_set_property (GtkStyleSet *set,
return;
}
if (node->property_type == GDK_TYPE_COLOR)
if (node->property_type == GDK_TYPE_RGBA)
{
/* Allow GtkSymbolicColor as well */
g_return_if_fail (value_type == GDK_TYPE_COLOR || value_type == GTK_TYPE_SYMBOLIC_COLOR);
g_return_if_fail (value_type == GDK_TYPE_RGBA || value_type == GTK_TYPE_SYMBOLIC_COLOR);
}
else if (node->property_type == CAIRO_GOBJECT_TYPE_PATTERN)
{
......@@ -710,15 +710,15 @@ static gboolean
resolve_color (GtkStyleSet *set,
GValue *value)
{
GdkColor color;
GdkRGBA color;
/* Resolve symbolic color to GdkColor */
/* Resolve symbolic color to GdkRGBA */
if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), set, &color))
return FALSE;
/* Store it back, this is where GdkColor caching happens */
/* Store it back, this is where GdkRGBA caching happens */
g_value_unset (value);
g_value_init (value, GDK_TYPE_COLOR);
g_value_init (value, GDK_TYPE_RGBA);
g_value_set_boxed (value, &color);
return TRUE;
......@@ -796,7 +796,7 @@ gtk_style_set_get_property (GtkStyleSet *set,
if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
{
g_return_val_if_fail (node->property_type == GDK_TYPE_COLOR, FALSE);
g_return_val_if_fail (node->property_type == GDK_TYPE_RGBA, FALSE);
if (!resolve_color (set, val))
return FALSE;
......@@ -863,7 +863,7 @@ gtk_style_set_get_valist (GtkStyleSet *set,
if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
{
g_return_if_fail (node->property_type == GDK_TYPE_COLOR);
g_return_if_fail (node->property_type == GDK_TYPE_RGBA);
if (!resolve_color (set, val))
val = &node->default_value;
......
......@@ -105,7 +105,7 @@ void gtk_style_set_merge (GtkStyleSet *set,
gboolean gtk_symbolic_color_resolve (GtkSymbolicColor *color,
GtkStyleSet *style_set,
GdkColor *resolved_color);
GdkRGBA *resolved_color);
gboolean gtk_gradient_resolve (GtkGradient *gradient,
GtkStyleSet *style_set,
cairo_pattern_t **resolved_gradient);
......
......@@ -42,7 +42,7 @@ struct _GtkSymbolicColor
union
{
GdkColor color;
GdkRGBA color;
gchar *name;
struct
......@@ -84,7 +84,7 @@ struct _GtkGradient
/**
* gtk_symbolic_color_new_literal:
* @color: a #GdkColor
* @color: a #GdkRGBA
*
* Creates a symbolic color pointing to a literal color.
*
......@@ -93,7 +93,7 @@ struct _GtkGradient
* Since: 3.0
**/
GtkSymbolicColor *
gtk_symbolic_color_new_literal (GdkColor *color)
gtk_symbolic_color_new_literal (GdkRGBA *color)
{
GtkSymbolicColor *symbolic_color;
......@@ -273,9 +273,9 @@ gtk_symbolic_color_unref (GtkSymbolicColor *color)
* Since: 3.0
**/
gboolean
gtk_symbolic_color_resolve (GtkSymbolicColor *color,
GtkStyleSet *style_set,
GdkColor *resolved_color)
gtk_symbolic_color_resolve (GtkSymbolicColor *color,
GtkStyleSet *style_set,
GdkRGBA *resolved_color)
{
g_return_val_if_fail (color != NULL, FALSE);
g_return_val_if_fail (GTK_IS_STYLE_SET (style_set), FALSE);
......@@ -301,14 +301,15 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
break;
case COLOR_TYPE_SHADE:
{
GdkColor shade;
GdkRGBA shade;
if (!gtk_symbolic_color_resolve (color->shade.color, style_set, &shade))
return FALSE;
resolved_color->red = CLAMP (shade.red * color->shade.factor, 0, 65535);
resolved_color->green = CLAMP (shade.green * color->shade.factor, 0, 65535);
resolved_color->blue = CLAMP (shade.blue * color->shade.factor, 0, 65535);
resolved_color->red = CLAMP (shade.red * color->shade.factor, 0, 1);
resolved_color->green = CLAMP (shade.green * color->shade.factor, 0, 1);
resolved_color->blue = CLAMP (shade.blue * color->shade.factor, 0, 1);
resolved_color->alpha = CLAMP (shade.alpha * color->shade.factor, 0, 1);
return TRUE;
}
......@@ -316,7 +317,7 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
break;
case COLOR_TYPE_MIX:
{
GdkColor color1, color2;
GdkRGBA color1, color2;
if (!gtk_symbolic_color_resolve (color->mix.color1, style_set, &color1))
return FALSE;
......@@ -324,9 +325,10 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
if (!gtk_symbolic_color_resolve (color->mix.color2, style_set, &color2))
return FALSE;
resolved_color->red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 65535);
resolved_color->green = CLAMP (color1.green + ((color2.green - color1.green) * color->mix.factor), 0, 65535);
resolved_color->blue = CLAMP (color1.blue + ((color2.blue - color1.blue) * color->mix.factor), 0, 65535);
resolved_color->red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 1);
resolved_color->green = CLAMP (color1.green + ((color2.green - color1.green) * color->mix.factor), 0, 1);
resolved_color->blue = CLAMP (color1.blue + ((color2.blue - color1.blue) * color->mix.factor), 0, 1);
resolved_color->alpha = CLAMP (color1.alpha + ((color2.alpha - color1.alpha) * color->mix.factor), 0, 1);
return TRUE;
}
......@@ -537,7 +539,7 @@ gtk_gradient_resolve (GtkGradient *gradient,
for (i = 0; i < gradient->stops->len; i++)
{
ColorStop *stop;
GdkColor color;
GdkRGBA color;
stop = &g_array_index (gradient->stops, ColorStop, i);
......@@ -547,10 +549,9 @@ gtk_gradient_resolve (GtkGradient *gradient,
return FALSE;
}
cairo_pattern_add_color_stop_rgb (pattern, stop->offset,
color.red / 65535.,
color.green / 65535.,
color.blue / 65535.);
cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
color.red, color.green,
color.blue, color.alpha);
}
*resolved_gradient = pattern;
......
......@@ -34,7 +34,7 @@ typedef struct _GtkGradient GtkGradient;
GType gtk_symbolic_color_get_type (void) G_GNUC_CONST;
GType gtk_gradient_get_type (void) G_GNUC_CONST;
GtkSymbolicColor * gtk_symbolic_color_new_literal (GdkColor *color);
GtkSymbolicColor * gtk_symbolic_color_new_literal (GdkRGBA *color);
GtkSymbolicColor * gtk_symbolic_color_new_name (const gchar *name);
GtkSymbolicColor * gtk_symbolic_color_new_shade (GtkSymbolicColor *color,
gdouble factor);
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment