Ask a Question related to Mac Programming, Design and Development.
-
John C. Randolph #1
Re: Cocoa color with alpha weirdness
"Liz S. Reynolds" wrote:
Liz,>
> Code snippet below. It goes in a drawRect method in a subclass of NSView.
>
> The first path fills a rectangle in the right half of the view colored
> transparent blue. the second path fills a rectangle in the bottom half of
> the view colored transparent yellow. Either of these by itself looks just
> like you'd expect.
>
> +------------------+
> | no color | blue |
> |------------------|
> | no color | blue |
> +------------------+
>
> +---------------------+
> | no color | no color |
> |---------------------|
> | yellow | yellow |
> +---------------------+
>
> When both are drawn, they intersect in the bottom right
> quadrant of the view. However, the quartered view looks like this:
>
> +------------------+
> | no color | green |
> |------------------|
> | yellow | blue |
> +------------------+
>
> while I expected this:
>
> +------------------+
> | no color | blue |
> |------------------|
> | yellow | green |
> +------------------+
>
> I'm totally puzzled, any clues?
What's tripping you up here is that unlike in Postscript, where the
"fill" operator consumes and destroys the current path, NSBezierPath
doesn't lose any of its state after you fill it. So, the second
sequence of -moveToPoint:/-lineToPoint: messages that you're sending to
the path are just getting appended to the existing path.
Try adding:>
> // top left bottom and right are args to the function
> // and represent the origin and origin + size in each direction
> NSColor *blue ;
> NSColor *yellow;
>
> NSBezierPath *thePath = [[ NSBezierPath alloc ] init];
> blue = [[NSColor blueColor] colorWithAlphaComponent: 0.5];
> yellow = [[NSColor yellowColor] colorWithAlphaComponent: 0.5];
>
> // down the center
> [ blue set];
> [thePath moveToPoint: NSMakePoint ((right / 2),top)];
> [thePath lineToPoint: NSMakePoint ((right / 2),bottom)];
> // bottom to left edge
> [thePath lineToPoint: NSMakePoint (right,bottom)];
> // bottom left to top left
> [thePath lineToPoint: NSMakePoint (right,top)];
> // top left to top center
> [thePath lineToPoint: NSMakePoint ((right / 2),top)];
> [thePath closePath];
> [thePath fill];
[thePath removeAllPoints]; //here.
Also, if you just want to fill in some rectangles, you don't need the>
> [ yellow set];
> // across the center
> [thePath moveToPoint: NSMakePoint (left, ((top - bottom) / 2))];
> [thePath lineToPoint: NSMakePoint (right,((top - bottom) / 2))];
> // center right to bottom right
> [thePath lineToPoint: NSMakePoint (right,bottom)];
> // bottom right to bottom left
> [thePath lineToPoint: NSMakePoint (left,bottom)];
> // up to center left
> [thePath lineToPoint: NSMakePoint (left, (top - bottom) / 2)];
> [thePath closePath];
> [thePath fill];
overhead of creating an NSBezierPath. You can just call NSRectFill() or
NSRectFillList(), or send +fillRect: to the NSBezierPath class itself.
HTH,
-jcr
John C. Randolph Guest
-
#40572 [NEW]: Alpha composite allows color to bleed through
From: seth at pricepages dot org Operating system: Mac 10.4 PHP version: 5.2.1 PHP Bug Type: GD related Bug description: ... -
Alpha color value?
Is there any COLOR code like 0xFFFFFF that means "0% alpha"? -
Bit shifts in Cocoa
Does anyone know how to do bit shifts in Cocoa? I have declared an integer and I want to shift it one bit to the right (same as dividing by 2). ... -
Q About Cocoa & CF Prefs..
In article <no-EA814A.20172229072003@netnews.upenn.edu>, Mark Haase <no@spam.please> wrote: Not only that, if the same preference file is... -
[Cocoa] Bug with NSTableView?
> I'll check these accessor methods, as this may be the problem. It was the setCol* methods that were causing the problem. I stupidly put:... -
Liz S. Reynolds #2
Re: Cocoa color with alpha weirdness
In article <3F4BD291.32BB9A6D@nospam.idiom.com>,
>
>What's tripping you up here is that unlike in Postscript, where the
>"fill" operator consumes and destroys the current path, NSBezierPath
>doesn't lose any of its state after you fill it. So, the second
>sequence of -moveToPoint:/-lineToPoint: messages that you're sending to
>the path are just getting appended to the existing path.That did it - thanks!>>> [thePath fill];
>Try adding:
>
>[thePath removeAllPoints]; //here.
>
It's just rectangles for practice, more complex shapes later, but thanks>
>Also, if you just want to fill in some rectangles, you don't need the
>overhead of creating an NSBezierPath. You can just call NSRectFill() or
>NSRectFillList(), or send +fillRect: to the NSBezierPath class itself.
for the tip.
-Liz
Liz S. Reynolds Guest



Reply With Quote

