Commit 8f2a5b3f authored by Guillaume Seguin's avatar Guillaume Seguin

Factorize wheel handling and patching

parent 2614bb5e
......@@ -154,14 +154,10 @@ class GcodeViewPanel(wxGLPanel):
self.parent.setlayercb(new_layer)
wx.CallAfter(self.Refresh)
def wheel(self, event):
"""react to mouse wheel actions:
without shift: set max layer
with shift: zoom viewport
"""
def handle_wheel(self, event):
delta = event.GetWheelRotation()
factor = 1.05
if event.ShiftDown():
if hasattr(self.parent, "model") and event.ShiftDown():
if not self.parent.model:
return
count = 1 if not event.ControlDown() else 10
......@@ -176,6 +172,14 @@ class GcodeViewPanel(wxGLPanel):
else:
self.zoom(1 / factor, (x, y))
def wheel(self, event):
"""react to mouse wheel actions:
without shift: set max layer
with shift: zoom viewport
"""
self.handle_wheel(event)
wx.CallAfter(self.Refresh)
def fit(self):
if not self.parent.model or not self.parent.model.loaded:
return
......
......@@ -103,6 +103,19 @@ class Plater(wx.Frame):
else:
orig_handler(event)
patch_method(viewer, "handle_rotation", handle_rotation)
# Patch handle_wheel on the fly
if hasattr(viewer, "handle_wheel"):
def handle_wheel(self, event, orig_handler):
if not event.ShiftDown():
delta = event.GetWheelRotation()
angle = 10
if delta > 0:
self.parent.rotate_shape(angle / 2)
else:
self.parent.rotate_shape(-angle / 2)
else:
orig_handler(event)
patch_method(viewer, "handle_wheel", handle_wheel)
self.s = viewer
self.mainsizer.Add(self.s, 1, wx.EXPAND)
......
......@@ -170,19 +170,8 @@ class StlViewPanel(wxGLPanel):
event.Skip()
wx.CallAfter(self.Refresh)
def wheel(self, event):
"""react to mouse wheel actions:
rotate object
with shift zoom viewport
"""
def handle_wheel(self, event):
delta = event.GetWheelRotation()
if not event.ShiftDown():
angle = 10
if delta > 0:
self.parent.rotate_shape(angle / 2)
else:
self.parent.rotate_shape(-angle / 2)
else:
factor = 1.05
x, y = event.GetPositionTuple()
x, y, _ = self.mouse_to_3d(x, y)
......@@ -190,6 +179,13 @@ class StlViewPanel(wxGLPanel):
self.zoom(factor, (x, y))
else:
self.zoom(1 / factor, (x, y))
def wheel(self, event):
"""react to mouse wheel actions:
rotate object
with shift zoom viewport
"""
self.handle_wheel(event)
wx.CallAfter(self.Refresh)
def keypress(self, event):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment