20 slouken@libsdl.org, vittorio.giovara@gmail.com |
20 slouken@libsdl.org, vittorio.giovara@gmail.com |
21 */ |
21 */ |
22 |
22 |
23 #include "PascalImports.h" |
23 #include "PascalImports.h" |
24 #import "SDL_uikitview.h" |
24 #import "SDL_uikitview.h" |
|
25 #import "SDL_uikitappdelegate.h" |
25 |
26 |
26 #if SDL_IPHONE_KEYBOARD |
27 #if SDL_IPHONE_KEYBOARD |
27 #import "SDL_keyboard_c.h" |
28 #import "SDL_keyboard_c.h" |
28 #import "keyinfotable.h" |
29 #import "keyinfotable.h" |
29 #import "SDL_uikitwindow.h" |
30 #import "SDL_uikitwindow.h" |
30 #import "SDL_uikitappdelegate.h" |
|
31 #endif |
31 #endif |
32 |
32 |
33 @implementation SDL_uikitview |
33 @implementation SDL_uikitview |
34 |
34 |
35 @synthesize initialDistance; |
35 @synthesize initialDistance, gestureStartPoint; |
36 |
36 |
37 - (void)dealloc { |
37 - (void)dealloc { |
38 #if SDL_IPHONE_KEYBOARD |
38 #if SDL_IPHONE_KEYBOARD |
39 SDL_DelKeyboard(0); |
39 SDL_DelKeyboard(0); |
40 [textField release]; |
40 [textField release]; |
65 #pragma mark - |
65 #pragma mark - |
66 #pragma mark Custom SDL_UIView input handling |
66 #pragma mark Custom SDL_UIView input handling |
67 |
67 |
68 // we override default touch input to implement our own gestures |
68 // we override default touch input to implement our own gestures |
69 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
69 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
70 |
|
71 /*NSEnumerator *enumerator = [touches objectEnumerator]; |
70 /*NSEnumerator *enumerator = [touches objectEnumerator]; |
72 UITouch *touch =(UITouch*)[enumerator nextObject]; |
71 UITouch *touch =(UITouch*)[enumerator nextObject]; |
73 |
72 |
74 /* associate touches with mice, so long as we have slots |
73 /* associate touches with mice, so long as we have slots |
75 int i; |
74 int i; |
110 |
109 |
111 /* switch back to our old mouse |
110 /* switch back to our old mouse |
112 SDL_SelectMouse(oldMouse); |
111 SDL_SelectMouse(oldMouse); |
113 |
112 |
114 } */ |
113 } */ |
|
114 |
115 UITouch *touch = [touches anyObject]; |
115 UITouch *touch = [touches anyObject]; |
|
116 gestureStartPoint = [touch locationInView:self]; |
|
117 |
|
118 if (1 == [touch tapCount] ) { |
|
119 //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].windowID, gestureStartPoint.x, gestureStartPoint.y); |
|
120 HW_click(); |
|
121 } |
|
122 |
116 if (2 == [touch tapCount] ) { |
123 if (2 == [touch tapCount] ) { |
117 HW_ammoMenu(); |
124 HW_ammoMenu(); |
118 } |
125 } |
119 |
126 |
120 if (2 == [touches count]) { |
127 if (2 == [touches count]) { |
125 } |
132 } |
126 } |
133 } |
127 |
134 |
128 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
135 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
129 initialDistance = 0; |
136 initialDistance = 0; |
|
137 NSLog(@"touches ended, sigh"); |
|
138 |
|
139 HW_allKeysUp(); |
130 /*NSEnumerator *enumerator = [touches objectEnumerator]; |
140 /*NSEnumerator *enumerator = [touches objectEnumerator]; |
131 UITouch *touch=nil; |
141 UITouch *touch=nil; |
132 |
142 |
133 while(touch = (UITouch *)[enumerator nextObject]) { |
143 while(touch = (UITouch *)[enumerator nextObject]) { |
134 /* search for the mouse slot associated with this touch |
144 /* search for the mouse slot associated with this touch |
156 [self touchesEnded: touches withEvent: event]; |
166 [self touchesEnded: touches withEvent: event]; |
157 } |
167 } |
158 |
168 |
159 |
169 |
160 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
170 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
161 |
171 UITouch *touch = [touches anyObject]; |
162 // NSEnumerator *enumerator = [touches objectEnumerator]; |
172 CGPoint currentPosition = [touch locationInView:self]; |
163 // UITouch *touch=nil; |
173 |
164 |
174 CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); |
|
175 CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); |
|
176 |
|
177 if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) { |
|
178 NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x); |
|
179 HW_walkLeft(); |
|
180 } |
|
181 else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){ |
|
182 NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y); |
|
183 HW_walkRight(); |
|
184 } |
|
185 |
165 if (2 == [touches count]) { |
186 if (2 == [touches count]) { |
166 NSArray *twoTouches = [touches allObjects]; |
187 NSArray *twoTouches = [touches allObjects]; |
167 UITouch *first = [twoTouches objectAtIndex:0]; |
188 UITouch *first = [twoTouches objectAtIndex:0]; |
168 UITouch *second = [twoTouches objectAtIndex:1]; |
189 UITouch *second = [twoTouches objectAtIndex:1]; |
169 CGFloat currentDistance = distanceBetweenPoints([first locationInView:self], [second locationInView:self]); |
190 CGFloat currentDistance = distanceBetweenPoints([first locationInView:self], [second locationInView:self]); |
178 NSLog(@"Inward pinch detected"); |
199 NSLog(@"Inward pinch detected"); |
179 HW_zoomIn(); |
200 HW_zoomIn(); |
180 } |
201 } |
181 } |
202 } |
182 |
203 |
183 /*while(touch = (UITouch *)[enumerator nextObject]) { |
204 /*NSEnumerator *enumerator = [touches objectEnumerator]; |
|
205 UITouch *touch=nil;while(touch = (UITouch *)[enumerator nextObject]) { |
184 // try to find the mouse associated with this touch |
206 // try to find the mouse associated with this touch |
185 int i, found = NO; |
207 int i, found = NO; |
186 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { |
208 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { |
187 if (mice[i].driverdata == touch) { |
209 if (mice[i].driverdata == touch) { |
188 // found proper mouse |
210 // found proper mouse |