Skip to content

Commit

Permalink
new experimental brush just dropped (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Feb 6, 2021
1 parent 861efac commit 68fe25d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
42 changes: 41 additions & 1 deletion src/tools/classic_tools/tool_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, window, **kwargs):
}
self._operator_label = "OVER"
self.operator2 = cairo.Operator.OVER
self._selected_mode = 'pressure'
self._selected_mode = 'feather-simple'

self.add_tool_action_enum('experiment_operator', self._operator_label)
self.add_tool_action_enum('experiment_mode', self._selected_mode)
Expand Down Expand Up @@ -175,6 +175,10 @@ def do_tool_operation(self, operation):
# if operation['is_preview']: # Previewing helps performance & debug
# return self.op_simple(operation, cairo_context)
self.op_airbrush(operation, cairo_context)
elif operation['mode'] == 'feather-simple':
if operation['is_preview']: # Previewing helps performance & debug
return self.op_simple(operation, cairo_context)
self.op_feather_simple(operation, cairo_context)
else:
self.op_simple(operation, cairo_context)

Expand Down Expand Up @@ -207,6 +211,42 @@ def op_smooth(self, operation, cairo_context):

############################################################################

def op_feather_simple(self, operation, cairo_context):
# TODO ok it draws something cool but filling a path isn't enough, it
# has to one parallelogram per segment and paint it on the canvas using
# an intermediate layer, like with the dynamic brush...
cairo_context.set_operator(cairo.Operator.OVER)
line_width = operation['line_width'] / 2
two_ways_path = []

feather_point = {'x': 1, 'y': -1}
for pt in operation['path']:
x = pt['x'] + feather_point['x'] * line_width
y = pt['y'] + feather_point['y'] * line_width
two_ways_path.append({'x': int(x), 'y': int(y)})

feather_point = {'x': -1, 'y': 1}
reversed_path = list(reversed(operation['path']))
for pt in reversed_path:
x = pt['x'] + feather_point['x'] * line_width
y = pt['y'] + feather_point['y'] * line_width
two_ways_path.append({'x': int(x), 'y': int(y)})

# Build a cairo path from the raw data
cairo_context.new_path()
for pt in two_ways_path:
cairo_context.line_to(pt['x'], pt['y'])
path = cairo_context.copy_path()

# Smooth it
cairo_context.new_path()
utilities_smooth_path(cairo_context, path)

# Draw it
cairo_context.fill()

############################################################################

def op_airbrush(self, operation, cairo_context):
cairo_context.set_operator(operation['operator']) # XXX but the blur?
cairo_context.set_line_width(1)
Expand Down
31 changes: 21 additions & 10 deletions src/tools/ui/tool-experiment.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@
<menu id="options-menu">

<section>
<attribute name="label">Pinceaux</attribute>
<attribute name="label">Pinceaux simples</attribute>
<item>
<attribute name="label">Simple</attribute>
<attribute name="label">Tracé brut</attribute>
<attribute name="action">win.experiment_mode</attribute>
<attribute name="target">simple</attribute>
</item>
<item>
<attribute name="label">Lisse (ajout de points)</attribute>
<attribute name="label">Lissé (ajout de points)</attribute>
<attribute name="action">win.experiment_mode</attribute>
<attribute name="target">smooth</attribute>
</item>
<item>
<attribute name="label">Dynamique (mixte)</attribute>
<attribute name="label">Plume pleine fixe</attribute>
<attribute name="action">win.experiment_mode</attribute>
<attribute name="target">feather-simple</attribute>
</item>
</section>
<section>
<attribute name="label">Pinceaux dynamiques</attribute>
<item>
<attribute name="label">Tracé brut (mixte)</attribute>
<attribute name="action">win.experiment_mode</attribute>
<attribute name="target">pressure</attribute>
</item>
<!-- <item> -->
<!-- <attribute name="label">Pinceau à motif</attribute> -->
<!-- <attribute name="action">win.experiment_mode</attribute> -->
<!-- <attribute name="target">pattern</attribute> -->
<!-- </item> -->
<item>
<attribute name="label">Aérographe</attribute>
<attribute name="label">Plume dynamique</attribute>
<!-- <attribute name="action">win.experiment_mode</attribute> -->
<!-- <attribute name="target">feather</attribute> -->
</item>
</section>
<section>
<attribute name="label">Pinceaux à motifs</attribute>
<item>
<attribute name="label">Aérographe aléatoire</attribute>
<attribute name="action">win.experiment_mode</attribute>
<attribute name="target">airbrush</attribute>
</item>
Expand Down

0 comments on commit 68fe25d

Please sign in to comment.