forked from OpenSmalltalk/opensmalltalk-vm
/
sqSqueakIPhoneApplication+events.m
267 lines (233 loc) · 11.7 KB
/
sqSqueakIPhoneApplication+events.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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
* sqSqueakIPhoneApplication+events.m
* SqueakNoOGLIPhone
*
* Created by John M McIntosh on 5/16/08.
*
Some of this code was funded via a grant from the European Smalltalk User Group (ESUG)
Copyright (c) 2008 Corporate Smalltalk Consulting Ltd. All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
"This product includes software developed by Corporate Smalltalk Consulting Ltd (http://www.smalltalkconsulting.com)
and its contributors", in the same place and form as other third-party acknowledgments.
Alternately, this acknowledgment may appear in the software itself, in the same form and location as other
such third-party acknowledgments.
*/
//
#import "sq.h"
#import "sqSqueakMainApplication+events.h"
#import "sqSqueakIPhoneApplication+events.h"
#import "sqDummyaio.h"
#import "sqMacHostWindow.h"
#import "SqueakNoOGLIPhoneAppDelegate.h"
#import "Queue.h"
#define MillisecondClockMask 536870911
extern SqueakNoOGLIPhoneAppDelegate *gDelegateApp;
extern struct VirtualMachine* interpreterProxy;
sqInt windowActive=1;
@implementation sqSqueakIPhoneApplication (events)
- (void ) processAsOldEventOrComplexEvent: (id) event placeIn: (sqInputEvent *) evt {
if ([event isKindOfClass: [NSData class]]) {
[super processAsOldEventOrComplexEvent: event placeIn: evt];
return;
}
if ([event isKindOfClass: [NSArray class]]) {
if ([event[0] intValue] == 1) {
[self buildTouchEventComplexObject: event[2] forType: event[1] placeIn: (sqComplexEvent *) evt];
return;
}
if ([event[0] intValue] == 2) { // acceleration dataa
[self buildAccelerationEventComplexObject: event[1] placeIn: (sqComplexEvent *) evt];
return;
}
if ([event[0] intValue] == 3) { // location data error
[self buildLocationEventComplexObject: event placeIn: (sqComplexEvent *) evt];
return;
}
if ([event[0] intValue] == 4) { // location data
[self buildLocationEventComplexObject: event placeIn: (sqComplexEvent *) evt];
return;
}
if ([event[0] intValue] == 5) { // memory warning
[self buildApplicationEventComplexObject: event placeIn: (sqComplexEvent *) evt];
return;
}
if ([event[0] intValue] == 6) { // termination warning
[self buildApplicationEventComplexObject: event placeIn: (sqComplexEvent *) evt];
return;
}
if ([event[0] intValue] == 7) { // keyboard
[(NSData *)event[1] getBytes: evt length: sizeof(sqInputEvent)];
return;
}
if ([event[0] intValue] == 8) { // window
[(NSData *)event[1] getBytes: evt length: sizeof(sqWindowEvent)];
return;
}
}
}
- (void) recordTouchEvent:(NSSet *) touches type: (UITouchPhase) phase {
NSMutableArray* data = [NSMutableArray arrayWithCapacity: 3];
[data addObject: @1];
[data addObject: @((signed) phase)];
[data addObject: touches];
[eventQueue addItem: data];
interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
}
- (CGPoint)translateToSmalltalk:(CGPoint)position {
/*
* Moves current point to Smalltalk coordinates (Fourth quadrant)
*/
//CGSize size = [[UIScreen mainScreen] bounds].size;
//CGPoint newPosition = CGPointMake(position.x, size.height - position.y);
//NSLog(@"POS OLD: %f,%f NEW: %f,%f", position.x, position.y, newPosition.x, newPosition.y);
//NSLog(@"POS OLD: %f,%f", position.x, position.y);
return position;
}
- (void) buildTouchEventComplexObject:(NSSet *) touches forType: (NSNumber *) aType placeIn: (sqComplexEvent *) evt {
sqInt count = [touches count];
sqInt arrayIndex=0;
sqInt squeakMSTimeNow = ioMSecs();
sqInt action;
UITouch *touch;
sqInt previousLocationInViewX;
sqInt previousLocationInViewY;
sqInt locationInViewX;
sqInt locationInViewY;
sqInt squeakMSTime;
sqInt view;
sqInt window;
sqInt tapCount;
sqInt phase;
sqInt timeStamp;
sqInt storageArea;
sqInt containerArray;
sqInt touchId;
interpreterProxy->pushRemappableOop(interpreterProxy->instantiateClassindexableSize(interpreterProxy->classArray(), count));
for (touch in touches) {
CGPoint location = [touch locationInView:[gDelegateApp mainView]];
CGPoint previousLocation = [touch previousLocationInView:[gDelegateApp mainView]];
interpreterProxy->pushRemappableOop(interpreterProxy->instantiateClassindexableSize(interpreterProxy->classArray(), 11));
interpreterProxy->pushRemappableOop(interpreterProxy->integerObjectOf(squeakMSTimeNow));
interpreterProxy->pushRemappableOop(interpreterProxy->floatObjectOf([touch timestamp]));
interpreterProxy->pushRemappableOop(interpreterProxy->integerObjectOf((signed)[touch phase]));
interpreterProxy->pushRemappableOop(interpreterProxy->integerObjectOf((signed)[touch tapCount]));
interpreterProxy->pushRemappableOop(interpreterProxy->positive64BitIntegerFor((sqLong)[touch window]));
interpreterProxy->pushRemappableOop(interpreterProxy->positive64BitIntegerFor((sqLong)[touch view]));
interpreterProxy->pushRemappableOop(interpreterProxy->floatObjectOf(location.x));
interpreterProxy->pushRemappableOop(interpreterProxy->floatObjectOf(location.y));
interpreterProxy->pushRemappableOop(interpreterProxy->floatObjectOf(previousLocation.x));
interpreterProxy->pushRemappableOop(interpreterProxy->floatObjectOf(previousLocation.y));
interpreterProxy->pushRemappableOop(interpreterProxy->positive64BitIntegerFor((sqLong)touch));
touchId = interpreterProxy->popRemappableOop();
previousLocationInViewY = interpreterProxy->popRemappableOop();
previousLocationInViewX = interpreterProxy->popRemappableOop();
locationInViewY = interpreterProxy->popRemappableOop();
locationInViewX = interpreterProxy->popRemappableOop();
view = interpreterProxy->popRemappableOop();
window = interpreterProxy->popRemappableOop();
tapCount = interpreterProxy->popRemappableOop();
phase = interpreterProxy->popRemappableOop();
timeStamp = interpreterProxy->popRemappableOop();
squeakMSTime = interpreterProxy->popRemappableOop();
storageArea = interpreterProxy->popRemappableOop();
containerArray = interpreterProxy->popRemappableOop();
interpreterProxy->storePointerofObjectwithValue(0, storageArea, squeakMSTime);
interpreterProxy->storePointerofObjectwithValue(1, storageArea, timeStamp);
interpreterProxy->storePointerofObjectwithValue(2, storageArea, phase);
interpreterProxy->storePointerofObjectwithValue(3, storageArea, tapCount);
interpreterProxy->storePointerofObjectwithValue(4, storageArea, window);
interpreterProxy->storePointerofObjectwithValue(5, storageArea, view);
interpreterProxy->storePointerofObjectwithValue(6, storageArea, locationInViewX);
interpreterProxy->storePointerofObjectwithValue(7, storageArea, locationInViewY);
interpreterProxy->storePointerofObjectwithValue(8, storageArea, previousLocationInViewX);
interpreterProxy->storePointerofObjectwithValue(9, storageArea, previousLocationInViewY);
interpreterProxy->storePointerofObjectwithValue(10, storageArea, touchId);
interpreterProxy->storePointerofObjectwithValue(arrayIndex++, containerArray, storageArea);
interpreterProxy->pushRemappableOop(containerArray);
}
evt->type = EventTypeComplex; //This is read as an integer and converted to an oop by interp.c
evt->timeStamp = interpreterProxy->integerObjectOf(squeakMSTimeNow);
switch ([aType integerValue]) {
case UITouchPhaseBegan:
action = ComplexEventTypeTouchsDown;
break;
case UITouchPhaseEnded:
action = ComplexEventTypeTouchsUp;
break;
case UITouchPhaseMoved:
action = ComplexEventTypeTouchsMoved;
break;
case UITouchPhaseStationary:
action = ComplexEventTypeTouchsStationary;
break;
case UITouchPhaseCancelled:
action = ComplexEventTypeTouchsCancelled;
break;
default:
action = 0;
break;
}
evt->action = interpreterProxy->integerObjectOf(action);
containerArray = interpreterProxy->popRemappableOop();
evt->objectPointer = containerArray;
evt->unused1 =interpreterProxy->integerObjectOf(0);
evt->unused2 = interpreterProxy->integerObjectOf(0);
evt->unused3 =interpreterProxy->integerObjectOf(0);
evt->windowIndex = interpreterProxy->integerObjectOf(windowActive);
}
- (void) buildAccelerationEventComplexObject: (UIAcceleration *) acceleration placeIn: (sqComplexEvent *) evt {
sqInt squeakMSTimeNow = ioMSecs();
interpreterProxy->pushRemappableOop(interpreterProxy->positive64BitIntegerFor(((usqInt) acceleration)));
evt->type = EventTypeComplex; //This is read as an integer and converted to an oop by interp.c
evt->timeStamp = interpreterProxy->integerObjectOf(squeakMSTimeNow);
evt->action = interpreterProxy->integerObjectOf(ComplexEventTypeAccelerationData);
evt->objectPointer = interpreterProxy->popRemappableOop();
evt->unused1 =interpreterProxy->integerObjectOf(0);
evt->unused2 = interpreterProxy->integerObjectOf(0);
evt->unused3 =interpreterProxy->integerObjectOf(0);
evt->windowIndex = interpreterProxy->integerObjectOf(windowActive);
}
- (void) buildLocationEventComplexObject: (NSMutableArray *) event placeIn: (sqComplexEvent *) evt {
sqInt squeakMSTimeNow = ioMSecs();
interpreterProxy->pushRemappableOop(interpreterProxy->positive64BitIntegerFor(((usqInt) event)));
evt->type = EventTypeComplex; //This is read as an integer and converted to an oop by interp.c
evt->timeStamp = interpreterProxy->integerObjectOf(squeakMSTimeNow);
evt->action = interpreterProxy->integerObjectOf(ComplexEventTypeLocationData);
evt->objectPointer = interpreterProxy->popRemappableOop();
evt->unused1 =interpreterProxy->integerObjectOf(0);
evt->unused2 = interpreterProxy->integerObjectOf(0);
evt->unused3 =interpreterProxy->integerObjectOf(0);
evt->windowIndex = interpreterProxy->integerObjectOf(windowActive);
}
- (void) buildApplicationEventComplexObject: (NSMutableArray *) event placeIn: (sqComplexEvent *) evt {
sqInt squeakMSTimeNow = ioMSecs();
interpreterProxy->pushRemappableOop(interpreterProxy->positive64BitIntegerFor(((usqInt) event)));
evt->type = EventTypeComplex; //This is read as an integer and converted to an oop by interp.c
evt->timeStamp = interpreterProxy->integerObjectOf(squeakMSTimeNow);
evt->action = interpreterProxy->integerObjectOf(ComplexEventTypeApplicationData);
evt->objectPointer = interpreterProxy->popRemappableOop();
evt->unused1 =interpreterProxy->integerObjectOf(0);
evt->unused2 = interpreterProxy->integerObjectOf(0);
evt->unused3 =interpreterProxy->integerObjectOf(0);
evt->windowIndex = interpreterProxy->integerObjectOf(windowActive);
}
@end