Re: NSBezierPath Problems
Re: NSBezierPath Problems
- Subject: Re: NSBezierPath Problems
- From: Greg Titus <email@hidden>
- Date: Sun, 29 Sep 2002 18:42:45 -0700
Hi King,
The problem you are having is that you are drawing your lines along the
"edges" of the pixels, so Quartz is anti-aliasing and halfway filling
the pixel on either side of your line. To avoid this, make sure that
the points you are drawing from/to are always in the "middle" of pixels
(i.e. have coordinates that are X.5). This is not a bug in Quartz -
it's exactly the way it is supposed to work.
So for your example code, if you use the following you'll get one-pixel
lines of the appropriate stroke color:
[NSBezierPath strokeLineFromPoint:NSMakePoint(minX + 11.5, minY + 0.5)
toPoint:NSMakePoint(minX + 11.5, minY + 6.5)];
[NSBezierPath strokeLineFromPoint:NSMakePoint(maxX - 11.5, minY + 0.5)
toPoint:NSMakePoint(maxX - 11.5, minY + 6.5)];
(or adjust by .5 in the other direction, whichever fits your
particular needs.)
Hope this helps,
- Greg
On Sunday, September 29, 2002, at 06:27 PM, King Chung Huang wrote:
Hi,
I'm implementing a custom NSControl/NSCell, and I'm having trouble with
drawing the widget in my NSCell's drawWithFrame:cellFrame
inView:controlView
function. This is the first time I've used NSBezierPath.
In my code, I've set the line width to 1.0 using [NSBezierPath
setDefaultLineWidth:1.0]. Then, I draw a series of lines. However,
some of
my lines are coming up with widths of 2 pixels, while others are 1
pixel as
expected.
For example,
[NSBezierPath strokeLineFromPoint:NSMakePoint(minX + 11, minY)
toPoint:NSMakePoint(minX + 11, minY + 6)];
[NSBezierPath strokeLineFromPoint:NSMakePoint(maxX - 11, minY)
toPoint:NSMakePoint(maxX - 11, minY + 6)];
Is drawing lines that are two pixels wide.
I found a reference to a similar encounter at
<http://lists.apple.com/archives/cocoa-dev/2001/Jun/14/
stupidcodeorbuginnsbe
zie.txt>. However, the only response to the post was a message that a
bug
was filed against Quartz.
Another problem I've been having is that the lines that do get drawn
seem to
be at < 100% opacity. The code I used to set the color is [[NSColor
colorWithDeviceRed:0.24 green:0.24 blue:0.24 alpha:1.00] set].
However, when
I draw, the DigitalColor Meter clearly shows that the resulting line
isn't
nearly as dark as I'd specified, and the areas where the lines overlap
are
darker than the rest of the line. If I set the line width to 2.0, then
they're the correct color, but I'm trying to get 1 pixel lines!
Any help or pointers are greatly appreciated. So far, this has been my
only
major bump on the road to Cocoa & QuickTime programming.
Thanks,
King Chung Huang
Learning Commons
University of Calgary
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.