Source

kinect-viewer / KinectViewerAppDelegate.m

/*
 * Copyright 2010 Cliff L. Biffle.  All Rights Reserved.
 * Use of this source code is governed by the Apache License 2.0,
 * which can be found in the LICENSE file.
 */

#import "KinectViewerAppDelegate.h"
#import "KVDepthView.h"
#import "KVDepthPlayer.h"

@implementation KinectViewerAppDelegate

#pragma mark --- Properties

@synthesize window;
@synthesize depthView;

#pragma mark --- NSApplication delegate methods

- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSApplication *)theApplication {
  return YES;
}

- (void)applicationDidFinishLaunching: (NSNotification *)aNotification {
  [window zoom: self];
  
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  NSString *replayFile = [defaults stringForKey: @"replay"];
  
  if (replayFile) {
    NSLog(@"Playing %@", replayFile);
    KVDepthPlayer *player = [[KVDepthPlayer alloc] init];
    [depthView bind: @"latestDepthSamples" toObject: player withKeyPath: @"latestDepthSamples" options: nil];
    [player open: replayFile];
  } else {
    kinect = [[KVKinectHardware alloc] init];
    [depthView bind: @"latestDepthSamples" toObject: kinect withKeyPath: @"latestDepthSamples" options: nil];
    [depthView bind: @"latestColorSamples" toObject: kinect withKeyPath: @"latestColorSamples" options: nil];
    [kinect open];
  }
}

@end