[racket] newb question - image-snip and adjust-cursor
Ah, yes. That super class is important indeed!
Robby
On Sun, Jul 13, 2014 at 11:32 PM, Joseph DiMuro <joseph.dimuro at biola.edu> wrote:
> Robby, thanks for the help. I'm going with your first version; given what I
> want to do, I think I'd rather put the code in the pasteboard instead of the
> snip.
>
> I've made one further adjustment to your code, and added (super on-event
> evt) to the define/override. That way, the pasteboard does what it normally
> does, in addition to changing the mouse cursor when it is over the snip.
> Without that line, the snip is no longer selectable/draggable/resizable.
> (Your second version, where the code is inside the snip, works fine as it
> is.)
>
> Thanks again.
>
> -Joseph
>
> #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)
> (super 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)