Hello,

I'm trying to implement an image-snip% subclass which has 
a new field (hash table) to store some metadata.

I follow the example described in the documentation, but 
the constructor of my image-snip subclass does not display
the bitmap.

Here is my code.. Thanks in advance.

(define image-data-snip%
  (class image-snip%
    (inherit set-snipclass
             get-flags set-flags
             get-admin
             get-extent
             draw)

    (init-field [metadata (make-hash)])
    (super-new)
    
    (set-snipclass image-data-snip-class)
    (send (get-the-snip-class-list) add image-data-snip-class)
    (set-flags (cons 'handles-events (get-flags)))
    
    (define/override (copy)
      (new image-data-snip% [metadata metadata]))
    
    (define/override (write f)
      (super write f)
      (send f put (list->bytes (hash->list metadata))))
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;Operations on the metadata ;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    (define/public (get-arg-pos arg)
      (hash-ref metadata arg '(0.5 0.5)))
    
    (define/public (set-arg-pos arg pos)
      (hash-set! metadata arg pos))
    
    (define/public (get-args-pos)
      (hash->list metadata))))

(define image-data-snip-class%
  (class snip-class%
    (inherit set-classname)
    
    (super-new)
    (set-classname (~s '(lib "main.rkt" "image-data-snip")))
    
    (define/override (read f)
      #;(super read f)
      (define size-b (box 0.0))
      (send f get size-b)
      ;; I do not know how can I restore the hash map here
      (new image-data-snip% [metadata (bytes->list (unbox size-b))]))))

(define image-data-snip-class (new image-data-snip-class%))

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to