[racket] drag events on a canvas

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Sep 5 13:44:29 EDT 2011

The `button-down?' method returns #t only for events that correspond to
a button press. The `get-left-down', etc., methods report whether the
button is held down during a given event.

(This is confusing, but we inherited the behavior originally from
wxWidgets years ago.)

At Mon, 05 Sep 2011 16:24:38 +0200, Marijn wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi list,
> 
> the following program defines a canvas%-derived that catches mouse
> events and prints the drag events. Unfortunately I was unable to make
> it report any drag events. It does report motion events and left-click
> events when generated by me (currently turned off). Is this a bug or
> am I doing something wrong here?
> 
> Marijn
> 
> 
> #lang racket/gui
> 
> (define (handle-drag event)
>   (print event))
> 
> (define (handle-motion event)
>   #f)
> 
> (define (handle-left-down event)
>   #f #;(print event))
> 
> (define drawtest%
>   (class canvas%
>     (init parent)
>     (super-new (parent parent))
> 
>     (define/override (on-event event)
>       (let ((type (send event get-event-type)))
>         (case type
>           ((motion)
>            (if (send event button-down?)
>                (handle-drag event)
>                (handle-motion event)))
>           ((left-down)
>            (handle-left-down event))  )))
> 
>     ))
> 
> (define root (new frame% (label "Draw Test")))
> 
> (new drawtest%
>      (parent root)
>      (min-width 100) (min-height 100)
>      (style '(border) #;'(combo control-border)))
> 
> (send root show #t)
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.18 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk5k26YACgkQp/VmCx0OL2zsvgCfbRwmpapGh1EL3AdL+8SN7DV+
> sYcAoI81YwOnJN7R03PpJt+IyH95h3Vu
> =Zx+r
> -----END PGP SIGNATURE-----
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.