-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFlowController.m
More file actions
154 lines (125 loc) · 3.22 KB
/
Copy pathFlowController.m
File metadata and controls
154 lines (125 loc) · 3.22 KB
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
//
// FlowController.m
// Flowrate
//
// Created by Nathan Vander Wilt on 11/7/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "FlowController.h"
#import <QuartzCore/QuartzCore.h>
#import "HostView.h"
#import "AlbumInfo.h"
#import "RateSet.h"
#import "ItemDisplay.h"
#import "StageController.h"
#import "NSColor+TLExtensions.h"
#import "TLSFX.h"
@interface FlowController () <ItemDisplayDataSource>
@end
@implementation FlowController
@synthesize autoHold;
- (id)initWithRateSet:(RateSet*)theRateSet {
self = [super init];
if (self) {
rateSet = theRateSet;
itemDisplay = [ItemDisplay new];
itemDisplay.dataSource = self;
itemDisplay.layer.backgroundColor = [[NSColor grayColor] tl_CGColor];
itemDisplay.layer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
itemDisplay.layer.frame = self.layer.bounds;
[self.layer addSublayer:itemDisplay.layer];
}
return self;
}
#pragma mark Item display data source
- (NSUInteger)position {
return [itemDisplay position];
}
- (NSUInteger)numberOfItemsInDisplay:(ItemDisplay*)anItemDisplay {
(void)anItemDisplay;
return [rateSet count];
}
- (CGImageRef)itemDisplayNeedsImage:(ItemDisplay*)anItemDisplay
forItemAtIndex:(NSUInteger)itemIdx
withSize:(NSUInteger)imageSize
{
(void)anItemDisplay;
id item = [rateSet itemAtIndex:itemIdx];
return [[AlbumInfo sharedAlbumInfo] imageForItem:item ofSize:imageSize];
}
- (CGFloat)itemDisplayNeedsAspectRatio:(ItemDisplay*)anItemDisplay
forItemAtIndex:(NSUInteger)itemIdx
{
(void)anItemDisplay;
id item = [rateSet itemAtIndex:itemIdx];
return [[AlbumInfo sharedAlbumInfo] aspectRatioForItem:item];
}
- (NSInteger)itemDisplayNeedsAlignment:(ItemDisplay*)anItemDisplay
forItemAtIndex:(NSUInteger)itemIdx
{
(void)anItemDisplay;
return [rateSet itemStatusAtIndex:itemIdx];
}
#pragma mark Event handling
- (void)retreat {
if (itemDisplay.position > 0) {
itemDisplay.position -= 1;
}
}
- (void)rateCurrentItem:(RateStatus)newStatus {
NSString* soundName = nil;
switch (newStatus) {
case RateStatusDown:
soundName = TLSFXNameDown;
break;
case RateStatusUp:
soundName = TLSFXNameUp;
break;
case RateStatusNoChange:
soundName = TLSFXNameNeutral;
break;
}
if (soundName) {
[self.hostView preventDefaultSound];
[[TLSFX sharedSFX] playSound:soundName];
}
[rateSet setItemStatus:newStatus atIndex:(itemDisplay.position)];
[itemDisplay.layer setNeedsLayout];
}
- (void)advance {
if (itemDisplay.position + 1 < rateSet.count) {
itemDisplay.position += 1;
}
else {
// pop from stack when done
[self.hostView popController];
}
}
- (void)buttonLeft {
[self retreat];
if (true) {
[self rateCurrentItem:RateStatusNoChange];
}
}
- (void)buttonRight {
if (self.autoHold && ![rateSet itemStatusAtIndex:(itemDisplay.position)]) {
[self rateCurrentItem:RateStatusDown];
}
[self advance];
}
- (void)buttonDown {
[self rateCurrentItem:RateStatusDown];
[self advance];
}
- (void)buttonUp {
[self rateCurrentItem:RateStatusUp];
[self advance];
}
- (void)buttonMenu {
[(StageController*)self.parentController showBreakMenu];
}
- (void)layerDidAppear {
[self rateCurrentItem:RateStatusNoChange];
[(StageController*)self.parentController checkBreakMenu];
}
@end