[racket] newb question - image-snip and adjust-cursor
I'm not sure why that isn't working: you probably need to at least set
the flags on the snip, but that's not sufficient.
But you can do this a different way, by overriding the on-event method
of the pasteboard.
Robby
#lang racket/gui
(define f (new frame%
[label "Adjust Cursor Test"]
[width 250]
[height 250]))
(define c (new editor-canvas% [parent f]))
(define hand-cursor-pasteboard%
(class pasteboard%
(inherit find-snip set-cursor)
(define hand-snips '())
(define/public (add-hand-snip s) (set! hand-snips (cons s hand-snips)))
(define/override (on-event evt)
(define snp (find-snip (send evt get-x) (send evt get-y)))
(set-cursor (if (member snp hand-snips)
hand-cursor
#f)))
(super-new)))
(define hand-cursor (make-object cursor% 'hand))
(define pb (new hand-cursor-pasteboard%))
(send c set-editor pb)
(define ufo (make-object image-snip% "ufo.jpg" 'jpeg))
(send pb insert ufo 100 100)
(send pb add-hand-snip ufo)
(send f show #t)
On Wed, Jul 9, 2014 at 10:44 AM, Joseph DiMuro <joseph.dimuro at biola.edu> wrote:
> Hello fellow Racketeers. I apologize in advance for asking an extremely dumb
> question:
>
> I am currently learning about the Graphical Interface Toolkit. I'm trying to
> do something that should be very simple: have a pasteboard with a single
> image-snip, and have the mouse cursor change to a hand when it is over the
> image-snip. Based on what I've read, it seems like I need to create a new
> subclass of image-snip%, and override adjust-cursor so that it changes the
> mouse cursor into a hand. Here's my code:
>
> #lang racket/gui
>
> (define f (new frame%
> [label "Adjust Cursor Test"]
> [width 250]
> [height 250]))
>
> (define c (new editor-canvas% [parent f]))
>
> (define pb (new pasteboard%))
> (send c set-editor pb)
>
> (define hand-cursor-snip%
> (class image-snip%
> (define/override (adjust-cursor dc x y editorx editory event)
> (make-object cursor% 'hand))
> (super-make-object)))
>
> (define ufo (make-object hand-cursor-snip% "ufo.jpg" 'jpeg))
> (send pb insert ufo)
>
> (send f show #t)
>
> My ufo picture does appear on the pasteboard, and it can be dragged and
> resized as usual. But the mouse cursor doesn't change when it is over the
> ufo.
>
> I'm sure this is a facepalm-worthy mistake; I'm a newb at this. What should
> I do instead? Thanks in advance.
>
> -Joseph DiMuro
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>