[gnome-control-center/wip/feborges/round-and-generate-user-images: 2/4] user-accounts: Round all user images
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/feborges/round-and-generate-user-images: 2/4] user-accounts: Round all user images
- Date: Wed, 6 Feb 2019 11:54:12 +0000 (UTC)
commit d263ce15499e087739869f23ac6345383a6144e3
Author: Felipe Borges <felipeborges gnome org>
Date: Mon Feb 4 15:27:19 2019 +0000
user-accounts: Round all user images
This is part of the effort in [0] to standardize the way we display
user images accross GNOME. Images are now going to be rounded and
borderless.
See https://gitlab.gnome.org/GNOME/Initiatives/issues/6
panels/user-accounts/cc-avatar-chooser.c | 21 ++++++++++++++++-----
panels/user-accounts/cc-user-image.c | 14 +++++++++-----
panels/user-accounts/user-utils.c | 28 ++++++++++++++++++++++++++++
panels/user-accounts/user-utils.h | 3 ++-
4 files changed, 55 insertions(+), 11 deletions(-)
---
diff --git a/panels/user-accounts/cc-avatar-chooser.c b/panels/user-accounts/cc-avatar-chooser.c
index 7b568ce6e..ca3c8d967 100644
--- a/panels/user-accounts/cc-avatar-chooser.c
+++ b/panels/user-accounts/cc-avatar-chooser.c
@@ -39,6 +39,7 @@
#include "cc-avatar-chooser.h"
#include "cc-crop-area.h"
+#include "user-utils.h"
#define ROW_SPAN 5
#define AVATAR_PIXEL_SIZE 80
@@ -397,18 +398,28 @@ static GtkWidget *
create_face_widget (gpointer item,
gpointer user_data)
{
+ g_autofree gchar *image_path = NULL;
+ g_autoptr(GdkPixbuf) source_pixbuf = NULL;
+ g_autoptr(GdkPixbuf) pixbuf = NULL;
GtkWidget *image;
- GIcon *icon;
- icon = g_file_icon_new (G_FILE (item));
- image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
+ image_path = g_file_get_path (G_FILE (item));
+
+ source_pixbuf = gdk_pixbuf_new_from_file_at_size (image_path,
+ AVATAR_PIXEL_SIZE,
+ AVATAR_PIXEL_SIZE,
+ NULL);
+ if (source_pixbuf == NULL)
+ return NULL;
+
+ pixbuf = round_image (source_pixbuf, AVATAR_PIXEL_SIZE);
+ image = gtk_image_new_from_pixbuf (pixbuf);
gtk_image_set_pixel_size (GTK_IMAGE (image), AVATAR_PIXEL_SIZE);
- g_object_unref (icon);
gtk_widget_show (image);
g_object_set_data (G_OBJECT (image),
- "filename", g_file_get_path (G_FILE (item)));
+ "filename", image_path);
return image;
}
diff --git a/panels/user-accounts/cc-user-image.c b/panels/user-accounts/cc-user-image.c
index 79fefc7cb..a8197c369 100644
--- a/panels/user-accounts/cc-user-image.c
+++ b/panels/user-accounts/cc-user-image.c
@@ -22,6 +22,8 @@
#include <act/act.h>
#include <sys/stat.h>
+#include "user-utils.h"
+
struct _CcUserImage {
GtkImage parent_instance;
@@ -68,7 +70,8 @@ render_user_icon (ActUser *user,
gint icon_size,
gint scale)
{
- GdkPixbuf *pixbuf;
+ g_autoptr(GdkPixbuf) source_pixbuf = NULL;
+ GdkPixbuf *pixbuf = NULL;
gboolean res;
GError *error;
const gchar *icon_file;
@@ -82,10 +85,11 @@ render_user_icon (ActUser *user,
if (icon_file) {
res = check_user_file (icon_file, MAX_FILE_SIZE);
if (res) {
- pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
- icon_size * scale,
- icon_size * scale,
- NULL);
+ source_pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
+ icon_size * scale,
+ icon_size * scale,
+ NULL);
+ pixbuf = round_image (source_pixbuf, icon_size * scale);
}
else {
pixbuf = NULL;
diff --git a/panels/user-accounts/user-utils.c b/panels/user-accounts/user-utils.c
index 1aafe82e0..70e578887 100644
--- a/panels/user-accounts/user-utils.c
+++ b/panels/user-accounts/user-utils.c
@@ -441,3 +441,31 @@ is_valid_username (const gchar *username, gchar **tip)
return valid;
}
+
+GdkPixbuf *
+round_image (GdkPixbuf *pixbuf,
+ gint icon_size)
+{
+ GdkPixbuf *dest = NULL;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ gint size;
+
+ size = gdk_pixbuf_get_width (pixbuf);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
+ cr = cairo_create (surface);
+
+ /* Clip a circle */
+ cairo_arc (cr, size/2, size/2, size/2, 0, 2 * G_PI);
+ cairo_clip (cr);
+ cairo_new_path (cr);
+
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+ cairo_paint (cr);
+
+ dest = gdk_pixbuf_get_from_surface (surface, 0, 0, size, size);
+ cairo_surface_destroy (surface);
+ cairo_destroy (cr);
+
+ return dest;
+}
diff --git a/panels/user-accounts/user-utils.h b/panels/user-accounts/user-utils.h
index be31a5776..2c49524c3 100644
--- a/panels/user-accounts/user-utils.h
+++ b/panels/user-accounts/user-utils.h
@@ -42,5 +42,6 @@ gboolean is_username_used (const gchar *username);
gboolean is_valid_name (const gchar *name);
gboolean is_valid_username (const gchar *name,
gchar **tip);
-
+GdkPixbuf *round_image (GdkPixbuf *pixbuf,
+ gint icon_size);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]