Skip to content

Commit

Permalink
add target display limits in order to make zoom and window resize wor…
Browse files Browse the repository at this point in the history
…k nicely together
  • Loading branch information
guillaumechauvat committed Dec 29, 2022
1 parent 9a4e6bf commit 1c83b06
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pymech/meshplot.py
Expand Up @@ -64,6 +64,7 @@ def __init__(
self.setLimits(mesh)
# current limits
self.limits = self.mesh_limits.copy()
self.target_limits = self.mesh_limits.copy()

# and a status bar
# self.CreateStatusBar()
Expand Down Expand Up @@ -136,8 +137,9 @@ def zoom(self, xcp, ycp, increment):
The centre (xcp, ycp) is given in pixels, not in mesh units.
"""

factor = self.zoom_factor**increment
factor = self.zoom_factor ** increment
xmin, xmax, ymin, ymax = self.limits
xmin_t, xmax_t, ymin_t, ymax_t = self.target_limits
size = self.GetGLExtents()
# get the centre location in mesh units
# xcp is 0 on the left, ycp is zero on the top
Expand All @@ -148,7 +150,12 @@ def zoom(self, xcp, ycp, increment):
xmax = xc + factor * (xmax - xc)
ymin = yc + factor * (ymin - yc)
ymax = yc + factor * (ymax - yc)
xmin_t = xc + factor * (xmin_t - xc)
xmax_t = xc + factor * (xmax_t - xc)
ymin_t = yc + factor * (ymin_t - yc)
ymax_t = yc + factor * (ymax_t - yc)
self.limits = [xmin, xmax, ymin, ymax]
self.target_limits = [xmin_t, xmax_t, ymin_t, ymax_t]
size = self.GetGLExtents()
self.updateLimits(size.width, size.height)
self.OnDraw()
Expand All @@ -163,10 +170,10 @@ def OnInitGL(self):
def updateLimits(self, width, height):
"""Update the view limits based on the dimensions of the window."""

xmin = self.limits[0]
xmax = self.limits[1]
ymin = self.limits[2]
ymax = self.limits[3]
xmin = self.target_limits[0]
xmax = self.target_limits[1]
ymin = self.target_limits[2]
ymax = self.target_limits[3]
# check whether the view is limited by width or height, and scale accordingly
lx = xmax - xmin
ly = ymax - ymin
Expand Down

0 comments on commit 1c83b06

Please sign in to comment.