forked from julius/silverflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSFCoverFlowView.m
179 lines (145 loc) · 5.83 KB
/
SFCoverFlowView.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
// SFCoverFlowView.m
// SilverFlow
//
// Created by Julius Eckert on 05.05.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "SFCoverFlowView.h"
@implementation SFCoverFlowView
@synthesize soAction, soIndirect;
- (id)initWithFrame:(NSRect)frame {
if (self = [super initWithFrame:frame]) {
[self setLayer:[CALayer layer]];
[self setWantsLayer:true];
//[[self layer] setBounds:NSRectToCGRect([self frame])];
[[self layer] setFrame:NSRectToCGRect([self frame])];
[[self layer] setDelegate:self];
CATransform3D sublayerTransform = CATransform3DIdentity;
sublayerTransform.m34 = 1. / -340.;
[[self layer] setSublayerTransform:sublayerTransform];
[[self layer] setNeedsDisplay];
//[self layer].edgeAntialiasingMask = kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge;
//[self layer].minificationFilter = kCAFilterNearest;
//[self layer].magnificationFilter = kCAFilterNearest;
coverFlow = [[SFCoverFlow alloc] initWithLayer:[self layer]];
[self setupLayers];
soAction = [[SFSelectorObject alloc] initWithLayer:[self layer] asSelector:2];
soIndirect = [[SFSelectorObject alloc] initWithLayer:[self layer] asSelector:3];
}
return self;
}
- (void)setSelector:(int)sel {
if (sel == 1) dof.opacity = 1;
else dof.opacity = 0;
[soAction setCurrentSelector:sel];
[soIndirect setCurrentSelector:sel];
[coverFlow setSelector:sel];
}
- (void)setText:(NSString*)text details:(NSString*)details {
[CATransaction flush];
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
[textLayer setString:text];
[textLayer2 setString:details];
[CATransaction commit];
textLayer3.opacity = 0.05;
}
- (void)setupLayers {
textLayer = [CATextLayer layer];
textLayer.name = @"textLayer";
textLayer.string = @"";
textLayer.font = [NSFont boldSystemFontOfSize:22.0];
textLayer.fontSize = 22;
textLayer.bounds = CGRectMake( 0, 0, 400, 40 );
textLayer.alignmentMode = kCAAlignmentCenter;
textLayer.anchorPoint = CGPointMake(0.5, 0.5);
textLayer.position = CGPointMake([[self layer] frame].size.width/2, 30);
textLayer.foregroundColor = CGColorCreateGenericRGB(255, 255, 255, 255);
textLayer.zPosition = 0;
textLayer.opacity = 1.0;
[[self layer] addSublayer:textLayer];
textLayer2 = [CATextLayer layer];
textLayer2.name = @"textLayer";
textLayer2.string = @"";
textLayer2.font = [NSFont boldSystemFontOfSize:12.0];
textLayer2.fontSize = 12;
textLayer2.bounds = CGRectMake( 0, 0, 400, 40 );
textLayer2.alignmentMode = kCAAlignmentCenter;
textLayer2.anchorPoint = CGPointMake(0.5, 0.5);
textLayer2.position = CGPointMake([[self layer] frame].size.width/2, 4);
textLayer2.foregroundColor = CGColorCreateGenericRGB(255, 255, 255, 255);
textLayer2.zPosition = 0;
textLayer2.opacity = 1.0;
[[self layer] addSublayer:textLayer2];
textLayer3 = [CATextLayer layer];
textLayer3.name = @"textLayer";
textLayer3.string = @"SilverFlow";
textLayer3.font = [NSFont boldSystemFontOfSize:60.0];
textLayer3.fontSize = 60;
textLayer3.shadowOffset = CGSizeMake ( 0, 0 );
textLayer3.shadowOpacity = 1.0;
textLayer3.shadowColor = CGColorCreateGenericRGB(255, 255, 255, 255);
textLayer3.shadowRadius = 24;
textLayer3.bounds = CGRectMake( 0, 0, 650, 140 );
textLayer3.alignmentMode = kCAAlignmentCenter;
textLayer3.anchorPoint = CGPointMake(0.5, 0.5);
textLayer3.position = CGPointMake([[self layer] frame].size.width/2, [[self layer] frame].size.height/2-40);
textLayer3.foregroundColor = CGColorCreateGenericRGB(255, 255, 255, 255);
textLayer3.zPosition = -250;
textLayer3.opacity = 0.85;
textLayer3.transform = CATransform3DMakeScale(1,1.2,1);
[[self layer] addSublayer:textLayer3];
[textLayer setTruncationMode:kCATruncationMiddle];
[textLayer2 setTruncationMode:kCATruncationMiddle];
//inited = false;
// ---------- Depth of Field Effect ---------------
dof = [CALayer layer];
dof.name = @"dof";
dof.bounds = CGRectMake(0, 0, 1800, 1000);
dof.position = CGPointMake(-100, -100);
dof.zPosition = -250;
dof.delegate = self;
[[self layer] addSublayer:dof];
[dof setNeedsDisplay];
//*
CIFilter* filter = [CIFilter filterWithName:@"CIGaussianBlur"];
filter.name = @"myFilter";
dof.backgroundFilters = [NSArray arrayWithObject:filter];
[dof setValue:[NSNumber numberWithInt:2] forKeyPath:@"backgroundFilters.myFilter.inputRadius"];
/**/
}
- (void)dofRedraw {
[CATransaction flush];
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
[dof setNeedsDisplay];
[CATransaction commit];
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)cgContext;
{
NSLog(@"draw");
[NSGraphicsContext saveGraphicsState];
NSRect drawingRect = NSRectFromCGRect( CGContextGetClipBoundingBox( cgContext ) );
NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:NO];
[NSGraphicsContext setCurrentContext:context];
if ([[layer name] isEqualToString:@"dof"]) {
/*
NSRect leftRect, rightRect;
NSDivideRect(drawingRect, &leftRect, &rightRect, 600, NSMaxXEdge);
NSColor* color1 = [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:.1];
NSColor* color2 = [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:1];
NSGradient* gradient = [[NSGradient alloc] initWithStartingColor:color1 endingColor:color2];
[gradient drawInRect:rightRect angle:180];
[gradient drawInRect:leftRect angle:0];
/**/
} else {
[[NSColor blackColor] setFill];
NSRectFillUsingOperation(drawingRect, NSCompositeCopy);
}
[NSGraphicsContext restoreGraphicsState];
}
- (SFCoverFlow*) coverflow { return coverFlow; }
@end