Re: Moveable/Resizable "Box" views and blurry frame
Re: Moveable/Resizable "Box" views and blurry frame
- Subject: Re: Moveable/Resizable "Box" views and blurry frame
- From: "Clark Cox" <email@hidden>
- Date: Tue, 31 Jul 2007 10:03:01 -0700
On 7/31/07, Yann Bizeul <email@hidden> wrote:
> Thanks for your answer,
>
> > The problem is that, when zoomed, 0.5 is no longer in the middle of a
> > pixel. You have to scale that offset
> Yes, I'm aware of that, and that is what I tried too.
>
> I determine my scale by getting the ratio of my contentView's frame
> and my contentView's bounds (You mentioned NSScreen and NSWindow
> methods, but this is not applicable here, I'm not talking about
> resolution independance drawing, but drawing in a zoomed NSScrollView)
Yes, but the basic principle still holds. You are converting from
points to pixels, and want integral pixels. Therefore, you need to
find the values in "points" that represent integer pixel-indices.
> But I can't get the magic formula to apply in the drawRect method of my view.
As outlined on the linked page:
1) Scale the rect by your scaling factor (moving you from
"point"-space to "pixel"-space)
2) Round the rect to integers, using NSIntegralRect. (still in "pixel" space)
3) Offset the rect's origin by (0.5,0.5).
4) Scale the rect by the inverse of your scaling factor (giving you
the "points" that represent integral pixel indices)
> I tried to draw the rect by after applying a 0.5*ratio offset,
> without success, which makes sense to me since I'm not even sure to
> be on integer coordinates. But even using NSIntegralRect on my frame
> do not solve the problem.
The key is *when* you do each of these things. If you use
NSIntegralRect on values that are still in "point" space, then you
will get integer points, not integer pixel indices; if, on the other
hand, you use NSIntegralRect on values in pixel-space, you will get
integer pixel indices.
--
Clark S. Cox III
email@hidden
_______________________________________________
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