diff options
author | Benjamin Otte <otte@redhat.com> | 2011-02-14 19:11:00 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2011-02-14 19:33:05 +0100 |
commit | 1c444548543720351f9674ec7cea3504d73cdad6 (patch) | |
tree | d775f9646616c9f6b3e3886bc7d6a3e340422758 | |
parent | fe3b6ffc7ae17ebec02b5cd8b0ec87127c57f5ec (diff) | |
download | gtk+-picture.tar.gz |
image: Only redraw changed parts of the picture, not the full picturepicture
-rw-r--r-- | gtk/gtkimage.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c index 380c18c7ba..fb2a77b54a 100644 --- a/gtk/gtkimage.c +++ b/gtk/gtkimage.c @@ -851,12 +851,45 @@ gtk_image_set_from_file (GtkImage *image, } static void +gtk_image_compute_picture_offset (GtkImage *image, + int *xoffset, + int *yoffset) +{ + GtkImagePrivate *priv = image->priv; + GtkMisc *misc = GTK_MISC (image); + GtkWidget *widget = GTK_WIDGET (image); + gint xpad, ypad; + gfloat xalign, yalign; + + gtk_misc_get_alignment (misc, &xalign, &yalign); + gtk_misc_get_padding (misc, &xpad, &ypad); + + if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR) + xalign = 1.0 - xalign; + + *xoffset = floor (xpad + ((gtk_widget_get_allocated_width (widget) - gdk_picture_get_width (priv->picture)) * xalign)); + *yoffset = floor (ypad + ((gtk_widget_get_allocated_height (widget) - gdk_picture_get_height (priv->picture)) * yalign)); +} + +static void gtk_image_picture_changed (GdkPicture *picture, const cairo_region_t *region, GtkImage *image) { - /* XXX: take region into account */ - gtk_widget_queue_draw (GTK_WIDGET (image)); + int x, y; + + gtk_image_compute_picture_offset (image, &x, &y); + + if (x || y) + { + cairo_region_t *copy = cairo_region_copy (region); + + cairo_region_translate (copy, x, y); + gtk_widget_queue_draw_region (GTK_WIDGET (image), copy); + cairo_region_destroy (copy); + } + else + gtk_widget_queue_draw_region (GTK_WIDGET (image), region); } static void @@ -1436,27 +1469,6 @@ gtk_image_unrealize (GtkWidget *widget) GTK_WIDGET_CLASS (gtk_image_parent_class)->unrealize (widget); } -static void -gtk_image_compute_picture_offset (GtkImage *image, - int *xoffset, - int *yoffset) -{ - GtkImagePrivate *priv = image->priv; - GtkMisc *misc = GTK_MISC (image); - GtkWidget *widget = GTK_WIDGET (image); - gint xpad, ypad; - gfloat xalign, yalign; - - gtk_misc_get_alignment (misc, &xalign, &yalign); - gtk_misc_get_padding (misc, &xpad, &ypad); - - if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR) - xalign = 1.0 - xalign; - - *xoffset = floor (xpad + ((gtk_widget_get_allocated_width (widget) - gdk_picture_get_width (priv->picture)) * xalign)); - *yoffset = floor (ypad + ((gtk_widget_get_allocated_height (widget) - gdk_picture_get_height (priv->picture)) * yalign)); -} - static gint gtk_image_draw (GtkWidget *widget, cairo_t *cr) |