cssimage: Make image transition a vfunc

This commit is contained in:
Benjamin Otte 2012-10-02 11:31:36 +02:00
parent 25271fe781
commit 558ffc24c2
4 changed files with 58 additions and 5 deletions

View File

@ -69,6 +69,15 @@ gtk_css_image_real_compute (GtkCssImage *image,
return g_object_ref (image);
}
GtkCssImage *
gtk_css_image_real_transition (GtkCssImage *start,
GtkCssImage *end,
guint property_id,
double progress)
{
return _gtk_css_image_cross_fade_new (start, end, progress);
}
static void
_gtk_css_image_class_init (GtkCssImageClass *klass)
{
@ -76,6 +85,7 @@ _gtk_css_image_class_init (GtkCssImageClass *klass)
klass->get_height = gtk_css_image_real_get_height;
klass->get_aspect_ratio = gtk_css_image_real_get_aspect_ratio;
klass->compute = gtk_css_image_real_compute;
klass->transition = gtk_css_image_real_transition;
}
static void
@ -143,6 +153,36 @@ _gtk_css_image_compute (GtkCssImage *image,
return klass->compute (image, property_id, provider, values, parent_values, dependencies);
}
GtkCssImage *
_gtk_css_image_transition (GtkCssImage *start,
GtkCssImage *end,
guint property_id,
double progress)
{
GtkCssImageClass *klass;
g_return_val_if_fail (start == NULL || GTK_IS_CSS_IMAGE (start), NULL);
g_return_val_if_fail (end == NULL || GTK_IS_CSS_IMAGE (end), NULL);
progress = CLAMP (progress, 0.0, 1.0);
if (start == NULL)
{
if (end == NULL)
return NULL;
else
{
start = end;
end = NULL;
progress = 1.0 - progress;
}
}
klass = GTK_CSS_IMAGE_GET_CLASS (start);
return klass->transition (start, end, property_id, progress);
}
void
_gtk_css_image_draw (GtkCssImage *image,
cairo_t *cr,

View File

@ -114,6 +114,9 @@ gtk_css_image_cross_fade_draw (GtkCssImage *image,
cairo_push_group (cr);
/* performance trick */
cairo_reset_clip (cr);
_gtk_css_image_draw (cross_fade->start, cr, width, height);
cairo_push_group (cr);

View File

@ -61,6 +61,11 @@ struct _GtkCssImageClass
GtkCssComputedValues *values,
GtkCssComputedValues *parent_values,
GtkCssDependencies *dependencies);
/* transition between start and end image (end may be NULL), returns new reference */
GtkCssImage *(* transition) (GtkCssImage *start,
GtkCssImage *end,
guint property_id,
double progress);
/* draw to 0,0 with the given width and height */
void (* draw) (GtkCssImage *image,
@ -90,6 +95,10 @@ GtkCssImage * _gtk_css_image_compute (GtkCssImage *
GtkCssComputedValues *values,
GtkCssComputedValues *parent_values,
GtkCssDependencies *dependencies);
GtkCssImage * _gtk_css_image_transition (GtkCssImage *start,
GtkCssImage *end,
guint property_id,
double progress);
void _gtk_css_image_draw (GtkCssImage *image,
cairo_t *cr,

View File

@ -72,13 +72,14 @@ gtk_css_value_image_transition (GtkCssValue *start,
guint property_id,
double progress)
{
GtkCssImage *fade;
GtkCssImage *transition;
fade = _gtk_css_image_cross_fade_new (_gtk_css_image_value_get_image (start),
_gtk_css_image_value_get_image (end),
progress);
transition = _gtk_css_image_transition (_gtk_css_image_value_get_image (start),
_gtk_css_image_value_get_image (end),
property_id,
progress);
return _gtk_css_image_value_new (fade);
return _gtk_css_image_value_new (transition);
}
static void