-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSMFMenuController.m
135 lines (127 loc) · 3.38 KB
/
SMFMenuController.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
//
// OFMediaMenuController.m
// Untitled
//
// Created by Thomas Cool on 10/22/10.
// Copyright 2010 tomcool.org. All rights reserved.
//
#import "SMFMenuController.h"
@implementation SMFMenuController
- (float)heightForRow:(long)row { return 0.0f;}
- (BOOL)rowSelectable:(long)row { return YES;}
- (long)itemCount { return (long)[_items count];}
- (id)itemForRow:(long)row { return [_items objectAtIndex:row];}
- (long)rowForTitle:(id)title { return (long)[_items indexOfObject:title];}
- (id)titleForRow:(long)row
{
return [[self itemForRow:row] text];
}
- (long)defaultIndex { return 0;}
- (id)init
{
self=[super init];
_items = [[NSMutableArray alloc]init];
_options = [[NSMutableArray alloc] init];
[[self list] setDatasource:self];
return self;
}
- (void)dealloc
{
[_items release];
[_options release];
[super dealloc];
}
-(id)everyLoad
{
return self;
}
-(int)getSelection
{
BRListControl *list = [self list];
int row;
NSMethodSignature *signature = [list methodSignatureForSelector:@selector(selection)];
NSInvocation *selInv = [NSInvocation invocationWithMethodSignature:signature];
[selInv setSelector:@selector(selection)];
[selInv invokeWithTarget:list];
if([signature methodReturnLength] == 8)
{
double retDoub = 0;
[selInv getReturnValue:&retDoub];
row = retDoub;
}
else
[selInv getReturnValue:&row];
return row;
}
-(void)leftActionForRow:(long)row
{
}
-(void)rightActionForRow:(long)row
{
}
-(BOOL)brEventAction:(BREvent *)event
{
int remoteAction = [event remoteAction];
if ([(BRControllerStack *)[self stack] peekController] != self)
remoteAction = 0;
int itemCount = [[(BRListControl *)[self list] datasource] itemCount];
switch (remoteAction)
{
case kBREventRemoteActionSwipeLeft:
case kBREventRemoteActionLeft:
if([event value] == 1)
[self leftActionForRow:[self getSelection]];
return YES;
break;
case kBREventRemoteActionSwipeRight:
case kBREventRemoteActionRight:
if([event value] == 1)
[self rightActionForRow:[self getSelection]];
return YES;
break;
case kBREventRemoteActionUp:
case kBREventRemoteActionHoldUp:
if([self getSelection] == 0 && [event value] == 1)
{
[self setSelection:itemCount-1];
return YES;
}
break;
case kBREventRemoteActionDown:
case kBREventRemoteActionHoldDown:
if([self getSelection] == itemCount-1 && [event value] == 1)
{
[self setSelection:0];
return YES;
}
break;
}
return [super brEventAction:event];
}
- (void)setSelection:(int)sel
{
BRListControl *list = [self list];
NSMethodSignature *signature = [list methodSignatureForSelector:@selector(setSelection:)];
NSInvocation *selInv = [NSInvocation invocationWithMethodSignature:signature];
[selInv setSelector:@selector(setSelection:)];
if(strcmp([signature getArgumentTypeAtIndex:2], "l"))
{
double dvalue = sel;
[selInv setArgument:&dvalue atIndex:2];
}
else
{
long lvalue = sel;
[selInv setArgument:&lvalue atIndex:2];
}
[selInv invokeWithTarget:list];
}
-(void)controlWasActivated
{
if([self respondsToSelector:@selector(everyLoad)])
[self everyLoad];
[super controlWasActivated];
}
- (void)wasExhumedByPoppingController:(id)fp8 {[self wasExhumed];}
-(void)wasExhumed {[[self list] reload];}
@end