From: tweenk Date: Thu, 16 Apr 2009 18:23:38 +0000 (+0000) Subject: Fix most icon issues: blurry icons, tiling, etc. (hooray!) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=279571c3b52fb405c355e112e13e04fdbdd7ac47;p=inkscape.git Fix most icon issues: blurry icons, tiling, etc. (hooray!) --- diff --git a/src/ink-action.cpp b/src/ink-action.cpp index dda63c160..d8673a3ab 100644 --- a/src/ink-action.cpp +++ b/src/ink-action.cpp @@ -200,9 +200,10 @@ static GtkWidget* ink_action_create_menu_item( GtkAction* action ) if ( SP_IS_ICON(child) ) { SPIcon* icon = SP_ICON(child); sp_icon_fetch_pixbuf( icon ); - GdkPixbuf* target = gtk_action_is_sensitive(action) ? icon->pb : icon->pb_faded; + GdkPixbuf* target = icon->pb; if ( target ) { child = gtk_image_new_from_pixbuf( target ); + gtk_widget_set_sensitive(child, gtk_action_is_sensitive(action)); gtk_widget_destroy( GTK_WIDGET(icon) ); } } diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index deb3e7301..f648a9440 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -140,7 +140,6 @@ sp_icon_init(SPIcon *icon) icon->psize = 0; icon->name = 0; icon->pb = 0; - icon->pb_faded = 0; } static void @@ -166,10 +165,6 @@ static void sp_icon_clear( SPIcon *icon ) { g_object_unref(G_OBJECT(icon->pb)); icon->pb = NULL; } - if (icon->pb_faded) { - g_object_unref(G_OBJECT(icon->pb_faded)); - icon->pb_faded = NULL; - } } static void @@ -230,8 +225,6 @@ void sp_icon_fetch_pixbuf( SPIcon *icon ) } if ( pb ) { icon->pb = pb; - icon->pb_faded = gdk_pixbuf_copy(icon->pb); - gdk_pixbuf_saturate_and_pixelate(icon->pb, icon->pb_faded, 0.5, TRUE); } else { /* TODO: We should do something more useful if we can't load the image. */ g_warning ("failed to load icon '%s'", icon->name); @@ -516,34 +509,35 @@ int sp_icon_get_phys_size(int size) static void sp_icon_paint(SPIcon *icon, GdkRectangle const *area) { GtkWidget &widget = *GTK_WIDGET(icon); - - GdkPixbuf *image = GTK_WIDGET_IS_SENSITIVE(&widget) ? icon->pb : icon->pb_faded; + GdkPixbuf *image = icon->pb; + bool unref_image = false; + + /* copied from the expose function of GtkImage */ + if (GTK_WIDGET_STATE (icon) != GTK_STATE_NORMAL && image) { + GtkIconSource *source = gtk_icon_source_new(); + gtk_icon_source_set_pixbuf(source, icon->pb); + gtk_icon_source_set_size(source, GTK_ICON_SIZE_SMALL_TOOLBAR); // note: this is boilerplate and not used + gtk_icon_source_set_size_wildcarded(source, FALSE); + image = gtk_style_render_icon (widget.style, source, gtk_widget_get_direction(&widget), + (GtkStateType) GTK_WIDGET_STATE(&widget), (GtkIconSize)-1, &widget, "gtk-image"); + gtk_icon_source_free(source); + unref_image = true; + } if (image) { - int const padx = ( ( widget.allocation.width > icon->psize ) - ? ( widget.allocation.width - icon->psize ) / 2 - : 0 ); - int const pady = ( ( widget.allocation.height > icon->psize ) - ? ( widget.allocation.height - icon->psize ) / 2 - : 0 ); - - int const x0 = std::max(area->x, widget.allocation.x + padx); - int const y0 = std::max(area->y, widget.allocation.y + pady); - int const x1 = std::min(area->x + area->width, widget.allocation.x + padx + static_cast(icon->psize) ); - int const y1 = std::min(area->y + area->height, widget.allocation.y + pady + static_cast(icon->psize) ); - - int width = x1 - x0; - int height = y1 - y0; + int x = floor(widget.allocation.x + ((widget.allocation.width - widget.requisition.width) * 0.5)); + int y = floor(widget.allocation.y + ((widget.allocation.height - widget.requisition.height) * 0.5)); + int width = gdk_pixbuf_get_width(image); + int height = gdk_pixbuf_get_height(image); // Limit drawing to when we actually have something. Avoids some crashes. if ( (width > 0) && (height > 0) ) { - gdk_draw_pixbuf(GDK_DRAWABLE(widget.window), NULL, image, - x0 - widget.allocation.x - padx, - y0 - widget.allocation.y - pady, - x0, y0, - width, height, - GDK_RGB_DITHER_NORMAL, x0, y0); + gdk_draw_pixbuf(GDK_DRAWABLE(widget.window), widget.style->black_gc, image, + 0, 0, x, y, width, height, + GDK_RGB_DITHER_NORMAL, x, y); } } + + if (unref_image) g_object_unref(G_OBJECT(image)); } GdkPixbuf *sp_icon_image_load_pixmap(gchar const *name, unsigned /*lsize*/, unsigned psize) diff --git a/src/widgets/icon.h b/src/widgets/icon.h index 45ab82223..1e2e04e10 100644 --- a/src/widgets/icon.h +++ b/src/widgets/icon.h @@ -30,7 +30,6 @@ struct SPIcon { gchar *name; GdkPixbuf *pb; - GdkPixbuf *pb_faded; }; struct SPIconClass {