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

Factorize wheel handling and patching

parent 2614bb5e
...@@ -154,14 +154,10 @@ class GcodeViewPanel(wxGLPanel): ...@@ -154,14 +154,10 @@ class GcodeViewPanel(wxGLPanel):
self.parent.setlayercb(new_layer) self.parent.setlayercb(new_layer)
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def wheel(self, event): def handle_wheel(self, event):
"""react to mouse wheel actions:
without shift: set max layer
with shift: zoom viewport
"""
delta = event.GetWheelRotation() delta = event.GetWheelRotation()
factor = 1.05 factor = 1.05
if event.ShiftDown(): if hasattr(self.parent, "model") and event.ShiftDown():
if not self.parent.model: if not self.parent.model:
return return
count = 1 if not event.ControlDown() else 10 count = 1 if not event.ControlDown() else 10
...@@ -176,6 +172,14 @@ class GcodeViewPanel(wxGLPanel): ...@@ -176,6 +172,14 @@ class GcodeViewPanel(wxGLPanel):
else: else:
self.zoom(1 / factor, (x, y)) 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): def fit(self):
if not self.parent.model or not self.parent.model.loaded: if not self.parent.model or not self.parent.model.loaded:
return return
......
...@@ -103,6 +103,19 @@ class Plater(wx.Frame): ...@@ -103,6 +103,19 @@ class Plater(wx.Frame):
else: else:
orig_handler(event) orig_handler(event)
patch_method(viewer, "handle_rotation", handle_rotation) 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.s = viewer
self.mainsizer.Add(self.s, 1, wx.EXPAND) self.mainsizer.Add(self.s, 1, wx.EXPAND)
......
...@@ -170,26 +170,22 @@ class StlViewPanel(wxGLPanel): ...@@ -170,26 +170,22 @@ class StlViewPanel(wxGLPanel):
event.Skip() event.Skip()
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def handle_wheel(self, event):
delta = event.GetWheelRotation()
factor = 1.05
x, y = event.GetPositionTuple()
x, y, _ = self.mouse_to_3d(x, y)
if delta > 0:
self.zoom(factor, (x, y))
else:
self.zoom(1 / factor, (x, y))
def wheel(self, event): def wheel(self, event):
"""react to mouse wheel actions: """react to mouse wheel actions:
rotate object rotate object
with shift zoom viewport with shift zoom viewport
""" """
delta = event.GetWheelRotation() self.handle_wheel(event)
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)
if delta > 0:
self.zoom(factor, (x, y))
else:
self.zoom(1 / factor, (x, y))
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def keypress(self, event): 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