void wxAnimationCtrl::DisplayStaticImage() { wxASSERT(!IsPlaying()); // m_bmpStaticReal will be updated only if necessary... UpdateStaticImage(); if (m_bmpStaticReal.IsOk()) { // show inactive bitmap gtk_image_set_from_pixbuf(GTK_IMAGE(m_widget), m_bmpStaticReal.GetPixbuf()); } else { if (m_anim) { // even if not clearly documented, gdk_pixbuf_animation_get_static_image() // always returns the first frame of the animation gtk_image_set_from_pixbuf(GTK_IMAGE(m_widget), gdk_pixbuf_animation_get_static_image(m_anim)); } else { ClearToBackgroundColour(); } } }
void vnr_tools_apply_embedded_orientation (GdkPixbufAnimation **anim) { GdkPixbuf *pixbuf; GdkPixbuf *original; if(!gdk_pixbuf_animation_is_static_image (*anim)) return; pixbuf = gdk_pixbuf_animation_get_static_image (*anim); original = pixbuf; pixbuf = gdk_pixbuf_apply_embedded_orientation(pixbuf); if(original == pixbuf) { g_object_unref(pixbuf); return; } GdkPixbufSimpleAnim *s_anim; s_anim = gdk_pixbuf_simple_anim_new (gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), -1); gdk_pixbuf_simple_anim_add_frame(s_anim, pixbuf); g_object_unref(pixbuf); g_object_unref(*anim); *anim = GDK_PIXBUF_ANIMATION(s_anim); }
gboolean tilem_animation_save(TilemAnimation *anim, const char *fname, const char *type, char **option_keys, char **option_values, GError **err) { FILE *fp; char *dname; int errnum; GdkPixbuf *pb; gboolean status; byte palette[768]; int i; g_return_val_if_fail(TILEM_IS_ANIMATION(anim), FALSE); g_return_val_if_fail(fname != NULL, FALSE); g_return_val_if_fail(type != NULL, FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); if (strcmp(type, "gif") != 0) { pb = gdk_pixbuf_animation_get_static_image (GDK_PIXBUF_ANIMATION(anim)); status = gdk_pixbuf_savev(pb, fname, type, option_keys, option_values, err); return status; } fp = g_fopen(fname, "wb"); if (!fp) { errnum = errno; dname = g_filename_display_name(fname); g_set_error(err, G_FILE_ERROR, g_file_error_from_errno(errnum), _("Failed to open '%s' for writing: %s"), dname, g_strerror(errnum)); g_free(dname); return FALSE; } for (i = 0; i < 256; i++) { palette[3 * i] = anim->palette[i] >> 16; palette[3 * i + 1] = anim->palette[i] >> 8; palette[3 * i + 2] = anim->palette[i]; } tilem_animation_write_gif(anim, palette, 256, fp); if (fclose(fp)) { errnum = errno; dname = g_filename_display_name(fname); g_set_error(err, G_FILE_ERROR, g_file_error_from_errno(errnum), _("Error while closing '%s': %s"), dname, g_strerror(errnum)); g_free(dname); return FALSE; } return TRUE; }
static void load_animation (GInputStream *input_stream, CbMedia *media) { GdkPixbufAnimation *animation; GdkPixbuf *frame; GError *error = NULL; cairo_surface_t *surface; cairo_t *ct; gboolean has_alpha; animation = gdk_pixbuf_animation_new_from_stream (input_stream, NULL, &error); if (error) { g_warning ("Couldn't load pixbuf: %s (%s)", error->message, media->url); mark_invalid (media); g_error_free (error); return; } frame = gdk_pixbuf_animation_get_static_image (animation); if (!gdk_pixbuf_animation_is_static_image (animation)) media->animation = animation; /* Takes ref */ else media->animation = NULL; has_alpha = gdk_pixbuf_get_has_alpha (frame); surface = cairo_image_surface_create (has_alpha ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, gdk_pixbuf_get_width (frame), gdk_pixbuf_get_height (frame)); ct = cairo_create (surface); gdk_cairo_set_source_pixbuf (ct, frame, 0.0, 0.0); cairo_paint (ct); cairo_destroy (ct); media->surface = surface; if (media->surface == NULL) { g_warning ("Surface of %p is null", media); mark_invalid (media); goto out; } media->width = gdk_pixbuf_get_width (frame); media->height = gdk_pixbuf_get_height (frame); media->loaded = TRUE; media->invalid = FALSE; out: if (media->animation == NULL) g_object_unref (animation); cb_media_loading_finished (media); }
GdkPixbuf* pgpug_static_icon (PgpugPixEnum icon_id, gint size) { GdkPixbufAnimation *anim; GdkPixbuf *result = NULL; anim = pgpug_animated_icon (icon_id, size); if (anim != NULL) { result = gdk_pixbuf_copy (gdk_pixbuf_animation_get_static_image (anim)); g_object_unref (anim); } return result; }
GdkPixbuf* pgpug_static_icon_compose (PgpugPixEnum icon_id, gint size, ...) { va_list var_args; GdkPixbufAnimation *anim = NULL; GdkPixbuf *result = NULL; va_start (var_args, size); anim = pgpug_animated_icon_compose_real (icon_id, size, var_args); va_end (var_args); g_return_val_if_fail ( anim!=NULL, NULL); result = gdk_pixbuf_copy (gdk_pixbuf_animation_get_static_image (anim)); g_object_unref (anim); return result; }
static void load_picture (gchar *filename) { anim_pb = gdk_pixbuf_animation_new_from_file (filename, NULL); orig_pb = gdk_pixbuf_animation_get_static_image (anim_pb); if (orig_pb) { if (gdk_pixbuf_animation_is_static_image (anim_pb)) gtk_image_set_from_pixbuf (GTK_IMAGE (picture), orig_pb); else { gtk_image_set_from_animation (GTK_IMAGE (picture), anim_pb); animated = TRUE; } loaded = TRUE; } else gtk_image_set_from_stock (GTK_IMAGE (picture), "gtk-missing-image", GTK_ICON_SIZE_DIALOG); }
void gaym_gtkconv_update_thumbnail(GaimConversation * conv, struct fetch_thumbnail_data *thumbnail_data) { GaimGtkConversation *gtkconv; char filename[256]; FILE *file; GError *err = NULL; size_t len; GdkPixbuf *buf; GdkPixbuf *scale; GdkPixmap *pm; GdkBitmap *bm; int scale_width, scale_height; GaimAccount *account; GaimPluginProtocolInfo *prpl_info = NULL; g_return_if_fail(conv != NULL); g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv)); g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_CHAT); gtkconv = GAIM_GTK_CONVERSATION(conv); GaymChatIcon *icon_data = g_hash_table_lookup(icons, conv); if (!thumbnail_data) return; if (!icon_data->show_icon) return; const char *data = thumbnail_data->pic_data; len = thumbnail_data->pic_data_len; account = gaim_conversation_get_account(conv); if (account && account->gc) prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); if (icon_data->anim != NULL) g_object_unref(G_OBJECT(icon_data->anim)); icon_data->anim = NULL; if (icon_data->icon_timer != 0) g_source_remove(icon_data->icon_timer); icon_data->icon_timer = 0; if (icon_data->iter != NULL) g_object_unref(G_OBJECT(icon_data->iter)); icon_data->iter = NULL; if (!gaim_prefs_get_bool ("/gaim/gtk/conversations/im/show_buddy_icons")) return; if (gaim_conversation_get_gc(conv) == NULL) return; /* this is such an evil hack, i don't know why i'm even considering it. we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */ /* gdk-pixbuf-loader was leaky? is it still? */ g_snprintf(filename, sizeof(filename), "%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d", g_get_tmp_dir(), thumbnail_data->who, getpid()); if (!(file = g_fopen(filename, "wb"))) return; fwrite(data, 1, len, file); fclose(file); icon_data->anim = gdk_pixbuf_animation_new_from_file(filename, &err); /* make sure we remove the file as soon as possible */ g_unlink(filename); if (err) { gaim_debug(GAIM_DEBUG_ERROR, "gtkconv", "Buddy icon error: %s\n", err->message); g_error_free(err); } if (!icon_data->anim) return; if (gdk_pixbuf_animation_is_static_image(icon_data->anim)) { icon_data->iter = NULL; buf = gdk_pixbuf_animation_get_static_image(icon_data->anim); } else { icon_data->iter = gdk_pixbuf_animation_get_iter(icon_data->anim, NULL); /* LEAK */ buf = gdk_pixbuf_animation_iter_get_pixbuf(icon_data->iter); } get_icon_scale_size(icon_data->anim, prpl_info ? &prpl_info->icon_spec : NULL, &scale_width, &scale_height); scale = gdk_pixbuf_scale_simple(buf, MAX(gdk_pixbuf_get_width(buf) * scale_width / gdk_pixbuf_animation_get_width (icon_data->anim), 1), MAX(gdk_pixbuf_get_height(buf) * scale_height / gdk_pixbuf_animation_get_height (icon_data->anim), 1), GDK_INTERP_NEAREST); gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); g_object_unref(G_OBJECT(scale)); icon_data->event = gtk_event_box_new(); gtk_container_add(GTK_CONTAINER(icon_data->frame), icon_data->event); gtk_widget_set_size_request(GTK_WIDGET(icon_data->frame), scale_width, scale_height); // g_signal_connect(G_OBJECT(icon_data->event), "button-press-event", // G_CALLBACK(icon_menu), conv); gtk_widget_show(icon_data->event); icon_data->icon = gtk_image_new_from_pixmap(pm, bm); gtk_container_add(GTK_CONTAINER(icon_data->event), icon_data->icon); gtk_widget_show(icon_data->icon); g_object_unref(G_OBJECT(pm)); if (bm) g_object_unref(G_OBJECT(bm)); }
void splash_create (gboolean be_verbose) { GtkWidget *frame; GtkWidget *vbox; GdkPixbufAnimation *pixbuf; GdkScreen *screen; g_return_if_fail (splash == NULL); pixbuf = splash_image_load (be_verbose); if (! pixbuf) return; splash = g_slice_new0 (GimpSplash); splash->window = g_object_new (GTK_TYPE_WINDOW, "type", GTK_WINDOW_TOPLEVEL, "type-hint", GDK_WINDOW_TYPE_HINT_SPLASHSCREEN, "title", _("GIMP Startup"), "role", "gimp-startup", "window-position", GTK_WIN_POS_CENTER, "resizable", FALSE, NULL); g_signal_connect_swapped (splash->window, "delete-event", G_CALLBACK (exit), GINT_TO_POINTER (0)); screen = gtk_widget_get_screen (splash->window); splash->width = MIN (gdk_pixbuf_animation_get_width (pixbuf), gdk_screen_get_width (screen)); splash->height = MIN (gdk_pixbuf_animation_get_height (pixbuf), gdk_screen_get_height (screen)); frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); gtk_container_add (GTK_CONTAINER (splash->window), frame); gtk_widget_show (frame); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); /* If the splash image is static, we use a drawing area and set the * image as back pixmap, otherwise a GtkImage is being used. */ if (gdk_pixbuf_animation_is_static_image (pixbuf)) { splash->area = gtk_drawing_area_new (); } else { splash->area = gtk_image_new_from_animation (pixbuf); } gtk_box_pack_start (GTK_BOX (vbox), splash->area, TRUE, TRUE, 0); gtk_widget_show (splash->area); gtk_widget_set_size_request (splash->area, splash->width, splash->height); /* create the pango layouts */ splash->upper = gtk_widget_create_pango_layout (splash->area, ""); splash->lower = gtk_widget_create_pango_layout (splash->area, ""); gimp_pango_layout_set_scale (splash->lower, PANGO_SCALE_SMALL); /* this sets the initial layout positions */ splash_position_layouts (splash, "", "", NULL); splash_average_text_area (splash, gdk_pixbuf_animation_get_static_image (pixbuf), &splash->color); gtk_widget_realize (splash->area); if (gdk_pixbuf_animation_is_static_image (pixbuf)) { GdkPixbuf *static_pixbuf = gdk_pixbuf_animation_get_static_image (pixbuf); GdkPixmap *pixmap; cairo_t *cr; pixmap = gdk_pixmap_new (gtk_widget_get_window (splash->area), splash->width, splash->height, -1); cr = gdk_cairo_create (pixmap); gdk_cairo_set_source_pixbuf (cr, static_pixbuf, 0.0, 0.0); cairo_paint (cr); cairo_destroy (cr); gdk_window_set_back_pixmap (gtk_widget_get_window (splash->area), pixmap, FALSE); g_object_unref (pixmap); } g_object_unref (pixbuf); g_signal_connect_after (splash->area, "expose-event", G_CALLBACK (splash_area_expose), splash); /* add a progress bar */ splash->progress = gtk_progress_bar_new (); gtk_box_pack_end (GTK_BOX (vbox), splash->progress, FALSE, FALSE, 0); gtk_widget_show (splash->progress); gtk_widget_show_now (splash->window); #ifdef STARTUP_TIMER splash->timer = g_timer_new (); #endif }
static void create_win_message(char *icon, char *text, int duration) { GtkWidget *gwin_message = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip(GTK_WINDOW(gwin_message), FALSE); gtk_container_set_border_width (GTK_CONTAINER (gwin_message), 0); gtk_widget_realize (gwin_message); GdkWindow *gdkwin = gtk_widget_get_window(gwin_message); set_no_focus(gwin_message); GtkWidget *hbox = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (gwin_message), hbox); if (icon[0] != '-') { GtkWidget *image = gtk_image_new_from_file(icon); if (text[0] == '-') { #if GTK_CHECK_VERSION(2,91,0) GdkPixbuf *pixbuf = NULL; GdkPixbufAnimation *anime = NULL; switch(gtk_image_get_storage_type(GTK_IMAGE(image))) { case GTK_IMAGE_PIXBUF: pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); break; case GTK_IMAGE_ANIMATION: anime = gtk_image_get_animation(GTK_IMAGE(image)); pixbuf = gdk_pixbuf_animation_get_static_image(anime); break; default: break; } cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); cairo_t *cr = cairo_create(img); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); cairo_paint(cr); cairo_region_t *mask = gdk_cairo_region_create_from_surface(img); gtk_widget_shape_combine_region(gwin_message, mask); cairo_region_destroy(mask); cairo_destroy(cr); cairo_surface_destroy(img); #else GdkBitmap *bitmap = NULL; gdk_pixbuf_render_pixmap_and_mask(gdk_pixbuf_new_from_file(icon, NULL), NULL, &bitmap, 128); gtk_widget_shape_combine_mask(gwin_message, bitmap, 0, 0); #endif } gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); } if (text[0] != '-') { GtkWidget *label = gtk_label_new(text); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); } gtk_widget_show_all(gwin_message); int width, height; get_win_size(gwin_message, &width, &height); int ox=-1, oy; int szx, szy; if (tray_da_win) { gdk_window_get_origin (tray_da_win, &ox, &oy); #if !GTK_CHECK_VERSION(2,91,0) gdk_drawable_get_size(tray_da_win, &szx, &szy); #else szx = gdk_window_get_width(tray_da_win); szy = gdk_window_get_height(tray_da_win); #endif if (oy<height) { oy = szy; } else { oy -= height; if (oy + height > dpy_yl) oy = dpy_yl - height; if (oy < 0) oy = 0; } if (ox + width > dpy_xl) ox = dpy_xl - width; if (ox < 0) ox = 0; } else if (icon_main) { GdkRectangle rect; GtkOrientation ori; if (gtk_status_icon_get_geometry(icon_main, NULL, &rect, &ori)) { dbg("rect %d,%d\n", rect.x, rect.y, rect.width, rect.height); if (ori==GTK_ORIENTATION_HORIZONTAL) { ox=rect.x; if (rect.y > 100) oy=rect.y - height; else oy=rect.y + rect.height; } else { oy=rect.y; if (rect.x > 100) ox=rect.x - width; else ox=rect.x + rect.width; } } } if (ox < 0) { ox = dpy_xl - width; oy = dpy_yl - height; } gtk_window_move(GTK_WINDOW(gwin_message), ox, oy); g_timeout_add(duration, (GSourceFunc)timeout_destroy_window, gwin_message); }