I recently started to work with the EventHandler
function to make it possible to Zoom, Pan, etc, with only the use of a mouse. I have found a way to zoom that is somewhat working without a keyboard, but was wondering if anyone had any tips to improve it. It works very slowly, often asking me if I'd like to disable dynamic updating. Obviously, this is unacceptable for any practical purpose. The code so far is as follows:
EventHandler[
Dynamic[Graphics3D[Cylinder[], ViewAngle -> Dynamic[viewval]],
Initialization :> (mousecoord1 = {0, 0}; mousecoord2 = {0, 0};
size = {0, 0}; fracmag = 0; difference = 0; anglediff = 0;
viewval = 7*Pi/36)], {"MouseDown" :> (mousecoord1 =
CurrentValue[MousePosition];
size = CurrentValue[
ImageSize])}, {"MouseDragged" :> (mousecoord2 =
CurrentValue[MousePosition];
difference = mousecoord2 - mousecoord1;
fracmag = Norm[difference]/Norm[size];
anglediff = fracmag*(Pi - viewval);
Which[difference[[2]] < 0,
Min[viewval = viewval + anglediff, Pi - 0.00001],
difference[[2]] > 0, Max[viewval = viewval - anglediff, 0.00001],
difference[[2]] = 0,
viewval = viewval])}, {"MouseUp" :> (anglediff = 0;
difference = {0, 0}; mousecoord1 = {0, 0}; mousecoord2 = {0, 0})}]
The code above uses a simple 3d Graphic, a cylinder, and the ViewAngle
option to track a mouse click and drag which then uses the ratio between the drag and the image size to determine how much to zoom in or out.
Overlay
is all you need then. $\endgroup$