CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/ios/iCade/iCadeReaderView.m
Views: 1401
1
/*
2
Copyright (C) 2011 by Stuart Carnie
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
THE SOFTWARE.
21
*/
22
23
#import "iCadeReaderView.h"
24
25
static const char * const ON_STATES = "wdxayhujikol";
26
static const char * const OFF_STATES = "eczqtrfnmpgv";
27
28
@interface iCadeReaderView()
29
30
- (void)didEnterBackground;
31
- (void)didBecomeActive;
32
33
@end
34
35
@implementation iCadeReaderView
36
37
@synthesize iCadeState=_iCadeState, delegate=_delegate, active;
38
39
- (id)initWithFrame:(CGRect)frame {
40
self = [super initWithFrame:frame];
41
inputView = [[UIView alloc] initWithFrame:CGRectZero];
42
43
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
44
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
45
46
return self;
47
}
48
49
- (void)dealloc {
50
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
51
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
52
}
53
54
- (void)didEnterBackground {
55
if (self.active)
56
[self resignFirstResponder];
57
}
58
59
- (void)didBecomeActive {
60
if (self.active)
61
[self becomeFirstResponder];
62
}
63
64
- (BOOL)canBecomeFirstResponder {
65
return YES;
66
}
67
68
- (void)setActive:(BOOL)value {
69
if (active == value) return;
70
71
active = value;
72
if (active) {
73
[self becomeFirstResponder];
74
} else {
75
[self resignFirstResponder];
76
}
77
}
78
79
- (UIView*) inputView {
80
return inputView;
81
}
82
83
- (void)setDelegate:(id<iCadeEventDelegate>)delegate {
84
_delegate = delegate;
85
if (!_delegate) return;
86
87
/*_delegateFlags.stateChanged = [_delegate respondsToSelector:@selector(stateChanged:)];
88
_delegateFlags.buttonDown = [_delegate respondsToSelector:@selector(buttonDown:)];
89
_delegateFlags.buttonUp = [_delegate respondsToSelector:@selector(buttonUp:)];*/
90
}
91
92
/*#pragma mark -
93
#pragma mark UIKeyInput Protocol Methods
94
95
- (BOOL)hasText {
96
return NO;
97
}
98
99
- (void)insertText:(NSString *)text {
100
101
char ch = [text characterAtIndex:0];
102
char *p = strchr(ON_STATES, ch);
103
bool stateChanged = false;
104
if (p) {
105
int index = p-ON_STATES;
106
_iCadeState |= (1 << index);
107
stateChanged = true;
108
if (_delegateFlags.buttonDown) {
109
[_delegate buttonDown:(1 << index)];
110
}
111
} else {
112
p = strchr(OFF_STATES, ch);
113
if (p) {
114
int index = p-OFF_STATES;
115
_iCadeState &= ~(1 << index);
116
stateChanged = true;
117
if (_delegateFlags.buttonUp) {
118
[_delegate buttonUp:(1 << index)];
119
}
120
}
121
}
122
123
if (stateChanged && _delegateFlags.stateChanged) {
124
[_delegate stateChanged:_iCadeState];
125
}
126
127
static int cycleResponder = 0;
128
if (++cycleResponder > 20) {
129
// necessary to clear a buffer that accumulates internally
130
cycleResponder = 0;
131
[self resignFirstResponder];
132
[self becomeFirstResponder];
133
}
134
}
135
136
- (void)deleteBackward {
137
// This space intentionally left blank to complete protocol
138
}*/
139
140
@end
141
142