mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 21:51:08 +00:00
css: Add a function to get color coords
This will be used in the implementation of relative colors.
This commit is contained in:
parent
d8492121aa
commit
b5fd894f77
@ -1820,5 +1820,37 @@ gtk_css_color_value_get_color (const GtkCssValue *color)
|
||||
return &color->color;
|
||||
}
|
||||
|
||||
float
|
||||
gtk_css_color_value_get_coord (const GtkCssValue *color,
|
||||
GtkCssColorSpace color_space,
|
||||
gboolean legacy_srgb,
|
||||
guint coord)
|
||||
{
|
||||
GtkCssColor origin;
|
||||
|
||||
g_assert (coord < 4);
|
||||
|
||||
if (color->type != COLOR_TYPE_COLOR)
|
||||
return 0;
|
||||
|
||||
if (color->type == COLOR_TYPE_COLOR)
|
||||
gtk_css_color_init_from_color (&origin, &color->color);
|
||||
else
|
||||
gtk_css_color_init (&origin, GTK_CSS_COLOR_SPACE_SRGB, (float *) &color->rgba);
|
||||
|
||||
if (color_space != origin.color_space)
|
||||
{
|
||||
GtkCssColor tmp;
|
||||
gtk_css_color_convert (&origin, color_space, &tmp);
|
||||
gtk_css_color_init_from_color (&origin, &tmp);
|
||||
}
|
||||
|
||||
/* Scale up r, g, b in legacy context */
|
||||
if (color_space == GTK_CSS_COLOR_SPACE_SRGB && legacy_srgb && coord < 3)
|
||||
return origin.values[coord] * 255.;
|
||||
else
|
||||
return origin.values[coord];
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
/* vim:set foldmethod=marker expandtab: */
|
||||
|
@ -48,6 +48,10 @@ GtkCssValue * gtk_css_color_value_new_color (GtkCssColorSpace color_
|
||||
const GtkCssColor *
|
||||
gtk_css_color_value_get_color (const GtkCssValue *color) G_GNUC_CONST;
|
||||
|
||||
float gtk_css_color_value_get_coord (const GtkCssValue *color,
|
||||
GtkCssColorSpace color_space,
|
||||
gboolean legacy_srgb,
|
||||
guint coord);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user