Re: invertrect, any cocoa versions suggested?
Re: invertrect, any cocoa versions suggested?
- Subject: Re: invertrect, any cocoa versions suggested?
- From: Camillo Lugaresi <email@hidden>
- Date: Tue, 24 Jan 2006 17:50:12 +0100
On 24/gen/06, at 16:47, John Stiles wrote:
Camillo Lugaresi wrote:
On 24/gen/06, at 06:15, John Stiles wrote:
The problem here is that Core Graphics doesn't really work in
terms of "pixels" per se. It's built around resolution-
independent vector graphics concepts. For example, you can apply
a transformation matrix to the view which will skew, rotate or
scale it. So conceptually, there really aren't any "pixels" for
you to get at, unfortunately.
I don't think CG offers an "invert" fill mode either,
unfortunately. I can't see any conceptual reason why not. My only
hunch is maybe that "invert" doesn't seem very useful in a
PostScript world, and CoreGraphics is descended from Display
PostScript.
Actually, using kCGBlendModeDifference with a fully-white source
image should invert the colors of the background image (1.0 - c).
Sweet, I looked around but didn't see that one. Does that mean the
OP can draw inverted rects with CG?
Sure, as long as he can require 10.4. Try putting this custom view in
one of your windows:
static inline CGRect CGRectFromNSRect(NSRect nsRect) { return *
(CGRect*)&nsRect; }
@implementation InvertView
- (void)drawRect:(NSRect)rect
{
CGContextRef context = (CGContextRef)[[NSGraphicsContext
currentContext] graphicsPort];
CGContextSaveGState (context);
CGContextSetBlendMode(context, kCGBlendModeDifference);
CGContextSetRGBFillColor (context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect (context, CGRectFromNSRect(rect));
CGContextRestoreGState (context);
}
@end
(put some other controls under it, since the effect might be hard to
appreciate with just the window background)
Camillo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden