Skip to content

Commit

Permalink
Fixed a little thing in EPGLTransitionView and added an iPad demo in …
Browse files Browse the repository at this point in the history
…landscape showing a pdf which pages can be turned with swipe gestures.
  • Loading branch information
epatel committed Feb 1, 2011
1 parent b3e5fd2 commit 85f3c4a
Show file tree
Hide file tree
Showing 19 changed files with 1,686 additions and 9 deletions.
8 changes: 4 additions & 4 deletions DemoProject-iPad/DemoProject.xcodeproj/project.pbxproj
Expand Up @@ -16,7 +16,6 @@
3A0BB4C211A9EA7400C6C3D4 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233A90DB2D0DB0083E9F9 /* MainViewController.m */; };
3A0BB4C311A9EA7400C6C3D4 /* FlipsideViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 289233AD0DB2D0DB0083E9F9 /* FlipsideViewController.m */; };
3A0BB4C411A9EA7400C6C3D4 /* DemoTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A112DA1113A8E8E004D04A4 /* DemoTransition.m */; };
3A0BB4C511A9EA7400C6C3D4 /* EPGLTransitionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A112DA3113A8E8E004D04A4 /* EPGLTransitionView.m */; };
3A0BB4C611A9EA7400C6C3D4 /* Demo2Transition.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A7D0F6F117A423D00CFAD01 /* Demo2Transition.m */; };
3A0BB4C811A9EA7400C6C3D4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
3A0BB4C911A9EA7400C6C3D4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
Expand All @@ -26,6 +25,7 @@
3A0BB4D611A9EA7500C6C3D4 /* FlipsideView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A0BB4D311A9EA7500C6C3D4 /* FlipsideView.xib */; };
3A0BB4D711A9EA7500C6C3D4 /* MainView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A0BB4D411A9EA7500C6C3D4 /* MainView.xib */; };
3A0BB4D811A9EA7500C6C3D4 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A0BB4D511A9EA7500C6C3D4 /* MainWindow.xib */; };
3A20F7BE12F87AD70015365E /* EPGLTransitionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A20F7BD12F87AD70015365E /* EPGLTransitionView.m */; };
3A4826D211D93FE10059B460 /* Demo3Transition.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A4826D111D93FE10059B460 /* Demo3Transition.m */; };
/* End PBXBuildFile section */

