-
Notifications
You must be signed in to change notification settings - Fork 8
/
ViewController.m
executable file
·120 lines (93 loc) · 3.47 KB
/
ViewController.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
//
// ViewController.m
// CALayerLayout
//
// Created by steve hooley on 14/08/2008.
// Copyright 2008 BestBefore Ltd. All rights reserved.
//
#import "ViewController.h"
#import "CALayerRootView.h"
#import "HooleyLayer.h"
#import "CustomCALayerManager.h"
#import "GridLayer.h"
#import <FScript/FScript.h>
//Explicit Animations
//CABasicAnimation *animation = [CABasicAnimation animation];
//[animation setToValue:[NSNumber numberWithBool:NO]];
//
//CABasicAnimation *animation = [CABasicAnimation animation];
//[animation setRemovedOnCompletion:NO];
//[animation setFillMode:kCAFillModeForwards];
//[animation setDelegate:self];
//
//- (void)animationDidStop:(CABasicAnimation *)theAnimation finished:(BOOL)flag
//{
// CALayer *layer = [testView layer];
// NSString *path = [theAnimation keyPath];
// [layer setValue:[theAnimation toValue] forKeyPath:path];
// [layer removeAnimationForKey:path];
//}
@implementation ViewController
#warning gravity is where the layer will sit when its bounds are lrger than parent layer - a bit like overflow
- (id)init {
self = [super init];
if (self) {
_myCustomLayoutManager = [[CustomCALayerManager alloc] init];
_onLayers = [[NSMutableArray array] retain];
}
return self;
}
- (void)dealloc {
[_onLayers release];
[_myCustomLayoutManager release];
[super dealloc];
}
- (void)awakeFromNib {
/* load FScript */
[[NSApp mainMenu] addItem:[[[FScriptMenuItem alloc] init] autorelease]];
[_rootView configureMainView];
CALayer* mainLayer = _rootView.layer;
[mainLayer setLayoutManager: _myCustomLayoutManager];
[mainLayer setValue:@"mainLayer" forKey:@"name"];
CGRect parentBounds = mainLayer.bounds;
// bounds x, y are always zero (unlike frame) so his just take width/2
CGFloat midX = CGRectGetMidX( parentBounds );
CGFloat midY = CGRectGetMidY( parentBounds );
GridLayer *gridLayer = [GridLayer layer];
[gridLayer setLayoutManager: _myCustomLayoutManager];
CGFloat desiredWidth = parentBounds.size.width * 0.8;
CGFloat desiredHeight = desiredWidth / 12.0;
[gridLayer sizeToUnitSize: CGSizeMake(desiredWidth, desiredHeight) of:parentBounds];
[gridLayer positionToUnitPosition: CGPointMake( midX, midY ) of: parentBounds];
[gridLayer setValue:@"gridLayer" forKey:@"name"];
[gridLayer setDelegate:self];
[gridLayer setUpGrid];
[mainLayer addSublayer: gridLayer];
[gridLayer lightOn:YES row:2 column:2];
// causes the layer content to be drawn in -drawRect:
[mainLayer setNeedsDisplay];
}
- (void)hitLayer:(HooleyLayer *)aLayer {
BOOL alreadyOn = [_onLayers containsObject:aLayer];
if(alreadyOn==NO){
[_onLayers makeObjectsPerformSelector:@selector(turnOff)];
[_onLayers removeAllObjects];
[aLayer turnOn];
[_onLayers addObject:aLayer];
}
}
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event {
// NSString *name = [layer valueForKey:@"name"];
// NSLog(@"EVent is %@ on layer %@", event, name);
// if ([event isEqualToString:@"bounds"] && [[layer valueForKey:@"layerCustomResizeType"] isEqualToString:@"myCustomLayerTypeName"] )
// {
// // disable animation for new layers being added to container layer
// return (id<CAAction>)[NSNull null];
// } else if ([event isEqualToString:@"position"] && [[layer valueForKey:@"layerCustomResizeType"] isEqualToString:@"myCustomLayerTypeName"] ) {
// return (id<CAAction>)[NSNull null];
// }
// for everything else, use default animation. note that
// nil means "default animation" in this case, not "no animation".
return nil;
}
@end