[gnome-music/wip/mschraal/gtk4: 140/143] WIP: covers



commit 71b38c5de6561920c0af1f0e3d4366fa5879747b
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Nov 8 11:50:37 2019 +0100

    WIP: covers

 data/ui/AlbumCover.ui            |  1 +
 gnomemusic/albumartcache.py      | 16 ++++---
 gnomemusic/coverpaintable.py     | 94 ++++++++++++++++++++++++++++++++++++++++
 gnomemusic/widgets/coverstack.py | 11 ++---
 4 files changed, 112 insertions(+), 10 deletions(-)
---
diff --git a/data/ui/AlbumCover.ui b/data/ui/AlbumCover.ui
index eaabd899..8d64a2d8 100644
--- a/data/ui/AlbumCover.ui
+++ b/data/ui/AlbumCover.ui
@@ -19,6 +19,7 @@
               <object class="GtkBox" id="_events">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="halign">center</property>
 <!--
                 <signal name="button-release-event" handler="_on_album_event" swapped="no"/>
 -->
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index 2e74e8e9..39609273 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -35,6 +35,7 @@ from gi.repository import (Gdk, GdkPixbuf, Gio, GLib, GObject, Gtk, MediaArt,
                            Gst, GstTag, GstPbutils)
 
 from gnomemusic import log
+from gnomemusic.coverpaintable import CoverPaintable
 
 
 logger = logging.getLogger(__name__)
@@ -139,13 +140,14 @@ class DefaultIcon(GObject.GObject):
 
     @log
     def _make_default_icon(self, icon_type, art_size, scale):
-        icon_info = self._default_theme.lookup_icon_for_scale(
-            icon_type.value, art_size.width / 3, scale, 0)
-        icon = icon_info.load_surface()
+        # icon_info = self._default_theme.lookup_icon_for_scale(
+        #     icon_type.value, art_size.width / 3, scale, 0)
+        # icon = icon_info.load_surface()
 
-        icon_surface = _make_icon_frame(icon, art_size, scale, True)
+        # icon_surface = _make_icon_frame(icon, art_size, scale, True)
 
-        return icon_surface
+        icon = CoverPaintable(art_size)
+        return icon
 
     @log
     def get(self, icon_type, art_size, scale=1):
@@ -211,6 +213,8 @@ class Art(GObject.GObject):
         except AttributeError:
             self._url = None
         self._surface = None
+        self.texture = None
+        self.pixbuf = None
         self._scale = scale
 
     @log
@@ -239,6 +243,8 @@ class Art(GObject.GObject):
         surface = None
         # surface = _make_icon_frame(surface, self._size, self._scale)
         self._surface = surface
+        # self.texture = Gdk.Texture.new_for_pixbuf(pixbuf)
+        self.pixbuf = pixbuf
 
         self.emit('finished')
 
