Mercurial > pidgin
diff src/gtkutils.c @ 13090:0aa231ebbfd5
[gaim-migrate @ 15452]
Changes to some pixbuf stuff.
I added a 'gaim_gtk_create_gaim_icon_with_status()' function to util.c,
and changed 'gaim_gtk_create_prpl_icon_with_status()' to accept a scale
factor because almost everywhere this function was used we would scale
the pixbuf to a smaller size as soon as we got it. So there's a bit less
code duplication.
Also, I think I added some g_object_unref()'s in one or two places where
it was missing.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 01 Feb 2006 22:38:34 +0000 |
parents | 1dc109c12ef5 |
children | 7aea8de78463 |
line wrap: on
line diff
--- a/src/gtkutils.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtkutils.c Wed Feb 01 22:38:34 2006 +0000 @@ -57,6 +57,7 @@ #include "gtkdialogs.h" #include "gtkimhtml.h" #include "gtkimhtmltoolbar.h" +#include "gtkstock.h" #include "gtkthemes.h" #include "gtkutils.h" @@ -1543,26 +1544,26 @@ } GdkPixbuf * -gaim_gtk_create_prpl_icon(GaimAccount *account) +gaim_gtk_create_prpl_icon(GaimAccount *account, double scale_factor) { GaimPlugin *prpl; - GaimPluginProtocolInfo *prpl_info = NULL; - GdkPixbuf *status = NULL; - char *filename = NULL; + GaimPluginProtocolInfo *prpl_info; const char *protoname = NULL; char buf[256]; /* TODO: We should use a define for max file length */ + char *filename = NULL; + GdkPixbuf *pixbuf, *scaled; g_return_val_if_fail(account != NULL, NULL); prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); - - if (prpl != NULL) { - prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); + if (prpl == NULL) + return NULL; - if (prpl_info->list_icon != NULL) - protoname = prpl_info->list_icon(account, NULL); - } + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); + if (prpl_info->list_icon == NULL) + return NULL; + protoname = prpl_info->list_icon(account, NULL); if (protoname == NULL) return NULL; @@ -1574,53 +1575,90 @@ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", buf, NULL); - status = gdk_pixbuf_new_from_file(filename, NULL); + pixbuf = gdk_pixbuf_new_from_file(filename, NULL); g_free(filename); - return status; + scaled = gdk_pixbuf_scale_simple(pixbuf, 30*scale_factor, + 30*scale_factor, GDK_INTERP_BILINEAR); + g_object_unref(pixbuf); + + return scaled; +} + +static GdkPixbuf * +overlay_status_onto_icon(GdkPixbuf *pixbuf, GaimStatusPrimitive primitive) +{ + const char *type_name; + char basename[256]; + char *filename; + GdkPixbuf *emblem; + + type_name = gaim_primitive_get_id_from_type(primitive); + + g_snprintf(basename, sizeof(basename), "%s.png", type_name); + filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", + "default", basename, NULL); + emblem = gdk_pixbuf_new_from_file(filename, NULL); + g_free(filename); + + if (emblem != NULL) { + int width, height, emblem_width, emblem_height, new_emblem_width, new_emblem_height; + width = gdk_pixbuf_get_width(pixbuf); + height = gdk_pixbuf_get_height(pixbuf); + emblem_width = gdk_pixbuf_get_width(emblem); + emblem_height = gdk_pixbuf_get_height(emblem); + new_emblem_width = width / 2; + new_emblem_height = height / 2; + /* Overlay emblem onto the bottom right corner of pixbuf */ + gdk_pixbuf_composite(emblem, pixbuf, + width - new_emblem_width, height - new_emblem_height, + new_emblem_width, new_emblem_height, + width - new_emblem_width, height - new_emblem_height, + (double)new_emblem_width / (double)emblem_width, + (double)new_emblem_height / (double)emblem_height, + GDK_INTERP_BILINEAR, + 255); + g_object_unref(emblem); + } + + return pixbuf; } GdkPixbuf * -gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type) +gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type, double scale_factor) { - char basename2[256]; - char *filename; - const char *type_name; - GdkPixbuf *pixbuf, *scale = NULL, *emblem; + GdkPixbuf *pixbuf; + + pixbuf = gaim_gtk_create_prpl_icon(account, scale_factor); + if (pixbuf == NULL) + return NULL; - pixbuf = gaim_gtk_create_prpl_icon(account); + /* + * TODO: Let the prpl pick the emblem on a per status basis, + * and only use the primitive as a fallback? + */ - if (pixbuf != NULL) { - scale = gdk_pixbuf_scale_simple(pixbuf, 32, 32, - GDK_INTERP_BILINEAR); - g_object_unref(G_OBJECT(pixbuf)); - } else { - return NULL; - } + return overlay_status_onto_icon(pixbuf, + gaim_status_type_get_primitive(status_type)); +} - /* TODO: let the prpl pick the emblem on a per status basis, and only - * use the primitive as a fallback */ - type_name = gaim_primitive_get_id_from_type(gaim_status_type_get_primitive(status_type)); - - g_snprintf(basename2, sizeof(basename2), "%s.png", - type_name); - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", - basename2, NULL); - emblem = gdk_pixbuf_new_from_file(filename, NULL); - g_free(filename); +GdkPixbuf * +gaim_gtk_create_gaim_icon_with_status(GaimStatusPrimitive primitive, double scale_factor) +{ + gchar *filename; + GdkPixbuf *orig, *pixbuf; - if (emblem) { - gdk_pixbuf_composite(emblem, - scale, 32-15, 32-15, - 15, 15, - 32-15, 32-15, - 1, 1, - GDK_INTERP_BILINEAR, - 255); + filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL); + orig = gdk_pixbuf_new_from_file(filename, NULL); + g_free(filename); + if (orig == NULL) + return NULL; - g_object_unref(emblem); - } - return scale; + pixbuf = gdk_pixbuf_scale_simple(orig, 30*scale_factor, + 30*scale_factor, GDK_INTERP_BILINEAR); + g_object_unref(G_OBJECT(orig)); + + return overlay_status_onto_icon(pixbuf, primitive); } static void