From 73ba5120f5867eeb40de9bbb3328e4bc2c77ab45 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Fri, 12 Jun 2015 18:05:49 +0200 Subject: [PATCH] Diagram.py: use color_to_rgba() more consistently --- Diagram.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Diagram.py b/Diagram.py index 0bc3925..457d3ba 100755 --- a/Diagram.py +++ b/Diagram.py @@ -139,8 +139,8 @@ class Diagram(object): cr = self.cr cr.save() - cr.set_source_rgba(fill_color[0], fill_color[1], fill_color[2], - fill_color[3]) + r, g, b, a = self.color_to_rgba(fill_color) + cr.set_source_rgba(r, g, b, a) cr.arc(cx, cy, size, 0, 2 * pi) cr.fill() cr.restore() @@ -157,8 +157,8 @@ class Diagram(object): cr.stroke() def draw_rect_from_center(self, cx, cy, width, height, theta=0, - fill=True, fill_color=[1, 1, 1], - stroke=False, stroke_color=[0, 0, 0]): + fill=True, fill_color=[1, 1, 1, 0.8], + stroke=False, stroke_color=[0, 0, 0, 0.5]): cr = self.cr mx = width / 2.0 @@ -173,19 +173,21 @@ class Diagram(object): if fill: cr.rectangle(0, 0, width, height) - cr.set_source_rgba(fill_color[0], fill_color[1], fill_color[2], 0.8) + r, g, b, a = self.color_to_rgba(fill_color) + cr.set_source_rgba(r, g, b, a) cr.fill() if stroke: cr.rectangle(0, 0, width, height) - cr.set_source_rgba(stroke_color[0], stroke_color[1], stroke_color[2], 0.5) + r, g, b, a = self.color_to_rgba(stroke_color) + cr.set_source_rgba(r, g, b, a) cr.stroke() - self.draw_dot(0, 0, 3.0, list(stroke_color) + [0.5]) + self.draw_dot(0, 0, 3.0, stroke_color) cr.restore() - def draw_rect(self, x, y, width, height, fill=True, fill_color=[1, 1, 1], - stroke=False, stroke_color=[0, 0, 0]): + def draw_rect(self, x, y, width, height, fill=True, fill_color=[1, 1, 1, 0.8], + stroke=False, stroke_color=[0, 0, 0, 0.5]): cr = self.cr cr.save() @@ -193,14 +195,16 @@ class Diagram(object): if fill: cr.rectangle(0, 0, width, height) - cr.set_source_rgba(fill_color[0], fill_color[1], fill_color[2], 0.8) + r, g, b, a = self.color_to_rgba(fill_color) + cr.set_source_rgba(r, g, b, a) cr.fill() if stroke: cr.rectangle(0, 0, width, height) - cr.set_source_rgba(stroke_color[0], stroke_color[1], stroke_color[2], 0.5) + r, g, b, a = self.color_to_rgba(stroke_color) + cr.set_source_rgba(r, g, b, a) cr.stroke() - self.draw_dot(0, 0, 3.0, list(stroke_color) + [0.5]) + self.draw_dot(0, 0, 3.0, stroke_color) cr.restore() @@ -226,8 +230,9 @@ class Diagram(object): cr.save() cr.translate(rx, ry) cr.rotate(theta) - self.draw_rect(0, -descent, width, ascent, fill_color=[1, 1, 1, 0.1], stroke=bounding_box) - cr.set_source_rgba(color[0], color[1], color[2], 0.8) + self.draw_rect(0, -descent, width, ascent, fill_color=[1, 1, 1, 0.8], stroke=bounding_box) + r, g, b, a = self.color_to_rgba(color) + cr.set_source_rgba(r, g, b, a) cr.move_to(0, 0) cr.show_text(text) cr.fill() -- 2.1.4