banshee r3510 - in trunk/banshee: . src/Clients/Nereid/Nereid src/Core/Banshee.ThickClient/Banshee.Gui src/Core/Banshee.ThickClient/Banshee.Gui.Widgets src/Core/Banshee.ThickClient/Banshee.Sources.Gui src/Core/Banshee.Widgets/Banshee.Widgets src/Libraries/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Data.Gui src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView src/Libraries/Hyena.Gui/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Gui.Theming



Author: abock
Date: Sat Mar 22 00:07:28 2008
New Revision: 3510
URL: http://svn.gnome.org/viewvc/banshee?rev=3510&view=rev

Log:
2008-03-21  Aaron Bockover  <abock gnome org>

    This commit should make Banshee look better on darker themes

    * src/Clients/Nereid/Nereid/Client.cs: Allow ignoring the gtkrc if
    --no-gtkrc is passed; nice for debugging

    * src/Clients/Nereid/Nereid/PlayerInterface.cs: Remove the subtle
    midtone coloring since I can't figure out a reliable way to make it
    work on darker themes and lighter themes; GTK themes seriously suck and
    I hate them and where in the hell is GTK 3. Seriously.

    * src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs:
    Hacky version of the mid tone stuff since it's absolutely necessary here

    * src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs:
    Set a GLib log handler when in --debug mode

    * src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs:
    * src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs:
    Get a proper mid tone using the base and text colors

    * src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs:
    Render text using the foreground, not text colors, like other text that
    should be rendered on background and not base

    * src/Libraries/Hyena.Gui/Hyena.Data.Gui/CellContext.cs:
    * src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs:
    * src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs: Allow
    rendering text in the cell as foreground or text colors

    * src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs:
    Fixed some small rendering/theme issues; do not render a highlight under
    the sorted column since it looks like ass on some themes and I'm tired
    of GTK themes

    * src/Libraries/Hyena.Gui/Hyena.Gui/CairoExtensions.cs:
    * src/Libraries/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs: Add some 
    color foo

    * src/Libraries/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs: Just something
    I'm working on, nothing interesting, never used



Added:
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Clients/Nereid/Nereid/Client.cs
   trunk/banshee/src/Clients/Nereid/Nereid/PlayerInterface.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs
   trunk/banshee/src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs
   trunk/banshee/src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am

Modified: trunk/banshee/src/Clients/Nereid/Nereid/Client.cs
==============================================================================
--- trunk/banshee/src/Clients/Nereid/Nereid/Client.cs	(original)
+++ trunk/banshee/src/Clients/Nereid/Nereid/Client.cs	Sat Mar 22 00:07:28 2008
@@ -37,7 +37,7 @@
             // This could go into GtkBaseClient, but it's probably something we
             // should really only support at each client level
             string user_gtkrc = Path.Combine (Banshee.Base.Paths.ApplicationData, "gtkrc"); 
-            if (File.Exists (user_gtkrc)) {
+            if (File.Exists (user_gtkrc) && !Banshee.Base.ApplicationContext.CommandLine.Contains ("no-gtkrc")) {
                 Gtk.Rc.AddDefaultFile (user_gtkrc);
             } 
             

Modified: trunk/banshee/src/Clients/Nereid/Nereid/PlayerInterface.cs
==============================================================================
--- trunk/banshee/src/Clients/Nereid/Nereid/PlayerInterface.cs	(original)
+++ trunk/banshee/src/Clients/Nereid/Nereid/PlayerInterface.cs	Sat Mar 22 00:07:28 2008
@@ -199,9 +199,7 @@
             footer_toolbar.ToolbarStyle = ToolbarStyle.BothHoriz;
 
             status_label = new Label ();
-            status_label.ModifyFg (StateType.Normal, Hyena.Gui.GtkUtilities.ColorBlend (
-                status_label.Style.Foreground (StateType.Normal), status_label.Style.Background (StateType.Normal)));
-
+            
             Alignment status_align = new Alignment (0.5f, 0.5f, 1.0f, 1.0f);
             status_align.Add (status_label);
 

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/TrackInfoDisplay.cs	Sat Mar 22 00:07:28 2008
@@ -236,9 +236,9 @@
 
         protected override void OnStyleSet (Style previous)
         {
-            text_color = CairoExtensions.GdkColorToCairoColor (Style.Text (StateType.Normal));          
-            text_light_color = CairoExtensions.ColorAdjustBrightness (text_color, 0.5);
+            text_color = CairoExtensions.GdkColorToCairoColor (Style.Foreground (StateType.Normal));
             background_color = CairoExtensions.GdkColorToCairoColor (Style.Background (StateType.Normal));
+            text_light_color = Hyena.Gui.Theming.GtkTheme.GetCairoTextMidColor (this);
             
             if (missing_audio_pixbuf != null) {
                 missing_audio_pixbuf.Dispose ();

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs	Sat Mar 22 00:07:28 2008
@@ -82,6 +82,10 @@
             
             PlatformHacks.GdkSetProgramClass (Application.InternalName);
 
+            if (ApplicationContext.Debugging) {
+                GLib.Log.SetLogHandler ("Gtk", GLib.LogLevelFlags.Critical, GLib.Log.PrintTraceLogFunction);
+            }
+            
             ServiceManager.ServiceStarted += OnServiceStarted;
             
             // Register specific services this client will care about

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs	Sat Mar 22 00:07:28 2008
@@ -162,8 +162,8 @@
                 
             Gdk.GC mod_gc = widget.Style.TextGC (state);
             if (!state.Equals (StateType.Selected)) {
-                Gdk.Color fgcolor = widget.Style.Foreground (state);
-                Gdk.Color bgcolor = widget.Style.Background (state);
+                Gdk.Color fgcolor = widget.Style.Base (state);
+                Gdk.Color bgcolor = widget.Style.Text (state);
                 
                 mod_gc = new Gdk.GC (drawable);
                 mod_gc.Copy (widget.Style.TextGC (state));

Modified: trunk/banshee/src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Widgets/Banshee.Widgets/SearchEntry.cs	Sat Mar 22 00:07:28 2008
@@ -426,8 +426,8 @@
 
                 text_gc = new Gdk.GC(text_window);
                 text_gc.Copy(Style.TextGC(StateType.Normal));
-                Gdk.Color color_a = parent.Style.Foreground(StateType.Normal);
-                Gdk.Color color_b = parent.Style.Background(StateType.Normal);
+                Gdk.Color color_a = parent.Style.Base(StateType.Normal);
+                Gdk.Color color_b = parent.Style.Text(StateType.Normal);
                 text_gc.RgbFgColor = DrawingUtilities.ColorBlend(color_a, color_b, 0.5);
             }
 

Modified: trunk/banshee/src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Widgets/Banshee.Widgets/StreamPositionLabel.cs	Sat Mar 22 00:07:28 2008
@@ -102,7 +102,7 @@
                 rect.Width = evnt.Area.Width - rect.Width;
             }
             
-            Gtk.Style.PaintLayout (Style, GdkWindow, StateType.Normal, true, rect, this, null, x, y, layout);
+            Gtk.Style.PaintLayout (Style, GdkWindow, StateType.Normal, false, rect, this, null, x, y, layout);
             
             return true;
         }

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/CellContext.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/CellContext.cs	Sat Mar 22 00:07:28 2008
@@ -41,6 +41,7 @@
         private Theme theme;
         private Gdk.Rectangle area;
         private Gdk.Rectangle clip;
+        private bool text_as_foreground = false;
         
         public CellContext (Cairo.Context context, Pango.Layout layout, Gtk.Widget widget,
             Gdk.Drawable drawable, Theme theme, Gdk.Rectangle area, Gdk.Rectangle clip)
@@ -81,5 +82,10 @@
         public Gdk.Rectangle Clip {
             get { return clip; }
         }
+        
+        public bool TextAsForeground {
+            get { return text_as_foreground; }
+            set { text_as_foreground = value; }
+        }
     }
 }

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs	Sat Mar 22 00:07:28 2008
@@ -62,19 +62,18 @@
             if (use_cairo_pango) {
                 context.Context.MoveTo (4, ((int)cellHeight - text_height) / 2);
                 PangoCairoHelper.LayoutPath (context.Context, context.Layout);
-                context.Context.Color = context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state);
+                context.Context.Color = context.Theme.Colors.GetWidgetColor (
+                    context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, state);
                 context.Context.Fill ();
             } else {
-                Style.PaintLayout (context.Widget.Style, context.Drawable, state, true, context.Clip,
-                    context.Widget, "text", context.Area.X + 4, context.Area.Y + (((int)cellHeight - text_height) / 2),
-                    context.Layout);
+                Style.PaintLayout (context.Widget.Style, context.Drawable, state, !context.TextAsForeground, 
+                    context.Clip, context.Widget, "text", context.Area.X + 4, 
+                    context.Area.Y + (((int)cellHeight - text_height) / 2), context.Layout);
             }
         }
         
         protected virtual string Text {
-            get {
-                return BoundObject == null ? String.Empty : BoundObject.ToString();
-            }
+            get { return BoundObject == null ? String.Empty : BoundObject.ToString(); }
         }
         
         protected int TextWidth {

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs	Sat Mar 22 00:07:28 2008
@@ -46,22 +46,23 @@
     
         public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
         {
-            if(data_handler == null) {
+            if (data_handler == null) {
                 return;
             }
             
+            context.TextAsForeground = true;
+            
             if (!has_sort) {
                 base.Render (context, state, cellWidth - 10, cellHeight);
                 return;
             }
             
             Gdk.Rectangle alloc = new Gdk.Rectangle ();
-            alloc.Width = (int)(cellHeight / 3.5);
+            alloc.Width = (int)(cellHeight / 3.0);
             alloc.Height = (int)((double)alloc.Width / 1.6);
             alloc.X = (int)cellWidth - alloc.Width - 10;
             alloc.Y = ((int)cellHeight - alloc.Height) / 2;
             
-            context.Theme.DrawColumnHighlight (context.Context, cellWidth, cellHeight);
             base.Render (context, state, cellWidth - 2 * alloc.Width - 10, cellHeight);
             context.Theme.DrawArrow (context.Context, alloc, ((ISortableColumn)data_handler ()).SortType);
         }

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs	Sat Mar 22 00:07:28 2008
@@ -210,6 +210,15 @@
             // Render the background to the primary canvas.
             Theme.DrawListBackground (cairo_context, canvas_alloc, true);
             
+            for (int ci = 0; ci < column_cache.Length; ci++) {
+                ColumnHeaderCellText cell = column_cache[ci].Column.HeaderCell as ColumnHeaderCellText;
+                if (cell != null && cell.HasSort) {
+                    cairo_context.Rectangle (column_cache[ci].X1, list_rendering_alloc.Y, column_cache[ci].Width, list_rendering_alloc.Height);
+                    cairo_context.Color = new Cairo.Color (0, 0, 0, 0.2);
+                    cairo_context.Fill ();
+                }
+            }
+            
             int first_row = top;
             int last_row = bottom;
             int first_row_y = 0;
@@ -220,7 +229,7 @@
                 // We're scrolling down, so shift the contents of the list up and
                 // render the new stuff in situ at the bottom.
                 int delta = (last_row - canvas_last_row) * RowHeight;
-                canvas1.DrawDrawable (Style.WhiteGC, canvas2, 0, delta, 0, 0,
+                canvas1.DrawDrawable (Style.BaseGC (StateType.Normal), canvas2, 0, delta, 0, 0,
                     list_rendering_alloc.Width, rows_in_view - delta);
                 
                 // If the bottom of the stuff we're shifting up is part of a selection
@@ -236,7 +245,7 @@
                 // We're scrolling up, so shift the contents of the list down and
                 // render the new stuff in situ at the top.
                 int delta = (canvas_first_row - first_row) * RowHeight;
-                canvas1.DrawDrawable (Style.WhiteGC, canvas2, 0, 0, 0, delta,
+                canvas1.DrawDrawable (Style.BaseGC (StateType.Normal), canvas2, 0, 0, 0, delta,
                     list_rendering_alloc.Width, rows_in_view - delta);
                 
                 // If the top of the stuff we're shifting down is part of a selection
@@ -414,8 +423,8 @@
                 GtkColorClass.Base, StateType.Normal), 0.0);
             stroke_color.A = 0.3;
             
-            cairo_context.Rectangle (x, header_rendering_alloc.Bottom, column.Width - 2,
-                list_rendering_alloc.Bottom - header_rendering_alloc.Bottom);
+            cairo_context.Rectangle (x, header_rendering_alloc.Bottom + 1, column.Width - 2,
+                list_rendering_alloc.Bottom - header_rendering_alloc.Bottom - 1);
             cairo_context.Color = fill_color;
             cairo_context.Fill ();
             

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs	Sat Mar 22 00:07:28 2008
@@ -40,6 +40,24 @@
         public GtkTheme (Widget widget) : base (widget)
         {
         }
+        
+        public static Cairo.Color GetCairoTextMidColor (Widget widget)
+        {
+            Cairo.Color text_color = CairoExtensions.GdkColorToCairoColor (widget.Style.Foreground (StateType.Normal));
+            Cairo.Color background_color = CairoExtensions.GdkColorToCairoColor (widget.Style.Background (StateType.Normal));
+            // This is lame
+            Cairo.Color c = CairoExtensions.ColorAdjustBrightness (text_color, 
+                CairoExtensions.ColorIsDark (background_color) ? 0.65 : 0.5);
+            return c;
+        }
+        
+        public static Gdk.Color GetGdkTextMidColor (Widget widget)
+        {
+            Cairo.Color color = GetCairoTextMidColor (widget);
+            Gdk.Color gdk_color = new Gdk.Color ((byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255));
+            Gdk.Colormap.System.AllocColor (ref gdk_color, true, true);
+            return gdk_color;
+        }
 
         protected override void OnColorsRefreshed ()
         {
@@ -85,11 +103,11 @@
         public override void DrawArrow (Context cr, Gdk.Rectangle alloc, Hyena.Data.SortType type)
         {
             cr.Translate (0.5, 0.5);
-            int x1 = alloc.X;
-            int x3 = alloc.X + alloc.Width / 2;
-            int x2 = x3 + (x3 - x1);
-            int y1 = alloc.Y;
-            int y2 = alloc.Bottom;
+            double x1 = alloc.X;
+            double x3 = alloc.X + alloc.Width / 2.0;
+            double x2 = x3 + (x3 - x1);
+            double y1 = alloc.Y;
+            double y2 = alloc.Bottom;
             
             if (type == Hyena.Data.SortType.Ascending) {
                 cr.MoveTo (x1, y1);
@@ -103,9 +121,9 @@
                 cr.LineTo (x3, y1);
             }
             
-            cr.Color = new Color (1, 1, 1, 0.4);
+            cr.Color = Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
             cr.FillPreserve ();
-            cr.Color = new Color (0, 0, 0, 1);
+            cr.Color = border_color;
             cr.Stroke ();
             cr.Translate (-0.5, -0.5);
         }
@@ -128,6 +146,20 @@
             cr.Stroke();
         }
         
+        public override void DrawColumnHighlight (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color)
+        {
+            Cairo.Color light_color = CairoExtensions.ColorShade (color, 1.6);
+            Cairo.Color dark_color = CairoExtensions.ColorShade (color, 1.3);
+            
+            LinearGradient grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom - 1);
+            grad.AddColorStop (0, light_color);
+            grad.AddColorStop (1, dark_color);
+            
+            cr.Pattern = grad;
+            cr.Rectangle (alloc.X + 1.5, alloc.Y + 1.5, alloc.Width - 3, alloc.Height - 2);
+            cr.Fill();
+        }
+
         public override void DrawHeaderBackground (Cairo.Context cr, Gdk.Rectangle alloc)
         {
             Cairo.Color gtk_background_color = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal);
@@ -182,20 +214,6 @@
             cr.Rectangle (alloc.X, alloc.Y, alloc.Width, alloc.Height);
             cr.Fill ();
         }
