[gnome-control-center/gbsneto/background: 5/7] background: Use widgets to render slideshow emblem



commit 83257118a1989dd45653356392ca292c44447da6
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed May 22 19:20:58 2019 -0300

    background: Use widgets to render slideshow emblem
    
    Instead of manually rendering it.

 panels/background/cc-background-chooser.c  | 19 +++++++-
 panels/background/cc-background-item.c     | 69 +-----------------------------
 panels/background/cc-background-preview.c  |  5 +++
 panels/background/cc-background-preview.ui | 17 ++++++++
 panels/background/preview.css              |  5 +++
 5 files changed, 46 insertions(+), 69 deletions(-)
---
diff --git a/panels/background/cc-background-chooser.c b/panels/background/cc-background-chooser.c
index 4a8dd23a9..070164ce1 100644
--- a/panels/background/cc-background-chooser.c
+++ b/panels/background/cc-background-chooser.c
@@ -67,8 +67,10 @@ create_widget_func (gpointer model_item,
   g_autoptr(GdkPixbuf) pixbuf = NULL;
   CcBackgroundChooser *self;
   CcBackgroundItem *item;
+  GtkWidget *overlay;
   GtkWidget *child;
   GtkWidget *image;
+  GtkWidget *icon;
 
   self = CC_BACKGROUND_CHOOSER (user_data);
   item = CC_BACKGROUND_ITEM (model_item);
@@ -80,11 +82,26 @@ create_widget_func (gpointer model_item,
   image = gtk_image_new_from_pixbuf (pixbuf);
   gtk_widget_show (image);
 
+  icon = g_object_new (GTK_TYPE_IMAGE,
+                       "icon-name", "slideshow-emblem",
+                       "pixel-size", 16,
+                       "margin", 8,
+                       "halign", GTK_ALIGN_END,
+                       "valign", GTK_ALIGN_END,
+                       "visible", cc_background_item_changes_with_time (item),
+                       NULL);
+  gtk_style_context_add_class (gtk_widget_get_style_context (icon), "slideshow-emblem");
+
+  overlay = gtk_overlay_new ();
+  gtk_container_add (GTK_CONTAINER (overlay), image);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), icon);
+  gtk_widget_show (overlay);
+
   child = g_object_new (GTK_TYPE_FLOW_BOX_CHILD,
                         "halign", GTK_ALIGN_CENTER,
                         "valign", GTK_ALIGN_CENTER,
                         NULL);
-  gtk_container_add (GTK_CONTAINER (child), image);
+  gtk_container_add (GTK_CONTAINER (child), overlay);
   gtk_widget_show (child);
 
   g_object_set_data_full (G_OBJECT (child), "item", g_object_ref (item), g_object_unref);
diff --git a/panels/background/cc-background-item.c b/panels/background/cc-background-item.c
index aa960ef5b..dc8850b66 100644
--- a/panels/background/cc-background-item.c
+++ b/panels/background/cc-background-item.c
@@ -52,7 +52,6 @@ struct _CcBackgroundItem
         guint64          modified;
 
         /* internal */
-        GdkPixbuf       *slideshow_emblem;
         GnomeBG         *bg;
         char            *mime_type;
         int              width;
@@ -88,64 +87,6 @@ static void     cc_background_item_finalize       (GObject               *object
 
 G_DEFINE_TYPE (CcBackgroundItem, cc_background_item, G_TYPE_OBJECT)
 
-static GdkPixbuf *slideshow_emblem = NULL;
-
-static GdkPixbuf *
-get_emblemed_pixbuf (CcBackgroundItem *item, GdkPixbuf *pixbuf, gint scale_factor)
-{
-        int eh;
-        int ew;
-        int h;
-        int w;
-        int x;
-        int y;
-
-        if (item->slideshow_emblem == NULL) {
-                if (slideshow_emblem == NULL) {
-                        g_autoptr(GIcon) icon = NULL;
-                        GtkIconTheme *theme;
-                        g_autoptr(GtkIconInfo) icon_info = NULL;
-                        g_autoptr(GError) error = NULL;
-
-                        icon = g_themed_icon_new ("slideshow-emblem");
-                        theme = gtk_icon_theme_get_default ();
-                        icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme,
-                                                                              icon,
-                                                                              16,
-                                                                              scale_factor,
-                                                                              GTK_ICON_LOOKUP_FORCE_SIZE |
-                                                                              GTK_ICON_LOOKUP_USE_BUILTIN);
-                        if (icon_info == NULL) {
-                                g_warning ("Your icon theme is missing the slideshow-emblem icon, "
-                                           "please file a bug against it");
-                                return g_object_ref (pixbuf);
-                        }
-
-                        slideshow_emblem = gtk_icon_info_load_icon (icon_info, &error);
-                        if (slideshow_emblem == NULL) {
-                                g_warning ("Failed to load slideshow emblem: %s", error->message);
-                                return g_object_ref (pixbuf);
-                        }
-
-                        g_object_add_weak_pointer (G_OBJECT (slideshow_emblem), (gpointer *) 
(&slideshow_emblem));
-                        item->slideshow_emblem = slideshow_emblem;
-                } else {
-                        item->slideshow_emblem = g_object_ref (slideshow_emblem);
-                }
-        }
-
-        eh = gdk_pixbuf_get_height (slideshow_emblem);
-        ew = gdk_pixbuf_get_width (slideshow_emblem);
-        h = gdk_pixbuf_get_height (pixbuf);
-        w = gdk_pixbuf_get_width (pixbuf);
-        x = w - ew;
-        y = h - eh;
-
-        gdk_pixbuf_composite (slideshow_emblem, pixbuf, x, y, ew, eh, x, y, 1.0, 1.0, GDK_INTERP_BILINEAR, 
255);
-
-        return g_object_ref (pixbuf);
-}
-
 static void
 set_bg_properties (CcBackgroundItem *item)
 {
@@ -271,13 +212,7 @@ cc_background_item_get_frame_thumbnail (CcBackgroundItem             *item,
                 }
         }
 
-        if (pixbuf != NULL
-            && frame != -2
-            && gnome_bg_changes_with_time (item->bg)) {
-                retval = get_emblemed_pixbuf (item, pixbuf, scale_factor);
-        } else {
-                retval = g_steal_pointer (&pixbuf);
-       }
+        retval = g_steal_pointer (&pixbuf);
 
         gnome_bg_get_image_size (item->bg,
                                  thumbs,
@@ -856,8 +791,6 @@ cc_background_item_finalize (GObject *object)
         if (item->bg != NULL)
                 g_object_unref (item->bg);
 
-        g_clear_object (&item->slideshow_emblem);
-
         G_OBJECT_CLASS (cc_background_item_parent_class)->finalize (object);
 }
 
diff --git a/panels/background/cc-background-preview.c b/panels/background/cc-background-preview.c
index 412f22238..45569721d 100644
--- a/panels/background/cc-background-preview.c
+++ b/panels/background/cc-background-preview.c
@@ -24,6 +24,7 @@ struct _CcBackgroundPreview
 {
   GtkBox            parent;
 
+  GtkWidget        *animated_background_icon;
   GtkLabel         *desktop_clock_label;
   GtkWidget        *drawing_area;
   GtkLabel         *lock_screen_label;
@@ -272,6 +273,7 @@ cc_background_preview_class_init (CcBackgroundPreviewClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/background/cc-background-preview.ui");
 
+  gtk_widget_class_bind_template_child (widget_class, CcBackgroundPreview, animated_background_icon);
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundPreview, desktop_clock_label);
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundPreview, drawing_area);
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundPreview, lock_screen_label);
@@ -316,6 +318,9 @@ cc_background_preview_set_item (CcBackgroundPreview *self,
   if (!g_set_object (&self->item, item))
     return;
 
+  gtk_widget_set_visible (self->animated_background_icon,
+                          cc_background_item_changes_with_time (item));
+
   gtk_widget_queue_draw (self->drawing_area);
 
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ITEM]);
diff --git a/panels/background/cc-background-preview.ui b/panels/background/cc-background-preview.ui
index c20b2c3e4..c9a8d61f9 100644
--- a/panels/background/cc-background-preview.ui
+++ b/panels/background/cc-background-preview.ui
@@ -135,6 +135,23 @@
           </object>
         </child>
 
+        <!-- Wallpaper -->
+        <child type="overlay">
+          <object class="GtkImage" id="animated_background_icon">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+            <property name="halign">end</property>
+            <property name="valign">end</property>
+            <property name="margin-end">8</property>
+            <property name="margin-bottom">8</property>
+            <property name="pixel-size">16</property>
+            <property name="icon-name">slideshow-emblem</property>
+            <style>
+              <class name="slideshow-icon" />
+            </style>
+          </object>
+        </child>
+
       </object>
     </child>
   </template>
diff --git a/panels/background/preview.css b/panels/background/preview.css
index f4966eb24..e0ee7d01a 100644
--- a/panels/background/preview.css
+++ b/panels/background/preview.css
@@ -25,3 +25,8 @@ frame.lock-screen-preview label {
   text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
   font-size: 1.2em;
 }
+
+image.slideshow-icon {
+  color: white;
+  -gtk-icon-shadow: 0 1px 2px rgba(0, 0, 0, 0.33);
+}


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