[banshee/grid: 29/30] Polished the line logo and artwork background rendering



commit 59d4287bed641333e2e55643741ecbe150d1340f
Author: Aaron Bockover <abockover novell com>
Date:   Tue Dec 15 16:41:14 2009 -0500

    Polished the line logo and artwork background rendering

 .../Banshee.CairoGlyphs/BansheeLineLogo.cs         |   57 ++++++++++++++-----
 .../Banshee.Collection.Gui/ArtworkRenderer.cs      |   12 +++-
 2 files changed, 51 insertions(+), 18 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.CairoGlyphs/BansheeLineLogo.cs b/src/Core/Banshee.ThickClient/Banshee.CairoGlyphs/BansheeLineLogo.cs
index 4d27b12..3ea41b4 100644
--- a/src/Core/Banshee.ThickClient/Banshee.CairoGlyphs/BansheeLineLogo.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.CairoGlyphs/BansheeLineLogo.cs
@@ -35,37 +35,64 @@ namespace Banshee.CairoGlyphs
         private static Color inner_color = Hyena.Gui.CairoExtensions.RgbaToColor (0xddddddff);
         private static Color outer_color = Hyena.Gui.CairoExtensions.RgbaToColor (0xddddddff);
 
-        public static void Render (Context cr, double x, double y, double size)
+        public static void Render (Context cr, Rectangle box)
         {
-            Render (cr, x, y, size, inner_color, outer_color);
+            Render (cr, box, inner_color, outer_color);
         }
 
-        public static void Render (Context cr, double x, double y, double size, Color innerColor, Color outerColor)
+        public static void Render (Context cr, Rectangle box, Color innerColor, Color outerColor)
         {
-            double original_size = 12; // largest dimension as computed in rendering
-            double scale = size / original_size;
-            double pixel_align = Math.Round (scale / 2.0) + (Math.Floor (scale) % 2 == 0 ? 0 : 0.5);
-            double tx = x - pixel_align;
-            double ty = y - pixel_align;
+            Render (cr, box, 0.5, 0.5, innerColor, outerColor);
+        }
+
+        public static void Render (Context cr, Rectangle box,
+            double xalign, double yalign, Color innerColor, Color outerColor)
+        {
+            // virtual size of the figure we will draw below on the 1:1 scale
+            double original_width = 8;
+            double original_height = 12;
+
+            // figure out the scale dimensions of the bounding box and the glyph
+            double box_size = Math.Min (box.Width, box.Height);
+            double original_size = Math.Max (original_width, original_height);
+
+            // create a scale for the box (ratio between virtual glyph size and the box),
+            // then re-scale to account for the extra size that will be added via stroke.
+            // glyph_scale is the stroke width and the actual transformation size
+            double box_scale = box_size / original_size;
+            double glyph_scale = Math.Floor ((box_size - box_scale) / original_size);
+
+            // compute the alignment to the pixel grid for the stroke/scale
+            double pixel_align = Math.Floor (glyph_scale + 0.5) / 2.0;
+
+            // figure out the actual size in pixels of the glyph
+            double actual_width = glyph_scale * original_width + 2 * Math.Floor (pixel_align);
+            double actual_height = glyph_scale * original_height + 2 * Math.Floor (pixel_align);
+
+            // compute the offset accounting for box, grid alignment, and figure alignment
+            double tx = box.X + pixel_align + Math.Round ((box.Width - actual_width) * xalign);
+            double ty = box.Y + pixel_align + Math.Round ((box.Height - actual_height) * yalign);
 
+            // save the context, and transform the current/new context
             cr.Save ();
             cr.Translate (tx, ty);
-            cr.Scale (scale, scale);
+            cr.Scale (glyph_scale, glyph_scale);
 
+            // define how the strokes look
             cr.LineWidth = 1;
             cr.LineCap = LineCap.Round;
             cr.LineJoin = LineJoin.Round;
 
-            // Inner B note
+            // inner 'b' note
             cr.Color = innerColor;
-            cr.MoveTo (1, 2);
-            cr.LineTo (3, 0);
-            cr.Arc (5, 8, 2, Math.PI, Math.PI * 3);
+            cr.MoveTo (0, 2);
+            cr.LineTo (2, 0);
+            cr.Arc (4, 8, 2, Math.PI, Math.PI * 3);
             cr.Stroke ();
 
-            // Outer circle
+            // outer 'cut' circle
             cr.Color = outerColor;
-            cr.Arc (5, 8, 4, Math.PI * 1.5, Math.PI * 1.12);
+            cr.Arc (4, 8, 4, Math.PI * 1.5, Math.PI * 1.12);
             cr.Stroke ();
 
             cr.Restore ();
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkRenderer.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkRenderer.cs
index 91a1358..47e2780 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkRenderer.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkRenderer.cs
@@ -84,10 +84,16 @@ namespace Banshee.Collection.Gui
                 cr.Fill ();
             } else {
                 CairoExtensions.RoundedRectangle (cr, x, y, width, height, radius, corners);
-                cr.Color = CairoExtensions.ColorFromHsb (random.Next (), 54 / 255.0, 102 / 255.0);
+
+                var grad = new LinearGradient (x, y, x, y + height);
+                grad.AddColorStop (0, CairoExtensions.ColorFromHsb (random.Next (), random.Next (50, 150) / 255.0, 0.75));
+                grad.AddColorStop (1, CairoExtensions.ColorFromHsb (random.Next (), random.Next (50, 150) / 255.0, 0.15));
+                cr.Pattern = grad;
                 cr.Fill ();
-                var size = Math.Min (width, height) - 20;
-                Banshee.CairoGlyphs.BansheeLineLogo.Render (cr, x + 18, y + 12, size,
+                grad.Destroy ();
+
+                Banshee.CairoGlyphs.BansheeLineLogo.Render (cr,
+                    new Rectangle (x + 15, y + 15, width - 30, height - 30),
                     CairoExtensions.RgbaToColor (0xffffff55),
                     CairoExtensions.RgbaToColor (0xffffff88));
             }



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