Created
October 1, 2011 04:11
-
-
Save OneSadCookie/1255579 to your computer and use it in GitHub Desktop.
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
@implementation EWWordLayout | |
- (CGSize)preferredSizeOfLayer:(CALayer *)layer | |
{ | |
size_t layerCount = [[layer sublayers] count]; | |
CGFloat totalWidth = layerCount * TILE_WIDTH + (layerCount - 1) * INTERTILE_GAP; | |
return CGSizeMake(totalWidth, TILE_HEIGHT); | |
} | |
- (void)invalidateLayoutOfLayer:(CALayer *)layer | |
{} | |
- (void)layoutSublayersOfLayer:(CALayer *)layer | |
{ | |
CGRect rect = [layer bounds]; | |
size_t layerCount = [[layer sublayers] count]; | |
CGFloat totalWidth = layerCount * TILE_WIDTH + (layerCount - 1) * INTERTILE_GAP; | |
CGFloat x = floor(0.5 * (rect.size.width - totalWidth)); | |
CGFloat y = floor(0.5 * (rect.size.height - TILE_HEIGHT)); | |
for (CALayer *sublayer in [layer sublayers]) | |
{ | |
// NSLog(@"putting %@ at (%f, %f)", sublayer, x, y); | |
[sublayer setPosition:CGPointMake(x, y)]; | |
x += TILE_WIDTH + INTERTILE_GAP; | |
} | |
} | |
@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
- (void)updateLetterTiles | |
{ | |
[gapLayers[0] removeFromSuperlayer]; | |
[gapLayers[1] removeFromSuperlayer]; | |
for (CALayer *l in letterLayers) | |
{ | |
[l removeFromSuperlayer]; | |
} | |
NSMutableArray *array = [NSMutableArray array]; | |
size_t j = 0; | |
for (size_t i = 0; i < [[game letters] length]; ++i) | |
{ | |
NSString *letterString = [NSString stringWithCharacters:(unichar[]){ toupper([[game letters] characterAtIndex:i]) } length:1]; | |
if (j < [letterLayers count] && [[[(CATextLayer *)[letterLayers objectAtIndex:j] string] string] isEqualToString:letterString]) | |
{ | |
[array addObject:[letterLayers objectAtIndex:j]]; | |
++j; | |
} | |
else | |
{ | |
[array addObject:[EWLayers letterLayer:letterString]]; | |
} | |
} | |
letterLayers = array; | |
[wordLayer addSublayer:gapLayers[0]]; | |
for (CALayer *l in letterLayers) | |
{ | |
[wordLayer addSublayer:l]; | |
} | |
[wordLayer addSublayer:gapLayers[1]]; | |
NSLog(@"wordLayer sublayers: %@", [wordLayer sublayers]); | |
[wordLayer layoutIfNeeded]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment