forked from brow/leaves
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for high quality zooming using CATiledLayer
- Loading branch information
Rodrigo Hammerly
authored and
Rodrigo Hammerly
committed
Aug 24, 2011
1 parent
67b10ed
commit 813e147
Showing
11 changed files
with
309 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,5 +101,4 @@ - (void) setPageSize:(CGSize)value { | |
pageSize = value; | ||
[self flush]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// LeavesTiledLayer.h | ||
// Leaves | ||
// | ||
// Created by Rodrigo Hammerly on 8/24/11. | ||
// Copyright 2011 Tom Brow. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
|
||
@interface LeavesTiledLayer : CATiledLayer { | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// LeavesTiledLayer.m | ||
// Leaves | ||
// | ||
// Created by Rodrigo Hammerly on 8/24/11. | ||
// Copyright 2011 Tom Brow. All rights reserved. | ||
// | ||
|
||
#import "LeavesTiledLayer.h" | ||
|
||
#define ZOOM_LEVELS 5 | ||
|
||
@implementation LeavesTiledLayer | ||
|
||
+ (CFTimeInterval)fadeDuration | ||
{ | ||
return 0.0; // No fading wanted | ||
} | ||
|
||
+ (id<CAAction>)defaultActionForKey:(NSString *)event | ||
{ | ||
return nil; | ||
} | ||
#pragma mark LeavesTiledLayer instance methods | ||
|
||
- (id)init | ||
{ | ||
if ((self = [super init])) | ||
{ | ||
self.levelsOfDetail = ZOOM_LEVELS; | ||
|
||
self.levelsOfDetailBias = (ZOOM_LEVELS - 1); | ||
|
||
CGFloat screenScale; // Points to pixels | ||
|
||
UIScreen *mainScreen = [UIScreen mainScreen]; | ||
|
||
if ([mainScreen respondsToSelector:@selector(scale)]) | ||
screenScale = [mainScreen scale]; | ||
else | ||
screenScale = 1.0f; | ||
|
||
CGRect screenBounds = [mainScreen bounds]; // Is in points | ||
|
||
CGFloat w_pixels = (screenBounds.size.width * screenScale); | ||
CGFloat h_pixels = (screenBounds.size.height * screenScale); | ||
|
||
CGFloat max = (w_pixels < h_pixels) ? h_pixels : w_pixels; | ||
|
||
CGFloat sizeOfTiles = (max < 512.0f) ? 512.0f : 1024.0f; | ||
|
||
self.tileSize = CGSizeMake(sizeOfTiles, sizeOfTiles); | ||
self.backgroundColor = [UIColor clearColor].CGColor; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// LeavesTiledLayerDelegate.h | ||
// Leaves | ||
// | ||
// Created by Rodrigo Hammerly on 8/24/11. | ||
// Copyright 2011 Tom Brow. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
@protocol LeavesViewDataSource; | ||
|
||
@interface LeavesTiledLayerDelegate : NSObject { | ||
id<LeavesViewDataSource> dataSource; | ||
NSInteger pageIndex; | ||
} | ||
|
||
@property (assign) id<LeavesViewDataSource> dataSource; | ||
@property (assign) NSInteger pageIndex; | ||
|
||
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// LeavesTiledLayerDelegate.m | ||
// Leaves | ||
// | ||
// Created by Rodrigo Hammerly on 8/24/11. | ||
// Copyright 2011 Tom Brow. All rights reserved. | ||
// | ||
|
||
#import "LeavesTiledLayerDelegate.h" | ||
#import "LeavesView.h" | ||
|
||
@implementation LeavesTiledLayerDelegate | ||
|
||
@synthesize dataSource; | ||
@synthesize pageIndex; | ||
|
||
- (id)init { | ||
|
||
if ((self = [super init])) { | ||
self.pageIndex = 0; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark LeavesViewTiledLayer delegated methods | ||
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context { | ||
|
||
[self.dataSource renderTiledPageAtIndex:self.pageIndex forLayer:layer inContext:context]; | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.