quarta-feira, 2 de Dezembro de 2015 às 13:34:21 UTC, Robby Findler escreveu:
> I think this code is doing what you want.
> 
> Robby
> 
> #lang racket/gui
> 
> (require (prefix-in - racket/base))
> (provide (rename-out [image-data-snip-class snip-class])
>          image-data-snip%)
> 
> (define image-data-snip%
>   (class image-snip%
>     (inherit set-snipclass
>              get-flags set-flags
>              get-admin
>              get-extent
>              draw)
> 
>     (define metadata (make-hash))
>     (define/public (set-metadata md) (set! metadata md))
>     (super-new)
> 
>     (set-snipclass image-data-snip-class)
>     (set-flags (cons 'handles-events (get-flags)))
> 
>     (define/override (copy)
>       (define ids (new image-data-snip%))
>       (send ids set-metadata metadata)
>       ids)
> 
>     (define/override (write f)
>       (define p (open-output-bytes))
>       (-write metadata p)
>       (define b (get-output-bytes p))
>       (send f put (bytes-length b) b))
> 
>     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>     ;;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)
>       (define byts (send f get-unterminated-bytes))
>       (define ids (new image-data-snip%))
>       (send ids set-metadata (-read (open-input-bytes byts)))
>       ids)))
> 
> (define image-data-snip-class (new image-data-snip-class%))
> (send (get-the-snip-class-list) add image-data-snip-class)

Thanks Robby, for the reply, this code do almost everything that I want.
The missing part is to display the bitmap when the object is created. 
For example, the following evocation returns an empty image

>> (define ids (make-object image-data-snip% "path/to/img.png"))
>> ids
|x|

But if I try..

>> (send ids get-bitmap)

It returns the filled bitmap. I tried to rewrite the draw method,
but in the subclass I don't have the bitmap yet unless I store it there.
However, it seems awkward to store the bitmap in this class again. 
Can you tell me what is the right way to solve this problem.

Thank you very much, and sorry for my inconvenience.

-- 
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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to