[hamster-applet] two functions - whan that turns whatever into color with normalized components.
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet] two functions - whan that turns whatever into color with normalized components.
- Date: Thu, 26 Nov 2009 22:31:39 +0000 (UTC)
commit 625462ff722a134e29dacd75b4af25a159d29e52
Author: Toms Bauģis <toms baugis gmail com>
Date: Thu Nov 26 22:24:24 2009 +0000
two functions - whan that turns whatever into color with normalized components.
the other returns same thing just in 0..255 range.
handy when you don't know in which format the color has been fed in
hamster/graphics.py | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/hamster/graphics.py b/hamster/graphics.py
index b308b95..226cf1f 100644
--- a/hamster/graphics.py
+++ b/hamster/graphics.py
@@ -77,10 +77,18 @@ class Area(gtk.DrawingArea):
w, h = self.layout.get_pixel_size()
return w, h
-
- def set_color(self, color, opacity = None):
+ def normalize_rgb(self, color):
+ #if any of values is over 1 - that means color has been entered in 0-255 range and we should normalize it
if color[0] > 1 or color[1] > 0 or color[2] > 0:
color = [c / 255.0 for c in color]
+ return color
+
+ def rgb(self, color):
+ #return color that has each component in 0..255 range
+ return [c*255 for c in self.normalize_rgb(color)]
+
+ def set_color(self, color, opacity = None):
+ color = self.normalize_rgb(color)
if opacity:
self.context.set_source_rgba(color[0], color[1], color[2], opacity)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]