From: Matthias Clasen Date: Wed, 8 Feb 2023 00:40:47 +0000 (-0500) Subject: gtk-demo: Rewrite the zoom demo slightly X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~7^2~20^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=dd3eedd510e5b4a3a2ec7b68a8707b4887eac6c5;p=gtk4.git gtk-demo: Rewrite the zoom demo slightly Use a texture directly instead of a paintable. This will be used in the following commit to introduce filters. --- diff --git a/demos/gtk-demo/demo3widget.c b/demos/gtk-demo/demo3widget.c index 9f8d943d14..abf2a09b63 100644 --- a/demos/gtk-demo/demo3widget.c +++ b/demos/gtk-demo/demo3widget.c @@ -3,7 +3,7 @@ enum { - PROP_PAINTABLE = 1, + PROP_TEXTURE = 1, PROP_SCALE }; @@ -11,7 +11,7 @@ struct _Demo3Widget { GtkWidget parent_instance; - GdkPaintable *paintable; + GdkTexture *texture; float scale; GtkWidget *menu; @@ -36,7 +36,7 @@ demo3_widget_dispose (GObject *object) { Demo3Widget *self = DEMO3_WIDGET (object); - g_clear_object (&self->paintable); + g_clear_object (&self->texture); gtk_widget_dispose_template (GTK_WIDGET (self), DEMO3_TYPE_WIDGET); @@ -54,8 +54,8 @@ demo3_widget_snapshot (GtkWidget *widget, width = gtk_widget_get_width (widget); height = gtk_widget_get_height (widget); - w = self->scale * gdk_paintable_get_intrinsic_width (self->paintable); - h = self->scale * gdk_paintable_get_intrinsic_height (self->paintable); + w = self->scale * gdk_texture_get_width (self->texture); + h = self->scale * gdk_texture_get_height (self->texture); x = MAX (0, (width - ceil (w)) / 2); y = MAX (0, (height - ceil (h)) / 2); @@ -63,7 +63,7 @@ demo3_widget_snapshot (GtkWidget *widget, gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height)); gtk_snapshot_save (snapshot); gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y)); - gdk_paintable_snapshot (self->paintable, snapshot, w, h); + gtk_snapshot_append_texture (snapshot, self->texture, &GRAPHENE_RECT_INIT (0, 0, w, h)); gtk_snapshot_restore (snapshot); gtk_snapshot_pop (snapshot); } @@ -81,9 +81,9 @@ demo3_widget_measure (GtkWidget *widget, int size; if (orientation == GTK_ORIENTATION_HORIZONTAL) - size = gdk_paintable_get_intrinsic_width (self->paintable); + size = gdk_texture_get_width (self->texture); else - size = gdk_paintable_get_intrinsic_height (self->paintable); + size = gdk_texture_get_height (self->texture); *minimum = *natural = self->scale * size; } @@ -113,9 +113,9 @@ demo3_widget_set_property (GObject *object, switch (prop_id) { - case PROP_PAINTABLE: - g_clear_object (&self->paintable); - self->paintable = g_value_dup_object (value); + case PROP_TEXTURE: + g_clear_object (&self->texture); + self->texture = g_value_dup_object (value); gtk_widget_queue_resize (GTK_WIDGET (object)); break; @@ -140,8 +140,8 @@ demo3_widget_get_property (GObject *object, switch (prop_id) { - case PROP_PAINTABLE: - g_value_set_object (value, self->paintable); + case PROP_TEXTURE: + g_value_set_object (value, self->texture); break; case PROP_SCALE: @@ -205,13 +205,13 @@ demo3_widget_class_init (Demo3WidgetClass *class) widget_class->measure = demo3_widget_measure; widget_class->size_allocate = demo3_widget_size_allocate; - g_object_class_install_property (object_class, PROP_PAINTABLE, - g_param_spec_object ("paintable", "Paintable", "Paintable", - GDK_TYPE_PAINTABLE, + g_object_class_install_property (object_class, PROP_TEXTURE, + g_param_spec_object ("texture", NULL, NULL, + GDK_TYPE_TEXTURE, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_SCALE, - g_param_spec_float ("scale", "Scale", "Scale", + g_param_spec_float ("scale", NULL, NULL, 0.0, 10.0, 1.0, G_PARAM_READWRITE)); @@ -229,16 +229,13 @@ GtkWidget * demo3_widget_new (const char *resource) { Demo3Widget *self; - GdkPixbuf *pixbuf; - GdkPaintable *paintable; + GdkTexture *texture; - pixbuf = gdk_pixbuf_new_from_resource (resource, NULL); - paintable = GDK_PAINTABLE (gdk_texture_new_for_pixbuf (pixbuf)); + texture = gdk_texture_new_from_resource (resource); - self = g_object_new (DEMO3_TYPE_WIDGET, "paintable", paintable, NULL); + self = g_object_new (DEMO3_TYPE_WIDGET, "texture", texture, NULL); - g_object_unref (pixbuf); - g_object_unref (paintable); + g_object_unref (texture); return GTK_WIDGET (self); }