Skip to content

Commit

Permalink
dynamic update of the "arc" tool preview #357
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Feb 13, 2023
1 parent cc16f3a commit 0b0fc6d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/tools/classic_tools/tool_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, window, **kwargs):
self._dashes_type = 'none'
self._arrow_type = 'none'
self._use_outline = False
self._path = None

self.add_tool_action_enum('line_shape', 'round')
self.add_tool_action_enum('dashes-type', self._dashes_type)
Expand Down Expand Up @@ -92,6 +93,9 @@ def on_options_changed(self):
self._arrow_type = self.get_option_value('arrow-type')
self.set_active_shape()

operation = self.build_operation()
self.do_tool_operation(operation)

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

def on_press_on_area(self, event, surface, event_x, event_y):
Expand All @@ -114,7 +118,7 @@ def on_motion_on_area(self, event, surface, event_x, event_y, render=True):

if not render:
return
operation = self.build_operation(event_x, event_y)
operation = self.build_operation()
self.do_tool_operation(operation)

def on_release_on_area(self, event, surface, event_x, event_y):
Expand All @@ -129,12 +133,12 @@ def on_release_on_area(self, event, surface, event_x, event_y):
self._1st_segment = None

self._path = cairo_context.copy_path()
operation = self.build_operation(event_x, event_y)
operation = self.build_operation()
self.apply_operation(operation)

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

def build_operation(self, event_x, event_y):
def build_operation(self):
operation = {
'tool_id': self.id,
'rgba': self.main_color,
Expand All @@ -147,14 +151,14 @@ def build_operation(self, event_x, event_y):
'arrow': self._arrow_type,
'outline': self._use_outline,
'path': self._path,
'x_release': event_x,
'y_release': event_y,
'x_press': self.x_press,
'y_press': self.y_press
}
return operation

def do_tool_operation(self, operation):
if operation['path'] is None:
return
cairo_context = self.start_tool_operation(operation)

cairo_context.set_operator(operation['operator'])
Expand All @@ -179,8 +183,8 @@ def do_tool_operation(self, operation):
if operation['arrow'] != 'none':
x1 = operation['x_press']
y1 = operation['y_press']
x2 = operation['x_release']
y2 = operation['y_release']
x2 = cairo_context.get_current_point()[0]
y2 = cairo_context.get_current_point()[1]
utilities_add_arrow_triangle(cairo_context, x2, y2, x1, y1, line_width)

if operation['outline']:
Expand Down

0 comments on commit 0b0fc6d

Please sign in to comment.