-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkLayer.m
68 lines (56 loc) · 1.74 KB
/
LinkLayer.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
//
// AnchorLayer.m
//
//
// Created by Rintarou on 2011/1/17.
// Copyright 2011 http://rintarou.dyndns.org. All rights reserved.
//
#import "LinkLayer.h"
@implementation LinkLayer
@synthesize rootLayer;
- (id) init {
self = [super init];
if (self) {
// Initialization code here.
linksArray = [[NSMutableArray alloc] init];
//[self removeAllAnimations];
}
return self;
}
- (void)dealloc
{
[linksArray removeAllObjects];
[linksArray release];
[super dealloc];
}
- (Link *)addLinkWithOwnerAnchor:(CGPoint)ownerAnchorPoint andAnchorOnTable:(CGPoint)anchorOfTable
{
Link *link = [[Link alloc] init];
link.ownerAnchorPoint = ownerAnchorPoint;
link.anchorOfTable = anchorOfTable;
[linksArray addObject:link];
[link release];
[self setNeedsDisplay];
return link;
}
- (void)setFrame:(CGRect)rect
{
[self setNeedsDisplay];
[super setFrame:rect];
}
- (void)drawInContext:(CGContextRef)ctx
{
// NSLog(@"linksArray count = %d", [linksArray count]);
// NSLog(@"bounds %f, %f, %f, %f", [self bounds].origin.x, [self bounds].origin.y, [self bounds].size.width, [self bounds].size.height);
CGContextSetRGBStrokeColor(ctx, 0.2, 0.2, 0.2, 1); // Link Color
CGContextBeginPath(ctx);
for (uint i = 0; i < [linksArray count]; i++) {
Link *link = [linksArray objectAtIndex:i];
CGPoint ownerAnchorPoint = [self convertPoint:link.ownerAnchorPoint fromLayer:rootLayer];
CGPoint anchorOfTable = [self convertPoint:link.anchorOfTable fromLayer:rootLayer];
CGContextMoveToPoint(ctx, ownerAnchorPoint.x, ownerAnchorPoint.y);
CGContextAddLineToPoint(ctx, anchorOfTable.x, anchorOfTable.y);
}
CGContextStrokePath(ctx);
}
@end