I would like to check if my custom NSButton is in the pressed state (the user clicks on it) in my custom drawRect method. Something like that:
- (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]; }
How would you check this out? Is it possible?
Decision
I ended up checking mouseDownFlags on a button cell. I don't know if this is the "right" way to do this, so let me know if you have a better suggestion:
- (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]; }
source share