-
Notifications
You must be signed in to change notification settings - Fork 1
/
CSEventView.m
74 lines (63 loc) · 2.25 KB
/
CSEventView.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
//
// CSEventView.m
//
// Created by David Hirsch on 12/17/09.
// Copyright 2009 David Hirsch ([email protected])
/*
This file is part of CSWeekView.
CSWeekView is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CSWeekView is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with CSWeekView. If not, see <http://www.gnu.org/licenses/>.
*/
#import "CSEventView.h"
#import "CSWeekView.h"
@implementation CSEventView
@synthesize startTime, duration, color, label;
- (id) setupWithStartTime: (NSNumber *) inStartTime
duration: (NSNumber *) inDuration
label: (NSString *) inLabel
color: (NSColor *) inColor {
startTime = [inStartTime intValue];
duration = [inDuration intValue];
color = inColor;
label = inLabel;
return self;
}
- (id) initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
label = [[NSString string] retain];
color = [NSColor blackColor];
return self;
}
- (void) dealloc {
[label release];
[super dealloc];
}
- (void)drawRect:(NSRect)rect {
NSColor *stringColor;
float brightness = ([color redComponent] + [color greenComponent] + [color blueComponent]) / 3.0;
if (brightness > 0.5) {
stringColor = [NSColor blackColor];
} else {
stringColor = [NSColor whiteColor];
}
NSDictionary *eventAttr = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont systemFontOfSize:kHeaderFontSize], NSFontAttributeName,
stringColor, NSForegroundColorAttributeName, nil];
NSRect myBounds = [self bounds];
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:myBounds xRadius:myBounds.size.height/2.0 yRadius:myBounds.size.height/2.0];
[color set];
[path fill];
[[NSColor blackColor] set];
[path stroke];
NSRect stringRect = NSInsetRect(myBounds, myBounds.size.height/2.0, 0);
[label drawInRect:stringRect withAttributes:eventAttr];
}
@end