[cheese] um-crop-area: Fix background rendering around the picture
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cheese] um-crop-area: Fix background rendering around the picture
- Date: Wed, 7 Jan 2015 15:41:06 +0000 (UTC)
commit 8b5bc7375e031fe1f6faec8c45d54d0b84bc4ef5
Author: Rui Matos <tiagomatos gmail com>
Date: Wed Jan 7 15:16:53 2015 +0100
um-crop-area: Fix background rendering around the picture
Instead of trying to fill the displayed pixbuf with the background
color (and failing at that), just make the pixbuf be an aspect correct
scaled size of the original picture and draw it at the correct offset
on the draw vfunc.
This allows us to get rid of deprecated gtk+ API usage and fixes the
background around the picture ending up black despite de code's
intent.
https://bugzilla.gnome.org/show_bug.cgi?id=742530
libcheese/um-crop-area.c | 62 ++++++++++++++++++++--------------------------
1 files changed, 27 insertions(+), 35 deletions(-)
---
diff --git a/libcheese/um-crop-area.c b/libcheese/um-crop-area.c
index 531408c..b8bc662 100644
--- a/libcheese/um-crop-area.c
+++ b/libcheese/um-crop-area.c
@@ -131,15 +131,21 @@ update_pixbufs (UmCropArea *area)
gint height;
GtkAllocation allocation;
gdouble scale;
- GdkRGBA color;
- guint32 pixel;
- gint dest_x, dest_y, dest_width, dest_height;
+ gint dest_width, dest_height;
GtkWidget *widget;
- GtkStyleContext *context;
widget = GTK_WIDGET (area);
gtk_widget_get_allocation (widget, &allocation);
- context = gtk_widget_get_style_context (widget);
+
+ width = gdk_pixbuf_get_width (priv->browse_pixbuf);
+ height = gdk_pixbuf_get_height (priv->browse_pixbuf);
+
+ scale = allocation.height / (gdouble)height;
+ if (scale * width > allocation.width)
+ scale = allocation.width / (gdouble)width;
+
+ dest_width = width * scale;
+ dest_height = height * scale;
if (priv->pixbuf == NULL ||
gdk_pixbuf_get_width (priv->pixbuf) != allocation.width ||
@@ -149,31 +155,14 @@ update_pixbufs (UmCropArea *area)
priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
gdk_pixbuf_get_has_alpha (priv->browse_pixbuf),
8,
- allocation.width, allocation.height);
-
- gtk_style_context_get_background_color (context, gtk_style_context_get_state (context),
&color);
- pixel = (((gint)(color.red * 1.0)) << 16) |
- (((gint)(color.green * 1.0)) << 8) |
- ((gint)(color.blue * 1.0));
- gdk_pixbuf_fill (priv->pixbuf, pixel);
-
- width = gdk_pixbuf_get_width (priv->browse_pixbuf);
- height = gdk_pixbuf_get_height (priv->browse_pixbuf);
-
- scale = allocation.height / (gdouble)height;
- if (scale * width > allocation.width)
- scale = allocation.width / (gdouble)width;
-
- dest_width = width * scale;
- dest_height = height * scale;
- dest_x = (allocation.width - dest_width) / 2;
- dest_y = (allocation.height - dest_height) / 2,
+ dest_width, dest_height);
+ gdk_pixbuf_fill (priv->pixbuf, 0x0);
gdk_pixbuf_scale (priv->browse_pixbuf,
priv->pixbuf,
- dest_x, dest_y,
+ 0, 0,
dest_width, dest_height,
- dest_x, dest_y,
+ 0, 0,
scale, scale,
GDK_INTERP_BILINEAR);
@@ -199,8 +188,8 @@ update_pixbufs (UmCropArea *area)
}
priv->scale = scale;
- priv->image.x = dest_x;
- priv->image.y = dest_y;
+ priv->image.x = (allocation.width - dest_width) / 2;
+ priv->image.y = (allocation.height - dest_height) / 2;
priv->image.width = dest_width;
priv->image.height = dest_height;
}
@@ -269,7 +258,7 @@ um_crop_area_draw (GtkWidget *widget,
UmCropArea *area = UM_CROP_AREA (widget);
UmCropAreaPrivate *priv = um_crop_area_get_instance_private (area);
GdkRectangle crop;
- gint width, height;
+ gint width, height, ix, iy;
if (priv->browse_pixbuf == NULL)
return FALSE;
@@ -280,14 +269,17 @@ um_crop_area_draw (GtkWidget *widget,
height = gdk_pixbuf_get_height (priv->pixbuf);
crop_to_widget (area, &crop);
- gdk_cairo_set_source_pixbuf (cr, priv->color_shifted, 0, 0);
- cairo_rectangle (cr, 0, 0, width, crop.y);
- cairo_rectangle (cr, 0, crop.y, crop.x, crop.height);
- cairo_rectangle (cr, crop.x + crop.width, crop.y, width - crop.x - crop.width, crop.height);
- cairo_rectangle (cr, 0, crop.y + crop.height, width, height - crop.y - crop.height);
+ ix = priv->image.x;
+ iy = priv->image.y;
+
+ gdk_cairo_set_source_pixbuf (cr, priv->color_shifted, ix, iy);
+ cairo_rectangle (cr, ix, iy, width, crop.y - iy);
+ cairo_rectangle (cr, ix, crop.y, crop.x - ix, crop.height);
+ cairo_rectangle (cr, crop.x + crop.width, crop.y, width - crop.width - (crop.x - ix), crop.height);
+ cairo_rectangle (cr, ix, crop.y + crop.height, width, height - crop.height - (crop.y - iy));
cairo_fill (cr);
- gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, ix, iy);
cairo_rectangle (cr, crop.x, crop.y, crop.width, crop.height);
cairo_fill (cr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]