• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Moveable/Resizable "Box" views and blurry frame
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Moveable/Resizable "Box" views and blurry frame


  • Subject: Re: Moveable/Resizable "Box" views and blurry frame
  • From: Yann Bizeul <email@hidden>
  • Date: Wed, 1 Aug 2007 15:09:03 +0200

Ok I tried some stuff and it seem I almost get a perfect result.

The problem is to convert the rectangle I'm drawing the frame to the pixel value in a 1:1 coordinate system, the window for example.
I can't just rely on my view frame because setting its frame to an integral rect will not avoid its superview to not have a non-integral rect.


On the other end, I can't use convertRect:toView:nil to get the rect in window coordinate system because it does not look to deal well with zooming.

The only solutions that comes to my mind would be to recursively get each superview frame coordinate until I get my contentView but it looks like a big overhead.

Thanks

Yann Bizeul - yann at tynsoe.org
Cocoa Developer

Tynsoe Projects
BuddyPop - GeekTool - SSH Tunnel Manager - ...
http://projects.tynsoe.org/


Le 31 juil. 07 à 19:03, Clark Cox a écrit :

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


  • Prev by Date: Re: Releasing by reference
  • Next by Date: Re: Releasing by reference
  • Previous by thread: Re: Hey email@hidden ;)
  • Next by thread: Re: How to be notified of scrolling an NSTableView
  • Index(es):
    • Date
    • Thread