Skip to content

Commit

Permalink
crop: move the preview with the left click in the central ninth #458
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Aug 20, 2022
1 parent 15574b4 commit 5d8ed11
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
11 changes: 8 additions & 3 deletions src/tools/transform_tools/abstract_transform_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

Expand Down
20 changes: 9 additions & 11 deletions src/tools/transform_tools/tool_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -66,10 +65,8 @@ def get_editing_tips(self):
if not self.get_image().get_mouse_is_pressed():
label_modifiers = _("Press <Alt>, <Shift>, 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))

############################################################################
Expand Down Expand Up @@ -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
Expand All @@ -150,17 +147,20 @@ 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
delta_y = event_y - self.y_motion

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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/tools/transform_tools/tool_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit 5d8ed11

Please sign in to comment.