summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Matos <tiagomatos@gmail.com>2014-11-28 19:28:30 +0100
committerRui Matos <tiagomatos@gmail.com>2015-01-07 16:43:34 +0100
commita56693207d55de183a126cef38b2590078518c64 (patch)
treede27cb5b6ab1b06b1f03cad4b5fe7f6c8bc891f0
parent1029d0c69ae0cc1255188f6ff6a8a5f6144fe573 (diff)
downloadgnome-control-center-a56693207d55de183a126cef38b2590078518c64.tar.gz
user-accounts/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=740986
-rw-r--r--panels/user-accounts/cc-crop-area.c62
1 files changed, 27 insertions, 35 deletions
diff --git a/panels/user-accounts/cc-crop-area.c b/panels/user-accounts/cc-crop-area.c
index 4d04f55b7..2ca8372bd 100644
--- a/panels/user-accounts/cc-crop-area.c
+++ b/panels/user-accounts/cc-crop-area.c
@@ -93,15 +93,21 @@ update_pixbufs (CcCropArea *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 (area->priv->browse_pixbuf);
+ height = gdk_pixbuf_get_height (area->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 (area->priv->pixbuf == NULL ||
gdk_pixbuf_get_width (area->priv->pixbuf) != allocation.width ||
@@ -111,31 +117,14 @@ update_pixbufs (CcCropArea *area)
area->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
gdk_pixbuf_get_has_alpha (area->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 (area->priv->pixbuf, pixel);
-
- width = gdk_pixbuf_get_width (area->priv->browse_pixbuf);
- height = gdk_pixbuf_get_height (area->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 (area->priv->pixbuf, 0x0);
gdk_pixbuf_scale (area->priv->browse_pixbuf,
area->priv->pixbuf,
- dest_x, dest_y,
+ 0, 0,
dest_width, dest_height,
- dest_x, dest_y,
+ 0, 0,
scale, scale,
GDK_INTERP_BILINEAR);
@@ -161,8 +150,8 @@ update_pixbufs (CcCropArea *area)
}
area->priv->scale = scale;
- area->priv->image.x = dest_x;
- area->priv->image.y = dest_y;
+ area->priv->image.x = (allocation.width - dest_width) / 2;
+ area->priv->image.y = (allocation.height - dest_height) / 2;
area->priv->image.width = dest_width;
area->priv->image.height = dest_height;
}
@@ -196,7 +185,7 @@ cc_crop_area_draw (GtkWidget *widget,
cairo_t *cr)
{
GdkRectangle crop;
- gint width, height;
+ gint width, height, ix, iy;
CcCropArea *uarea = CC_CROP_AREA (widget);
if (uarea->priv->browse_pixbuf == NULL)
@@ -208,14 +197,17 @@ cc_crop_area_draw (GtkWidget *widget,
height = gdk_pixbuf_get_height (uarea->priv->pixbuf);
crop_to_widget (uarea, &crop);
- gdk_cairo_set_source_pixbuf (cr, uarea->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 = uarea->priv->image.x;
+ iy = uarea->priv->image.y;
+
+ gdk_cairo_set_source_pixbuf (cr, uarea->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, uarea->priv->pixbuf, 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, uarea->priv->pixbuf, ix, iy);
cairo_rectangle (cr, crop.x, crop.y, crop.width, crop.height);
cairo_fill (cr);