MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: EventHandler in Graphics

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132458] Re: EventHandler in Graphics
  • From: "E. Martin-Serrano" <eMartinSerrano at telefonica.net>
  • Date: Sat, 22 Mar 2014 00:05:21 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20140320092805.AC1936A1D@smc.vnet.net>

Hi David,

Try <Deploy>, If I understood your question, it does work for me.


Deploy@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}]

]

-----Mensaje original-----
De: djmpark [mailto:djmpark at comcast.net] 
Enviado el: jueves, 20 de marzo de 2014 10:28
Para: mathgroup at smc.vnet.net
Asunto: 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 at comcast.net 

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

 







  • Prev by Date: EventHandler in Graphics
  • Next by Date: Re: EventHandler in Graphics
  • Previous by thread: EventHandler in Graphics
  • Next by thread: Re: EventHandler in Graphics