move collecting-blit helper to common code

original commit: 5dd568050b8ea693302f71561406d7be5e3bdfec
This commit is contained in:
Matthew Flatt 2010-10-10 18:38:06 -06:00
parent 5ad1f535b4
commit 5c3ee6847e
3 changed files with 23 additions and 28 deletions

View File

@ -717,16 +717,7 @@
(cons win r)))))))
(define/public (register-collecting-blit x y w h on off on-x on-y off-x off-y)
(let ([on (if (and (zero? on-x)
(zero? on-y)
(= (send on get-width) w)
(= (send on get-height) h))
on
(let ([bm (make-object bitmap% w h)])
(let ([dc (make-object bitmap-dc% on)])
(send dc draw-bitmap-section on 0 0 on-x on-y w h)
(send dc set-bitmap #f)
bm)))])
(let ([on (fix-bitmap-size on w h on-x on-y)])
(let ([img (bitmap->image on)])
(atomically
(set! blits (cons (list x y w h img) blits))

View File

@ -1,9 +1,11 @@
#lang racket/base
(require racket/class
racket/draw
"backing-dc.rkt")
(provide canvas-autoscroll-mixin
canvas-mixin)
canvas-mixin
fix-bitmap-size)
;; Implements canvas autoscroll, applied *before* platform-specific canvas
;; methods:
@ -160,3 +162,16 @@
(when (or paint-queued
(not (send (get-dc) can-backing-flush?)))
(do-on-paint #f #f)))))
;; useful for fixing the size of a collecting blit:
(define (fix-bitmap-size on w h on-x on-y)
(if (and (zero? on-x)
(zero? on-y)
(= (send on get-width) w)
(= (send on get-height) h))
on
(let ([bm (make-object bitmap% w h)])
(let ([dc (make-object bitmap-dc% on)])
(send dc draw-bitmap-section on 0 0 on-x on-y w h)
(send dc set-bitmap #f)
bm))))

View File

@ -560,23 +560,12 @@
(cons win r))))))
(define/public (register-collecting-blit x y w h on off on-x on-y off-x off-y)
(let ([fix-size (lambda (on on-x on-y)
(if (and (zero? on-x)
(zero? on-y)
(= (send on get-width) w)
(= (send on get-height) h))
on
(let ([bm (make-object bitmap% w h)])
(let ([dc (make-object bitmap-dc% on)])
(send dc draw-bitmap-section on 0 0 on-x on-y w h)
(send dc set-bitmap #f)
bm))))])
(let ([on (fix-size on on-x on-y)]
[off (fix-size off off-x off-y)])
(let ([on-pixbuf (bitmap->pixbuf on)]
[off-pixbuf (bitmap->pixbuf off)])
(atomically
(set! reg-blits (cons (register-one-blit x y w h on-pixbuf off-pixbuf) reg-blits)))))))
(let ([on (fix-bitmap-size on w h on-x on-y)]
[off (fix-bitmap-size off w h off-x off-y)])
(let ([on-pixbuf (bitmap->pixbuf on)]
[off-pixbuf (bitmap->pixbuf off)])
(atomically
(set! reg-blits (cons (register-one-blit x y w h on-pixbuf off-pixbuf) reg-blits))))))
(define/public (unregister-collecting-blits)
(atomically