| 1 |
|
| 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 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 37 |
|
| 38 |
|
| 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 |
|
| 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 |
|