title: Checking if NSButton is down on drawRect
body: <p>I would like to check if my custom NSButton is currently in a pressed state (the user is clicking down on it) in my custom drawRect method. Something like this:</p>
  
  <pre><code>- (void)drawRect:(NSRect)dirtyRect{
      if ([self buttonIsInPressedState]) {
          [[self alternateBGImage] drawInRect:dirtyRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
      }else{
          [[self BGImage] drawInRect:dirtyRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
      }
      [super drawRect:dirtyRect];
  }
  </code></pre>
  
  <p>How would you check a thing like that? Is it possible?</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>I ended up checking the mouseDownFlags on the buttons cell. Don't know if it's the "right" way to do it, so let me know if you have a better suggestion:</p>
  
  <pre><code>- (void)drawRect:(NSRect)dirtyRect{        
      if ([self.cell mouseDownFlags] == 0) {
          [[self BGImage] drawInRect:dirtyRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
      }else{
          [[self alternateBGImage] drawInRect:dirtyRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
      }
  
      [super drawRect:dirtyRect];
  }
  </code></pre>