-
Notifications
You must be signed in to change notification settings - Fork 22
/
ZennyPerformanceViewController.m
222 lines (182 loc) · 6.89 KB
/
ZennyPerformanceViewController.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//
// ZennyPerformanceViewController.m
// CPU Dasher
//
// Created by zenny_chen on 13-4-12.
//
//
#import "ZennyPerformanceViewController.h"
#import "ZennyCalcViewController.h"
#import "ZennyLinearSearchViewController.h"
#import "ZennySelectionSortViewController.h"
#import "ZennyMemoryCopyViewController.h"
#import "ZennyColor2GrayViewController.h"
#import "ZennyKernelAverageSmootherViewController.h"
@interface ZennyPerformanceViewController ()<UITableViewDataSource, UITableViewDelegate>
@end
@implementation ZennyPerformanceViewController
static NSString *sectionTitles[] = {
@"Common Algorithms",
@"Image Processing"
};
static SEL callbackMethods[6];
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
CGRect screenBounds = [UIScreen mainScreen].bounds;
CGFloat totalHeight = screenBounds.size.height - 20.0f;
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, screenBounds.size.width, totalHeight)];
aView.backgroundColor = [UIColor whiteColor];
self.view = aView;
[aView release];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect screenBounds = [UIScreen mainScreen].bounds;
CGFloat totalHeight = screenBounds.size.height - 20.0f;
totalHeight -= 45.0f;
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, screenBounds.size.width, 35.0f)];
title.backgroundColor = [UIColor colorWithRed:0.5098f green:0.8627f blue:0.7539f alpha:1.0f];
title.textAlignment = UITextAlignmentCenter;
title.textColor = [UIColor colorWithRed:0.7961f green:0.1922f blue:0.4588f alpha:1.0f];
title.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
title.text = @"CPU Dasher";
[self.view addSubview:title];
[title release];
CGSize size = self.view.frame.size;
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 35.0f, size.width, totalHeight - 35.0f) style:UITableViewStyleGrouped];
tableView.backgroundColor = [UIColor clearColor];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
[tableView release];
[self createCells];
callbackMethods[0] = @selector(calcAppears);
callbackMethods[1] = @selector(linearSearchAppears);
callbackMethods[2] = @selector(selectionSortAppears);
callbackMethods[3] = @selector(memoryCopyAppears);
callbackMethods[4] = @selector(colorToGrayAppears);
callbackMethods[5] = @selector(kernelAverageSmootherAppears);
}
- (void)dealloc
{
if(mTableCellList != nil)
{
for(size_t i = 0; i < sizeof(sectionTitles) / sizeof(sectionTitles[0]); i++)
{
[mTableCellList[i] removeAllObjects];
[mTableCellList[i] release];
}
free(mTableCellList);
}
[super dealloc];
}
- (void)addCellForSection:(NSUInteger)section titles:(NSArray*)titles
{
const NSUInteger count = [titles count];
for(size_t i = 0; i < count; i++)
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 0.0f, 300.0f, cell.bounds.size.height)];
title.backgroundColor = [UIColor clearColor];
title.textAlignment = UITextAlignmentLeft;
title.textColor = [UIColor blackColor];
title.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
title.text = titles[i];
[cell.contentView addSubview:title];
[title release];
[mTableCellList[section] addObject:cell];
[cell release];
}
}
- (void)createCells
{
mTableCellList = (NSMutableArray**)malloc(sizeof(sectionTitles) / sizeof(sectionTitles[0]) * sizeof(*mTableCellList));
// Create section 0
mTableCellList[0] = [[NSMutableArray alloc] initWithCapacity:8];
[self addCellForSection:0 titles:@[@"Matrix Multiplication", @"Linear Search", @"Selection Sort", @"Memory Copy"]];
mTableCellList[1] = [[NSMutableArray alloc] initWithCapacity:8];
[self addCellForSection:1 titles:@[@"Color to Gray", @"Kernel Average Smoother"]];
}
#pragma mark - UIViewTable data source & delegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [mTableCellList[[indexPath section]] objectAtIndex:[indexPath row]];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return sizeof(sectionTitles) / sizeof(*sectionTitles);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [mTableCellList[section] count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return sectionTitles[section];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger index;
if([indexPath section] == 0)
index = [indexPath row];
else
index = 4 + [indexPath row];
[self performSelector:callbackMethods[index]];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - All kinds of callback methods for next controller
- (void)calcAppears
{
ZennyCalcViewController *ctrl = [[ZennyCalcViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:YES];
[ctrl release];
}
- (void)linearSearchAppears
{
ZennyLinearSearchViewController *ctrl = [[ZennyLinearSearchViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:YES];
[ctrl release];
}
- (void)selectionSortAppears
{
ZennySelectionSortViewController *ctrl = [[ZennySelectionSortViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:YES];
[ctrl release];
}
- (void)memoryCopyAppears
{
ZennyMemoryCopyViewController *ctrl = [[ZennyMemoryCopyViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:YES];
[ctrl release];
}
- (void)colorToGrayAppears
{
ZennyColor2GrayViewController *ctrl = [[ZennyColor2GrayViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:YES];
[ctrl release];
}
- (void)kernelAverageSmootherAppears
{
ZennyKernelAverageSmootherViewController *ctrl = [[ZennyKernelAverageSmootherViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:YES];
[ctrl release];
}
#pragma mark -
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end