[gnome-control-center] user-accounts: render user's icons as surface with scale
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user-accounts: render user's icons as surface with scale
- Date: Tue, 20 Jan 2015 16:09:51 +0000 (UTC)
commit 006b5970a63c3e5df6769b61ffc3c75534e948e7
Author: Ondrej Holy <oholy redhat com>
Date: Tue Jan 13 16:31:10 2015 +0100
user-accounts: render user's icons as surface with scale
This patch is needed for future hidpi support.
https://bugzilla.gnome.org/show_bug.cgi?id=742395
panels/user-accounts/um-user-panel.c | 31 +++++++++++++++--------------
panels/user-accounts/um-utils.c | 36 ++++++++++++++++++++-------------
panels/user-accounts/um-utils.h | 5 ++-
3 files changed, 41 insertions(+), 31 deletions(-)
---
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 7b005e2..0b47dc8 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -34,6 +34,7 @@
#include <polkit/polkit.h>
#include <act/act.h>
#include <libgd/gd-notification.h>
+#include <cairo-gobject.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-languages.h>
@@ -190,7 +191,7 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
GtkListStore *store;
GtkTreeIter iter;
GtkTreeIter dummy;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
gchar *text, *title;
GtkTreeSelection *selection;
gint sort_key;
@@ -205,7 +206,7 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
store = GTK_LIST_STORE (model);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
- pixbuf = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48);
+ surface = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48, 1);
text = get_name_col_str (user);
if (act_user_get_uid (user) == getuid ()) {
@@ -219,14 +220,14 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
gtk_list_store_set (store, &iter,
USER_COL, user,
- FACE_COL, pixbuf,
+ FACE_COL, surface,
NAME_COL, text,
USER_ROW_COL, TRUE,
TITLE_COL, NULL,
HEADING_ROW_COL, FALSE,
SORT_KEY_COL, sort_key,
-1);
- g_object_unref (pixbuf);
+ cairo_surface_destroy (surface);
g_free (text);
if (sort_key == 1 &&
@@ -342,7 +343,7 @@ user_changed (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
GtkTreeModel *model;
GtkTreeIter iter;
ActUser *current;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
char *text;
tv = (GtkTreeView *)get_widget (d, "list-treeview");
@@ -353,15 +354,15 @@ user_changed (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
do {
gtk_tree_model_get (model, &iter, USER_COL, ¤t, -1);
if (current == user) {
- pixbuf = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48);
+ surface = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48, 1);
text = get_name_col_str (user);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
USER_COL, user,
- FACE_COL, pixbuf,
+ FACE_COL, surface,
NAME_COL, text,
-1);
- g_object_unref (pixbuf);
+ cairo_surface_destroy (surface);
g_free (text);
g_object_unref (current);
@@ -877,18 +878,18 @@ show_user (ActUser *user, CcUserPanelPrivate *d)
{
GtkWidget *image;
GtkWidget *label;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
gchar *lang, *text, *name;
GtkWidget *widget;
gboolean show, enable;
ActUser *current;
- pixbuf = render_user_icon (user, UM_ICON_STYLE_NONE, 48);
+ surface = render_user_icon (user, UM_ICON_STYLE_NONE, 48, 1);
image = get_widget (d, "user-icon-image");
- gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
+ gtk_image_set_from_surface (GTK_IMAGE (image), surface);
image = get_widget (d, "user-icon-image2");
- gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
- g_object_unref (pixbuf);
+ gtk_image_set_from_surface (GTK_IMAGE (image), surface);
+ cairo_surface_destroy (surface);
um_photo_dialog_set_user (d->photo_dialog, user);
@@ -1569,7 +1570,7 @@ setup_main_window (CcUserPanel *self)
userlist = get_widget (d, "list-treeview");
store = gtk_list_store_new (NUM_USER_LIST_COLS,
ACT_TYPE_USER,
- GDK_TYPE_PIXBUF,
+ CAIRO_GOBJECT_TYPE_SURFACE,
G_TYPE_STRING,
G_TYPE_BOOLEAN,
G_TYPE_STRING,
@@ -1602,7 +1603,7 @@ setup_main_window (CcUserPanel *self)
column = gtk_tree_view_column_new ();
cell = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, FALSE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "pixbuf", FACE_COL);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "surface", FACE_COL);
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "visible", USER_ROW_COL);
cell = gtk_cell_renderer_text_new ();
g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
diff --git a/panels/user-accounts/um-utils.c b/panels/user-accounts/um-utils.c
index c1a1812..34cd0ea 100644
--- a/panels/user-accounts/um-utils.c
+++ b/panels/user-accounts/um-utils.c
@@ -867,7 +867,7 @@ check_user_file (const char *filename,
}
static GdkPixbuf *
-frame_pixbuf (GdkPixbuf *source)
+frame_pixbuf (GdkPixbuf *source, gint scale)
{
GdkPixbuf *dest;
cairo_t *cr;
@@ -877,7 +877,7 @@ frame_pixbuf (GdkPixbuf *source)
int frame_width;
double radius;
- frame_width = 2;
+ frame_width = 2 * scale;
w = gdk_pixbuf_get_width (source) + frame_width * 2;
h = gdk_pixbuf_get_height (source) + frame_width * 2;
@@ -908,7 +908,7 @@ frame_pixbuf (GdkPixbuf *source)
}
static GdkPixbuf *
-logged_in_pixbuf (GdkPixbuf *pixbuf)
+logged_in_pixbuf (GdkPixbuf *pixbuf, gint scale)
{
cairo_format_t format;
cairo_surface_t *surface;
@@ -931,7 +931,8 @@ logged_in_pixbuf (GdkPixbuf *pixbuf)
/* Draw pattern */
cairo_rectangle (cr, 0, 0, width, height);
- pattern = cairo_pattern_create_radial (width - 9.5, height - 10, 0, width - 8.5, height - 7.5, 7.7);
+ pattern = cairo_pattern_create_radial (width - 9.5 * scale, height - 10 * scale, 0,
+ width - 8.5 * scale, height - 7.5 * scale, 7.7 * scale);
cairo_pattern_add_color_stop_rgb (pattern, 0, 0.4, 0.9, 0);
cairo_pattern_add_color_stop_rgb (pattern, 0.7, 0.3, 0.6, 0);
cairo_pattern_add_color_stop_rgb (pattern, 0.8, 0.4, 0.4, 0.4);
@@ -940,8 +941,8 @@ logged_in_pixbuf (GdkPixbuf *pixbuf)
cairo_fill (cr);
/* Draw border */
- cairo_set_line_width (cr, 0.9);
- cairo_arc (cr, width - 8.5, height - 8.5, 6, 0, 2 * G_PI);
+ cairo_set_line_width (cr, 0.9 * scale);
+ cairo_arc (cr, width - 8.5 * scale, height - 8.5 * scale, 6 * scale, 0, 2 * G_PI);
gdk_rgba_parse (&color, "#ffffff");
gdk_cairo_set_source_rgba (cr, &color);
cairo_stroke (cr);
@@ -956,16 +957,18 @@ logged_in_pixbuf (GdkPixbuf *pixbuf)
#define MAX_FILE_SIZE 65536
-GdkPixbuf *
+cairo_surface_t *
render_user_icon (ActUser *user,
UmIconStyle style,
- gint icon_size)
+ gint icon_size,
+ gint scale)
{
GdkPixbuf *pixbuf;
GdkPixbuf *framed;
gboolean res;
GError *error;
const gchar *icon_file;
+ cairo_surface_t *surface = NULL;
g_return_val_if_fail (ACT_IS_USER (user), NULL);
g_return_val_if_fail (icon_size > 12, NULL);
@@ -976,8 +979,8 @@ render_user_icon (ActUser *user,
res = check_user_file (icon_file, MAX_FILE_SIZE);
if (res) {
pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
- icon_size,
- icon_size,
+ icon_size * scale,
+ icon_size * scale,
NULL);
}
else {
@@ -993,7 +996,7 @@ render_user_icon (ActUser *user,
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
"avatar-default",
- icon_size,
+ icon_size * scale,
GTK_ICON_LOOKUP_FORCE_SIZE,
&error);
if (error) {
@@ -1004,7 +1007,7 @@ render_user_icon (ActUser *user,
out:
if (pixbuf != NULL && (style & UM_ICON_STYLE_FRAME)) {
- framed = frame_pixbuf (pixbuf);
+ framed = frame_pixbuf (pixbuf, scale);
if (framed != NULL) {
g_object_unref (pixbuf);
pixbuf = framed;
@@ -1012,14 +1015,19 @@ render_user_icon (ActUser *user,
}
if (pixbuf != NULL && (style & UM_ICON_STYLE_STATUS) && act_user_is_logged_in (user)) {
- framed = logged_in_pixbuf (pixbuf);
+ framed = logged_in_pixbuf (pixbuf, scale);
if (framed != NULL) {
g_object_unref (pixbuf);
pixbuf = framed;
}
}
- return pixbuf;
+ if (pixbuf != NULL) {
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
+ g_object_unref (pixbuf);
+ }
+
+ return surface;
}
void
diff --git a/panels/user-accounts/um-utils.h b/panels/user-accounts/um-utils.h
index 221c5dd..e6a95e8 100644
--- a/panels/user-accounts/um-utils.h
+++ b/panels/user-accounts/um-utils.h
@@ -75,9 +75,10 @@ void generate_username_choices (const gchar *name,
gchar * get_smart_date (GDateTime *date);
-GdkPixbuf * render_user_icon (ActUser *user,
+cairo_surface_t *render_user_icon (ActUser *user,
UmIconStyle style,
- gint icon_size);
+ gint icon_size,
+ gint scale);
void set_user_icon_data (ActUser *user,
GdkPixbuf *pixbuf);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]