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)]
[col (send brush get-color)]
[gradient (send brush get-gradient)])
(if gradient
(make-gradient-pattern cr gradient)
(if st
(install-stipple st col s
(lambda () brush-stipple-s)
(lambda (v) (set! brush-stipple-s v) v))
(let ([horiz (lambda (cr2)
(cairo_move_to cr2 0 3.5)
(cairo_line_to cr2 12 3.5)
(cairo_move_to cr2 0 7.5)
(cairo_line_to cr2 12 7.5)
(cairo_move_to cr2 0 11.5)
(cairo_line_to cr2 12 11.5))]
[vert (lambda (cr2)
(cairo_move_to cr2 3.5 0)
(cairo_line_to cr2 3.5 12)
(cairo_move_to cr2 7.5 0)
(cairo_line_to cr2 7.5 12)
(cairo_move_to cr2 11.5 0)
(cairo_line_to cr2 11.5 12))]
[bdiag (lambda (cr2)
(for ([i (in-range -2 3)])
(let ([y (* i 6)])
(cairo_move_to cr2 -1 (+ -1 y))
(cairo_line_to cr2 13 (+ 13 y)))))]
[fdiag (lambda (cr2)
(for ([i (in-range -2 3)])
(let ([y (* i 6)])
(cairo_move_to cr2 13 (+ -1 y))
(cairo_line_to cr2 -1 (+ 13 y)))))])
(if (and gradient
(not (collapse-bitmap-b&w?)))
(make-gradient-pattern cr gradient)
(if st
(install-stipple st col s
(lambda () brush-stipple-s)
(lambda (v) (set! brush-stipple-s v) v))
(let ([horiz (lambda (cr2)
(cairo_move_to cr2 0 3.5)
(cairo_line_to cr2 12 3.5)
(cairo_move_to cr2 0 7.5)
(cairo_line_to cr2 12 7.5)
(cairo_move_to cr2 0 11.5)
(cairo_line_to cr2 12 11.5))]
[vert (lambda (cr2)
(cairo_move_to cr2 3.5 0)
(cairo_line_to cr2 3.5 12)
(cairo_move_to cr2 7.5 0)
(cairo_line_to cr2 7.5 12)
(cairo_move_to cr2 11.5 0)
(cairo_line_to cr2 11.5 12))]
[bdiag (lambda (cr2)
(for ([i (in-range -2 3)])
(let ([y (* i 6)])
(cairo_move_to cr2 -1 (+ -1 y))
(cairo_line_to cr2 13 (+ 13 y)))))]
[fdiag (lambda (cr2)
(for ([i (in-range -2 3)])
(let ([y (* i 6)])
(cairo_move_to cr2 13 (+ -1 y))
(cairo_line_to cr2 -1 (+ 13 y)))))])
(case s
[(horizontal-hatch)
(make-pattern-surface
cr col
horiz)]
[(vertical-hatch)
(make-pattern-surface
cr col
vert)]
[(cross-hatch)
(make-pattern-surface
cr col
(lambda (cr) (horiz cr) (vert cr)))]
[(bdiagonal-hatch)
(make-pattern-surface
cr col
bdiag)]
[(fdiagonal-hatch)
(make-pattern-surface
cr col
fdiag)]
[(crossdiag-hatch)
(make-pattern-surface
cr col
(lambda (cr) (bdiag cr) (fdiag cr)))]
[else
(install-color cr
(if (eq? s 'hilite) hilite-color col)
alpha
#f)])))))
(case s
[(horizontal-hatch)
(make-pattern-surface
cr col
horiz)]
[(vertical-hatch)
(make-pattern-surface
cr col
vert)]
[(cross-hatch)
(make-pattern-surface
cr col
(lambda (cr) (horiz cr) (vert cr)))]
[(bdiagonal-hatch)
(make-pattern-surface
cr col
bdiag)]
[(fdiagonal-hatch)
(make-pattern-surface
cr col
fdiag)]
[(crossdiag-hatch)
(make-pattern-surface
cr col
(lambda (cr) (bdiag cr) (fdiag cr)))]
[else
(install-color cr
(if (eq? s 'hilite) hilite-color col)
alpha
#f)])))))
(cairo_fill_preserve cr))))
(when pen?
(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
gradient that is a @racket[linear-gradient%] or
@racket[radial-gradient%]. For each point in a drawing destination, a
gradient associates a color to the point based on starting and 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 is that touched when drawing with the brush.
@racket[radial-gradient%]. When a brush has a gradient and the target
for drawing is not monochrome, then other brush settings are
ignored. With a gradient, for each point in a drawing destination,
the gradient associates a color to the point based on starting and
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
has a gradient):
has a gradient and the target is not monochrome):
@itemize[
@ -115,7 +117,9 @@ Gets the stipple bitmap, or @scheme[#f] if the brush has no stipple.
}
@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.

View File

@ -24,7 +24,7 @@ Colors transitions are based on a line, where colors are assigned to
[y0 real?]
[x1 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])
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)
(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.

View File

@ -24,7 +24,7 @@ Colors transitions are based on two circles and the sequence of circles that
[x1 real?]
[y1 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
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)
(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.