diff --git a/gnomemusic/coverpaintable.py b/gnomemusic/coverpaintable.py
new file mode 100644
index 00000000..df86f021
--- /dev/null
+++ b/gnomemusic/coverpaintable.py
@@ -0,0 +1,94 @@
+from math import pi
+
+import gi
+gi.require_versions({"Gdk": "4.0", "Gtk": "4.0"})
+from gi.repository import Gtk, GObject, Graphene, Gdk
+
+# from gnomemusic.albumartcache import Art
+
+
+class CoverPaintable(GObject.GObject, Gdk.Paintable):
+
+    __gtype_name__ = "CoverPaintable"
+
+    def __init__(self, art_size):
+        super().__init__()
+
+        self._art_size = art_size
+        print("CoverPaintable")
+
+    def do_snapshot(self, snapshot, width, height):
+        width = self._art_size.width
+        height = self._art_size.height
+        w = width
+        h = height
+
+        border = 3
+        degrees = pi / 180
+        radius = 3
+
+        theme = Gtk.IconTheme.get_default()
+
+        pixbuf = theme.load_icon("content-loading-symbolic", w, 0)
+        rect = Graphene.Rect().init(0, 0, width, height)
+        snapshot.append_texture(pixbuf, rect)
+
+
+        size = min(width, height)
+
+        cr = snapshot.append_cairo(Graphene.Rect().init(
+            (width - size) / 2.0, (height - size) / 2.0, size, size))
+
+        # draw outline
+        cr.new_sub_path()
+        cr.arc(w - radius, radius, radius - 0.5, -90 * degrees, 0 * degrees)
+        cr.arc(w - radius, h - radius, radius - 0.5, 0 * degrees, 90 * degrees)
+        cr.arc(radius, h - radius, radius - 0.5, 90 * degrees, 180 * degrees)
+        cr.arc(radius, radius, radius - 0.5, 180 * degrees, 270 * degrees)
+        cr.close_path()
+        cr.set_line_width(0.6)
+        cr.set_source_rgba(0, 0, 0, 0.7)
+        cr.stroke_preserve()
+
+        cr.set_source_rgb(1, 1, 1)
+        cr.fill()
+        cr.set_source_rgba(0, 0, 0, 0.3)
+        #ctx.mask_surface(icon_surface, w / 3, h / 3)
+        cr.fill()
+        # Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0)
+        color = Gdk.RGBA(red=0.9, green=0.75, blue=0.75, alpha=.5)
+        color.red = 0.9
+        color.alpha = 1.0
+        rect = Graphene.Rect().init(0, 0, width, height)
+
+        pixbuf = theme.load_icon("content-loading-symbolic", w, 0)
+        rect = Graphene.Rect().init(0 + border, 0 + border, width - border, height - border)
+        snapshot.append_texture(pixbuf, rect)
+        # snapshot.append_color(color, rect)
+
+        # size = min(width, height)
+
+        # cr = snapshot.append_cairo(Graphene.Rect().init(
+        #     (width - size) / 2.0, (height - size) / 2.0, size, size))
+
+        # cr.translate(width / 2.0, height / 2.0)
+        # cr.scale(size, size)
+        # cr.rotate(0.0)
+
+        # PI = 3.14159
+        # cr.arc(0, 0, 0.1, -PI, PI)
+        # cr.fill()
+
+        # cr.set_line_width(0.3)
+        # cr.set_dash([0.3 * PI / 3], 1.0)
+        # cr.arc(0, 0, 0.3, -PI, PI)
+        # cr.stroke()
+
+    def do_get_flags(self):
+        return Gdk.PaintableFlags.SIZE | Gdk.PaintableFlags.CONTENTS
+
+    def do_get_intrinsic_height(self):
+        return self._art_size.height
+
+    def do_get_intrinsic_width(self):
+        return self._art_size.width
diff --git a/gnomemusic/widgets/coverstack.py b/gnomemusic/widgets/coverstack.py
index 686449c9..b2e0bb13 100644
--- a/gnomemusic/widgets/coverstack.py
+++ b/gnomemusic/widgets/coverstack.py
@@ -61,6 +61,7 @@ class CoverStack(Gtk.Stack):
         self._timeout = None
 
         self._loading_cover = Gtk.Image()
+        self.set_size_request(size.width, size.height)
         self._cover_a = Gtk.Image()
         self._cover_b = Gtk.Image()
 
@@ -89,9 +90,9 @@ class CoverStack(Gtk.Stack):
         """
         self._size = value
 
-        # icon = self._default_icon.get(
-        #     DefaultIcon.Type.LOADING, self.props.size, self.props.scale_factor)
-        # self._loading_cover.props.surface = icon
+        paintable = self._default_icon.get(
+            DefaultIcon.Type.LOADING, self.props.size, self.props.scale_factor)
+        self._loading_cover.props.paintable = paintable
 
     @log
     def update(self, coresong):
@@ -130,10 +131,10 @@ class CoverStack(Gtk.Stack):
             self._timeout = None
 
         if self._active_child == "B":
-            # self._cover_a.props.surface = klass.surface
+            self._cover_a.set_from_pixbuf(klass.pixbuf)
             self.props.visible_child_name = "A"
         else:
-            # self._cover_b.props.surface = klass.surface
+            self._cover_b.set_from_pixbuf(klass.pixbuf)
             self.props.visible_child_name = "B"
 
         self._active_child = self.props.visible_child_name


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