92 // HW_chat() HW_tab() HW_pause() |
95 // HW_chat() HW_tab() HW_pause() |
93 break; |
96 break; |
94 } |
97 } |
95 } |
98 } |
96 |
99 |
|
100 #pragma mark - |
|
101 #pragma mark Custom SDL_UIView input handling |
|
102 #define kMinimumPinchDelta 50 |
|
103 #define kMinimumGestureLength 10 |
|
104 #define kMaximumVariance 3 |
|
105 |
|
106 // we override default touch input to implement our own gestures |
|
107 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
|
108 NSArray *twoTouches; |
|
109 UITouch *touch = [touches anyObject]; |
|
110 |
|
111 switch ([touches count]) { |
|
112 case 1: |
|
113 gestureStartPoint = [touch locationInView:self.view]; |
|
114 initialDistanceForPinching = 0; |
|
115 switch ([touch tapCount]) { |
|
116 case 1: |
|
117 NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
|
118 SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
|
119 (int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x); |
|
120 HW_click(); |
|
121 break; |
|
122 case 2: |
|
123 HW_ammoMenu(); |
|
124 break; |
|
125 default: |
|
126 break; |
|
127 } |
|
128 break; |
|
129 case 2: |
|
130 if (2 == [touch tapCount]) { |
|
131 HW_zoomReset(); |
|
132 } |
|
133 |
|
134 // pinching |
|
135 twoTouches = [touches allObjects]; |
|
136 UITouch *first = [twoTouches objectAtIndex:0]; |
|
137 UITouch *second = [twoTouches objectAtIndex:1]; |
|
138 initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
|
139 break; |
|
140 default: |
|
141 break; |
|
142 } |
|
143 |
|
144 } |
|
145 |
|
146 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
|
147 initialDistanceForPinching = 0; |
|
148 gestureStartPoint.x = 0; |
|
149 gestureStartPoint.y = 0; |
|
150 HW_allKeysUp(); |
|
151 } |
|
152 |
|
153 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
|
154 // this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances. |
|
155 // Usually (it seems) all active touches are canceled. |
|
156 [self touchesEnded:touches withEvent:event]; |
|
157 } |
|
158 |
|
159 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
160 NSArray *twoTouches; |
|
161 CGPoint currentPosition; |
|
162 UITouch *touch = [touches anyObject]; |
|
163 |
|
164 switch ([touches count]) { |
|
165 case 1: |
|
166 currentPosition = [touch locationInView:self.view]; |
|
167 // panning |
|
168 SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
|
169 (int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x); |
|
170 // remember that we have x and y inverted |
|
171 /* temporarily disabling hog movements for camera panning testing |
|
172 CGFloat vertDiff = gestureStartPoint.x - currentPosition.x; |
|
173 CGFloat horizDiff = gestureStartPoint.y - currentPosition.y; |
|
174 CGFloat deltaX = fabsf(vertDiff); |
|
175 CGFloat deltaY = fabsf(horizDiff); |
|
176 |
|
177 if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) { |
|
178 NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x); |
|
179 if (horizDiff > 0) HW_walkLeft(); |
|
180 else HW_walkRight(); |
|
181 } else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){ |
|
182 NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y); |
|
183 if (vertDiff < 0) HW_aimUp(); |
|
184 else HW_aimDown(); |
|
185 } |
|
186 */ |
|
187 break; |
|
188 case 2: |
|
189 twoTouches = [touches allObjects]; |
|
190 UITouch *first = [twoTouches objectAtIndex:0]; |
|
191 UITouch *second = [twoTouches objectAtIndex:1]; |
|
192 CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
|
193 |
|
194 if (0 == initialDistanceForPinching) |
|
195 initialDistanceForPinching = currentDistanceOfPinching; |
|
196 |
|
197 if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta) |
|
198 HW_zoomOut(); |
|
199 else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta) |
|
200 HW_zoomIn(); |
|
201 |
|
202 currentDistanceOfPinching = initialDistanceForPinching; |
|
203 break; |
|
204 default: |
|
205 break; |
|
206 } |
|
207 } |
|
208 |
|
209 |
97 |
210 |
98 @end |
211 @end |