Skip to content

Commit

Permalink
Refactor & add procedural example.
Browse files Browse the repository at this point in the history
  • Loading branch information
brow committed Apr 21, 2010
1 parent 33195fb commit 630e653
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 28 deletions.
7 changes: 6 additions & 1 deletion Classes/ExamplesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#import "ExamplesViewController.h"
#import "PDFExampleViewController.h"
#import "ImageExampleViewController.h"
#import "ProceduralExampleViewController.h"

enum {PDF, IMAGE, NUM_EXAMPLES};
enum {PDF, IMAGE, PROCEDURAL, NUM_EXAMPLES};

@implementation ExamplesViewController

Expand Down Expand Up @@ -49,6 +50,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
switch (indexPath.row) {
case PDF: cell.textLabel.text = @"PDF example"; break;
case IMAGE: cell.textLabel.text = @"Image example"; break;
case PROCEDURAL: cell.textLabel.text = @"Procedural example"; break;
default: cell.textLabel.text = @"";
}
return cell;
Expand All @@ -65,6 +67,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
case IMAGE:
viewController = [[[ImageExampleViewController alloc] init] autorelease];
break;
case PROCEDURAL:
viewController = [[[ProceduralExampleViewController alloc] init] autorelease];
break;
default:
viewController = [[[UIViewController alloc] init] autorelease];
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/ImageExampleViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "LeavesViewController.h"

@interface ImageExampleViewController : LeavesViewController <LeavesViewDataSource, LeavesViewDelegate> {
@interface ImageExampleViewController : LeavesViewController {
NSArray *images;
}

Expand Down
9 changes: 0 additions & 9 deletions Classes/ImageExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,4 @@ - (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {
CGContextDrawImage(ctx, imageRect, [image CGImage]);
}

#pragma mark UIViewController methods

- (void) viewDidLoad {
[super viewDidLoad];
leavesView.dataSource = self;
leavesView.delegate = self;
[leavesView reloadData];
}

@end
1 change: 0 additions & 1 deletion Classes/LeavesAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ - (void)dealloc {
[super dealloc];
}


@end
2 changes: 1 addition & 1 deletion Classes/PDFExampleViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "LeavesViewController.h"

@interface PDFExampleViewController : LeavesViewController <LeavesViewDataSource, LeavesViewDelegate> {
@interface PDFExampleViewController : LeavesViewController {
CGPDFDocumentRef pdf;
}

Expand Down
8 changes: 0 additions & 8 deletions Classes/PDFExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,4 @@ - (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {
CGContextDrawPDFPage(ctx, page);
}

#pragma mark UIViewController methods

- (void) viewDidLoad {
[super viewDidLoad];
leavesView.dataSource = self;
leavesView.delegate = self;
[leavesView reloadData];
}
@end
16 changes: 16 additions & 0 deletions Classes/ProceduralExampleViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// MinimalExampleViewController.h
// Leaves
//
// Created by Tom Brow on 4/20/10.
// Copyright 2010 Tom Brow. All rights reserved.
//

#import "LeavesViewController.h"


@interface ProceduralExampleViewController : LeavesViewController {

}

@end
29 changes: 29 additions & 0 deletions Classes/ProceduralExampleViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// MinimalExampleViewController.m
// Leaves
//
// Created by Tom Brow on 4/20/10.
// Copyright 2010 Tom Brow. All rights reserved.
//

#import "ProceduralExampleViewController.h"


@implementation ProceduralExampleViewController

#pragma mark LeavesViewDataSource methods

- (NSUInteger) numberOfPagesInLeavesView:(LeavesView*)leavesView {
return 10;
}

- (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {
CGRect bounds = CGContextGetClipBoundingBox(ctx);
CGContextSetFillColorWithColor(ctx, [[UIColor colorWithHue:index/10.0
saturation:0.8
brightness:0.8
alpha:1.0] CGColor]);
CGContextFillRect(ctx, CGRectInset(bounds, 100, 100));
}

@end
6 changes: 6 additions & 0 deletions Leaves.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
D33D4ED2117D8D4500BA7203 /* paper.pdf in Resources */ = {isa = PBXBuildFile; fileRef = D33D4ECA117D8D4500BA7203 /* paper.pdf */; };
D33D4F01117D8EAE00BA7203 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D33D4F00117D8EAE00BA7203 /* main.m */; };
D33D4F41117E244C00BA7203 /* ExamplesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D33D4F40117E244C00BA7203 /* ExamplesViewController.m */; };
D33D5176117E780300BA7203 /* ProceduralExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D33D5175117E780300BA7203 /* ProceduralExampleViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -56,6 +57,8 @@
D33D4F00117D8EAE00BA7203 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = SOURCE_ROOT; };
D33D4F3F117E244C00BA7203 /* ExamplesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExamplesViewController.h; sourceTree = "<group>"; };
D33D4F40117E244C00BA7203 /* ExamplesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExamplesViewController.m; sourceTree = "<group>"; };
D33D5174117E780300BA7203 /* ProceduralExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProceduralExampleViewController.h; sourceTree = "<group>"; };
D33D5175117E780300BA7203 /* ProceduralExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProceduralExampleViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -84,6 +87,8 @@
D33D4B50117C473500BA7203 /* PDFExampleViewController.m */,
D33D4F3F117E244C00BA7203 /* ExamplesViewController.h */,
D33D4F40117E244C00BA7203 /* ExamplesViewController.m */,
D33D5174117E780300BA7203 /* ProceduralExampleViewController.h */,
D33D5175117E780300BA7203 /* ProceduralExampleViewController.m */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -233,6 +238,7 @@
D33D4ECC117D8D4500BA7203 /* Utilities.m in Sources */,
D33D4F01117D8EAE00BA7203 /* main.m in Sources */,
D33D4F41117E244C00BA7203 /* ExamplesViewController.m in Sources */,
D33D5176117E780300BA7203 /* ProceduralExampleViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion Leaves/LeavesViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
#import "LeavesView.h"

@interface LeavesViewController : UIViewController {
@interface LeavesViewController : UIViewController <LeavesViewDataSource, LeavesViewDelegate> {
LeavesView *leavesView;
}

Expand Down
23 changes: 17 additions & 6 deletions Leaves/LeavesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,30 @@ - (void)dealloc {
[super dealloc];
}

#pragma mark LeavesViewDataSource methods

- (NSUInteger) numberOfPagesInLeavesView:(LeavesView*)leavesView {
return 0;
}

- (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {

}

#pragma mark UIViewController methods

- (void)loadView {
[super loadView];
leavesView.frame = self.view.bounds;
leavesView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:leavesView];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
- (void) viewDidLoad {
[super viewDidLoad];
leavesView.dataSource = self;
leavesView.delegate = self;
[leavesView reloadData];
}
*/

@end

0 comments on commit 630e653

Please sign in to comment.