Skip to content

Commit

Permalink
text tool: correct detection of the pointer target type, #357
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed May 10, 2022
1 parent fe2e308 commit b50972a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
35 changes: 27 additions & 8 deletions src/tools/classic_tools/tool_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_editing_tips(self):
self._set_background_style()

# get_editing_tips is likely called because an option changed
self._force_refresh()
self._preview_text()

label_options = self.label + " - " + self._font_fam_name
if self._background_id != 'none':
Expand Down Expand Up @@ -148,7 +148,20 @@ def _set_string(self, string):
############################################################################

def on_press_on_area(self, event, surface, event_x, event_y):
self._last_click_btn = event.button
self.set_common_values(self._last_click_btn, event_x, event_y)
self._pointer_target = 'input'
if not self._has_current_text():
return

should_input, should_move = self.on_draw_above(None, self.get_context())
if should_input:
return
elif not should_move:
self._pointer_target = 'apply'
return

self._pointer_target = 'move'

def on_motion_on_area(self, event, surface, event_x, event_y, render=True):
if 'move' == self._pointer_target:
Expand Down Expand Up @@ -229,25 +242,31 @@ def _preview_text(self, *args):
def on_draw_above(self, area, ccontext):
if not self._has_current_text():
return
ccontext.new_path()
ccontext.set_font_size(self.tool_width * 2)
ccontext.move_to(self._text_x, self._text_y)
ext = ccontext.text_extents(self.text_string)

sorigin_x = -1 * self.get_image().scroll_x
sorigin_y = -1 * self.get_image().scroll_y
if area is None:
sorigin_x = 0
sorigin_y = 0

actual_width = self._preview_width
actual_height = self._preview_height

sorigin_x = -1 * self.get_image().scroll_x
sorigin_y = -1 * self.get_image().scroll_y
ccontext.new_path()
ccontext.move_to(sorigin_x, sorigin_y)
ccontext.rel_move_to(self._text_x, self._text_y)
ccontext.rel_line_to(actual_width, 0)
ccontext.rel_line_to(0, actual_height)
ccontext.rel_line_to(-1 * actual_width, 0)
ccontext.rel_line_to(0, -1 * actual_height)

should_input = ccontext.in_fill(self.x_press, self.y_press)

thickness = self.get_overlay_thickness()
utilities_show_composite_overlay(ccontext, thickness)
should_move = utilities_show_composite_overlay(ccontext, thickness, \
sorigin_x + self.x_press, sorigin_y + self.y_press)

return should_input, should_move

def _on_cancel(self, *args):
self._hide_entry()
Expand Down
10 changes: 8 additions & 2 deletions src/utilities/utilities_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
################################################################################
# Classic tools overlay ########################################################

def utilities_show_composite_overlay(ccontext, thickness=1):
def utilities_show_composite_overlay(ccontext, thickness=1, x_press=None, y_press=None):
ccontext.set_line_width(thickness)
ccontext.set_dash([thickness * 3, thickness * 3])

x1, y1 ,x2, y2 = ccontext.path_extents()
x1, y1, x2, y2 = ccontext.path_extents()
radius = _get_radius((x2 - x1), (y2 - y1), thickness)

radius_with_margin = (radius + 10) * 1.2
Expand All @@ -22,6 +22,10 @@ def utilities_show_composite_overlay(ccontext, thickness=1):
ccontext.close_path()

ccontext.set_fill_rule(cairo.FillRule.EVEN_ODD)
if x_press is not None and y_press is not None:
press_in_filled_area = ccontext.in_fill(x_press, y_press)
else:
press_in_filled_area = None

ccontext.set_source_rgba(0.3, 0.3, 0.3, 0.2)
ccontext.fill_preserve()
Expand All @@ -43,6 +47,8 @@ def utilities_show_composite_overlay(ccontext, thickness=1):
_draw_arc_handle(ccontext, x2, y2, radius, 'se')
_draw_arc_handle(ccontext, x1, y2, radius, 'sw')

return press_in_filled_area

################################################################################
# Selection overlay ############################################################

Expand Down

0 comments on commit b50972a

Please sign in to comment.