[gnome-initial-setup/wip/pwithnall/misc-fixes: 55/70] Add darker border to generated avatar




commit acd2d26bf54d6386da428c80bebdcfa439adc341
Author: Philip Chimento <philip endlessm com>
Date:   Fri Aug 9 10:35:56 2019 -0700

    Add darker border to generated avatar
    
    This was part of the original designs for this feature
    
(https://gitlab.gnome.org/Teams/Design/os-mockups/raw/master/initial-setup/user-account-default-picture.png)
    and makes it look a bit more deliberate if there's no text in the
    avatar.
    
    Upstream: https://gitlab.gnome.org/GNOME/gnome-initial-setup/-/merge_requests/99
    
    https://phabricator.endlessm.com/T27460

 gnome-initial-setup/pages/account/um-utils.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c
index 108fd219..d916e79b 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -532,6 +532,7 @@ generate_username_choices (const gchar  *name,
 }
 
 #define IMAGE_SIZE 512
+#define IMAGE_BORDER_WIDTH 7.2  /* At least 1px when avatar rendered at 72px */
 
 /* U+1F464 "bust in silhouette"
  * U+FE0E Variant Selector 15 to force text style (monochrome) emoji
@@ -631,6 +632,13 @@ get_color_for_name (const gchar *name)
         return color;
 }
 
+static void
+darken_color (GdkRGBA *color, gdouble fraction) {
+        color->red = CLAMP(color->red + color->red * fraction, 0, 255);
+        color->green = CLAMP(color->green + color->green * fraction, 0, 255);
+        color->blue = CLAMP(color->blue + color->blue * fraction, 0, 255);
+}
+
 cairo_surface_t *
 generate_user_picture (const gchar *name) {
         PangoFontDescription *font_desc;
@@ -651,6 +659,13 @@ generate_user_picture (const gchar *name) {
         cairo_set_source_rgb (cr, color.red/255.0, color.green/255.0, color.blue/255.0);
         cairo_fill (cr);
 
+        cairo_arc (cr, IMAGE_SIZE / 2, IMAGE_SIZE / 2, IMAGE_SIZE / 2 - IMAGE_BORDER_WIDTH / 2,
+                   0, 2 * G_PI);
+        darken_color(&color, -0.3);
+        cairo_set_source_rgb (cr, color.red / 255.0, color.green / 255.0, color.blue / 255.0);
+        cairo_set_line_width (cr, IMAGE_BORDER_WIDTH);
+        cairo_stroke (cr);
+
         /* Draw the initials on top */
         cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
         layout = pango_cairo_create_layout (cr);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]