Debian Codegraph @

src/tools/classic_tools/brushes/abstract_brush.py

raw symbols SCIP
1 # Licensed under GPL3 https://github.com/maoschanz/drawing/blob/master/LICENSE
2
3 import cairo
4
5 class AbstractBrush():
6 __gtype_name__ = 'AbstractBrush'
7
8 def __init__(self, brush_id, brush_tool, *args):
9 self._id = brush_id
10 self._tool = brush_tool
11
12 def _get_tips(self, use_pressure, brush_direction):
13 return [_("Brush")]
14
15 ############################################################################
16
17 def draw_preview(self, operation, cairo_context):
18 cairo_context.set_operator(operation['operator'])
19 cairo_context.set_line_width(operation['line_width'])
20 cairo_context.new_path()
21 for pt in operation['path']:
22 cairo_context.line_to(pt['x'], pt['y'])
23 cairo_context.stroke()
24
25 def operation_on_mask(self, operation, original_context):
26 if operation['operator'] == cairo.Operator.CLEAR \
27 or operation['operator'] == cairo.Operator.SOURCE:
28 # When using CLEAR or SOURCE, we don't need to use a temporary
29 # surface, and actually we can't because using it as a mask would
30 # just erase the entire image.
31 original_context.set_operator(operation['operator'])
32 original_context.set_source_rgba(*operation['rgba'])
33 self.do_masked_brush_op(original_context, operation)
34 return
35
36 # Creation of a blank surface with a new context; each brush decides how
37 # to apply the options set by the user (`operation`), except for the
38 # operator which has to be "wrongly" set to SOURCE.
39 w = self._tool.get_surface().get_width()
40 h = self._tool.get_surface().get_height()
41 mask = cairo.ImageSurface(cairo.Format.ARGB32, w, h)
42 context2 = cairo.Context(mask)
43
44 if operation['antialias']:
45 antialias = cairo.Antialias.DEFAULT
46 else:
47 antialias = cairo.Antialias.NONE
48 context2.set_antialias(antialias)
49
50 context2.set_operator(cairo.Operator.SOURCE)
51 context2.set_source_rgba(*operation['rgba'])
52
53 self.do_masked_brush_op(context2, operation)
54
55 # Paint the surface onto the actual image with the chosen operator
56 original_context.set_operator(operation['operator'])
57 original_context.set_source_surface(mask)
58 original_context.paint()
59
60 ############################################################################
61
62 def do_brush_operation(self, cairo_context, operation):
63 pass
64
65 def do_masked_brush_op(self, cairo_context, operation):
66 pass
67
68 ############################################################################
69 ################################################################################
70