QCFullscreen

How to center an NSView

jrs's picture

Could someone please explain to me how to center an NSView - I'm looking to use cwrights QCFullscreen as a basis for wrapping a composition into an app but can't get the composition to take up the full screen. Currently I'm just using a test composition which is a white square that takes up the full rendering dimensions and a slightly smaller red square on to of that. But when I use QCFullscreen to display it I get a black bar at the top when using my mac book pros native display and when using a macmini with a res of 2048x768 it displays ok height wise but I get a black bar down the left side of around 100px.

The attached picture (screen sharing into the mac mini) shows that it seems to be shifting the composition to the right and not just displaying it in a subset of the screen. As you can see in the below code I've checked the bounds for the view and they are fine and I'm not sure where else to look or why on one computer it shifts it to the right and on another to the bottom.

Any help would be much appreciated - James

- (void) applicationWillFinishLaunching:(NSNotification*)notification
{
   NSScreen *screen = [[NSScreen screens] lastObject];
   NSRect winFrame = [screen frame];
 
    NSLog(@"Bounds: %@", NSStringFromRect(winFrame));
 
   [visWindow setFrame: winFrame display: YES animate: NO];
 
    // Capture the main display
    if (CGDisplayCapture( kCGDirectMainDisplay ) != kCGErrorSuccess) {
        NSLog( @"Couldn't capture the main display!" );
    }
 
    int windowLevel = CGShieldingWindowLevel();
    [visWindow setLevel: windowLevel];
 
   [visView loadCompositionFromFile:  
     [Bad link];
     [visView startRendering];
 
    NSLog(@"visView Bounds: %@", NSStringFromRect([visView bounds]));
    NSLog(@"visView Frame: %@", NSStringFromRect([visView frame]));