Re: Advice for rotating content in a window so it doesn't get clipped
On 9/7/12, Uli Kusterer wrote: > On 06.09.2012, at 09:48, Eric Wing 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. > Thanks for the replies. Right: Pythagorean Theorem. But I just discovered that setFrameCenterRotation has this weird wobbly behavior. It looks like it is simultaneously translating the object and rotating it. I'm guessing Apple is actually rotating along the bottom-left corner, but is shifting it while rotating so it kind of stays in the center. But the result is this very odd rotation. I'm not sure it actually fits in the hypotenuse. Sigh. I guess I can just make the window overly big, but I'm rethinking things now since the animation looks so bad. On 9/7/12, Graham Cox wrote: > > Or, much more simply, hypot( b.x - a.x, b.y - a.y ); Neat. I didn't realize that existed and was part of the C99 spec until I looked it up just now. Thanks, Eric -- Beginning iPhone Games Development http://playcontrol.net/iphonegamebook/ ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Advice for rotating content in a window so it doesn't get clipped
On 07/09/2012, at 7:14 PM, Uli Kusterer wrote: > distance between two points is sqrt(pow(a.x -b.x,2) + pow(a.y -b.y,2)), Or, much more simply, hypot( b.x - a.x, b.y - a.y ); --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Advice for rotating content in a window so it doesn't get clipped
On 06.09.2012, at 09:48, Eric Wing 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Advice for rotating content in a window so it doesn't get clipped
I have a bunch of content in a non-square window I want to rotate with setFrameCenterRotation (using the animator). The content fills the existing window perfectly (i.e. to the edges), so for it to not be clipped on the edges of the window when it rotates, I need to increase the window size temporarily in all 4 directions. 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. Additional details: My window is already transparent/borderless. My existing content is done programmatically (no nibs). Thanks, Eric -- Beginning iPhone Games Development http://playcontrol.net/iphonegamebook/ ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com