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
This commit is contained in:
parent
3ababb4bf8
commit
d263ce1549
4 changed files with 55 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue