disable brush gradient when the target is monochrome

This commit is contained in:
Matthew Flatt 2011-01-04 17:31:34 -07:00
parent 6c3feabb52
commit 577755630a
4 changed files with 77 additions and 72 deletions

View File

@ -787,67 +787,68 @@
(let ([st (send brush get-stipple)] (let ([st (send brush get-stipple)]
[col (send brush get-color)] [col (send brush get-color)]
[gradient (send brush get-gradient)]) [gradient (send brush get-gradient)])
(if gradient (if (and gradient
(make-gradient-pattern cr gradient) (not (collapse-bitmap-b&w?)))
(if st (make-gradient-pattern cr gradient)
(install-stipple st col s (if st
(lambda () brush-stipple-s) (install-stipple st col s
(lambda (v) (set! brush-stipple-s v) v)) (lambda () brush-stipple-s)
(let ([horiz (lambda (cr2) (lambda (v) (set! brush-stipple-s v) v))
(cairo_move_to cr2 0 3.5) (let ([horiz (lambda (cr2)
(cairo_line_to cr2 12 3.5) (cairo_move_to cr2 0 3.5)
(cairo_move_to cr2 0 7.5) (cairo_line_to cr2 12 3.5)
(cairo_line_to cr2 12 7.5) (cairo_move_to cr2 0 7.5)
(cairo_move_to cr2 0 11.5) (cairo_line_to cr2 12 7.5)
(cairo_line_to cr2 12 11.5))] (cairo_move_to cr2 0 11.5)
[vert (lambda (cr2) (cairo_line_to cr2 12 11.5))]
(cairo_move_to cr2 3.5 0) [vert (lambda (cr2)
(cairo_line_to cr2 3.5 12) (cairo_move_to cr2 3.5 0)
(cairo_move_to cr2 7.5 0) (cairo_line_to cr2 3.5 12)
(cairo_line_to cr2 7.5 12) (cairo_move_to cr2 7.5 0)
(cairo_move_to cr2 11.5 0) (cairo_line_to cr2 7.5 12)
(cairo_line_to cr2 11.5 12))] (cairo_move_to cr2 11.5 0)
[bdiag (lambda (cr2) (cairo_line_to cr2 11.5 12))]
(for ([i (in-range -2 3)]) [bdiag (lambda (cr2)
(let ([y (* i 6)]) (for ([i (in-range -2 3)])
(cairo_move_to cr2 -1 (+ -1 y)) (let ([y (* i 6)])
(cairo_line_to cr2 13 (+ 13 y)))))] (cairo_move_to cr2 -1 (+ -1 y))
[fdiag (lambda (cr2) (cairo_line_to cr2 13 (+ 13 y)))))]
(for ([i (in-range -2 3)]) [fdiag (lambda (cr2)
(let ([y (* i 6)]) (for ([i (in-range -2 3)])
(cairo_move_to cr2 13 (+ -1 y)) (let ([y (* i 6)])
(cairo_line_to cr2 -1 (+ 13 y)))))]) (cairo_move_to cr2 13 (+ -1 y))
(cairo_line_to cr2 -1 (+ 13 y)))))])
(case s
[(horizontal-hatch) (case s
(make-pattern-surface [(horizontal-hatch)
cr col (make-pattern-surface
horiz)] cr col
[(vertical-hatch) horiz)]
(make-pattern-surface [(vertical-hatch)
cr col (make-pattern-surface
vert)] cr col
[(cross-hatch) vert)]
(make-pattern-surface [(cross-hatch)
cr col (make-pattern-surface
(lambda (cr) (horiz cr) (vert cr)))] cr col
[(bdiagonal-hatch) (lambda (cr) (horiz cr) (vert cr)))]
(make-pattern-surface [(bdiagonal-hatch)
cr col (make-pattern-surface
bdiag)] cr col
[(fdiagonal-hatch) bdiag)]
(make-pattern-surface [(fdiagonal-hatch)
cr col (make-pattern-surface
fdiag)] cr col
[(crossdiag-hatch) fdiag)]
(make-pattern-surface [(crossdiag-hatch)
cr col (make-pattern-surface
(lambda (cr) (bdiag cr) (fdiag cr)))] cr col
[else (lambda (cr) (bdiag cr) (fdiag cr)))]
(install-color cr [else
(if (eq? s 'hilite) hilite-color col) (install-color cr
alpha (if (eq? s 'hilite) hilite-color col)
#f)]))))) alpha
#f)])))))
(cairo_fill_preserve cr)))) (cairo_fill_preserve cr))))
(when pen? (when pen?
(let ([s (send pen get-style)]) (let ([s (send pen get-style)])

View File

@ -17,14 +17,16 @@ In addition to its color and style, a brush can have a stipple bitmap.
As an alternative to a color, style, and stipple, a brush can have a As an alternative to a color, style, and stipple, a brush can have a
gradient that is a @racket[linear-gradient%] or gradient that is a @racket[linear-gradient%] or
@racket[radial-gradient%]. For each point in a drawing destination, a @racket[radial-gradient%]. When a brush has a gradient and the target
gradient associates a color to the point based on starting and ending for drawing is not monochrome, then other brush settings are
colors and starting and ending lines (for a linear gradient) or ignored. With a gradient, for each point in a drawing destination,
circles (for a radial gradient). A gradient-assigned color is applied the gradient associates a color to the point based on starting and
for each point is that touched when drawing with the brush. ending colors and starting and ending lines (for a linear gradient)
or circles (for a radial gradient); a gradient-assigned color is
applied for each point that is touched when drawing with the brush.
A brush's style is one of the following (but is ignored if the brush A brush's style is one of the following (but is ignored if the brush
has a gradient): has a gradient and the target is not monochrome):
@itemize[ @itemize[
@ -115,7 +117,9 @@ Gets the stipple bitmap, or @scheme[#f] if the brush has no stipple.
} }
@defmethod[(get-gradient) @defmethod[(get-gradient)
(or/c (is-a?/c gradient<%>) #f)]{ (or/c (is-a?/c linear-gradient%)
(is-a?/c radial-gradient%)
#f)]{
Gets the gradient, or @scheme[#f] if the brush has no gradient. Gets the gradient, or @scheme[#f] if the brush has no gradient.

View File

@ -24,7 +24,7 @@ Colors transitions are based on a line, where colors are assigned to
[y0 real?] [y0 real?]
[x1 real?] [x1 real?]
[y1 real?] [y1 real?]
[stops (listof/c (list/c (real-in 0 1) (is-a?/c color%)))])]{ [stops (listof (list/c (real-in 0 1) (is-a?/c color%)))])]{
Creates a linear gradient with a line from (@racket[x0], @racket[y0]) Creates a linear gradient with a line from (@racket[x0], @racket[y0])
to end point (@racket[x1], @racket[y1]). The @racket[stops] list to end point (@racket[x1], @racket[y1]). The @racket[stops] list
@ -70,7 +70,7 @@ Returns the gradient's control line as @racket[_x0], @racket[_y0],
} }
@defmethod[(get-stops) @defmethod[(get-stops)
(listof/c (list/c (real-in/c 0 1) (is-a?/c color%)))]{ (listof (list/c (real-in/c 0 1) (is-a?/c color%)))]{
Returns the gradient's list of color stops. Returns the gradient's list of color stops.

View File

@ -24,7 +24,7 @@ Colors transitions are based on two circles and the sequence of circles that
[x1 real?] [x1 real?]
[y1 real?] [y1 real?]
[r1 real?] [r1 real?]
[stops (listof/c (list/c (real-in 0 1) (is-a?/c color%)))])]{ [stops (listof (list/c (real-in 0 1) (is-a?/c color%)))])]{
Creates a radial gradient with the starting circle as the one with Creates a radial gradient with the starting circle as the one with
radius @racket[r0] centered at (@racket[x0], @racket[y0]) and the radius @racket[r0] centered at (@racket[x0], @racket[y0]) and the
@ -68,7 +68,7 @@ Returns the gradient's boundary circles as @racket[_x0], @racket[_y0],
} }
@defmethod[(get-stops) @defmethod[(get-stops)
(listof/c (list/c (real-in 0 1) (is-a?/c color%)))]{ (listof (list/c (real-in 0 1) (is-a?/c color%)))]{
Returns the gradient's list of color stops. Returns the gradient's list of color stops.