2
$\begingroup$

When I have one Locator I can move a line defined by that Locator by clicking anywhere on the line. But, if I have two Locators (using PaneSelector), I can't move the line by clicking anywhere. I have to click on the point I set with Locator or near it. How can I move a line, by clicking anywhere, when I have two Locators? I NEED to use Manipulate and Locator!

Right now I have a line defined by pt which is linked to my controls.

Manipulate[
 Module[{pt},
  pt = If[ctrl == 1, pt1, pt2];

  Graphics[{
    PointSize@0.04, Point@pt,
    Thick, Dashed, Line[{{-1, pt[[2]]}, {1, pt[[2]]}}]
    }, Frame -> True, PlotRange -> {{-1, 1}, {-1, 1}}]
  ],
 Control[{{ctrl, 1}, {1, 2}, Setter}],
 PaneSelector[{
   1 -> Control[{{pt1, {0, 0}}, Locator, Appearance -> None}],
   1 -> Control[{{pt2, {0, 0}}, Locator, Appearance -> None}]
   }, Dynamic@ctrl]
 ]
$\endgroup$
1
$\begingroup$

Is something like this what you have in mind? (Note that this version doesn't exactly use a locator, though.)

DynamicModule[
 {y = 0},

 Graphics[{
   EventHandler[
    Dynamic[Line[{{0, y}, {1, y}}]],
    {"MouseDragged" :> (y = MousePosition["Graphics"][[2]])}
    ]
   },
  PlotRange -> 2,
  Axes -> True
  ]
 ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.