blob: 29d660de1ff28b1bbeddccc33785a3b81a4dc141 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
from OpenGL.GLUT import *
class MouseDragMonitor:
def __init__(self, button, drag_callback, zoom_callback):
self.button = button
self.active = False
self.drag_callback = drag_callback
self.zoom_callback = zoom_callback
def on_mouse(self, button, state, x, y):
if button == self.button:
self.active = (state == GLUT_DOWN)
self.last_x = x
self.last_y = y
if button == 3:
self.zoom_callback(-1.0)
elif button == 4:
self.zoom_callback(1.0)
def on_mouse_move(self, x, y):
if self.active:
delta_x = self.last_x - x
delta_y = y - self.last_y
self.last_x = x
self.last_y = y
self.drag_callback(delta_x, delta_y)
|