Skip to content

Commit

Permalink
ZoomableMixin: preserve scale across image size
Browse files Browse the repository at this point in the history
If the previous image is a different size than the current one, assume
that it is representing the same scene but with a different resolution.

Therefore, try to preserve the apparent size of things on screen by
adjusting the zoom level accordingly.

Reset this scaling whenever switching back the fitted view. This means
that we always get the 'true' resolution when zooming initially.
  • Loading branch information
aevri committed Mar 5, 2024
1 parent 2bdf522 commit 9c6c5c5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mel/lib/fullscreenui.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def __init__(self):
self._transform = None
self._zoom_pos = None
self._zoom_virt_pos = None
self._zoom_orig_shape = None
self._is_zoomed = False
self._zoom_level = 1

Expand All @@ -201,8 +202,20 @@ def zoomable_transform_update(self, image, window_rect):
self._zoom_virt_pos = self._zoom_pos / image.shape[:2]
else:
self._zoom_pos = self._zoom_virt_pos * image.shape[:2]
if self._zoom_orig_shape is None:
self._zoom_orig_shape = image.shape[:2]
zoom_scale = (
sum(
[
self._zoom_orig_shape[0] / image.shape[0],
self._zoom_orig_shape[1] / image.shape[1],
]
)
/ 2
)
zoom_level = self._zoom_level * zoom_scale
self._transform = mel.lib.fullscreenui.ZoomedImageTransform(
image, self._zoom_pos, window_rect, scale=self._zoom_level
image, self._zoom_pos, window_rect, scale=zoom_level
)
else:
self._transform = mel.lib.fullscreenui.FittedImageTransform(
Expand All @@ -214,6 +227,7 @@ def zoomable_transform_render(self):

def set_fitted(self):
self._is_zoomed = False
self._zoom_orig_shape = None

def set_zoom_level(self, zoom_level=1):
self._zoom_level = zoom_level
Expand Down

0 comments on commit 9c6c5c5

Please sign in to comment.