cssimage: Implement dynamic values

No image actually implements it yet, but this is the plumbing.
This commit is contained in:
Benjamin Otte 2018-02-13 07:04:21 +01:00
parent 3322599e99
commit d774406573
3 changed files with 81 additions and 2 deletions

View File

@ -96,6 +96,19 @@ gtk_css_image_real_transition (GtkCssImage *start,
return _gtk_css_image_cross_fade_new (start, end, progress);
}
static gboolean
gtk_css_image_real_is_dynamic (GtkCssImage *image)
{
return FALSE;
}
static GtkCssImage *
gtk_css_image_real_get_dynamic_image (GtkCssImage *image,
gint64 monotonic_time)
{
return g_object_ref (image);
}
static void
_gtk_css_image_class_init (GtkCssImageClass *klass)
{
@ -105,6 +118,8 @@ _gtk_css_image_class_init (GtkCssImageClass *klass)
klass->compute = gtk_css_image_real_compute;
klass->equal = gtk_css_image_real_equal;
klass->transition = gtk_css_image_real_transition;
klass->is_dynamic = gtk_css_image_real_is_dynamic;
klass->get_dynamic_image = gtk_css_image_real_get_dynamic_image;
}
static void
@ -264,6 +279,31 @@ gtk_css_image_snapshot (GtkCssImage *image,
klass->snapshot (image, snapshot, width, height);
}
gboolean
gtk_css_image_is_dynamic (GtkCssImage *image)
{
GtkCssImageClass *klass;
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), FALSE);
klass = GTK_CSS_IMAGE_GET_CLASS (image);
return klass->is_dynamic (image);
}
GtkCssImage *
gtk_css_image_get_dynamic_image (GtkCssImage *image,
gint64 monotonic_time)
{
GtkCssImageClass *klass;
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
klass = GTK_CSS_IMAGE_GET_CLASS (image);
return klass->get_dynamic_image (image, monotonic_time);
}
void
_gtk_css_image_print (GtkCssImage *image,
GString *string)

View File

@ -75,6 +75,11 @@ struct _GtkCssImageClass
GtkSnapshot *snapshot,
double width,
double height);
/* does this image change based on timestamp? (optional) */
gboolean (* is_dynamic) (GtkCssImage *image);
/* get image for given timestamp or @image when not dynamic (optional) */
GtkCssImage *(* get_dynamic_image) (GtkCssImage *image,
gint64 monotonic_time);
/* parse CSS, return TRUE on success */
gboolean (* parse) (GtkCssImage *image,
GtkCssParser *parser);
@ -112,6 +117,9 @@ void gtk_css_image_snapshot (GtkCssImage *
GtkSnapshot *snapshot,
double width,
double height);
gboolean gtk_css_image_is_dynamic (GtkCssImage *image);
GtkCssImage * gtk_css_image_get_dynamic_image (GtkCssImage *image,
gint64 monotonic_time);
void _gtk_css_image_print (GtkCssImage *image,
GString *string);

View File

@ -81,6 +81,37 @@ gtk_css_value_image_transition (GtkCssValue *start,
return _gtk_css_image_value_new (transition);
}
static gboolean
gtk_css_value_image_is_dynamic (GtkCssValue *value)
{
GtkCssImage *image = _gtk_css_image_value_get_image (value);
if (image == NULL)
return FALSE;
return gtk_css_image_is_dynamic (image);
}
static GtkCssValue *
gtk_css_value_image_get_dynamic_value (GtkCssValue *value,
gint64 monotonic_time)
{
GtkCssImage *image, *dynamic;
image = _gtk_css_image_value_get_image (value);
if (image == NULL)
return gtk_css_value_ref (value);
dynamic = gtk_css_image_get_dynamic_image (image, monotonic_time);
if (dynamic == image)
{
g_object_unref (dynamic);
return gtk_css_value_ref (value);
}
return _gtk_css_image_value_new (dynamic);
}
static void
gtk_css_value_image_print (const GtkCssValue *value,
GString *string)
@ -96,8 +127,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
gtk_css_value_image_compute,
gtk_css_value_image_equal,
gtk_css_value_image_transition,
NULL,
NULL,
gtk_css_value_image_is_dynamic,
gtk_css_value_image_get_dynamic_value,
gtk_css_value_image_print
};