I would like to be able to change which action specified events take depending on some condition. For example, I have established a SetterBar
SetterBar[Dynamic[setter], {Zoom, Pan}]
and created a graphic that I would like the left mouse button to cause to either zoom or pan, depending on what the value of setter
is when the event occurs.
DynamicModule[{frac = 0, zoomval = 7*Pi/36, drag = {0, 0},
pt = CurrentValue[ImageSize], CurrentPosition = {1/2, 1/2},
panvalue = {0, 0}},
EventHandler[
Dynamic[Show[graphics,
ViewCenter -> {{1/2, 1/2,
1/2}, {x = CurrentPosition[[1]] + panvalue[[1]],
y = CurrentPosition[[2]] - panvalue[[2]]}},
ViewAngle -> (Which[drag[[2]] > 0,
zoomval = Min[Pi*0.7, zoomval + frac*(Pi - zoomval)],
drag[[2]] < 0,
zoomval = Max[zoomval - frac*(Pi - zoomval), 0.2],
drag[[2]] == 0, zoomval = zoomval]),
RotationAction -> "Clip"]], {{"MouseDown",
1} :> (a = CurrentValue[MousePosition]), {"MouseDragged",
1} :> {Which[
setter == Zoom, {b = CurrentValue[MousePosition], drag = b - a,
frac = 0.5 Norm[drag]/Norm[pt]},
setter == Pan, {b = CurrentValue[MousePosition], drag = b - a,
panvalue = {drag[[1]]/(pt[[1]]),
drag[[2]]/(pt[[2]])}}]}, {"MouseUp", 1} :> {frac = 0,
drag = {0, 0}, panvalue = {0, 0}, CurrentPosition[[1]] = x,
CurrentPosition[[2]] = y}}]]
This may be a little difficult to follow, but esentially I want the Which
function to alter the action taken by the event "MouseDragged"
depending on if setter is set to Zoom or Pan. Currently, everything works when the value is set to Zoom, but no action occurs upon setting the value to Pan.
Also, graphics
is simply a red cylinder created for example.
graphics = Graphics3D[{Red, Cylinder[]}];