-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRyderNameView.m
60 lines (47 loc) · 1.95 KB
/
RyderNameView.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
// Ryder.app
//
// (c) 2008-2009 Liam Cooke
// MIT Licensed -- see LICENSE.txt
#import "RyderNameView.h"
@implementation RyderNameView
@synthesize name, font, parStyle, fontAttribs;
- (id)initWithFrame:(NSRect)frame
{
if (self = [super initWithFrame:frame]) {
name = @"Blast Hardcheese";
font = [NSFont fontWithName:@"Futura-CondensedMedium" size:40];
parStyle = [[NSMutableParagraphStyle alloc] init];
[parStyle setAlignment:NSCenterTextAlignment];
fontAttribs = [NSMutableDictionary new];
[fontAttribs setObject:font forKey:NSFontAttributeName];
[fontAttribs setObject:parStyle forKey:NSParagraphStyleAttributeName];
[fontAttribs setValue:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
[fontAttribs setValue:[NSNumber numberWithFloat:-0.5] forKey:NSKernAttributeName];
shadowAttribs = [NSMutableDictionary dictionaryWithDictionary:fontAttribs];
[shadowAttribs setValue:[NSColor colorWithCalibratedWhite:0.9 alpha:0.5]
forKey:NSForegroundColorAttributeName];
}
return self;
}
- (void)drawRect:(NSRect)rect
{
NSString *displayName = [[name uppercaseString]
stringByReplacingOccurrencesOfString:@"." withString:@""];
NSSize stringSize = [displayName
boundingRectWithSize:rect.size
options:(NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingDisableScreenFontSubstitution)
attributes:fontAttribs].size;
NSRect drawRect = rect;
drawRect.size.height = stringSize.height;
drawRect.origin.y = rect.origin.y + (rect.size.height - stringSize.height)/2;
#ifdef DEBUG
[[NSColor colorWithCalibratedWhite:0.2 alpha:0.2] set];
[NSBezierPath strokeRect:rect];
[NSBezierPath strokeRect:drawRect];
#endif
[displayName drawInRect:drawRect withAttributes:shadowAttribs];
drawRect.origin.y += 1;
[displayName drawInRect:drawRect withAttributes:fontAttribs];
}
@end