forked from bps/scrobblepod
-
Notifications
You must be signed in to change notification settings - Fork 3
/
BGPointWindow.m
74 lines (60 loc) · 1.92 KB
/
BGPointWindow.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
//
// BGPointWindow.m
// PointWindow
//
// Created by Ben Gummer on 22/04/08.
// Copyright 2008 Ben Gummer. All rights reserved.
//
#import "BGPointWindow.h"
@implementation BGPointWindow
@synthesize shouldClose;
-(id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {
if (!(self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:flag]))
return nil;
[self setBackgroundColor:[NSColor clearColor]];
[self setOpaque:NO];
[self setLevel:NSStatusWindowLevel+1];
[self setHasShadow:YES];
[self setDelegate:self];
[self setShouldClose:YES];
return self;
}
-(void)awakeFromNib {
// Register for Fadeout end notifications
CAAnimation *anim = [CABasicAnimation animation];
[anim setDelegate:self];
[self setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"alphaValue"]];
}
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag
{
if (self.alphaValue == 0.00) [self properClose]; //detect end of fade out and close the window
}
-(BOOL)canBecomeKeyWindow {
return YES;
}
-(BOOL)canBecomeMainWindow {
return YES;
}
-(void)windowDidResignKey:(NSNotification *)notification {
if (self.shouldClose) [self close:self];
}
-(IBAction)close:(id)sender {
if (self.isVisible) [self.animator setAlphaValue:0.0];
}
-(void)properClose {
[super close];
}
-(void)positionAtMenuBarForHorizontalValue:(float)xVal andVerticalValue:(float)yVal {
float windowWidth = [self.contentView frame].size.width;
float screenWidth = [[NSScreen mainScreen] frame].size.width;
float overflow = screenWidth - (xVal + windowWidth);
if (overflow < 0.0) {
overflow -= 20;
xVal += overflow;
float currentCenter = [[self contentView] triangleCenter];
[self.contentView setTriangleCenter:currentCenter - overflow];
}
[self setFrameOrigin:NSMakePoint(xVal,yVal)];
self.alphaValue = 1.0f;
}
@end