Skip to content

Commit

Permalink
text tool: update the cursor icon when hovering the area
Browse files Browse the repository at this point in the history
this commit finally fixes #357, and also #604 (partial duplicate)

there are still visual glitches when the user zooms in or out but idc
  • Loading branch information
maoschanz committed May 8, 2023
1 parent 32a92e4 commit dbbfbbc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
19 changes: 16 additions & 3 deletions src/tools/classic_tools/tool_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ToolText(AbstractClassicTool):

def __init__(self, window, **kwargs):
super().__init__('text', _("Text"), 'tool-text-symbolic', window)
self.cursor_name = 'text'

# There are several types of possible interactions with the canvas,
# depending on where the pointer is during the press event.
Expand Down Expand Up @@ -247,8 +248,10 @@ def _preview_text(self, *args):

def on_draw_above(self, area, ccontext):
if not self._has_current_text():
return
return True, False
return self._update_overlay(area, ccontext, self.x_press, self.y_press)

def _update_overlay(self, area, ccontext, test_x, test_y):
sorigin_x = -1 * self.get_image().scroll_x
sorigin_y = -1 * self.get_image().scroll_y
if area is None:
Expand All @@ -266,11 +269,11 @@ def on_draw_above(self, area, ccontext):
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)
should_input = ccontext.in_fill(test_x, test_y)

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

return should_input, should_move

Expand All @@ -281,6 +284,16 @@ def _on_cancel(self, *args):
def on_unclicked_motion_on_area(self, event, surface):
if not self._has_current_text():
self.cursor_name = 'text'
self.window.set_cursor(True)
return

x, y = self.get_image().get_event_coords(event)
should_input, should_move = self._update_overlay(None, \
self.get_context(), x, y)
if should_input:
self.cursor_name = 'text'
elif should_move:
self.cursor_name = 'grab'
else:
self.cursor_name = 'pointer'
self.window.set_cursor(True)
Expand Down
8 changes: 4 additions & 4 deletions src/utilities/utilities_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def utilities_show_composite_overlay(ccontext, thickness=1, x_press=None, y_pres
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
if x_press is None or y_press is None:
return None

press_in_filled_area = ccontext.in_fill(x_press, y_press)

ccontext.set_source_rgba(0.3, 0.3, 0.3, 0.2)
ccontext.fill_preserve()
Expand Down

0 comments on commit dbbfbbc

Please sign in to comment.