Skip navigation.
 
mlPattern colors and alpha
FROM : Luke Evans
DATE : Mon Jan 14 00:12:48 2008

I'm trying to create a hatch pattern to be drawn over some other 
graphics in a custom view.

Researching how to draw hatches (at least in Cocoa, not the underlying 
Quartz 2D), suggested that the way to go was to create an appropriate 
image and then use NSColor's colorWithPatternImage: to generate a 
color that can be use to fill out the required area e.g. with 
NSRectFill.

In my code, I draw the background, and some other objects, then I do 
the NSRectFill having set this color.  Indeed, the result is that my 
hatch appears in the correct place, but unfortunately the bits between 
the black bars of the hatch (which I'd left fully transparent in my 
source image driving the color) renders as completely transparent 
through the window.  Stuff that is beneath the window (i.e. other 
applications and the desktop) show right through.

Now, I've experimented a bit with different compositing modes in the 
active NSGraphicsContext, but the NSRectFill with the pattern color 
seems to completely ignore this (in contrast to other drawing that I 
can see is respecting the asserted composition mode).

Could it be that pattern colors NEVER respect the composition mode? 
If so, how is one supposed to draw a hatch over other graphics? 
Presumably one could simply render the pattern image over the graphics 
(I know that will work), but AFAIK this would mean doing any tiling 
myself, which is the whole point of a pattern IMHO.  Another option 
might be to use the color to paint into an image (getting the alpha 
there), then painting the appropriately sized image over the rest off 
my graphics - this offends my developer's sense of frugality.

Anyway, there's every chance I'm just being dumb - which is easily 
overcome by somebody telling me my glaring oversight and I'll be on my 
way ;-)

-- Lwe

Related mailsAuthorDate
mlPattern colors and alpha Luke Evans Jan 14, 00:12
ml[RESOLVED] Re: Pattern colors and alpha Luke Evans Jan 14, 01:38