-
-        public override void DrawColumnHighlight (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color)
-        {
-            Cairo.Color light_color = CairoExtensions.ColorShade (color, 1.6);
-            Cairo.Color dark_color = CairoExtensions.ColorShade (color, 1.3);
-            
-            LinearGradient grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom - 1);
-            grad.AddColorStop (0, light_color);
-            grad.AddColorStop (1, dark_color);
-            
-            cr.Pattern = grad;
-            cr.Rectangle (alloc.X + 1.5, alloc.Y + 1.5, alloc.Width - 3, alloc.Height - 2);
-            cr.Fill();
-        }
         
         public override void DrawRowSelection (Cairo.Context cr, int x, int y, int width, int height,
             bool filled, bool stroked, Cairo.Color color, CairoCorners corners)

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp	Sat Mar 22 00:07:28 2008
@@ -59,6 +59,7 @@
     <File name="Hyena.Widgets/AnimatedVBox.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Widgets/AnimatedWidget.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Gui.Theatrics/Choreographer.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Gui/ShadingTestWindow.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/CairoExtensions.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/CairoExtensions.cs	Sat Mar 22 00:07:28 2008
@@ -47,7 +47,7 @@
     }
     
     public static class CairoExtensions
-    {        
+    {
         public static Cairo.Color GdkColorToCairoColor(Gdk.Color color)
         {
             return GdkColorToCairoColor(color, 1.0);
@@ -62,6 +62,13 @@
                 alpha);
         }
         
+        public static bool ColorIsDark (Cairo.Color color)
+        {
+            double h, s, b;
+            HsbFromColor (color, out h, out s, out b);
+            return b < 0.5;
+        }
+        
         public static void HsbFromColor(Cairo.Color color, out double hue, 
             out double saturation, out double brightness)
         {

Added: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs	Sat Mar 22 00:07:28 2008
@@ -0,0 +1,83 @@
+//
+// ShadingTestWindow.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Gtk;
+
+namespace Hyena.Gui
+{
+    public class ShadingTestWindow : Window
+    {
+        private int steps = 16;
+    
+        public ShadingTestWindow () : base ("Shading Test")
+        {
+            SetSizeRequest (512, 512);
+        }
+        
+        protected override bool OnExposeEvent (Gdk.EventExpose evnt)
+        {
+            Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window);
+            
+            double step_width = Allocation.Width / (double)steps;
+            double step_height = Allocation.Height / (double)steps;
+            double h = 1.0;
+            double s = 0.0;
+            
+            for (int xi = 0, i = 0; xi < steps; xi++) {
+                for (int yi = 0; yi < steps; yi++, i++) {
+                    double bg_b = (double)(i / 255.0);
+                    double fg_b = 1.0 - bg_b;
+                    
+                    double x = Allocation.X + xi * step_width;
+                    double y = Allocation.Y + yi * step_height;
+                
+                    cr.Rectangle (x, y, step_width, step_height);
+                    cr.Color = CairoExtensions.ColorFromHsb (h, s, bg_b);
+                    cr.Fill ();
+                    
+                    int tw, th;
+                    Pango.Layout layout = new Pango.Layout (PangoContext);
+                    layout.SetText (((int)(bg_b * 255.0)).ToString ());
+                    layout.GetPixelSize (out tw, out th);
+                    
+                    cr.Translate (0.5, 0.5);
+                    cr.MoveTo (x + (step_width - tw) / 2.0, y + (step_height - th) / 2.0);
+                    PangoCairoHelper.LayoutPath (cr, layout);
+                    cr.Color = CairoExtensions.ColorFromHsb (h, s, fg_b);
+                    cr.Fill ();
+                    cr.Translate (-0.5, -0.5);
+                }
+            }
+            
+            CairoExtensions.DisposeContext (cr);
+            return true;
+        }
+
+    }
+}

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am	Sat Mar 22 00:07:28 2008
@@ -36,6 +36,7 @@
 	Hyena.Gui/EntryUndoAdapter.cs \
 	Hyena.Gui/GtkUtilities.cs \
 	Hyena.Gui/PangoCairoHelper.cs \
+	Hyena.Gui/ShadingTestWindow.cs \
 	Hyena.Query.Gui/DateQueryValueEntry.cs \
 	Hyena.Query.Gui/FileSizeQueryValueEntry.cs \
 	Hyena.Query.Gui/IntegerQueryValueEntry.cs \



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