Re: Avoid drawing in half pixel
Re: Avoid drawing in half pixel
- Subject: Re: Avoid drawing in half pixel
- From: Alastair Houghton <email@hidden>
- Date: Thu, 6 May 2010 11:46:40 +0100
On 5 May 2010, at 17:01, Simone Tellini wrote:
> you can turn it on/off according to your needs: ie. turn it off, draw
> vertical/horizontal lines that you don't want to become blurry, turn it on
> and draw the rest.
I wouldn't be inclined to do that, actually.
Much easier in the long run to use your brain and figure out where you need to draw to avoid things being fuzzy. Of course, you need first of all to ensure that your view has integer co-ordinates (if they have a fractional part, you'll get fuzziness), then you need to remember that at the default 1pt = 1px mapping, a 1pt wide vertical line is drawn with 0.5px either side of the x-coordinate you specify, while a 1pt wide horizontal line is drawn with 0.5px either side of the y-coordinate you specify. Therefore, by default, you want to adjust vertical lines so that their x-coordinates end in 0.5, and horizontal lines such that their y-coordinates end in 0.5. You only want to do this adjustment when *stroking*, rather than filling, because the stroke is drawn straddling the path whereas the fill only fills its interior.
It's also worth noting that the *current* default mapping of 1pt = 1px is just that, the *current* default. If Apple releases machines with high-DPI displays (maybe 200dpi or higher), it no longer makes sense to pretend that the screen resolution is 72dpi, and at that point the default mapping is liable to change. There was a lot of talk at one point about this issue, and if you want to support arbitrary pt:px ratios then you probably want to go and review the material in the docs about it; e.g. getting single pixel lines under such circumstances probably requires the use of the -userSpaceScaleFactor method on NSWindow, and there are some rounding functions you can use to adjust rectangles appropriately also.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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