forked from kgn/BBlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BBNSButton.m
54 lines (45 loc) · 1.17 KB
/
BBNSButton.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// BBNSButton.m
// BBlock
//
// Created by David Keegan on 4/10/12.
// Copyright (c) 2012 David Keegan. All rights reserved.
//
#import "BBNSButton.h"
@implementation BBNSButton{
BBNSButtonCallback _inCallback;
BBNSButtonCallback _outCallback;
}
- (void)setInCallback:(BBNSButtonCallback)block{
_inCallback = [block copy];
}
- (void)setOutCallback:(BBNSButtonCallback)block{
_outCallback = [block copy];
}
- (void)setInCallback:(BBNSButtonCallback)inBlock
andOutCallback:(BBNSButtonCallback)outBlock{
[self setInCallback:inBlock];
[self setOutCallback:outBlock];
}
- (id)initWithFrame:(NSRect)frame{
if((self = [super initWithFrame:frame])){
NSTrackingArea *trackingArea =
[[NSTrackingArea alloc]
initWithRect:self.visibleRect
options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways
owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
}
return self;
}
- (void)mouseEntered:(NSEvent *)theEvent{
if(self.isEnabled && _inCallback){
_inCallback();
}
}
- (void)mouseExited:(NSEvent *)theEvent{
if(_outCallback){
_outCallback();
}
}
@end