Re: Avoid drawing in half pixel
Re: Avoid drawing in half pixel
- Subject: Re: Avoid drawing in half pixel
- From: Corbin Dunn <email@hidden>
- Date: Wed, 05 May 2010 09:55:34 -0700
On May 5, 2010, at 8:18 AM, Gustavo Pizano wrote:
> Hello all.
>
> I have a split view and inside I have custom views, in one subview Im drawing lines with a NSBezierPath, and when I move the divider I see sometimes the lines very thin some others no, so I know this last behavior its because Im drawing in half a pixel.
>
> I was reading the apple docs about this topic, and I tried at the beginning of my drawRect method I did as in "Converting Coordinate Values" topic suggest to convert my starting drawing point, but that din't help. I still see the above behavior.
> I realize then that when I resize the window I have the same behavior, so what I did was in the windowDelegate windowWillResize method, I did the following:
>
> if((NSInteger)frameSize.width % 2 != 0){
> frameSize.width += 1.0f;
>
> }
> if((NSInteger)frameSize.height % 2 != 0){
> frameSize.height += 1.0f;
> }
>
> and when I resize the window I don't see hte problem anymore. I tried applying this same to the splitview delegate when resizing, but unfortunately this approach didn't work well, I started getting warnings in the console that the size of the subviews weren't correct and it was being recalculated at the cost of performance.
>
> So any other idea on what can I do to avoid this behavior?
First off, is frameSize from self.frame.size? If you have a view's frame that is not integral (ie: x=3.5, or width=300.5), then the view's contents will draw fuzzy. You don't want that. So, do some consistent truncing/ceiling. ie: frame.origin.x = trunc(frame.origin.x), or rounding -- rounding usually isn't what you want, since sometimes it will round up and other times it will round down. It is better to be consistent with trunc/ceil, but it depends on what you are doing.
The same advice goes for the rects you are using as bezier paths.
corbin
_______________________________________________
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