-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyView.m
50 lines (41 loc) · 1.22 KB
/
KeyView.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
//
// KeyView.m
// keyboardviz
//
// Created by Patrick on 12/3/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "KeyView.h"
#import "KeyAnimation.h"
@implementation KeyView
@synthesize presses;
@synthesize whiteout;
- (KeyView*) initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame: frameRect])) {
anim = [[KeyAnimation alloc] initWithView:self];
[anim setAnimationBlockingMode:NSAnimationNonblocking];
[self setStringValue: @""];
[self setDrawsBackground:YES];
[self setAlignment: NSCenterTextAlignment];
[self setFont: [NSFont systemFontOfSize: 18]];
[self setTextColor: [NSColor whiteColor]];
[self setEditable: NO];
[self setSelectable: NO];
[self setBordered:YES];
}
return self;
}
- (void)computeAndSetBackgroundColor {
[self setBackgroundColor:[NSColor colorWithCalibratedHue: .7-presses * .004 saturation: 1-whiteout brightness: whiteout+.2+(presses * .004) alpha:1]];
}
-(void)keypress {
presses++;
[anim setCurrentProgress:0.0];
[anim startAnimation];
}
- (void) decay {
if (presses == 0.0) return;
presses /= pow(2.0, 1/1200.0);
[self computeAndSetBackgroundColor];
}
@end