-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSMFComplexDropShadowControl.mm
236 lines (213 loc) · 6.43 KB
/
SMFComplexDropShadowControl.mm
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//
// SMFComplexDropShadowControl.m
// SMFramework
//
// Created by Thomas Cool on 2/28/11.
// Copyright 2011 Thomas Cool. All rights reserved.
//
#import "SMFComplexDropShadowControl.h"
#import "SMFThemeInfo.h"
#import "SMFDefines.h"
#import <substrate.h>
#define SHRINK_RECT CGRectMake(270.0,85.0,730.0,530.0)
@implementation SMFComplexDropShadowControl
@synthesize title=_title;
@synthesize subtitle=_subtitle;
@synthesize progress=_progress;
@synthesize blocking=_blocking;
@synthesize delegate;
-(id)init
{
self=[super init];
CGRect f = CGRectMake(256.0,72.0,768.0,576.0);//(s.width*0.2, s.height*0.1, s.width*0.6, s.height*0.8);
[self setFrame:f];
_bg=[[BRControl alloc] init];
_progress=[[SMFProgressBarControl alloc]init];
_titleControl=[[BRMetadataTitleControl alloc]init];
_scrolling=[[BRScrollingTextBoxControl alloc]init];
_list=MSHookIvar<BRListControl *>(_scrolling, "_list");
[_list setSelectionLozengeStyle:0];
_list.avoidsCursor = TRUE;
_list.displaysSelectionWidget = FALSE;
self.backgroundColor=[[SMFThemeInfo sharedTheme]blackColor];
self.borderColor=[[SMFThemeInfo sharedTheme] whiteColor];
self.borderWidth=3.0;
self.title=@" ";
self.subtitle=@" ";
[self setContent:_bg];
_text=[[NSMutableString alloc] initWithString:@" "];
[self addObserver:self forKeyPath:@"title" options:0 context:nil];
[self addObserver:self forKeyPath:@"subtitle" options:0 context:nil];
return self;
}
void logFrame(CGRect frame)
{
NSLog(@"{{%f, %f},{%f,%f}}",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
}
//this is taken care of by the superclass now
//-(void)addToController:(BRController *)ctrl
//{
//
// CGRect f = CGRectMake(256.0,72.0,768.0,576.0);//(s.width*0.2, s.height*0.1, s.width*0.6, s.height*0.8);
// [self setFrame:f];
// [ctrl addControl:self];
// [ctrl setFocusedControl:self];
// [ctrl _setFocus:self];
//
//}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)o change:(NSDictionary *)change context:(void *)context
{
if (o==self && [keyPath isEqualToString:@"title"]) {
// NSLog(@"changing title");
[_titleControl setTitle:_title];
[_titleControl layoutSubcontrols];
}
else if(o==self && [keyPath isEqualToString:@"subtitle"])
{
// NSLog(@"changing subtitle");
[_titleControl setTitleSubtext:_subtitle];
[_titleControl layoutSubcontrols];
}
}
-(void)reload
{
[_bg _removeAllControls];
CGRect pf = [self frame];
[_progress setFrame:CGRectMake(pf.size.width*0.2f, pf.size.height*0.02f, pf.size.width*0.6f, pf.size.height*0.06f)];
[_bg addControl:_progress];
[_titleControl setTitle:_title];
[_titleControl setTitleSubtext:_subtitle];
[_titleControl setFrame:CGRectMake(pf.size.width*0.02f, pf.size.height*0.83f, pf.size.width*0.6f, pf.size.height*0.15f)];
[_bg addControl:_titleControl];
[_scrolling setFrame:CGRectMake(0.0, pf.size.height*0.11, pf.size.width, pf.size.height*0.75f)];
[_scrolling setText:[self attributedStringForString:_text]];
[_bg addControl:_scrolling];
}
-(id)attributedStringForString:(NSString*)s
{
NSMutableDictionary *d = [[[[BRThemeInfo sharedTheme]metadataTitleAttributes] mutableCopy] autorelease];
[d setObject:[NSNumber numberWithInt:0] forKey:@"BRTextAlignmentKey"];
[d setObject:[NSNumber numberWithInt:0] forKey:@"BRLineBreakModeKey"];
return [[[NSAttributedString alloc]initWithString:s attributes:d]autorelease];
}
-(void)appendToText:(NSString *)t
{
[_text appendString:t];
[_scrolling setText:[self attributedStringForString:_text]];
[_list setSelection:([_list dataCount]-1)];
[_scrolling layoutSubcontrols];
[self _setFocus:nil];
[self setFocusedControl:nil];
}
- (void)removeBlueLozenge //thats (sort of) the weird thing going on when you use this controller in conjunction w/ SMFMoviePreviewController
{
NSEnumerator *controlEnum = [[_list controls] objectEnumerator];
id current = nil;
while ((current = [controlEnum nextObject]))
{
NSString *currentClass = NSStringFromClass([current class]);
if ([currentClass isEqualToString:@"BRBlueGlowSelectionLozengeLayer"])
{
[current removeFromParent];
[_list layoutSubcontrols];
}
}
}
//- (CGRect)focusCursorFrame
//{
// //right now i am just shrinking the rect down so its only noticable during its exit animation (which was a default animation that we have nothing to do w/)
// return SHRINK_RECT;
//}
-(void)controlWasActivated
{
[super controlWasActivated];
//NSArray *listControls = [_list controls];
// if ([listControls count] > 1)
// {
// [self removeBlueLozenge];
// }
[self reload];
}
-(void)setShowsProgressBar:(BOOL)shows
{
[_progress setHidden:!shows];
_pbShows=shows;
}
-(BOOL)showsProgressBar
{
return _pbShows;
}
-(void)setShowsWaitSpinner:(BOOL)shows
{
[_spinner setHidden:!shows];
_showWaitSpinner=shows;
}
-(BOOL)brEventAction:(BREvent*)event
{
int remoteAction = [event remoteAction];
switch (remoteAction)
{
case kBREventRemoteActionMenu:
[self removeFromParent];
return YES;
break;
case kBREventRemoteActionUp:
if (event.value==1) {
if ([_list selection]==0)
{
[_list setSelection:([_list dataCount]-1)];
return YES;
}
}
break;
case kBREventRemoteActionDown:
if (event.value==1) {
if ([_list selection]==([_list dataCount]-1)) {
return YES;
}
}
break;
}
return [super brEventAction:event];
}
-(BOOL)showsWaitSpinner
{
return _showWaitSpinner;
}
-(void)updateHeader
{
[_titleControl setTitle:_title];
[_titleControl setTitleSubtext:_subtitle];
[_titleControl layoutSubcontrols];
}
//- (void)updateTitle:(NSString *)t
//{
// _title = t;
// [self reload];
//}
//
//- (void)updateSubtitle:(NSString *)t
//{
// _subtitle = t;
// [self reload];
//}
-(void)dealloc
{
[_titleControl release];
_titleControl=nil;
[_bg release];
_bg=nil;
[_scrolling release];
_scrolling=nil;
[_progress release];
_progress=nil;
[_spinner release];
_spinner = nil;
_list=nil;
[self removeObserver:self forKeyPath:@"title"];
[self removeObserver:self forKeyPath:@"subtitle"];
self.title=nil;
self.subtitle=nil;
[super dealloc];
}
@end