[gnome-music/wip/mschraal/gtk4: 54/80] WIP: covers



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

    WIP: covers

 gnomemusic/albumartcache.py      | 16 ++++---
 gnomemusic/coverpaintable.py     | 94 ++++++++++++++++++++++++++++++++++++++++
 gnomemusic/widgets/coverstack.py | 11 ++---
 3 files changed, 111 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index cc3d2796..37115a5f 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -33,6 +33,7 @@ gi.require_version('MediaArt', '2.0')
 from gi.repository import (Gdk, GdkPixbuf, Gio, GLib, GObject, Gtk, MediaArt,
                            Gst, GstTag, GstPbutils)
 
+from gnomemusic.coverpaintable import CoverPaintable
 from gnomemusic.musiclogger import MusicLogger
 
 
@@ -128,13 +129,14 @@ class DefaultIcon(GObject.GObject):
         super().__init__()
 
     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
 
     def get(self, icon_type, art_size, scale=1):
         """Returns the requested symbolic icon
@@ -195,6 +197,8 @@ class Art(GObject.GObject):
         except AttributeError:
             self._url = None
         self._surface = None
+        self.texture = None
+        self.pixbuf = None
         self._scale = scale
 
     def lookup(self):
@@ -220,6 +224,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 b5a837c2..1b1d2983 100644
--- a/gnomemusic/widgets/coverstack.py
+++ b/gnomemusic/widgets/coverstack.py
@@ -52,6 +52,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()
 
@@ -82,9 +83,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
 
     def update(self, coresong):
         """Update the stack with the given CoreSong
@@ -120,10 +121,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]