[racket] newb question - image-snip and adjust-cursor

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Jul 13 04:26:12 EDT 2014

You can also put the code into the snip instead of the pasteboard like
this, if that's important for your use-case.

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-mixin %)
  (class %
    (inherit get-admin get-extent)
    (define wb (box 0.0))
    (define hb (box 0.0))
    (define/override (on-event dc x y editorx editory event)
      (define admin (get-admin))
      (when admin
        (define ed (send admin get-editor))
        (get-extent dc x y wb hb)
        (send ed set-cursor
              (cond
                [(and (<= 0 (- (send event get-x) x) (unbox wb))
                      (<= 0 (- (send event get-y) y) (unbox hb)))
                 hand-cursor]
                [else #f]))))
    (super-new)))

(define hand-cursor-image-snip% (hand-cursor-mixin image-snip%))
(define hand-cursor (make-object cursor% 'hand))

(define pb (new pasteboard%))
(send c set-editor pb)

(define ufo (make-object hand-cursor-image-snip% "ufo.jpg" 'jpeg))
(send pb insert ufo 100 100)
(send ufo set-flags (cons 'handles-all-mouse-events (send ufo get-flags)))
(send f show #t)

Posted on the users mailing list.