[libadwaita/wip/exalm/warning: 2/4] Code improvements
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/warning: 2/4] Code improvements
- Date: Mon, 1 Nov 2021 09:51:02 +0000 (UTC)
commit a53527237213930971643210fb5c0e7a5d6c690d
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Mon Nov 1 09:55:08 2021 +0100
Code improvements
src/adw-avatar.c | 39 +++++++++++----------------------------
1 file changed, 11 insertions(+), 28 deletions(-)
---
diff --git a/src/adw-avatar.c b/src/adw-avatar.c
index ef74e010..f09b1825 100644
--- a/src/adw-avatar.c
+++ b/src/adw-avatar.c
@@ -50,7 +50,7 @@ struct _AdwAvatar
GtkLabel *label;
GtkImage *icon;
GtkImage *custom_image;
- GdkPaintable *square_image;
+ GdkPaintable *custom_image_source;
char *icon_name;
char *text;
@@ -287,7 +287,7 @@ adw_avatar_finalize (GObject *object)
g_clear_pointer (&self->icon_name, g_free);
g_clear_pointer (&self->text, g_free);
- g_clear_object (&self->square_image);
+ g_clear_object (&self->custom_image_source);
G_OBJECT_CLASS (adw_avatar_parent_class)->finalize (object);
}
@@ -613,44 +613,27 @@ adw_avatar_set_custom_image (AdwAvatar *self,
g_return_if_fail (ADW_IS_AVATAR (self));
g_return_if_fail (custom_image == NULL || GDK_IS_PAINTABLE (custom_image));
- if (gtk_image_get_paintable (self->custom_image) == custom_image)
+ if (self->custom_image_source == custom_image)
return;
- g_clear_object (&self->square_image);
+ self->custom_image_source = custom_image;
if (custom_image) {
- int height, width;
-
- height = gdk_paintable_get_intrinsic_height(custom_image);
- width = gdk_paintable_get_intrinsic_width(custom_image);
+ int height = gdk_paintable_get_intrinsic_height (custom_image);
+ int width = gdk_paintable_get_intrinsic_width (custom_image);
if (height == width) {
gtk_image_set_from_paintable (self->custom_image, custom_image);
} else {
GtkSnapshot *snapshot = gtk_snapshot_new ();
- graphene_point_t* point;
- graphene_size_t* s;
- int size;
-
- if (height > width) {
- size = width;
- } else {
- size = height;
- }
-
- point = graphene_point_init (graphene_point_alloc (), (width - size) / -2.0, (height - size) / -2.0);
- gtk_snapshot_translate (snapshot, point);
+ g_autoptr (GdkPaintable) square_image = NULL;
+ int size = MIN (width, height);
+ gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT ((size - width) / 2.f, (size - height) / 2.f));
gdk_paintable_snapshot (custom_image, snapshot, width, height);
- s = graphene_size_init (graphene_size_alloc (), size, size);
-
- self->square_image = gtk_snapshot_free_to_paintable (snapshot, s);
-
- graphene_point_free (point);
- graphene_size_free (s);
-
- gtk_image_set_from_paintable (self->custom_image, self->square_image);
+ square_image = gtk_snapshot_free_to_paintable (snapshot, &GRAPHENE_SIZE_INIT (size, size));
+ gtk_image_set_from_paintable (self->custom_image, square_image);
}
gtk_widget_add_css_class (self->gizmo, "image");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]