mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 13:11:13 +00:00
demos: Stop using deprecated api
Use texture apis instead of pixbuf ones.
This commit is contained in:
parent
4efc736a6e
commit
6b2c088a29
@ -43,6 +43,7 @@ update_image (void)
|
||||
cairo_t *cr;
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkPixbuf *pixbuf2;
|
||||
GdkTexture *texture;
|
||||
cairo_font_options_t *fopt;
|
||||
cairo_hint_style_t hintstyle;
|
||||
cairo_hint_metrics_t hintmetrics;
|
||||
@ -120,8 +121,17 @@ update_image (void)
|
||||
cairo_destroy (cr);
|
||||
g_object_unref (layout);
|
||||
|
||||
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface));
|
||||
pixbuf2 = gdk_pixbuf_scale_simple (pixbuf, gdk_pixbuf_get_width (pixbuf) * scale, gdk_pixbuf_get_height (pixbuf) * scale, GDK_INTERP_NEAREST);
|
||||
pixbuf = gdk_pixbuf_new_from_data (cairo_image_surface_get_data (surface),
|
||||
GDK_COLORSPACE_RGB, TRUE, 8,
|
||||
cairo_image_surface_get_width (surface),
|
||||
cairo_image_surface_get_height (surface),
|
||||
cairo_image_surface_get_stride (surface),
|
||||
NULL, NULL);
|
||||
|
||||
pixbuf2 = gdk_pixbuf_scale_simple (pixbuf,
|
||||
gdk_pixbuf_get_width (pixbuf) * scale,
|
||||
gdk_pixbuf_get_height (pixbuf) * scale,
|
||||
GDK_INTERP_NEAREST);
|
||||
|
||||
g_object_unref (pixbuf);
|
||||
cairo_surface_destroy (surface);
|
||||
@ -278,14 +288,24 @@ retry:
|
||||
pango_layout_iter_free (iter);
|
||||
g_object_unref (layout);
|
||||
|
||||
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface));
|
||||
pixbuf2 = gdk_pixbuf_scale_simple (pixbuf, gdk_pixbuf_get_width (pixbuf) * scale, gdk_pixbuf_get_height (pixbuf) * scale, GDK_INTERP_NEAREST);
|
||||
pixbuf = gdk_pixbuf_new_from_data (cairo_image_surface_get_data (surface),
|
||||
GDK_COLORSPACE_RGB, TRUE, 8,
|
||||
cairo_image_surface_get_width (surface),
|
||||
cairo_image_surface_get_height (surface),
|
||||
cairo_image_surface_get_stride (surface),
|
||||
NULL, NULL);
|
||||
|
||||
pixbuf2 = gdk_pixbuf_scale_simple (pixbuf,
|
||||
gdk_pixbuf_get_width (pixbuf) * scale,
|
||||
gdk_pixbuf_get_height (pixbuf) * scale,
|
||||
GDK_INTERP_NEAREST);
|
||||
g_object_unref (pixbuf);
|
||||
cairo_surface_destroy (surface);
|
||||
}
|
||||
|
||||
gtk_picture_set_pixbuf (GTK_PICTURE (image), pixbuf2);
|
||||
|
||||
texture = gdk_texture_new_for_pixbuf (pixbuf2);
|
||||
gtk_picture_set_paintable (GTK_PICTURE (image), GDK_PAINTABLE (texture));
|
||||
g_object_unref (pixbuf2);
|
||||
g_object_unref (pixbuf2);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ progressive_prepared_callback (GdkPixbufLoader *loader,
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
GtkWidget *picture;
|
||||
GdkTexture *texture;
|
||||
|
||||
picture = GTK_WIDGET (data);
|
||||
|
||||
@ -40,7 +41,9 @@ progressive_prepared_callback (GdkPixbufLoader *loader,
|
||||
*/
|
||||
gdk_pixbuf_fill (pixbuf, 0xaaaaaaff);
|
||||
|
||||
gtk_picture_set_pixbuf (GTK_PICTURE (picture), pixbuf);
|
||||
texture = gdk_texture_new_for_pixbuf (pixbuf);
|
||||
gtk_picture_set_paintable (GTK_PICTURE (picture), GDK_PAINTABLE (texture));
|
||||
g_object_unref (texture);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -51,22 +54,18 @@ progressive_updated_callback (GdkPixbufLoader *loader,
|
||||
int height,
|
||||
gpointer data)
|
||||
{
|
||||
GtkWidget *picture;
|
||||
GdkPixbuf *pixbuf;
|
||||
GtkWidget *picture = GTK_WIDGET (data);
|
||||
GdkTexture *texture;
|
||||
|
||||
picture = GTK_WIDGET (data);
|
||||
|
||||
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
|
||||
gtk_picture_set_pixbuf (GTK_PICTURE (picture), NULL);
|
||||
gtk_picture_set_pixbuf (GTK_PICTURE (picture), pixbuf);
|
||||
texture = gdk_texture_new_for_pixbuf (gdk_pixbuf_loader_get_pixbuf (loader));
|
||||
gtk_picture_set_paintable (GTK_PICTURE (picture), GDK_PAINTABLE (texture));
|
||||
g_object_unref (texture);
|
||||
}
|
||||
|
||||
static int
|
||||
progressive_timeout (gpointer data)
|
||||
{
|
||||
GtkWidget *picture;
|
||||
|
||||
picture = GTK_WIDGET (data);
|
||||
GtkWidget *picture = GTK_WIDGET (data);
|
||||
|
||||
/* This shows off fully-paranoid error handling, so looks scary.
|
||||
* You could factor out the error handling code into a nice separate
|
||||
|
@ -1210,12 +1210,12 @@ typedef struct {
|
||||
static void
|
||||
add_background (GtkWidget *flowbox,
|
||||
const char *filename,
|
||||
GdkPixbuf *pixbuf,
|
||||
GdkTexture *texture,
|
||||
gboolean is_resource)
|
||||
{
|
||||
GtkWidget *child;
|
||||
|
||||
child = gtk_picture_new_for_pixbuf (pixbuf);
|
||||
child = gtk_picture_new_for_paintable (GDK_PAINTABLE (texture));
|
||||
gtk_widget_set_size_request (child, 110, 70);
|
||||
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1);
|
||||
child = gtk_widget_get_parent (child);
|
||||
@ -1231,6 +1231,7 @@ background_loaded_cb (GObject *source,
|
||||
{
|
||||
BackgroundData *bd = data;
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkTexture *texture;
|
||||
GError *error = NULL;
|
||||
|
||||
pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);
|
||||
@ -1241,8 +1242,11 @@ background_loaded_cb (GObject *source,
|
||||
return;
|
||||
}
|
||||
|
||||
add_background (bd->flowbox, bd->filename, pixbuf, FALSE);
|
||||
texture = gdk_texture_new_for_pixbuf (pixbuf);
|
||||
add_background (bd->flowbox, bd->filename, texture, FALSE);
|
||||
|
||||
g_object_unref (texture);
|
||||
g_object_unref (pixbuf);
|
||||
g_free (bd->filename);
|
||||
g_free (bd);
|
||||
}
|
||||
@ -1259,7 +1263,10 @@ populate_flowbox (GtkWidget *flowbox)
|
||||
GInputStream *stream;
|
||||
BackgroundData *bd;
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkTexture *texture;
|
||||
GtkWidget *child;
|
||||
guchar *data;
|
||||
GBytes *bytes;
|
||||
int i;
|
||||
const char *resources[] = {
|
||||
"sunset.jpg", "portland-rose.jpg", "beach.jpg", "nyc.jpg"
|
||||
@ -1270,9 +1277,14 @@ populate_flowbox (GtkWidget *flowbox)
|
||||
|
||||
g_object_set_data (G_OBJECT (flowbox), "populated", GUINT_TO_POINTER (1));
|
||||
|
||||
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 110, 70);
|
||||
gdk_pixbuf_fill (pixbuf, 0xffffffff);
|
||||
child = gtk_picture_new_for_pixbuf (pixbuf);
|
||||
data = g_malloc (4 * 110 * 70);
|
||||
memset (data, 0xff, 4 * 110 * 70);
|
||||
bytes = g_bytes_new_take (data, 4 * 110 * 70);
|
||||
texture = gdk_memory_texture_new (110, 70, GDK_MEMORY_DEFAULT, bytes, 4 * 110);
|
||||
child = gtk_picture_new_for_paintable (GDK_PAINTABLE (texture));
|
||||
g_object_unref (texture);
|
||||
g_bytes_unref (bytes);
|
||||
|
||||
gtk_widget_add_css_class (child, "frame");
|
||||
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1);
|
||||
|
||||
@ -1280,7 +1292,10 @@ populate_flowbox (GtkWidget *flowbox)
|
||||
{
|
||||
filename = g_strconcat ("/org/gtk/WidgetFactory4/", resources[i], NULL);
|
||||
pixbuf = gdk_pixbuf_new_from_resource_at_scale (filename, 110, 110, TRUE, NULL);
|
||||
add_background (flowbox, filename, pixbuf, TRUE);
|
||||
texture = gdk_texture_new_for_pixbuf (pixbuf);
|
||||
add_background (flowbox, filename, texture, TRUE);
|
||||
g_object_unref (texture);
|
||||
g_object_unref (pixbuf);
|
||||
}
|
||||
|
||||
location = "/usr/share/backgrounds/gnome";
|
||||
|
Loading…
Reference in New Issue
Block a user