forked from ttscoff/nv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatusItemView.m
75 lines (60 loc) · 1.87 KB
/
StatusItemView.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// StatusItemView.m
// Notation
//
// Created by elasticthreads on 07/03/2010.
// Copyright 2010 elasticthreads. All rights reserved.
//
#import "StatusItemView.h"
static NSRect itemRect;
@implementation StatusItemView
@synthesize sbIconType;
- (id)initWithFrame:(NSRect)frameRect{
if ((self=[super initWithFrame:frameRect])) {
itemRect=NSMakeRect(4.0, 3.0, 16.0, 16.0);
self.sbIconType=DarkMenuIcon;
}
return self;
}
- (void)drawRect:(NSRect)rect {
CGFloat fract;
NSString *iconName;
if (sbIconType==SelectedMenuIcon) {
fract=0.87;
iconName = @"nvMenuW";
[[NSColor selectedMenuItemColor] setFill];
}else {
fract=1.0;
iconName = @"nvMenuDark";
[[NSColor clearColor] setFill];
}
NSRectFill(rect);
[[NSImage imageNamed:iconName] drawInRect:itemRect fromRect:NSZeroRect operation: NSCompositeSourceOver fraction:fract];
}
- (void)mouseDown:(NSEvent *)event
{
self.sbIconType=SelectedMenuIcon;
NSUInteger flags=[event modifierFlags];
if (((flags&NSDeviceIndependentModifierFlagsMask)==(flags&NSControlKeyMask))&&((flags&NSDeviceIndependentModifierFlagsMask)>0)) {
[[NSNotificationCenter defaultCenter]postNotificationName:@"StatusItemMenuShouldDrop" object:nil];
self.sbIconType=DarkMenuIcon;
}else{
[[NSNotificationCenter defaultCenter]postNotificationName:@"NVShouldActivate" object:self];
}
}
- (void)mouseUp:(NSEvent *)event {
self.sbIconType=DarkMenuIcon;
// [self viewWillDraw];
}
- (void)rightMouseDown:(NSEvent *)event {
self.sbIconType=SelectedMenuIcon;
[[NSNotificationCenter defaultCenter]postNotificationName:@"StatusItemMenuShouldDrop" object:nil];
self.sbIconType=DarkMenuIcon;
}
- (void)setSbIconType:(StatusIconType)type{
if (sbIconType!=type) {
sbIconType=type;
[self setNeedsDisplay:YES];
}
}
@end