Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/common/Util
diff options
context:
space:
mode:
Diffstat (limited to 'common/Util')
-rw-r--r--common/Util/CairoUtil.py44
-rw-r--r--common/Util/ThemeWidgets.py25
2 files changed, 48 insertions, 21 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()
diff --git a/common/Util/ThemeWidgets.py b/common/Util/ThemeWidgets.py
index 5eb6da5..a941ebf 100644
--- a/common/Util/ThemeWidgets.py
+++ b/common/Util/ThemeWidgets.py
@@ -4,15 +4,12 @@ import cairo
import logging
import common.Config as Config
from common.Config import imagefile
+from common.Util import CairoUtil
from sugar3.graphics.combobox import ComboBox
from sugar3.graphics.palette import Palette, WidgetInvoker
-def gdk_color_to_cairo(color):
- return (color.red / 65536.0, color.green / 65536.0, color.blue / 65536.0)
-
-
class ImageVScale(Gtk.VScale):
def __init__(self, image_name, adjustment=None, slider_border=0,
@@ -703,7 +700,7 @@ class RoundFixed(Gtk.Fixed):
# within the dirty rect, but drawing seems to be quite fast compared
# to python code, so just leave it at clipping by each geometry feature
- cr.set_source_rgb(*gdk_color_to_cairo(self.bordercolor))
+ cr.set_source_rgb(*CairoUtil.gdk_color_to_cairo(self.bordercolor))
if self.borderW:
if stopY > self.corner and startY < self.heightMINcorner:
if startX < self.borderW: # draw left border
@@ -1223,30 +1220,16 @@ class keyButton(Gtk.Button):
self.cr = self.window.cairo_create()
self.cr.set_source_rgb(self.fillcolor[0], self.fillcolor[1],
self.fillcolor[2])
- self.draw_round_rect(self.cr, self.drawX - self.width // 2,
+ CairoUtil.draw_round_rect(self.cr, self.drawX - self.width // 2,
self.drawY - self.height // 2, self.width, self.height, 10)
self.cr.fill()
self.cr.set_line_width(3)
self.cr.set_source_rgb(self.strokecolor[0], self.strokecolor[1],
self.strokecolor[2])
- self.draw_round_rect(self.cr, self.drawX - self.width // 2,
+ CairoUtil.draw_round_rect(self.cr, self.drawX - self.width // 2,
self.drawY - self.height // 2, self.width, self.height, 10)
self.cr.stroke()
- def draw_round_rect(self, context, x, y, w, h, r):
- context.move_to(x + r, y) # Move to A
- context.line_to(x + w - r, y) # Straight line to B
- # Curve to C, Control points are both at Q
- context.curve_to(x + w, y, x + w, y, x + w, y + r)
- context.line_to(x + w, y + h - r) # Move to D
- # Curve to E
- context.curve_to(x + w, y + h, x + w, y + h, x + w - r, y + h)
- context.line_to(x + r, y + h) # Line to F
- context.curve_to(x, y + h, x, y + h, x, y + h - r) # Curve to G
- context.line_to(x, y + r) # Line to H
- context.curve_to(x, y, x, y, x + r, y) # Curve to A
- return
-
def set_fillcolor(self, r, g, b):
self.fillcolor = [r, g, b]
self.queue_draw()