css: Add helper functions
We need to be able to translate css color spaces into gdk color states, and css hue interplation into gsk hue interpolation.
This commit is contained in:
@@ -1167,6 +1167,46 @@ gtk_css_color_interpolation_method_print (GtkCssColorSpace in,
|
||||
/* }}} */
|
||||
/* {{{ GdkColor conversion */
|
||||
|
||||
/*< private >
|
||||
* gtk_css_color_space_get_color_state:
|
||||
* @color_space: a CSS color space
|
||||
*
|
||||
* Returns the best-matching GdkColorState for a given CSS color
|
||||
* space.
|
||||
*
|
||||
* Note that we don't guarantee a 1:1 match between CSS color
|
||||
* spaces and color states, so conversion of the color may
|
||||
* still be necessary.
|
||||
*
|
||||
* Returns: (transfer none): the `GdkColorState`
|
||||
*/
|
||||
GdkColorState *
|
||||
gtk_css_color_space_get_color_state (GtkCssColorSpace color_space)
|
||||
{
|
||||
switch (color_space)
|
||||
{
|
||||
case GTK_CSS_COLOR_SPACE_SRGB:
|
||||
case GTK_CSS_COLOR_SPACE_HSL:
|
||||
case GTK_CSS_COLOR_SPACE_HWB:
|
||||
case GTK_CSS_COLOR_SPACE_OKLAB:
|
||||
case GTK_CSS_COLOR_SPACE_OKLCH:
|
||||
return GDK_COLOR_STATE_SRGB;
|
||||
|
||||
case GTK_CSS_COLOR_SPACE_SRGB_LINEAR:
|
||||
return GDK_COLOR_STATE_SRGB_LINEAR;
|
||||
|
||||
case GTK_CSS_COLOR_SPACE_REC2020:
|
||||
case GTK_CSS_COLOR_SPACE_DISPLAY_P3:
|
||||
case GTK_CSS_COLOR_SPACE_XYZ:
|
||||
case GTK_CSS_COLOR_SPACE_REC2100_PQ:
|
||||
return GDK_COLOR_STATE_REC2100_PQ;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_color_to_color (const GtkCssColor *css,
|
||||
GdkColor *color)
|
||||
@@ -1211,5 +1251,11 @@ gtk_css_color_to_color (const GtkCssColor *css,
|
||||
}
|
||||
}
|
||||
|
||||
GskHueInterpolation
|
||||
gtk_css_hue_interpolation_to_hue_interpolation (GtkCssHueInterpolation interp)
|
||||
{
|
||||
return (GskHueInterpolation) interp;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
/* vim:set foldmethod=marker expandtab: */
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "gtk/css/gtkcssparserprivate.h"
|
||||
#include "gtkcsstypesprivate.h"
|
||||
#include "gdk/gdkcolorprivate.h"
|
||||
#include "gsk/gskrendernodeprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -106,6 +107,8 @@ void gtk_css_color_space_get_coord_range (GtkCssColorSpace color_space,
|
||||
float *lower,
|
||||
float *upper);
|
||||
|
||||
GdkColorState *gtk_css_color_space_get_color_state (GtkCssColorSpace color_space);
|
||||
|
||||
gboolean gtk_css_color_interpolation_method_can_parse (GtkCssParser *parser);
|
||||
|
||||
gboolean gtk_css_color_interpolation_method_parse (GtkCssParser *parser,
|
||||
@@ -116,6 +119,8 @@ void gtk_css_color_interpolation_method_print (GtkCssColorSpace in,
|
||||
GtkCssHueInterpolation interp,
|
||||
GString *string);
|
||||
|
||||
GskHueInterpolation gtk_css_hue_interpolation_to_hue_interpolation (GtkCssHueInterpolation interp);
|
||||
|
||||
static inline gboolean
|
||||
gtk_css_color_is_clear (const GtkCssColor *color)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user