Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Calculate a NSView's frame in QuickDraw coordinates (See related posts)

@interface NSView (frameAsQuickDrawRect)
- (Rect)frameAsQuickDrawRect;
@end
@implementation NSView (frameAsQuickDrawRect)
- (Rect)frameAsQuickDrawRect {
    NSRect  nsrect = [self convertRect:[self bounds] toView:[[self window] contentView]];
    float   windowHeight = NSHeight( [[[self window] contentView] frame] );
    
    float   nsrectHeight = NSHeight( nsrect );
    
    Rect qdrect;
    qdrect.top = windowHeight - (nsrect.origin.y + nsrectHeight);
    qdrect.left = nsrect.origin.x;
    qdrect.bottom = qdrect.top + nsrectHeight;
    qdrect.right = qdrect.left + NSWidth( nsrect );
    
    return qdrect;
}
@end

You need to create an account or log in to post comments to this site.


Click here to browse all 5137 code snippets

Related Posts