From 00ef7da640a31ae3f8abfd1298d4503259a0600c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 27 May 2012 06:38:30 -0600 Subject: [PATCH] racket/draw: background and text colors in `record-dc%' Also, improve docs to clarify how the recorded settings interact with the target DC's settings. --- collects/racket/draw/private/record-dc.rkt | 24 ++++++++++++++++++- .../scribblings/draw/record-dc-class.scrbl | 12 ++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/collects/racket/draw/private/record-dc.rkt b/collects/racket/draw/private/record-dc.rkt index 916f0cb3ec..6a09bc621c 100644 --- a/collects/racket/draw/private/record-dc.rkt +++ b/collects/racket/draw/private/record-dc.rkt @@ -347,6 +347,7 @@ (inherit get-origin get-scale get-rotation get-initial-matrix get-pen get-brush get-font get-smoothing get-text-mode + get-background get-text-background get-text-foreground get-alpha get-clipping-region translate rotate scale) @@ -489,6 +490,9 @@ [(s) (get-smoothing)] [(f) (get-font)] [(tm) (get-text-mode)] + [(bg) (get-background)] + [(tbg) (get-text-background)] + [(tfg) (get-text-foreground)] [(a) (get-alpha)] [(cr) (get-clipping-region)] [(to-default?) (applies-to-default?)]) @@ -502,7 +506,19 @@ (unless (and to-default? (eq? s 'unsmoothed)) (set-smoothing s)) (unless (and to-default? (eq? tm 'transparent)) (set-text-mode tm)) (unless (and to-default? (= a 1.0)) (set-alpha a)) - (unless (and to-default? (not cr)) (set-clipping-region cr)))) + (unless (and to-default? (not cr)) (set-clipping-region cr)) + (unless (and to-default? (and (= (color-red bg) 255) + (= (color-green bg) 255) + (= (color-blue bg) 255))) + (set-background bg)) + (unless (and to-default? (and (= (color-red tbg) 255) + (= (color-green tbg) 255) + (= (color-blue tbg) 255))) + (set-text-background tbg)) + (unless (and to-default? (and (= (color-red tfg) 0) + (= (color-green tfg) 0) + (= (color-blue tfg) 0))) + (set-text-foreground tfg)))) (define/public (applies-to-default?) #t) @@ -725,6 +741,9 @@ (define s (send dc get-smoothing)) (define f (send dc get-font)) (define tm (send dc get-text-mode)) + (define bg (send dc get-background)) + (define tbg (send dc get-text-background)) + (define tfg (send dc get-text-foreground)) (define a (send dc get-alpha)) (define cr (send dc get-clipping-region)) @@ -742,5 +761,8 @@ (send dc set-font f) (send dc set-smoothing s) (send dc set-text-mode tm) + (send dc set-background bg) + (send dc set-text-background tbg) + (send dc set-text-foreground tfg) (send dc set-alpha a) (send dc set-clipping-region cr))) diff --git a/collects/scribblings/draw/record-dc-class.scrbl b/collects/scribblings/draw/record-dc-class.scrbl index b0941f54ba..0a439e657b 100644 --- a/collects/scribblings/draw/record-dc-class.scrbl +++ b/collects/scribblings/draw/record-dc-class.scrbl @@ -10,6 +10,18 @@ A @racket[record-dc%] object records drawing actions for replay into (that can be printed with @racket[write] and recreated with @racket[read]) via @method[record-dc% get-recorded-datum]. +When drawing recorded actions, the target drawing context's pen, +brush, font, text, background, text background, and text foreground do +not affect the recorded actions. The target drawing context's +transformation, alpha, and clipping region compose with settings in +the recorded actions (so that, for example, a recorded action to set +the clipping region actually intersects the region with the drawing +context's clipping region at the time that the recorded commands are +replayed). After recoded commands are replayed, all settings in the +target drawing context, such as its clipping region or current font, +are as before the replay. + + @defconstructor[([width (>=/c 0) 640] [height (>=/c 0) 480])]{