racket/draw: add make-dc' convenience method to bitmap%'

This commit is contained in:
Matthew Flatt 2012-09-14 15:58:47 -06:00
parent 7fd4f59e5a
commit d1cd4621de
4 changed files with 16 additions and 7 deletions

View File

@ -22,10 +22,15 @@
make-platform-bitmap
read-bitmap
make-monochrome-bitmap
-bitmap-dc%
(protect-out make-alternate-bitmap-kind
build-cairo-surface
quartz-bitmap%
win32-no-hwnd-bitmap%))
win32-no-hwnd-bitmap%
install-bitmap-dc-class!))
(define -bitmap-dc% #f)
(define (install-bitmap-dc-class! v) (set! -bitmap-dc% v))
;; FIXME: there must be some way to abstract over all many of the
;; ARGB/RGBA/BGRA iterations.
@ -286,6 +291,8 @@
(define/public (get-bitmap-gl-context)
#f)
(define/public (make-dc) (make-object -bitmap-dc% this))
(define/public (load-file in
[kind 'unknown]
[bg #f]

View File

@ -26,7 +26,6 @@
(provide dc-mixin
dc-backend<%>
default-dc-backend%
install-bitmap-dc-class!
do-set-pen!
do-set-brush!)
@ -45,9 +44,6 @@
black)
(color->immutable-color c)))
(define -bitmap-dc% #f)
(define (install-bitmap-dc-class! v) (set! -bitmap-dc% v))
;; dc-backend : interface
;;
;; This is the interface that the backend specific code must implement

View File

@ -241,6 +241,12 @@ For PNG loading, if @racket[bg-color] is not @racket[#f], then it is
}
@defmethod[(make-dc)
boolean?]{
Return @racket[(make-object bitmap-dc% this)].}
@defmethod[(ok?)
boolean?]{

View File

@ -11,13 +11,13 @@
(let ([w (send bm0 get-width)]
[h (send bm0 get-height)])
(let ([bm (make-bitmap w h)])
(let ([dc (make-object bitmap-dc% bm)])
(let ([dc (send bm make-dc)])
(send dc draw-bitmap bm0 0 0)
(send dc set-bitmap #f))
bm)))]
@interaction-eval[#:eval draw-eval (define (line-bitmap mode)
(let* ([bm (make-bitmap 30 4)]
[dc (make-object bitmap-dc% bm)])
[dc (send bm make-dc)])
(send dc set-smoothing mode)
(send dc draw-line 0 2 30 2)
(send dc set-bitmap #f)