-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLCameraTimelineLayer.m
58 lines (47 loc) · 1.72 KB
/
TLCameraTimelineLayer.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
//
// TLCameraTimelineLayer.m
// Mercatalog
//
// Created by Nathan Vander Wilt on 12/3/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "TLCameraTimelineLayer.h"
#import "TLOffsetTimestamp.h"
#include "TLGeometry.h"
#import "TLCocoaToolbag.h"
@implementation TLCameraTimelineLayer
@synthesize dataSource;
- (void)reloadData {
[self setNeedsDisplay];
}
- (void)drawInContext:(CGContextRef)ctx withInfo:(id < TLTimelineInfo >)timelineInfo {
CGRect boundsToDraw = CGContextGetClipBoundingBox(ctx);
TLTimeRange drawRange = TLTimelineInfoTimeRangeForBounds(timelineInfo, boundsToDraw);
NSDate* drawStartDate = TLTimeToDate(drawRange.start);
NSDate* drawEndDate = TLTimeToDate(drawRange.start + drawRange.duration);
NSArray* offsetTimestamps = nil;
if ([dataSource respondsToSelector:@selector(cameraTimelineLayer:offsetsFromDate:toDate:)]) {
offsetTimestamps = [dataSource cameraTimelineLayer:self
offsetsFromDate:drawStartDate
toDate:drawEndDate];
}
if (![offsetTimestamps count]) return;
CGColorRef cameraOffsetColor = TLCGColorCreateGenericHSB(40.0f / 360.0f, 1.0f, 1.0f, 1.0f);
CGContextSetStrokeColorWithColor(ctx, cameraOffsetColor);
CGColorRelease(cameraOffsetColor);
CGContextSetLineWidth(ctx, 0.15f * TLSizeGetAverageWidth([timelineInfo millimeterSize]));
BOOL firstPoint = YES;
for (TLOffsetTimestamp* timestamp in offsetTimestamps) {
TLTimePair timePair = TLTimePairMakeWithDate([timestamp time], [timestamp offset]);
CGPoint point = [timelineInfo pointForTime:timePair];
if (firstPoint) {
CGContextMoveToPoint(ctx, point.x, point.y);
firstPoint = NO;
}
else {
CGContextAddLineToPoint(ctx, point.x, point.y);
}
}
CGContextStrokePath(ctx);
}
@end