Message Boards Message Boards

2
|
4156 Views
|
1 Reply
|
4 Total Likes
View groups...
Share
Share this post:

Syncing image sizes while keeping mouse position information

Posted 11 years ago
Hi,
I want to sync the image size of both graphics and also I need the mouse position information as the following code does:
DynamicModule[{imx = 400, imy = Automatic, pos = 0}, 
  {Graphics[{Circle[]}, Epilog -> Dynamic[pos = First[MousePosition[{"Graphics", Graphics}, {True, 0}]]; {}],
  ImageSize -> Dynamic[{imx, imy}]],
  Graphics[Disk[], ImageSize -> Dynamic[{imx, imy}]],
  Dynamic[Print[1]; {imx, imy, pos}]}] 

This code print 1 as long as the image size got updated.

My problem was, is there a way to avoid image size getting updated triggered by MousePosition?

For example: this code doesn't have MousePosition and {imx, imy} changes only when image got resized.
DynamicModule[{imx = 400, imy = Automatic},
  {Graphics[{Circle[]}, ImageSize -> Dynamic[{imx, imy}]], Graphics[Disk[], ImageSize -> Dynamic[{imx, imy}]],
  Dynamic[Print[1]; {imx, imy}]}] 

I want the imx and imy got updated only when the image got resized AND also have mouse position information as the first piece of code. Any help?

Thanks
POSTED BY: MinHsuan Peng
Have a look at the TrackedSymbols Option for Dynamic. This code should do what you want:
DynamicModule[{imx = 400, imy = Automatic, pos = 0},
  {Graphics[{Circle[]},
   Epilog -> Dynamic[pos = First[MousePosition[{"Graphics", Graphics}, {True, 0}]]; {}],
   ImageSize -> Dynamic[{imx, imy}]],
   Graphics[Disk[], ImageSize -> Dynamic[{imx, imy}]],
   Dynamic[Print[1]; {imx, imy, pos}, TrackedSymbols :> {imx, imy}]}] 
POSTED BY: Markus van
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract