diff options
author | Benjamin Otte <otte@redhat.com> | 2012-10-02 11:31:36 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-10-02 14:16:36 +0200 |
commit | 558ffc24c216ceed593458a00250572d220b89a0 (patch) | |
tree | fb2ec632971a0fc786f26ae86297647ab9fa24c9 | |
parent | 25271fe781df135b72c9e95a6551d6f4017d9c1b (diff) | |
download | gtk+-558ffc24c216ceed593458a00250572d220b89a0.tar.gz |
cssimage: Make image transition a vfunc
-rw-r--r-- | gtk/gtkcssimage.c | 40 | ||||
-rw-r--r-- | gtk/gtkcssimagecrossfade.c | 3 | ||||
-rw-r--r-- | gtk/gtkcssimageprivate.h | 9 | ||||
-rw-r--r-- | gtk/gtkcssimagevalue.c | 11 |
4 files changed, 58 insertions, 5 deletions
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c index 89dc6f2699..3df759892a 100644 --- a/gtk/gtkcssimage.c +++ b/gtk/gtkcssimage.c @@ -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, diff --git a/gtk/gtkcssimagecrossfade.c b/gtk/gtkcssimagecrossfade.c index baf1f659f0..2aa9f29539 100644 --- a/gtk/gtkcssimagecrossfade.c +++ b/gtk/gtkcssimagecrossfade.c @@ -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); diff --git a/gtk/gtkcssimageprivate.h b/gtk/gtkcssimageprivate.h index 4b8362b0de..e0b7465b50 100644 --- a/gtk/gtkcssimageprivate.h +++ b/gtk/gtkcssimageprivate.h @@ -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, diff --git a/gtk/gtkcssimagevalue.c b/gtk/gtkcssimagevalue.c index d44e72be1e..17f904c4ba 100644 --- a/gtk/gtkcssimagevalue.c +++ b/gtk/gtkcssimagevalue.c @@ -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 |