I’m trying to navigate on my panel. The user keeps the middle click button pressed and moves the mouse, and the panel should be navigated to the left or right, in the mouse movement direction.
I save the original x and y mouse positions in 2 variables:
self.panel.Bind(wx.EVT_MIDDLE_DOWN, self.onMouseMiddleDown) self.panel.Bind(wx.EVT_MOTION, self.onMotion)
def onMouseMiddleDown(self, evt): self.org_x = evt.GetX() self.org_y = evt.GetY()
Then the user moves the mouse while middle button is pressed, and I calculate the delta x
def onMotion(self, evt): x_pos = evt.GetX() y_pos = evt.GetY() middle_is_down = evt.MiddleIsDown() if middle_is_down: delta_x = x_pos - self.org_x self.panel.navigate_with_middle_click(delta_x) return
However, after the user moves to left and without releasing the middle button, he starts to move mouse to right, the panel is still navigated to left, because delta x is still positive.
Delta x will be always positive, until the cursor moves to the right of the original x pos (self.org_x). But I want the panel to be navigated in the direction of mouse movement, regardless of the cursor being on the left or right of the original x pos.
Do you have any suggestions?