Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoawindow.m @ 4673:c17ac64abb70
Fixed the code so we receive Cocoa touch events
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 28 Jul 2010 23:32:13 -0700 |
parents | 524dfefd554c |
children | 89d5e2201b00 |
comparison
equal
deleted
inserted
replaced
4672:013b0ea263dd | 4673:c17ac64abb70 |
---|---|
23 | 23 |
24 #include "SDL_syswm.h" | 24 #include "SDL_syswm.h" |
25 #include "../SDL_sysvideo.h" | 25 #include "../SDL_sysvideo.h" |
26 #include "../../events/SDL_keyboard_c.h" | 26 #include "../../events/SDL_keyboard_c.h" |
27 #include "../../events/SDL_mouse_c.h" | 27 #include "../../events/SDL_mouse_c.h" |
28 #include "../../events/SDL_touch_c.h" | |
28 #include "../../events/SDL_windowevents_c.h" | 29 #include "../../events/SDL_windowevents_c.h" |
29 | 30 |
30 #include "SDL_cocoavideo.h" | 31 #include "SDL_cocoavideo.h" |
31 | 32 |
32 static __inline__ void ConvertNSRect(NSRect *r) | 33 static __inline__ void ConvertNSRect(NSRect *r) |
58 } | 59 } |
59 [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp]; | 60 [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp]; |
60 [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp]; | 61 [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp]; |
61 | 62 |
62 [_data->nswindow setAcceptsMouseMovedEvents:YES]; | 63 [_data->nswindow setAcceptsMouseMovedEvents:YES]; |
64 [[_data->nswindow contentView] setAcceptsTouchEvents:YES]; | |
63 } | 65 } |
64 | 66 |
65 - (void)close | 67 - (void)close |
66 { | 68 { |
67 NSNotificationCenter *center; | 69 NSNotificationCenter *center; |
264 y += 0.9f; | 266 y += 0.9f; |
265 } else if (y < 0) { | 267 } else if (y < 0) { |
266 y -= 0.9f; | 268 y -= 0.9f; |
267 } | 269 } |
268 SDL_SendMouseWheel(_data->window, (int)x, (int)y); | 270 SDL_SendMouseWheel(_data->window, (int)x, (int)y); |
271 } | |
272 | |
273 - (void)touchesBeganWithEvent:(NSEvent *) theEvent | |
274 { | |
275 [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent]; | |
276 } | |
277 | |
278 - (void)touchesMovedWithEvent:(NSEvent *) theEvent | |
279 { | |
280 [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent]; | |
281 } | |
282 | |
283 - (void)touchesEndedWithEvent:(NSEvent *) theEvent | |
284 { | |
285 [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent]; | |
286 } | |
287 | |
288 - (void)touchesCancelledWithEvent:(NSEvent *) theEvent | |
289 { | |
290 [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent]; | |
291 } | |
292 | |
293 - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event | |
294 { | |
295 NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil]; | |
296 | |
297 NSEnumerator *enumerator = [touches objectEnumerator]; | |
298 NSTouch *touch = (NSTouch*)[enumerator nextObject]; | |
299 while (touch) { | |
300 long touchId = (long)[touch device]; | |
301 if (!SDL_GetTouch(touchId)) { | |
302 SDL_Touch touch; | |
303 | |
304 touch.id = touchId; | |
305 touch.x_min = 0; | |
306 touch.x_max = 1; | |
307 touch.xres = touch.x_max - touch.x_min; | |
308 touch.y_min = 0; | |
309 touch.y_max = 1; | |
310 touch.yres = touch.y_max - touch.y_min; | |
311 touch.pressure_min = 0; | |
312 touch.pressure_max = 1; | |
313 touch.pressureres = touch.pressure_max - touch.pressure_min; | |
314 | |
315 if (SDL_AddTouch(&touch, "") < 0) { | |
316 return; | |
317 } | |
318 } | |
319 float x = [touch normalizedPosition].x; | |
320 float y = [touch normalizedPosition].y; | |
321 long fingerId = (long)[touch identity]; | |
322 switch (type) { | |
323 case COCOA_TOUCH_DOWN: | |
324 SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1); | |
325 break; | |
326 case COCOA_TOUCH_UP: | |
327 case COCOA_TOUCH_CANCELLED: | |
328 SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1); | |
329 break; | |
330 case COCOA_TOUCH_MOVE: | |
331 SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1); | |
332 break; | |
333 } | |
334 | |
335 touch = (NSTouch*)[enumerator nextObject]; | |
336 } | |
269 } | 337 } |
270 | 338 |
271 @end | 339 @end |
272 | 340 |
273 @interface SDLWindow : NSWindow | 341 @interface SDLWindow : NSWindow |