-
Notifications
You must be signed in to change notification settings - Fork 0
/
RootLayer.m
90 lines (72 loc) · 2.36 KB
/
RootLayer.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// RootLayerDelegate.m
//
//
// Created by Rintarou on 2010/12/26.
// Copyright 2010 http://rintarou.dyndns.org. All rights reserved.
//
#import "RootLayer.h"
#import "Column.h"
#define COLUMN_LEFT_PADDING 100
#define COLUMN_WIDTH 700
@implementation RootLayer
@synthesize width, height, clickPoint;
- (id) init {
self = [super init];
if (self) {
// Initialization code here.
//self.geometryFlipped = YES;
columns = [[NSMutableArray alloc] init];
//[self removeAllAnimations];
//[self setBounds:CGRectMake(0, 0, 1000, 1000)];
/*
CGRect myFrame = [self frame];
NSLog(@"myFrame origin (%f, %f)", myFrame.origin.x, myFrame.origin.y);
myFrame.origin.x = 0;
myFrame.origin.y = 0;
[self setFrame:myFrame];
*/
//[self setAnchorPoint:CGPointMake(0, 0)];
}
return self;
}
- (void)dealloc {
// NSLog(@"RootLayer is deallocated");
[columns removeAllObjects];
[columns release];
[super dealloc];
}
- (void)addTable:(TableLayer *)table atColumn:(uint)col {
Column *column = nil;
/* try to find if the column exist */
if ([columns count] > col) {
column = [columns objectAtIndex:col];
} else {
/* create new column */
column = [[Column alloc] init];
column.frameX = col * COLUMN_WIDTH + COLUMN_LEFT_PADDING;
[columns addObject:column];
[column release]; // now it's owned by columns
width = column.frameX + COLUMN_WIDTH;
}
/* add table to the column indexed by col */
[column addTable:table];
[self addSublayer:table];
//NSLog(@"RootLayer contentsRect = %f, %f", [self contentsRect].size.width, [self contentsRect].size.height);
/* update bounds height */
// Do not update the bounds, just update width and height only.
// Since it will be too big and cost a lot of memory even without drawing anything.
if (column.lastTableBottom > height) {
height = column.lastTableBottom;
}
/* set dirty bit */
[table setNeedsDisplay];
}
- (void)drawInContext:(CGContextRef)ctx
{
CGContextSetRGBFillColor(ctx, 0, 0, 0, 1);
CGContextFillRect(ctx, [self bounds]);
CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
CGContextFillRect(ctx, CGRectMake(clickPoint.x, clickPoint.y, 100, 100));
}
@end