Expand All @@ -52,11 +52,11 @@
3A112DA0113A8E8E004D04A4 /* DemoTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DemoTransition.h; path = ../src/DemoTransition.h; sourceTree = SOURCE_ROOT; };
3A112DA1113A8E8E004D04A4 /* DemoTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DemoTransition.m; path = ../src/DemoTransition.m; sourceTree = SOURCE_ROOT; };
3A112DA2113A8E8E004D04A4 /* EPGLTransitionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EPGLTransitionView.h; path = ../src/EPGLTransitionView.h; sourceTree = SOURCE_ROOT; };
3A112DA3113A8E8E004D04A4 /* EPGLTransitionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EPGLTransitionView.m; path = ../src/EPGLTransitionView.m; sourceTree = SOURCE_ROOT; };
3A112DA8113A8EB2004D04A4 /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.txt; sourceTree = "<group>"; };
3A112DAD113A8ED3004D04A4 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
3A112DC1113A8F7B004D04A4 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
3A112DDF113A9345004D04A4 /* painting.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = painting.jpg; sourceTree = "<group>"; };
3A20F7BD12F87AD70015365E /* EPGLTransitionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EPGLTransitionView.m; path = ../src/EPGLTransitionView.m; sourceTree = SOURCE_ROOT; };
3A4826D011D93FE10059B460 /* Demo3Transition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Demo3Transition.h; path = ../src/Demo3Transition.h; sourceTree = SOURCE_ROOT; };
3A4826D111D93FE10059B460 /* Demo3Transition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Demo3Transition.m; path = ../src/Demo3Transition.m; sourceTree = SOURCE_ROOT; };
3A7D0F6E117A423D00CFAD01 /* Demo2Transition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Demo2Transition.h; path = ../src/Demo2Transition.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -187,7 +187,7 @@
3A4826D011D93FE10059B460 /* Demo3Transition.h */,
3A4826D111D93FE10059B460 /* Demo3Transition.m */,
3A112DA2113A8E8E004D04A4 /* EPGLTransitionView.h */,
3A112DA3113A8E8E004D04A4 /* EPGLTransitionView.m */,
3A20F7BD12F87AD70015365E /* EPGLTransitionView.m */,
);
name = EPGLTransitionView;
sourceTree = "<group>";
Expand Down Expand Up @@ -264,9 +264,9 @@
3A0BB4C211A9EA7400C6C3D4 /* MainViewController.m in Sources */,
3A0BB4C311A9EA7400C6C3D4 /* FlipsideViewController.m in Sources */,
3A0BB4C411A9EA7400C6C3D4 /* DemoTransition.m in Sources */,
3A0BB4C511A9EA7400C6C3D4 /* EPGLTransitionView.m in Sources */,
3A0BB4C611A9EA7400C6C3D4 /* Demo2Transition.m in Sources */,
3A4826D211D93FE10059B460 /* Demo3Transition.m in Sources */,
3A20F7BE12F87AD70015365E /* EPGLTransitionView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
22 changes: 22 additions & 0 deletions FlipReader-iPad/Classes/FlipReaderAppDelegate.h
@@ -0,0 +1,22 @@
//
// FlipReaderAppDelegate.h
// FlipReader
//
// Created by Edward Patel on 2011-02-01.
// Copyright 2011 Memention AB. All rights reserved.
//

#import <UIKit/UIKit.h>

@class FlipReaderViewController;

@interface FlipReaderAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
FlipReaderViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet FlipReaderViewController *viewController;

@end

71 changes: 71 additions & 0 deletions FlipReader-iPad/Classes/FlipReaderAppDelegate.m
@@ -0,0 +1,71 @@
//
// FlipReaderAppDelegate.m
// FlipReader
//
// Created by Edward Patel on 2011-02-01.
// Copyright 2011 Memention AB. All rights reserved.
//

#import "FlipReaderAppDelegate.h"
#import "FlipReaderViewController.h"

@implementation FlipReaderAppDelegate

@synthesize window;
@synthesize viewController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after app launch.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];

return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}


- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}


- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}


@end
19 changes: 19 additions & 0 deletions FlipReader-iPad/Classes/FlipReaderViewController.h
@@ -0,0 +1,19 @@
//
// FlipReaderViewController.h
// FlipReader
//
// Created by Edward Patel on 2011-02-01.
// Copyright 2011 Memention AB. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "MyPDFView.h"

@interface FlipReaderViewController : UIViewController<UIGestureRecognizerDelegate> {
MyPDFView *mpv;
int pageNumber;
}

@end

127 changes: 127 additions & 0 deletions FlipReader-iPad/Classes/FlipReaderViewController.m
@@ -0,0 +1,127 @@
//
// FlipReaderViewController.m
// FlipReader
//
// Created by Edward Patel on 2011-02-01.
// Copyright 2011 Memention AB. All rights reserved.
//

#import "FlipReaderViewController.h"
#import "EPGLTransitionView.h"
#import "FlipTransitions.h"

@implementation FlipReaderViewController


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];

pageNumber = 0;

CGRect rect = CGRectMake(0, 0, 1024, 768);

mpv = [[MyPDFView alloc] initWithFrame:rect];
[[self view] insertSubview:mpv atIndex:0];
[mpv gotoPage:pageNumber];
[mpv release];

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
[mpv addGestureRecognizer:swipeRight];

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = self;
[mpv addGestureRecognizer:swipeLeft];
}

- (void)swipeLeftAction:(id)sender {
if (pageNumber >= 312)
return;

NSObject<EPGLTransitionViewDelegate> *transition = [[[FlipForward alloc] init] autorelease];

EPGLTransitionView *glview = [[[EPGLTransitionView alloc]
initWithView:self.view
delegate:transition] autorelease];

pageNumber += 2;
[mpv gotoPage:pageNumber];

[glview prepareTextureTo:self.view];

[glview setClearColorRed:0.0
green:0.0
blue:0.0
alpha:1.0];

[glview startTransition];
}

- (void)swipeRightAction:(id)sender {
if (pageNumber <= 0)
return;

NSObject<EPGLTransitionViewDelegate> *transition = [[[FlipBackward alloc] init] autorelease];

EPGLTransitionView *glview = [[[EPGLTransitionView alloc]
initWithView:self.view
delegate:transition] autorelease];

pageNumber -= 2;
[mpv gotoPage:pageNumber];

[glview prepareTextureTo:self.view];

[glview setClearColorRed:0.0
green:0.0
blue:0.0
alpha:1.0];

[glview startTransition];
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
}

@end
17 changes: 17 additions & 0 deletions FlipReader-iPad/Classes/MyPDFView.h
@@ -0,0 +1,17 @@
//
// MyPDFView.h
// GoForth
//
// Created by Edward Patel on 2010-12-25.
// Copyright 2010 Memention AB. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface MyPDFView : UIView {
CGPDFDocumentRef book;
int pageNumber;
}
- (void)gotoPage:(int)nextPage;
@end
70 changes: 70 additions & 0 deletions FlipReader-iPad/Classes/MyPDFView.m
@@ -0,0 +1,70 @@
//
// MyPDFView.m
// GoForth
//
// Created by Edward Patel on 2010-12-25.
// Copyright 2010 Memention AB. All rights reserved.
//

#import "MyPDFView.h"

@implementation MyPDFView

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSURL *bookURL = [[NSBundle mainBundle] URLForResource:@"thinking-forth-color" withExtension:@"pdf"];
book = CGPDFDocumentCreateWithURL((CFURLRef)bookURL);
pageNumber = 1;
}
return self;
}

- (void)gotoPage:(int)nextPage
{
pageNumber = nextPage;
[self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
CGPDFPageRef page1;
CGPDFPageRef page2;

page1 = CGPDFDocumentGetPage(book, pageNumber);
page2 = CGPDFDocumentGetPage(book, pageNumber+1);

CGRect pageRect;
if (page1)
pageRect = CGPDFPageGetBoxRect(page1, kCGPDFMediaBox);
else
pageRect = CGPDFPageGetBoxRect(page2, kCGPDFMediaBox);

CGRect frameRect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
CGFloat scaleFactorWidth = 0.5*frameRect.size.width/pageRect.size.width;

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, frameRect);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextScaleCTM(context, scaleFactorWidth, scaleFactorWidth);
if (page1)
CGContextDrawPDFPage(context, page1);
CGContextTranslateCTM(context, 0.5*rect.size.height*scaleFactorWidth, 0);
if (page2)
CGContextDrawPDFPage(context, page2);
CGContextMoveToPoint(context, 0.5*scaleFactorWidth, 0);
CGContextAddLineToPoint(context, 0.5*scaleFactorWidth, rect.size.width*scaleFactorWidth);
CGContextStrokePath(context);
}

- (void)dealloc {
CGPDFDocumentRelease(book);
[super dealloc];
}

@end

0 comments on commit 85f3c4a

Please sign in to comment.