From 5d8ed11e3836020af256f6bc63b599fd5a679f21 Mon Sep 17 00:00:00 2001 From: "Romain F. T" Date: Sat, 20 Aug 2022 13:45:35 +0200 Subject: [PATCH] crop: move the preview with the left click in the central ninth #458 --- .../abstract_transform_tool.py | 11 +++++++--- src/tools/transform_tools/tool_crop.py | 20 +++++++++---------- src/tools/transform_tools/tool_rotate.py | 3 ++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/tools/transform_tools/abstract_transform_tool.py b/src/tools/transform_tools/abstract_transform_tool.py index 2e7b5092..eb44b64d 100644 --- a/src/tools/transform_tools/abstract_transform_tool.py +++ b/src/tools/transform_tools/abstract_transform_tool.py @@ -170,16 +170,21 @@ def _set_cursor_name(self): else: self.cursor_name = self._directions + '-resize' - def set_directional_cursor(self, event_x, event_y): + def set_directional_cursor(self, event_x, event_y, movable_center=False): """Set the accurate cursor depending on the position of the pointer on the canvas.""" n_sizes = self.get_image().get_nineths_sizes(self.apply_to_selection, \ self._x, self._y) # if we're transforming the selection from its top and/or left, coords # to decide the direction depend on local deltas (self._x and self._y) - if self._set_directions(event_x, event_y, n_sizes): + if not self._set_directions(event_x, event_y, n_sizes): + # directions haven't changed + return + if movable_center and self._directions == '': + self.cursor_name = 'move' + else: self._set_cursor_name() - self.window.set_cursor(True) + self.window.set_cursor(True) ############################################################################ diff --git a/src/tools/transform_tools/tool_crop.py b/src/tools/transform_tools/tool_crop.py index 8fc931d8..8fdfd9a7 100644 --- a/src/tools/transform_tools/tool_crop.py +++ b/src/tools/transform_tools/tool_crop.py @@ -32,7 +32,6 @@ def __init__(self, window): self._y = self.y_press = self.y_motion = 0 self._unclicked = True # the lock will prevent operations coming from # the 'value-changed' signals, to avoid infinite loops - self._behavior = 'resize' self.add_tool_action_enum('crop-expand', 'initial') def try_build_pane(self): @@ -66,10 +65,8 @@ def get_editing_tips(self): if not self.get_image().get_mouse_is_pressed(): label_modifiers = _("Press , , or both, to " + \ "quickly change the 'expand with' option") - label_behavior = _("Change the size with the left click, adjust " + \ - "the position with the right click") - full_list = [label_action, label_direction, label_confirm, label_behavior, label_modifiers] + full_list = [label_action, label_direction, label_confirm, label_modifiers] return list(filter(None, full_list)) ############################################################################ @@ -133,7 +130,7 @@ def move_west(self, delta): ############################################################################ def on_unclicked_motion_on_area(self, event, surface): - self.set_directional_cursor(event.x, event.y) + self.set_directional_cursor(event.x, event.y, True) def on_press_on_area(self, event, surface, event_x, event_y): self.x_press = self.x_motion = event_x @@ -150,9 +147,10 @@ def on_press_on_area(self, event, surface, event_x, event_y): self._force_expansion_rgba('initial') if event.button == 3: - self._behavior = 'move' - else: - self._behavior = 'resize' + self._directions = '' + self.cursor_name = 'move' + self.window.set_cursor(True) + # interacting with the right click will move instead of cropping def on_motion_on_area(self, event, surface, event_x, event_y, render=True): delta_x = event_x - self.x_motion @@ -160,7 +158,9 @@ def on_motion_on_area(self, event, surface, event_x, event_y, render=True): render = render or (event_x % 4 == 0) # artificially less restrictive - if self._behavior == 'move': + if self._directions == '': + # the user interacts with the central part of the image, or uses the + # right-click, to adjust the canvas position. self._x -= delta_x self._y -= delta_y self.x_motion = event_x @@ -181,8 +181,6 @@ def on_motion_on_area(self, event, surface, event_x, event_y, render=True): self.build_and_do_op() return - if self._directions == '': - return if 'n' in self._directions: self.move_north(delta_y) if 's' in self._directions: diff --git a/src/tools/transform_tools/tool_rotate.py b/src/tools/transform_tools/tool_rotate.py index 06b6dd5b..57b8e200 100644 --- a/src/tools/transform_tools/tool_rotate.py +++ b/src/tools/transform_tools/tool_rotate.py @@ -205,7 +205,8 @@ def do_tool_operation(self, operation): surface0.set_device_scale(self.scale_factor(), self.scale_factor()) coefs = self._get_rotation_matrix(cairo_rotation, \ surface0.get_width(), surface0.get_height()) - new_surface = self.get_deformed_surface(surface0, coefs) + new_surface = self.get_resized_surface(surface0, coefs) + new_surface = self.get_deformed_surface(surface0, new_surface, coefs) new_pixbuf = Gdk.pixbuf_get_from_surface(new_surface, 0, 0, \ new_surface.get_width(), new_surface.get_height())