user-accounts: Simplify render_user_icon function
This commit is contained in:
parent
ff6aabb511
commit
c86d1c09c8
1 changed files with 23 additions and 23 deletions
|
@ -32,44 +32,44 @@ struct _CcUserImage {
|
||||||
|
|
||||||
G_DEFINE_TYPE (CcUserImage, cc_user_image, GTK_TYPE_IMAGE)
|
G_DEFINE_TYPE (CcUserImage, cc_user_image, GTK_TYPE_IMAGE)
|
||||||
|
|
||||||
|
static cairo_surface_t *
|
||||||
|
render_rounded (GdkPixbuf *source, gint scale)
|
||||||
|
{
|
||||||
|
g_autoptr(GdkPixbuf) rounded_pixbuf = NULL;
|
||||||
|
rounded_pixbuf = round_image (source);
|
||||||
|
return gdk_cairo_surface_create_from_pixbuf (rounded_pixbuf, scale, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static cairo_surface_t *
|
static cairo_surface_t *
|
||||||
render_user_icon (ActUser *user,
|
render_user_icon (ActUser *user,
|
||||||
gint icon_size,
|
gint icon_size,
|
||||||
gint scale)
|
gint scale)
|
||||||
{
|
{
|
||||||
g_autoptr(GdkPixbuf) source_pixbuf = NULL;
|
const gchar *icon_file;
|
||||||
g_autoptr(GdkPixbuf) avatar_pixbuf = NULL;
|
g_autoptr(GdkPixbuf) default_pixbuf = NULL;
|
||||||
g_autoptr(GdkPixbuf) pixbuf = NULL;
|
|
||||||
const gchar *icon_file;
|
|
||||||
cairo_surface_t *surface = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (ACT_IS_USER (user), NULL);
|
g_return_val_if_fail (ACT_IS_USER (user), NULL);
|
||||||
g_return_val_if_fail (icon_size > 12, NULL);
|
g_return_val_if_fail (icon_size > 12, NULL);
|
||||||
|
|
||||||
icon_file = act_user_get_icon_file (user);
|
icon_file = act_user_get_icon_file (user);
|
||||||
if (icon_file) {
|
if (icon_file) {
|
||||||
source_pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
|
g_autoptr(GdkPixbuf) icon_pixbuf = NULL;
|
||||||
icon_size * scale,
|
|
||||||
icon_size * scale,
|
icon_pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
|
||||||
NULL);
|
icon_size * scale,
|
||||||
if (source_pixbuf)
|
icon_size * scale,
|
||||||
pixbuf = round_image (source_pixbuf);
|
NULL);
|
||||||
|
if (icon_pixbuf) {
|
||||||
|
return render_rounded (icon_pixbuf, scale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pixbuf != NULL) {
|
default_pixbuf = generate_default_avatar (user, icon_size * scale);
|
||||||
goto out;
|
if (default_pixbuf) {
|
||||||
|
return render_rounded (default_pixbuf, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
avatar_pixbuf = generate_default_avatar (user, icon_size * scale);
|
return NULL;
|
||||||
if (avatar_pixbuf)
|
|
||||||
pixbuf = round_image (avatar_pixbuf);
|
|
||||||
out:
|
|
||||||
|
|
||||||
if (pixbuf != NULL) {
|
|
||||||
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return surface;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Reference in a new issue