Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/common/Util/CairoUtil.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2013-01-23 16:03:32 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2013-01-25 22:07:42 (GMT)
commitc2adf88db4df23513e7476e1057275f6b6467bd5 (patch)
tree129141ab0c8e2c411404f4c5c74d2c180690dcb7 /common/Util/CairoUtil.py
parent20bf81d221e56080997d8cf60ee8d24b21ed127a (diff)
Partial port drawing operations to cairo
The activity starts but the canvas draw is wrong. The old code used bitmap masks to define non rectangular areas, like in the drum instruments or the loops. Part of this is implemented with cairo, but is not finished. As a final note, this is a too big patch, more work is needed, and probably part of the code can be refactored. Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'common/Util/CairoUtil.py')
-rw-r--r--common/Util/CairoUtil.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/common/Util/CairoUtil.py b/common/Util/CairoUtil.py
new file mode 100644
index 0000000..7918210
--- /dev/null
+++ b/common/Util/CairoUtil.py
@@ -0,0 +1,44 @@
+# useful methods to work with cairo in TamTam
+from gi.repository import Gdk
+
+def gdk_color_to_cairo(color):
+ return (color.red / 65536.0, color.green / 65536.0, color.blue / 65536.0)
+
+def get_gdk_color(str_color):
+ result, color = Gdk.Color.parse(str_color)
+ return color
+
+def draw_round_rect(ctx, x, y, width, height, radio=10):
+ # Move to A
+ ctx.move_to(x + radio, y)
+ # Straight line to B
+ ctx.line_to(x + width - radio, y)
+ # Curve to C, Control points are both at Q
+ ctx.curve_to(x + width, y, x + width, y, x + width, y + radio)
+ # Move to D
+ ctx.line_to(x + width, y + height - radio)
+ # Curve to E
+ ctx.curve_to(x + width, y + height, x + width, y + height,
+ x + width - radio, y + height)
+ # Line to F
+ ctx.line_to(x + radio, y + height)
+ # Curve to G
+ ctx.curve_to(x, y + height, x, y + height, x, y + height - radio)
+ # Line to H
+ ctx.line_to(x, y + radio)
+ # Curve to A
+ ctx.curve_to(x, y, x, y, x + radio, y)
+
+def draw_drum_mask(ctx, x, y, size):
+ side = size / 3
+ ctx.move_to(x + side, y)
+ ctx.new_path()
+ ctx.line_to(x + side * 2, y)
+ ctx.line_to(x + size, y + side)
+ ctx.line_to(x + size, y + side * 2)
+ ctx.line_to(x + side * 2, y + size)
+ ctx.line_to(x + side, y + size)
+ ctx.line_to(x, y + side * 2)
+ ctx.line_to(x, y + side)
+ ctx.line_to(x + side, y)
+ ctx.close_path()