Re: Unwanted transparency in NSBezierPath?
Re: Unwanted transparency in NSBezierPath?
- Subject: Re: Unwanted transparency in NSBezierPath?
- From: Greg Titus <email@hidden>
- Date: Sun, 2 Feb 2003 09:41:47 -0800
On Sunday, February 2, 2003, at 08:17 AM, Christian Brunschen wrote:
Nope. The graphics system is doing exactly what you ask it to do.
The issue is that the coordinate system behaves differently from what
you expect: The integer valued coordinates (in the default coordinate
system) lie precisely on the edges between pixels; and each pixel
covers an area of 1.0 by 1.0 coordinate units:
(x, y+1) (x+1, y+1)
+---------+
| |
| |
| |
+---------+
(x, y) (x+1, y)
Likewise, when you are drawing a line, you will paint pixels to half
the line's width to each side of the line's center. So, by drawing
your line on in integer coordinates, you are drawing it right between
pixels; and by drawing it one unit in width, you are instructing the
graphics system to pain one-half pixel's width to each side of the
line (which as we just discovered, lies precisely between pixels). So
what happens is that both the pixels above and below the line, get
half-painted (due to anti-aliasing).
Yep, this is exactly right.
In order to get the line painted exactly on the pixels themselves,
move your coordinates by 0.5:
NSPoint start = NSMakePoint(10.5, 10.5);
NSPoint end = NSMakePoint(109.5, 10.5);
But here you run into yet another interesting wrinkle with the
coordinate system and NSBezierPath. The default line cap style for
bezier paths is NSButtLineCapStyle, which means that the beginning of
the line is exactly the coordinate value, not half-the-line-width
farther. (See the pictures in the NSBezierPath docs under
+setDefaultLineCapStyle: to see what I mean.) So these coordinates will
result in a half-painted pixel at each end of the line.
You want to either use:
NSPoint start = NSMakePoint(10, 10.5);
NSPoint end = NSMakePoint(110, 10.5);
Or you want to change your path's line cap style to be
NSSquareLineCapStyle, which will fill half-the-line-width farther than
the coordinates:
[line setLineCapStyle:NSSquareLineCapStyle];
Hope this helps,
- Greg
_______________________________________________
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.