Date: Mar 20, 2014 5:28 AM
Author: David Park
Subject: EventHandler in Graphics


Dear MathGroup,

I would like to design a custom slider as a Graphics element. I would like
it to be a Graphics element with everything specified in Graphics
coordinates so I can precisely place the elements. (I don't want to use
Inset that has unspecified fillings and whose size cannot be given in
graphical coordinates and that does not adjust if the graphic is dragged to
a different size.)

So here is something that pretty much works. The invisible Rectangle
provides the area over which the EventHandler operates. The only problem is
that as soon as the area is clicked the entire graphic is selected. (With
the red box and handles around the graphic.) Is there any way to suppress
that selection? The selection occurs as soon as the area is clicked.

DynamicModule[{position = {0, 0}, xposition = 0},

Column[{

Graphics[

{Style[Line[{{-1, 0}, {1, 0}}], Antialiasing -> False],

EventHandler[

{FaceForm[Opacity[0.0]],

Rectangle[{-1.1, -0.2}, {1.1, 0.2}]},

{"MouseDragged" :> (position = {Clip[

First@MousePosition["Graphics"], {-1, 1}], 0};

xposition = First[position])}],

AbsolutePointSize[7], Red,

Point[Dynamic[position]]},

PlotRange -> {{-1.5, 1.5}, {-0.5, 0.5}},

Frame -> True,

ImageSize -> 300,

ContentSelectable -> False],

Dynamic@xposition}]

]



If one substitutes "MouseClicked" for "MouseDragged" no selection occurs -
as is desired.



I was also looking at the idea of nested EventHandlers but could not find a
single example of its usage in help although they are mentioned in the
EventHandles Details and Options. It is not clear how the nesting would be
arranged. Does anyone have any ideas on that?



David Park

djmpark@comcast.net

http://home.comcast.net/~djmpark/index.html