Skip to content

Commit

Permalink
Fix scaling while preserving proportions
Browse files Browse the repository at this point in the history
This fixes issues with preserving proportions when editing the
dimensions with the SpinButtons.

Closes #637
  • Loading branch information
ARAKHNID committed Jun 6, 2024
1 parent a353526 commit 6530ca7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/tools/transform_tools/tool_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def on_tool_selected(self, *args):
self._spinbtns_disabled = False
self._width_btn.set_value(width)
self._height_btn.set_value(height)
self._previous_width = width
self._previous_height = height
self.build_and_do_op() # Ensure a correct preview

def _get_original_size(self):
Expand Down Expand Up @@ -166,7 +168,10 @@ def set_preserve_ratio(self, for_spinbtns=False):
if self._preserve_ratio == former_setting:
return
if self._preserve_ratio:
self._ratio = self._get_width() / self._get_height()
if for_spinbtns:
self._ratio = self._get_previous_width() / self._get_previous_height()
else:
self._ratio = self._get_width() / self._get_height()

def _try_scale_dimensions(self):
if self._reload_is_locked:
Expand Down Expand Up @@ -226,6 +231,10 @@ def on_spinbtn_changed(self, *args):
self.set_preserve_ratio(True)
self._try_scale_dimensions()

if not self._preserve_ratio:
self._previous_width = self._get_width()
self._pervious_height = self._get_height()

def on_spinbtn100_changed(self, *args):
if self._spinbtns_disabled:
return
Expand All @@ -249,13 +258,27 @@ def _apply_deltas_to_spinbtns(self, new_width, new_height, dx=0, dy=0):
else:
self._height_btn.set_value(new_height)
self._width_btn.set_value(new_width)
self._previous_height = new_height
self._previous_width = new_width

def _get_width(self):
return self._width_btn.get_value_as_int()

def _get_height(self):
return self._height_btn.get_value_as_int()

def _get_previous_width(self):
try:
return self._previous_width
finally:
self._previous_width = self._get_width()

def _get_previous_height(self):
try:
return self._previous_height
finally:
self._previous_height = self._get_height()

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

def on_unclicked_motion_on_area(self, event, surface):
Expand Down

0 comments on commit 6530ca7

Please sign in to comment.