Re: Advice for rotating content in a window so it doesn't get clipped
Re: Advice for rotating content in a window so it doesn't get clipped
- Subject: Re: Advice for rotating content in a window so it doesn't get clipped
- From: Uli Kusterer <email@hidden>
- Date: Fri, 07 Sep 2012 11:14:43 +0200
On 06.09.2012, at 09:48, Eric Wing <email@hidden> wrote:
> I want the thing I'm rotating to stay centered relative to its
> original screen position, so when I resize the window, I need the view to not shift in absolute terms despite the fact that the window's origin (lower-left corner) will need to move.
>
> I'm looking for ideas on the best/easiest way of accomplishing this.
Easiest way? Before you start the rotation, make the window larger, and offset all views by the amount you made it larger. Do the rotation, then make the window smaller again once you're done. You can remember the difference in an ivar. Or just create your window larger to start with. It's borderless and transparent, who would notice?
Larger by how much? Well, any rotated point can extend outside the rectangle of the view at most by the radius of the rotation. The radius extends past the view's edges the most when it is horizontal or vertical.
So that means calculate the distance between the center of your view and each of its corners. (distance between two points is sqrt(pow(a.x -b.x,2) + pow(a.y -b.y,2)), if I remember maths class correctly). Remember the largest of these. Then calculate the distance between your view's center and its edges (NSMaxX(box) -NSMidX(box) and NSMaxY(box) -NSMidY(box)). Again, remember the largest.
Now you know how far one of your corners can at most be from the center, and how far your edges are right now. The difference between the two is how much you have to make the window larger to see all of that view.
Do that for every view you're rotating, done.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.lookandfeelcast.com
_______________________________________________
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