NSColor colorWithPatternImage: texture origin?
NSColor colorWithPatternImage: texture origin?
- Subject: NSColor colorWithPatternImage: texture origin?
- From: email@hidden
- Date: Mon, 21 Jan 2002 18:16:33 -0800
I am using [NSColor colorWithPatternImage:] to fill areas with a
textured pattern loaded from an image.
I am finding that no matter where I draw the rectangle, the color
pattern origin seems attached to the window origin.
I would like to make the pattern be relative to my rectangle's origin.
I've tried creating transformation matrices to translate to the origin
of my rectangles before i set the patterned color with no effect.
- (void)fill:(NSRect)r color:(NSColor *)texture
{
NSAffineTransform *ctm = [NSAffineTransform transform];
[[NSGraphicsContext currentContext] saveGraphicsState];
[ctm translateXBy:r.origin.x yBy:r.origin.y];
[ctm concat];
[texture set];
NSRectFill(NSMakeRect(0,0,r.size.width,r.size.height));
[[NSGraphicsContext currentContext] restoreGraphicsState];
}
Even more confusing is when the y origin of the pattern seems to reset
every 8 scanlines... making a rectangle's pattern seem to "jump" every
time the rectangle moves up or down 8 pixels.
Does anyone have any experience making textures start where you want
them? This seems to work for drawing the Aqua stripes in cocoa apps, so
it must be possible.
Thank you.
-tw