-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathBorderView.m
46 lines (35 loc) · 1014 Bytes
/
BorderView.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
#import "BorderView.h"
@implementation BorderView
const CGFloat RADIUS = 2;
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
NSColor *color = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:@"color"]];
CGFloat size = [[NSUserDefaults standardUserDefaults] doubleForKey:@"size"];
NSRect innerRect = [self cleanRect:dirtyRect size:size];
NSBezierPath *border = [NSBezierPath bezierPathWithRoundedRect:innerRect xRadius:RADIUS yRadius:RADIUS];
[border setLineWidth:size];
[color set];
[border stroke];
}
- (NSRect)cleanRect:(NSRect)dirtyRect size:(CGFloat)size
{
return NSInsetRect(dirtyRect, size / 2, size / 2);
}
- (IBAction)updateColor:(id)sender
{
[self display];
[[self window] orderFront:sender];
}
- (IBAction)updateWidth:(id)sender
{
[self display];
[[self window] orderFront:sender];
}
@end