comparison src/gtkconv.c @ 9318:01c50436203e

[gaim-migrate @ 10126] i think this is more intelligent scaling. it would certainly be hard for it to be less intelligent scaling committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 19 Jun 2004 17:34:29 +0000
parents 8e1ddf5d81d0
children a4257646861a
comparison
equal deleted inserted replaced
9317:8e1ddf5d81d0 9318:01c50436203e
107 "#7d26cd", /* purple3 */ 107 "#7d26cd", /* purple3 */
108 }; 108 };
109 109
110 #define NUM_NICK_COLORS (sizeof(nick_colors) / sizeof(*nick_colors)) 110 #define NUM_NICK_COLORS (sizeof(nick_colors) / sizeof(*nick_colors))
111 111
112 #define SCALE(x) \
113 ((gdk_pixbuf_animation_get_width(x) <= 48 && gdk_pixbuf_animation_get_height(x) <= 48) ? 48 : \
114 (gdk_pixbuf_animation_get_width(x) > 75 && gdk_pixbuf_animation_get_height(x) > 75) ? 96 : 50)
115
116 typedef struct 112 typedef struct
117 { 113 {
118 GtkWidget *window; 114 GtkWidget *window;
119 115
120 GtkWidget *entry; 116 GtkWidget *entry;
2274 if (status != NULL) 2270 if (status != NULL)
2275 g_object_unref(status); 2271 g_object_unref(status);
2276 } 2272 }
2277 } 2273 }
2278 2274
2275 static void
2276 get_icon_scale_size(GdkPixbufAnimation *icon, GaimBuddyIconSpec *spec, int *width, int *height)
2277 {
2278 *width = gdk_pixbuf_animation_get_width(icon);
2279 *height = gdk_pixbuf_animation_get_height(icon);
2280
2281 /* this should eventually get smarter about preserving the aspect
2282 * ratio when scaling, but gimmie a break, I just woke up */
2283 if(spec && spec->scale_rules & GAIM_ICON_SCALE_DISPLAY) {
2284 if(*width < spec->min_width)
2285 *width = spec->min_width;
2286 else if(*width > spec->max_width)
2287 *width = spec->max_width;
2288
2289 if(*height < spec->min_height)
2290 *height = spec->min_height;
2291 else if(*width > spec->max_height)
2292 *height = spec->max_height;
2293 }
2294
2295 /* and now for some arbitrary sanity checks */
2296 if(*width > 100)
2297 *width = 100;
2298 if(*height > 100)
2299 *height = 100;
2300 }
2301
2279 static gboolean 2302 static gboolean
2280 redraw_icon(gpointer data) 2303 redraw_icon(gpointer data)
2281 { 2304 {
2282 GaimConversation *conv = (GaimConversation *)data; 2305 GaimConversation *conv = (GaimConversation *)data;
2283 GaimGtkConversation *gtkconv; 2306 GaimGtkConversation *gtkconv;
2307 GaimAccount *account;
2308 GaimPluginProtocolInfo *prpl_info = NULL;
2284 2309
2285 GdkPixbuf *buf; 2310 GdkPixbuf *buf;
2286 GdkPixbuf *scale; 2311 GdkPixbuf *scale;
2287 GdkPixmap *pm; 2312 GdkPixmap *pm;
2288 GdkBitmap *bm; 2313 GdkBitmap *bm;
2289 gint delay; 2314 gint delay;
2315 int scale_width, scale_height;
2290 2316
2291 if (!g_list_find(gaim_get_ims(), conv)) { 2317 if (!g_list_find(gaim_get_ims(), conv)) {
2292 gaim_debug(GAIM_DEBUG_WARNING, "gtkconv", 2318 gaim_debug(GAIM_DEBUG_WARNING, "gtkconv",
2293 "Conversation not found in redraw_icon. I think this " 2319 "Conversation not found in redraw_icon. I think this "
2294 "is a bug.\n"); 2320 "is a bug.\n");
2295 return FALSE; 2321 return FALSE;
2296 } 2322 }
2297 2323
2298 gtkconv = GAIM_GTK_CONVERSATION(conv); 2324 gtkconv = GAIM_GTK_CONVERSATION(conv);
2325 account = gaim_conversation_get_account(conv);
2326 if(account && account->gc)
2327 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl);
2299 2328
2300 gdk_pixbuf_animation_iter_advance(gtkconv->u.im->iter, NULL); 2329 gdk_pixbuf_animation_iter_advance(gtkconv->u.im->iter, NULL);
2301 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); 2330 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter);
2302 2331
2332 get_icon_scale_size(gtkconv->u.im->anim, prpl_info ? &prpl_info->icon_spec :
2333 NULL, &scale_width, &scale_height);
2334
2335 /* this code is ugly, and scares me */
2303 scale = gdk_pixbuf_scale_simple(buf, 2336 scale = gdk_pixbuf_scale_simple(buf,
2304 MAX(gdk_pixbuf_get_width(buf) * SCALE(gtkconv->u.im->anim) / 2337 MAX(gdk_pixbuf_get_width(buf) * scale_width /
2305 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), 2338 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1),
2306 MAX(gdk_pixbuf_get_height(buf) * SCALE(gtkconv->u.im->anim) / 2339 MAX(gdk_pixbuf_get_height(buf) * scale_height /
2307 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), 2340 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1),
2308 GDK_INTERP_NEAREST); 2341 GDK_INTERP_NEAREST);
2309 2342
2310 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); 2343 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100);
2311 g_object_unref(G_OBJECT(scale)); 2344 g_object_unref(G_OBJECT(scale));
5403 GtkWidget *event; 5436 GtkWidget *event;
5404 GtkWidget *frame; 5437 GtkWidget *frame;
5405 GdkPixbuf *scale; 5438 GdkPixbuf *scale;
5406 GdkPixmap *pm; 5439 GdkPixmap *pm;
5407 GdkBitmap *bm; 5440 GdkBitmap *bm;
5408 int sf = 0; 5441 int scale_width, scale_height;
5442
5443 GaimAccount *account;
5444 GaimPluginProtocolInfo *prpl_info = NULL;
5409 5445
5410 GaimButtonStyle button_type; 5446 GaimButtonStyle button_type;
5411 5447
5412 g_return_if_fail(conv != NULL); 5448 g_return_if_fail(conv != NULL);
5413 g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv)); 5449 g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv));
5414 g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_IM); 5450 g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_IM);
5415 5451
5416 gtkconv = GAIM_GTK_CONVERSATION(conv); 5452 gtkconv = GAIM_GTK_CONVERSATION(conv);
5453 account = gaim_conversation_get_account(conv);
5454 if(account && account->gc)
5455 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl);
5417 5456
5418 remove_icon(gtkconv); 5457 remove_icon(gtkconv);
5419 5458
5420 if (!gaim_prefs_get_bool("/gaim/gtk/conversations/im/show_buddy_icons")) 5459 if (!gaim_prefs_get_bool("/gaim/gtk/conversations/im/show_buddy_icons"))
5421 return; 5460 return;
5496 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter); 5535 buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter);
5497 if (gtkconv->u.im->animate) 5536 if (gtkconv->u.im->animate)
5498 start_anim(NULL, conv); 5537 start_anim(NULL, conv);
5499 } 5538 }
5500 5539
5501 sf = SCALE(gtkconv->u.im->anim); 5540 get_icon_scale_size(gtkconv->u.im->anim, prpl_info ? &prpl_info->icon_spec :
5541 NULL, &scale_width, &scale_height);
5502 scale = gdk_pixbuf_scale_simple(buf, 5542 scale = gdk_pixbuf_scale_simple(buf,
5503 MAX(gdk_pixbuf_get_width(buf) * sf / 5543 MAX(gdk_pixbuf_get_width(buf) * scale_width /
5504 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1), 5544 gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1),
5505 MAX(gdk_pixbuf_get_height(buf) * sf / 5545 MAX(gdk_pixbuf_get_height(buf) * scale_height /
5506 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1), 5546 gdk_pixbuf_animation_get_height(gtkconv->u.im->anim), 1),
5507 GDK_INTERP_NEAREST); 5547 GDK_INTERP_NEAREST);
5508 5548
5509 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); 5549 gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100);
5510 g_object_unref(G_OBJECT(scale)); 5550 g_object_unref(G_OBJECT(scale));
5534 g_signal_connect(G_OBJECT(event), "button-press-event", 5574 g_signal_connect(G_OBJECT(event), "button-press-event",
5535 G_CALLBACK(icon_menu), conv); 5575 G_CALLBACK(icon_menu), conv);
5536 gtk_widget_show(event); 5576 gtk_widget_show(event);
5537 5577
5538 gtkconv->u.im->icon = gtk_image_new_from_pixmap(pm, bm); 5578 gtkconv->u.im->icon = gtk_image_new_from_pixmap(pm, bm);
5539 gtk_widget_set_size_request(gtkconv->u.im->icon, sf, sf); 5579 gtk_widget_set_size_request(gtkconv->u.im->icon, scale_width, scale_height);
5540 gtk_container_add(GTK_CONTAINER(event), gtkconv->u.im->icon); 5580 gtk_container_add(GTK_CONTAINER(event), gtkconv->u.im->icon);
5541 gtk_widget_show(gtkconv->u.im->icon); 5581 gtk_widget_show(gtkconv->u.im->icon);
5542 5582
5543 g_object_unref(G_OBJECT(pm)); 5583 g_object_unref(G_OBJECT(pm));
5544 5584