adjust 2htdp/image so that they work properly as wxme-mode snips
Before, they would create a crippled version in that mode, but that is no longer necessary (it may never have been necessary, but it certainly hasn't been necessary in a while)
This commit is contained in:
parent
34de786970
commit
8fb8f561c4
|
@ -2,61 +2,13 @@
|
||||||
(require racket/class
|
(require racket/class
|
||||||
wxme
|
wxme
|
||||||
"private/image-core-snipclass.rkt"
|
"private/image-core-snipclass.rkt"
|
||||||
"private/regmk.rkt")
|
"image-core.rkt")
|
||||||
(provide reader image<%>)
|
(provide reader image<%>)
|
||||||
|
|
||||||
(define guiless-image%
|
|
||||||
(class* object% (equal<%> image<%>)
|
|
||||||
(init-field pinhole bb)
|
|
||||||
(define/public (equal-to? that eq-recur)
|
|
||||||
(cond
|
|
||||||
[(eq? this that) #t]
|
|
||||||
[else (error 'image% "cannot do equality comparison without gui libraries")]))
|
|
||||||
(define/public (equal-hash-code-of y) 42)
|
|
||||||
(define/public (equal-secondary-hash-code-of y) 3)
|
|
||||||
|
|
||||||
(define/public (get-shape)
|
|
||||||
(error 'image% "cannot get-shape without gui libraries"))
|
|
||||||
(define/public (set-shape s)
|
|
||||||
(error 'image% "cannot get-shape without gui libraries"))
|
|
||||||
(define/public (get-bb) bb)
|
|
||||||
(define/public (get-pinhole) pinhole)
|
|
||||||
(define/public (get-normalized?) #f)
|
|
||||||
(define/public (set-normalized? n?) (void))
|
|
||||||
|
|
||||||
(define/public (get-normalized-shape)
|
|
||||||
(error 'image% "cannot get-normalized-shape without gui libraries"))
|
|
||||||
|
|
||||||
(super-new)))
|
|
||||||
|
|
||||||
(define reader
|
(define reader
|
||||||
(new
|
(new
|
||||||
(class* object% (snip-reader<%>)
|
(class* object% (snip-reader<%>)
|
||||||
(define/public (read-header vers stream)
|
(define/public (read-header vers stream) (void))
|
||||||
(void))
|
|
||||||
(define/public (read-snip text? cvers stream)
|
(define/public (read-snip text? cvers stream)
|
||||||
(let* ([lst (fetch (send stream read-raw-bytes '2htdp/image))])
|
(snipclass-bytes->image (send stream read-raw-bytes '2htdp/image)))
|
||||||
(if text?
|
|
||||||
#"."
|
|
||||||
(let ([marshalled-img (list-ref lst 0)]
|
|
||||||
[marshalled-bb (list-ref lst 1)]
|
|
||||||
[marshalled-pinhole (list-ref lst 2)])
|
|
||||||
(new guiless-image%
|
|
||||||
[bb (if (and (vector? marshalled-bb)
|
|
||||||
(= 4 (vector-length marshalled-bb))
|
|
||||||
(eq? (vector-ref marshalled-bb 0) 'struct:bb)
|
|
||||||
(number? (vector-ref marshalled-bb 1))
|
|
||||||
(number? (vector-ref marshalled-bb 2))
|
|
||||||
(number? (vector-ref marshalled-bb 3)))
|
|
||||||
(apply make-bb (cdr (vector->list marshalled-bb)))
|
|
||||||
(make-bb 100 100 100))]
|
|
||||||
[pinhole
|
|
||||||
(if (and (vector? marshalled-pinhole)
|
|
||||||
(= 3 (vector-length marshalled-pinhole))
|
|
||||||
(eq? (vector-ref marshalled-pinhole 0) 'struct:point)
|
|
||||||
(number? (vector-ref marshalled-pinhole 1))
|
|
||||||
(number? (vector-ref marshalled-pinhole 2)))
|
|
||||||
(make-point (vector-ref marshalled-pinhole 1)
|
|
||||||
(vector-ref marshalled-pinhole 2))
|
|
||||||
#f)])))))
|
|
||||||
(super-new))))
|
(super-new))))
|
||||||
|
|
|
@ -37,7 +37,6 @@ has been moved out).
|
||||||
racket/math
|
racket/math
|
||||||
racket/contract
|
racket/contract
|
||||||
"private/image-core-bitmap.rkt"
|
"private/image-core-bitmap.rkt"
|
||||||
"image-core-wxme.rkt"
|
|
||||||
"private/image-core-snipclass.rkt"
|
"private/image-core-snipclass.rkt"
|
||||||
"private/regmk.rkt"
|
"private/regmk.rkt"
|
||||||
racket/snip
|
racket/snip
|
||||||
|
@ -440,8 +439,11 @@ has been moved out).
|
||||||
(define racket/base:read read)
|
(define racket/base:read read)
|
||||||
(define image-snipclass%
|
(define image-snipclass%
|
||||||
(class snip-class%
|
(class snip-class%
|
||||||
(define/override (read f)
|
(define/override (read f) (snipclass-bytes->image (send f get-unterminated-bytes)))
|
||||||
(let ([lst (parse (fetch (send f get-unterminated-bytes)))])
|
(super-new)))
|
||||||
|
|
||||||
|
(define (snipclass-bytes->image bytes)
|
||||||
|
(define lst (parse (fetch bytes)))
|
||||||
(cond
|
(cond
|
||||||
[(not lst)
|
[(not lst)
|
||||||
(make-image (make-translate 50 50 (make-ellipse 100 100 0 'solid "black"))
|
(make-image (make-translate 50 50 (make-ellipse 100 100 0 'solid "black"))
|
||||||
|
@ -452,8 +454,7 @@ has been moved out).
|
||||||
(make-image (list-ref lst 0)
|
(make-image (list-ref lst 0)
|
||||||
(list-ref lst 1)
|
(list-ref lst 1)
|
||||||
#f
|
#f
|
||||||
(list-ref lst 2))])))
|
(list-ref lst 2))]))
|
||||||
(super-new)))
|
|
||||||
|
|
||||||
(provide snip-class)
|
(provide snip-class)
|
||||||
(define snip-class (new image-snipclass%))
|
(define snip-class (new image-snipclass%))
|
||||||
|
@ -1372,7 +1373,9 @@ the mask bitmap and the original bitmap are all together in a single bytes!
|
||||||
image-snip%
|
image-snip%
|
||||||
|
|
||||||
curve-segment->path
|
curve-segment->path
|
||||||
mode-color->pen)
|
mode-color->pen
|
||||||
|
|
||||||
|
snipclass-bytes->image)
|
||||||
|
|
||||||
;; method names
|
;; method names
|
||||||
(provide get-shape get-bb get-pinhole get-normalized? get-normalized-shape)
|
(provide get-shape get-bb get-pinhole get-normalized? get-normalized-shape)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user