Post a notification when mouse enters/leaves OakRolloverButton

This commit is contained in:
Allan Odgaard
2018-07-10 19:14:56 +02:00
parent 1002c868c3
commit 051ffb68b3
2 changed files with 10 additions and 0 deletions

View File

@@ -1,5 +1,8 @@
#include <oak/misc.h>
extern NSString* const OakRolloverButtonMouseDidEnterNotification;
extern NSString* const OakRolloverButtonMouseDidLeaveNotification;
PUBLIC @interface OakRolloverButton : NSButton
@property (nonatomic) NSImage* regularImage;
@property (nonatomic) NSImage* pressedImage;

View File

@@ -1,5 +1,8 @@
#import "OakRolloverButton.h"
NSString* const OakRolloverButtonMouseDidEnterNotification = @"OakRolloverButtonMouseDidEnterNotification";
NSString* const OakRolloverButtonMouseDidLeaveNotification = @"OakRolloverButtonMouseDidLeaveNotification";
typedef NS_ENUM(NSUInteger, OakImageState) {
OakImageStateRegular = 0,
OakImageStatePressed,
@@ -163,7 +166,11 @@ typedef NS_ENUM(NSUInteger, OakImageState) {
{
if(_mouseInside == flag)
return;
_mouseInside = flag;
[self updateImage];
NSString* notification = _mouseInside ? OakRolloverButtonMouseDidEnterNotification : OakRolloverButtonMouseDidLeaveNotification;
[NSNotificationCenter.defaultCenter postNotificationName:notification object:self];
}
@end