w00t. I have successfully hacked NSStatusItem to look, if not act, like an NSMenuExtra.
[MenuTunes.git] / MenuTunesView.m
1 #import "MenuTunesView.h"
2
3 extern NSColor* _NSGetThemePartColorPattern(int, int, int);
4 // extern NSColor* _NSGetThemePartColorPattern(int imageID, _NSThemeState state, int color);
5
6 @implementation MenuTunesView
7
8 - (id)initWithFrame:(NSRect)frame
9 {
10     if ( (self = [super initWithFrame:frame]) )
11     {
12         image = [NSImage imageNamed:@"menu"];
13         altImage = [NSImage imageNamed:@"selected_image"];
14         mouseIsPressed = NO;
15     }
16     return self;
17 }
18
19 - (void)drawRect:(NSRect)rect
20 {
21     NSImage *icon;
22     NSColor *background;
23     
24     if ( mouseIsPressed ) {
25         icon = altImage;
26         background = _NSGetThemePartColorPattern(44, 2, 0);
27     } else {
28         icon = image;
29         background = [NSColor clearColor];
30     }
31     [background set];
32     NSRectFill(rect);
33     [icon compositeToPoint:NSMakePoint(((rect.size.width - [icon size].width) / 2), 0)
34                  operation:NSCompositeSourceOver];
35 }
36
37 - (void)mouseDown:(NSEvent *)event
38 {
39     mouseIsPressed = YES;
40     [self setNeedsDisplay:YES];
41     [super mouseDown:event];
42 }
43
44 - (void)mouseUp:(NSEvent *)event
45 {
46     mouseIsPressed = NO;
47     [self setNeedsDisplay:YES];
48     [super mouseUp:event];
49 }
50
51 @end