Hi, yes, this requirement is not as easy as it looks like.
I just listed all the methods that most useful, by reading their docs, you
can easily find your algorithm to compute the correct location.

I  mentioned you snip% does not have its own mouse event object,
 therefore, you cannot obtain the enter and leave event stats of a snip.
Sometimes it works, because your mouse happens to leaving the listbox and
entering the editor-canvas%. Here is my solution:

(define &hover (box #false)) ; the last hovered snip

(define/override (on-event mouse)
  (super on-event mouse)
  (define &editor-x (box (send mouse get-x)))
  (define &editor-y (box (send mouse get-y)))
  (global-to-local &editor-x &editor-y)
  (define maybe-snip (find-snip (unbox &editor-x) (unbox &editor-y)))
  (let ([hovered (unbox &hover)])
    (when (and hovered (not (eq? hovered maybe-snip)))
      '(on-leaving))
    (set-box! &hover maybe-snip)
    (when (and maybe-snip (send mouse moving?) (not (send mouse
get-left-down)))
      '(on-hover))))


On Thu, May 25, 2017 at 12:59 AM, Erich Rast <er...@snafu.de> wrote:

> Hi,
>
> Thanks a lot for your answer! The methods you mention for A3 do not
> give the right results, though. Here is my current callback with your
> method, where show-info really just opens a window at the x and y
> coordinate:
>
>  (lambda (snip evt dc show?)
>   (and-let* ((admin (send snip get-admin))
>              (editor (send admin get-editor))
>              (editorx (box 0))
>              (editory (box 0))
>              (win (get-top-level-edit-target-window)))
>     (send admin get-view x y w h snip)
>     (send editor get-snip-location snip editorx editory)
>     (send editor local-to-global editorx editory)
>     (let*-values (((tx ty) (send win client->screen (inexact->exact
>  (unbox editorx)) (inexact->exact (unbox editory)))))
>       (displayln (format "position x=~s y=~s" tx ty))
>       (send snip show-info
>             (inexact->exact (+ tx (unbox w)))
>             (inexact->exact (+ ty (unbox h)))
>             show?))))
>
> In this case, I'd like to have the window left below the snip, but it
> shows up in a completely different place. (The x coordinate seems
> roughly close, but skewed, the y-coordinate is far too small.)
>
> The closest I got to a solution so far is this clumsy callback:
>
> (lambda (snip evt dc show?)
>   (and-let* ((admin (send snip get-admin))
>              (canvas (get-canvas))
>              (editor (send admin get-editor))
>              (editor-canvas (send editor get-canvas))
>              (panel (send editor-canvas get-parent))
>              (p2 (send panel get-parent))
>              (x (box 0))
>              (y (box 0))
>              (w (box 0))
>              (h (box 0))
>              (editorx (box 0))
>              (editory (box 0))
>              (win (get-top-level-edit-target-window)))
>     (send admin get-view x y w h snip)
>     (send editor get-snip-location snip editorx editory)
>     (send editor local-to-global editorx editory)
>     (let-values (((tx ty)
>                   (send win client->screen
>                         (inexact->exact (unbox editorx))
>                         (inexact->exact (unbox editory)))))
>       (send snip show-info
>             (inexact->exact (+ (send p2 get-x) tx (unbox w)))
>             (inexact->exact (+ (send panel get-y) ty (unbox h)))
>             show?))))
>
> (Please ignore any unused variables, I've experimented with many
> different approaches.)
>
> This nearly gives the right result, so it seems as if I have to
> traverse the nested hierarchy of controls in order to find the 'right'
> control that doesn't have a 0 x- and y-coordinates because it is just
> locally embedded. This unfortunately means that if I change the layout
> geometry, the approach will fail. Not very good.
>
> In any case, the window location is still off, a little bit too much to
> the left and about the size of the tab panel heading to the top of
> where it ought to be. See the @"Notes":26 test window as a popup for
> the purple snip in the attached screenshot.
>
> Is there any way to fix this or a more general, easier way to get the
> coordinates?
>
> Best,
>
> Erich
>
> p.s. Another, more serious issue is that hovering the mouse over the
> snip and leaving it only works sometimes (e.g. when I hover from the
> listbox directly to the snip) and fails most of the time. But one thing
> at a time.
>
> On Wed, 24 May 2017 07:03:45 +0800
> WarGrey Gyoudmon Ju <juzhenli...@gmail.com> wrote:
>
> > Hi Rast
> >
> > the mouse event object of editor% and snip% is always the one passed
> > to the on-event method of editor-canvas% (that's why event handlers
> > of snip% have lots of extra arguments to provide you the location
> > information, racket/snip do the computing for you). When it is used
> > with a snip% instance directly, you have to check the docs to see the
> > proper way to use it correctly. Another thing you should take care is
> > that, the event object itself is not able to tell you the snip%s'
> > enter and leave stats.
> >
> > A1 & A2: You have get-top-level-windows and get-current-mouse-state.
> > (But the Question 1 is not necessary for your requirements here).
> > A3: You have get-snip-location, local-to-global, and client->screen.
> >
> >
> > On Tue, May 23, 2017 at 10:24 PM, Erich Rast <er...@snafu.de> wrote:
> >
> > > Hi,
> > >
> > > For me personally, coordinates are probably the most unintuitive
> > > aspect of Racket's GUI management. The problem comes up again and
> > > again, and I never get it right, so maybe someone can clarify this
> > > once and for all.
> > >
> > > I have a mouse-event% in on-event of a snip% and would like to
> > > display a floating frame% just below the mouse.
> > >
> > > Question 1: What is the right way to obtain the window in a
> > > potentially nested hierarchy of editors? I'm currently using:
> > >
> > > (define top-window (and-let* ((canvas (get-canvas))
> > >                                (top (send canvas
> > > get-top-level-window))) top))
> > >
> > > is that correct?
> > >
> > > Question 2: How do I obtain the right coordinates for the frame%
> > > that I would like to show below the mouse?
> > >
> > > I assume it has something to do with top-window above, but how do I
> > > convert from the coordinates of the mouse-event to the 'right'
> > > coordinates? Currently, the frame% appears offset about 20 to 20
> > > pixels below the top-window's top-left corner and not at all where
> > > the mouse is located.
> > >
> > > Are the mouse-event coordinates relative to the editor? Or relative
> > > to the snip within the editor? How do I convert them?
> > >
> > > Question 3: Suppose I want to do the same with a snip% displayed in
> > > a text% with one editor-canvas%, i.e., show a floating window just
> > > below the snip%. Use cases: tooltips, spell corrections, etc.
> > >
> > > How do I do that?
> > >
> > > Thanks a lot in advance!
> > >
> > > Best,
> > >
> > > Erich
> > >
> > >
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Racket Users" group.
> > > To unsubscribe from this group and stop receiving emails from it,
> > > send an email to racket-users+unsubscr...@googlegroups.com.
> > > For more options, visit https://groups.google.com/d/optout.
> > >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to