Commits

Cliff Biffle committed 9dd4e79

KVDepthView now uses bindings to sync renderer properties, rather than manually copying values back and forth.

  • Participants
  • Parent commits b2f26bb

Comments (0)

Files changed (2)

 @property(assign) BOOL frozen;
 @property(assign, nonatomic) BOOL anaglyph;
 @property(assign, nonatomic) BOOL lightsOn;
+@property(assign, nonatomic) BOOL textured;
 @property(nonatomic) BOOL recording;
 @property(assign, nonatomic) projective_transform_t colorTransform;
 
 #pragma mark --- Properties ---
 
 @synthesize lightsOn;
+
+- (void) setLightsOn: (BOOL)flag {
+  lightsOn = flag;
+  
+  [[self openGLContext] makeCurrentContext];
+  if (flag) {
+    glEnable(GL_LIGHTING);
+  } else {
+    glDisable(GL_LIGHTING);
+  }
+  [self setNeedsDisplay: YES];  
+}
+
+@synthesize textured;
 @synthesize depthMap;
 @synthesize colorTransform;
 @synthesize renderer;
 
 - (void) setColorTransform: (projective_transform_t)newTransform {
   colorTransform = newTransform;
-  [self updateColorTransform];
+  [self setNeedsDisplay: YES];
 }
 
-// Used internally to apply color transform changes.
 - (void) updateColorTransform {
-  renderer.colorTransform = colorTransform;
-  [self setNeedsDisplay: YES];
+  // A bit of a hack, but it triggers automatic KVO and the setter above.
+  self.colorTransform = colorTransform;
 }
 
 - (void) setRenderer: (NSObject <KVRenderer> *)newRenderer {
   NSObject <KVRenderer> *currentRenderer = renderer;
   renderer = [newRenderer retain];
+  
+  [currentRenderer unbind: @"lit"];
+  [currentRenderer unbind: @"textured"];
+  [currentRenderer unbind: @"colorTransform"];
   [currentRenderer release];
+
+  [renderer bind: @"lit" toObject: self withKeyPath: @"lightsOn" options: nil];
+  [renderer bind: @"textured" toObject: self withKeyPath: @"textured" options: nil];
+  [renderer bind: @"colorTransform" toObject: self withKeyPath: @"colorTransform" options: nil];
   
-  renderer.lit = lightsOn;
-  renderer.colorTransform = colorTransform;
   [self setNeedsDisplay: YES];
 }
 
 - (void) awakeFromNib {
   deviceWhite = [[NSColor colorWithDeviceRed: 1.F green: 1.F blue: 1.F alpha: 1.F] retain];
   
-  colorTransform = (projective_transform_t) {
+  self.colorTransform = (projective_transform_t) {
     .offset = { 14, 40, 0 },
     .scale = { 0.92F, 0.92F },
   };
 }
 
 - (IBAction) toggleLighting: sender {
-  self.lightsOn = !self.lightsOn;
-  [sender setState: self.lightsOn? NSOnState : NSOffState];
-  [[self openGLContext] makeCurrentContext];
-  if (self.lightsOn) {
-    glEnable(GL_LIGHTING);
-  } else {
-    glDisable(GL_LIGHTING);
-  }
-  renderer.lit = self.lightsOn;
-  [self setNeedsDisplay: YES];
+  self.lightsOn = !lightsOn;
+  [sender setState: lightsOn? NSOnState : NSOffState];
 }
 
 - (IBAction) toggleRecording: sender {
 }
 
 - (IBAction) toggleTextures: sender {
-  renderer.textured = !renderer.textured;
+  self.textured = !textured;
   [self setNeedsDisplay: YES];
-  [sender setState: renderer.textured? NSOnState : NSOffState];
+  [sender setState: textured? NSOnState : NSOffState];
 }
 
 #pragma mark --- KFKinect Delegate Implementation ---