[billreminder/fresh] Some fixes on color manipulation.



commit dfc51565c1b43f5479de27c88f13fbe73aa161b1
Author: Luiz Armesto <luiz armesto gmail com>
Date:   Tue Jan 26 00:05:49 2010 -0200

    Some fixes on color manipulation.

 src/gui/widgets/charting.py |    2 +-
 src/gui/widgets/graphics.py |   14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/src/gui/widgets/charting.py b/src/gui/widgets/charting.py
index 24ecd60..cd106d7 100644
--- a/src/gui/widgets/charting.py
+++ b/src/gui/widgets/charting.py
@@ -630,7 +630,7 @@ class HorizontalBarChart(Chart):
                 if i in self.bars_selected:
                     last_color = self.get_style().bg[gtk.STATE_SELECTED].to_string()
                 elif i == self.mouse_bar:
-                    last_color = self.get_style().base[gtk.STATE_PRELIGHT].to_string()
+                    last_color = self.colors.darker(self.key_colors.get(self.keys[i]),  -50) if self.key_colors.get(self.keys[i]) else self.get_style().base[gtk.STATE_PRELIGHT].to_string()
                 else:
                     last_color = self.key_colors.get(self.keys[i]) or base_color
 
diff --git a/src/gui/widgets/graphics.py b/src/gui/widgets/graphics.py
index ff9330b..e305ba8 100644
--- a/src/gui/widgets/graphics.py
+++ b/src/gui/widgets/graphics.py
@@ -52,12 +52,20 @@ class Colors(object):
         
     def is_light(self, color):
         # tells you if color is dark or light, so you can up or down the scale for improved contrast
-        return colorsys.rgb_to_hls(*self.rgb(color))[1] > 150
+        return math.sqrt(self.rgb(color)[0]**2 * .241 + self.rgb(color)[1]**2 * .691 + self.rgb(color)[2]**2 * .068) > 160
 
     def darker(self, color, step):
         # returns color darker by step (where step is in range 0..255)
-        hls = colorsys.rgb_to_hls(*self.rgb(color))
-        return colorsys.hls_to_rgb(hls[0], hls[1] - step, hls[2])
+        (r, g, b) = self.rgb(color)
+        if step < 0:
+            r -= (255 - r) * (step/255.)
+            g -= (255 - g) * (step/255.)
+            b -= (255 - b) * (step/255.)
+        else:
+            r -= r * (step/255.)
+            g -= g * (step/255.)
+            b -= b * (step/255.)
+        return (r, g, b)
         
 
 class Area(gtk.DrawingArea):



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