4
$\begingroup$

It seems that this issue has been raised a few times, but what exactly does MousePosition["Graphics"] answer?

This code

Dynamic @ p
 Graphics[
 EventHandler[
  Disk[], {"MouseMoved" :> (p = MousePosition["Graphics"])}]]

nicely displays mouse position in the "current graphics" coordinate.

But try to put the graphics in another Graphics (GraphicsColumn in this case):

Dynamic @ p
GraphicsColumn @ 
 List @ Graphics[
   EventHandler[
    Disk[], {"MouseMoved" :> (p = MousePosition["Graphics"])}]]

The coordinates now seem to be in the coordinate system defined by GraphicsColumn.

I will greatly appreciate any answer with a workaround (even not so generic solution).

P.S. Interesting enough GraphicsColumn breaks LocatorPane behaviour. LocatorPane manages to get correct coordinates (it uses custom LocatorPaneBox) but locators do not display:

pts = {};
GraphicsColumn @ 
 List @ LocatorPane[Dynamic[pts], Graphics[Circle[]], 
   LocatorAutoCreate -> All]
Dynamic[pts]
$\endgroup$
1
  • $\begingroup$ Whenever possible I try to use Row, Column, and Grid directly instead of their Graphics variants for other reasons. This works as expected, Column@{Dynamic@{p,p2},Graphics[EventHandler[Disk[],{"MouseMoved":>(p=MousePosition["Graphics"])}],Frame->True],Graphics[EventHandler[Disk[],{"MouseMoved":>(p2=MousePosition["Graphics"])}],Frame->True]}, but it doesn't have head Graphics so it might not work for your use case. $\endgroup$
    – Jason B.
    Dec 27 '21 at 0:07
2
$\begingroup$

In the example above

MousePosition["Graphics"] should be changed to MousePosition[{"Graphics", Graphics}] to limit the coordinate system to the innermost expression with head Graphics.

Unfortunately this does not work either.

After the discussion with the developers this was reported to WRI.

$\endgroup$
3
  • 1
    $\begingroup$ Have you ever heard back from this? Just discovered that this is still not fixed and also appears for other things than Graphics, e.g. Panes... $\endgroup$ Dec 25 '21 at 21:25
  • 1
    $\begingroup$ @AlbertRetey unfortunately it's still "in progress" $\endgroup$ Dec 26 '21 at 6:08
  • 1
    $\begingroup$ OK, I was afraid so, thanks for sharing... $\endgroup$ Dec 26 '21 at 10:48

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.