forked from julius/bezelhud
-
Notifications
You must be signed in to change notification settings - Fork 3
/
BHWindow.m
75 lines (58 loc) · 1.63 KB
/
BHWindow.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
//
// BHWindow.m
// BezelHUD
//
// Created by Julius Eckert on 05.05.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "BHWindow.h"
@implementation BHWindow
@synthesize shouldBlur;
-(void) awakeFromNib {
[super awakeFromNib];
[self bind:@"shouldBlur" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:@"values.BezelHUD.blur" options:nil];
blurFilter = -1;
fEditor = nil;
}
-(void) applyBlurEffect {
if (!self.shouldBlur) return;
if (blurFilter != -1) return;
CGSNewCIFilterByName(_CGSDefaultConnection(), (CFStringRef)@"CIGaussianBlur", &blurFilter);
CGSAddWindowFilter(_CGSDefaultConnection(), [self windowNumber], blurFilter, 12289);
NSDictionary* dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.5] forKey:@"inputRadius"];
CGSSetCIFilterValuesFromDictionary(_CGSDefaultConnection(), blurFilter, dict);
}
-(void) removeBlurEffect {
if (blurFilter == -1) return;
CGSRemoveWindowFilter(_CGSDefaultConnection(), [self windowNumber], blurFilter);
CGSReleaseCIFilter(_CGSDefaultConnection(), blurFilter);
blurFilter = -1;
}
-(void) makeKeyAndOrderFront:(id)sender {
[super makeKeyAndOrderFront:sender];
[self applyBlurEffect];
}
- (NSTimeInterval)animationResizeTime:(NSRect)newWindowFrame
{
return 0.05f;
}
//*
-(NSText*) fieldEditor:(BOOL)createWhenNeeded forObject:(id)anObject {
if (!fEditor)
fEditor = [[BHFieldEditor alloc] init];
//[anObject addSubview:fe];
return fEditor;
}
/**/
- (void)setShouldBlur:(BOOL)blur {
shouldBlur = blur;
if (blur)
{
[self applyBlurEffect];
}
else
{
[self removeBlurEffect];
}
}
@end