diff options
author | Benjamin Otte <otte@redhat.com> | 2010-08-19 12:50:40 +0200 |
---|---|---|
committer | Sergey V. Udaltsov <svu@gnome.org> | 2010-08-25 18:11:32 +0100 |
commit | 5af27af7b67d8b2ae08d0bb7fb884a6167e8164c (patch) | |
tree | 69ab0f8f047a14a5b07567d5759ab184d7cb84d0 | |
parent | c3272e30f1f723989ffbfa27e04b2bc72a99df7d (diff) | |
download | libgnomekbd-5af27af7b67d8b2ae08d0bb7fb884a6167e8164c.tar.gz |
Draw flag pixbuf using Cairo
No complicated pixbuf scaling code needed anymore, Cairo does that
automatically.
https://bugzilla.gnome.org/show_bug.cgi?id=627353
-rw-r--r-- | libgnomekbd/gkbd-indicator.c | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/libgnomekbd/gkbd-indicator.c b/libgnomekbd/gkbd-indicator.c index f6064fa..cb2ed56 100644 --- a/libgnomekbd/gkbd-indicator.c +++ b/libgnomekbd/gkbd-indicator.c @@ -272,44 +272,29 @@ flag_exposed (GtkWidget * flag, GdkEventExpose * event, GdkPixbuf * image) int iw = gdk_pixbuf_get_width (image); int ih = gdk_pixbuf_get_height (image); GtkAllocation allocation; - gboolean scaling_needed; double xwiratio, ywiratio, wiratio; - int sw, sh, ox, oy; - GdkPixbuf *scaled; + cairo_t *cr; gtk_widget_get_allocation (flag, &allocation); - scaling_needed = - !((allocation.width == iw && - allocation.height <= ih) || - (allocation.width >= iw && allocation.height == ih)); + + cr = gdk_cairo_create (event->window); + gdk_cairo_region (cr, event->region); + cairo_clip (cr); /* widget-to-image scales, X and Y */ xwiratio = 1.0 * allocation.width / iw; ywiratio = 1.0 * allocation.height / ih; wiratio = xwiratio < ywiratio ? xwiratio : ywiratio; - /* scaled width and height */ - sw = iw * wiratio; - sh = ih * wiratio; - - /* offsets */ - ox = (allocation.width - sw) >> 1; - oy = (allocation.height - sh) >> 1; - - scaled = - scaling_needed ? gdk_pixbuf_scale_simple (image, sw, sh, - GDK_INTERP_HYPER) : - image; - - gdk_draw_pixbuf (GDK_DRAWABLE (gtk_widget_get_window (flag)), - NULL, - scaled, - 0, 0, - ox, oy, sw, sh, - scaling_needed ? GDK_RGB_DITHER_NORMAL : - GDK_RGB_DITHER_NONE, 0, 0); - if (scaling_needed) - g_object_unref (G_OBJECT (scaled)); + /* transform cairo context */ + cairo_translate (cr, allocation.width / 2.0, allocation.height / 2.0); + cairo_scale (cr, wiratio, wiratio); + cairo_translate (cr, - iw / 2.0, - ih / 2.0); + + gdk_cairo_set_source_pixbuf (cr, image, 0, 0); + cairo_paint (cr); + + cairo_destroy (cr); } gchar * |