Re: Goofy behavior with CICheckerboardGenerator filter and transparency
Re: Goofy behavior with CICheckerboardGenerator filter and transparency
- Subject: Re: Goofy behavior with CICheckerboardGenerator filter and transparency
- From: Graham Cox <email@hidden>
- Date: Fri, 11 Jul 2008 14:53:22 +1000
I don't know the answer to your question, but might I suggest a much
easier way to do this?
If you create an image of one square of your checkerboard pattern, you
can tile it over the view simply by using it as an NSColor and
painting it (using [NSColor colorWithPatternImage:]). The same
approach can be extended to building the image tile on the fly with
different colours and sizes. I can't see much benefit to using a
CIFilter as a generator for this sort of thing unless you are
cascading it with a number of other filter effects.
Also, I would recommend not picking up input values from controls as
part of drawRect: (this may just be test code, and you know this), as
it violates MVC and drawRect should purely be concerned with drawing.
Instead, methods that do respond to actions from controls should set
the desired parameter somewhere and call -setNeedsDisplay:. Combining
this with the above suggestion, you could generate the tile image from
the parameters on each parameter change, and simply paint it in
drawRect:. Your drawing code then collapses to two lines (set color
then paint bounds), which seems to be a worthwhile saving!
Feel free to ignore if you are committed to this approach for some
reason, and maybe someone more familiar with CIFilter can help.
cheers, Graham
On 11 Jul 2008, at 2:34 pm, Randall Meadows wrote:
I have an NSImageView subclass that I'm filling with a checkerboard
pattern, using this method:
- (void)drawRect:(NSRect)aRect
{
NSColor *nsColor;
CIColor *inputColor0, *inputColor1;
float alpha;
NSNumber *inputWidth;
nsColor = [[[prefsWdw gridColor1] color]
colorUsingColorSpaceName:NSDeviceRGBColorSpace];
alpha = [[prefsWdw gridSlider1] floatValue];
inputColor0 = [CIColor colorWithRed:[nsColor redComponent]
green:[nsColor greenComponent]
blue:[nsColor blueComponent]
alpha:alpha];
nsColor = [[[prefsWdw gridColor2] color]
colorUsingColorSpaceName:NSDeviceRGBColorSpace];
alpha = [[prefsWdw gridSlider2] floatValue];
inputColor1 = [CIColor colorWithRed:[nsColor redComponent]
green:[nsColor greenComponent]
blue:[nsColor blueComponent]
alpha:alpha];
inputWidth = [NSNumber numberWithFloat:[[prefsWdw gridSlider]
floatValue]];
CIFilter *theFilter = [CIFilter
filterWithName:@"CICheckerboardGenerator"];
[theFilter setDefaults];
[theFilter setValue:inputColor0 forKey:@"inputColor0"];
[theFilter setValue:inputColor1 forKey:@"inputColor1"];
[theFilter setValue:inputWidth forKey:@"inputWidth"];
CIImage *transparentBG = [theFilter valueForKey:@"outputImage"];
CIContext *context = [[NSGraphicsContext currentContext] CIContext];
[context drawImage:transparentBG
atPoint:CGPointZero
fromRect:CGRectMake(aRect.origin.x, aRect.origin.y,
aRect.size.width, aRect.size.height)];
}
When I adjust the alpha value of the color of the checkerboard
pattern, I get really weird behavior; it's kind of hard to describe,
so I shot a movie of it and posted it at <http://www.not-pc.com/CheckerboardAlpha.mov
>. As you can see, the colors don't "scale" appropriately. All the
computing is done in this routine, there's no outside stuff being
done beyond adjusting the sliders and colors. I also tried
NSCalibratedRGBColorSpace, and it behaved the same way.
Any ideas on what is going on? What I might have done wrong?
Thanks!
randy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden