Skip to content

Commit 9deb16a

Browse files
committed
fix size and position computations for the "expand to fit" action (#332)
1 parent 4fa4f6a commit 9deb16a

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/tools/transform_tools/tool_crop.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,23 @@ def build_selection_fit_operation(self):
197197
but from the selection menu. The parameters are determined automatically
198198
from the state of the selection manager."""
199199
self._update_expansion_color()
200-
selection = self.get_selection()
201-
new_origin_x = min(0, selection.selection_x)
202-
new_origin_y = min(0, selection.selection_y)
203-
s_width = selection.selection_x + selection.selection_pixbuf.get_width()
204-
new_width = max(self.get_main_pixbuf().get_width(), s_width)
205-
s_height = selection.selection_y + selection.selection_pixbuf.get_height()
206-
new_height = max(self.get_main_pixbuf().get_height(), s_height)
200+
s = self.get_selection()
201+
new_x = min(0, s.selection_x)
202+
new_y = min(0, s.selection_y)
203+
204+
s_width = max(0, s.selection_x) + s.selection_pixbuf.get_width()
205+
new_width = max(-1 * new_x + self.get_main_pixbuf().get_width(), s_width)
206+
207+
s_height = max(0, s.selection_y) + s.selection_pixbuf.get_height()
208+
new_height = max(-1 * new_y + self.get_main_pixbuf().get_height(), s_height)
207209

208210
operation = {
209211
'tool_id': self.id,
210212
'is_selection': False,
211213
'is_preview': False,
212-
'local_dx': int(new_origin_x),
213-
'local_dy': int(new_origin_y),
214+
'is_etf': True,
215+
'local_dx': int(new_x),
216+
'local_dy': int(new_y),
214217
'width': new_width,
215218
'height': new_height,
216219
'rgba': self._expansion_color
@@ -222,6 +225,7 @@ def build_operation(self):
222225
'tool_id': self.id,
223226
'is_selection': self.apply_to_selection,
224227
'is_preview': True,
228+
'is_etf': False,
225229
'local_dx': int(self._x),
226230
'local_dy': int(self._y),
227231
'width': self.get_width(),
@@ -244,6 +248,9 @@ def do_tool_operation(self, operation):
244248
source_pixbuf = self.get_main_pixbuf()
245249
self.get_image().set_temp_pixbuf(source_pixbuf.copy())
246250
self._crop_temp_pixbuf(x, y, width, height, is_selection, rgba)
251+
if operation['is_etf']:
252+
s_pixbuf = self.get_selection_pixbuf()
253+
self.get_selection().update_from_transform_tool(s_pixbuf, -1 * x, -1 * y)
247254
self.common_end_operation(operation)
248255

249256
def _crop_temp_pixbuf(self, x, y, width, height, is_selection, rgba):

0 commit comments

Comments
 (0)