Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoakeyboard.m @ 4671:1f0e8f6417d9
Finished (untested) OS X code.
author | jimtla |
---|---|
date | Tue, 27 Jul 2010 05:21:24 +0400 |
parents | ad4f32e874ee |
children | c17ac64abb70 |
comparison
equal
deleted
inserted
replaced
4670:ad4f32e874ee | 4671:1f0e8f6417d9 |
---|---|
24 #include "SDL_cocoavideo.h" | 24 #include "SDL_cocoavideo.h" |
25 | 25 |
26 #include "../../events/SDL_keyboard_c.h" | 26 #include "../../events/SDL_keyboard_c.h" |
27 #include "../../events/scancodes_darwin.h" | 27 #include "../../events/scancodes_darwin.h" |
28 | 28 |
29 //Touch Code | |
30 #include "../../events/SDL_touch_c.h" | |
31 #include "SDL_cocoatouch.h" | |
32 | |
29 #include <Carbon/Carbon.h> | 33 #include <Carbon/Carbon.h> |
30 | 34 |
31 //#define DEBUG_IME NSLog | 35 //#define DEBUG_IME NSLog |
32 #define DEBUG_IME | 36 #define DEBUG_IME |
33 | 37 |
65 NSRange _selectedRange; | 69 NSRange _selectedRange; |
66 SDL_Rect _inputRect; | 70 SDL_Rect _inputRect; |
67 } | 71 } |
68 - (void) doCommandBySelector:(SEL)myselector; | 72 - (void) doCommandBySelector:(SEL)myselector; |
69 - (void) setInputRect:(SDL_Rect *) rect; | 73 - (void) setInputRect:(SDL_Rect *) rect; |
74 - (void) handleTouches:(cocoaTouchType)type WithEvent:(NSEvent*) event; | |
70 @end | 75 @end |
71 | 76 |
72 @implementation SDLTranslatorResponder | 77 @implementation SDLTranslatorResponder |
73 | 78 |
74 - (void) setInputRect:(SDL_Rect *) rect | 79 - (void) setInputRect:(SDL_Rect *) rect |
198 - (id)initWithFrame:(CGRect)frame { | 203 - (id)initWithFrame:(CGRect)frame { |
199 if (self = [super initWithFrame:frame]) { | 204 if (self = [super initWithFrame:frame]) { |
200 [self setAcceptsTouchEvents:YES]; | 205 [self setAcceptsTouchEvents:YES]; |
201 [self setWantsRestingTouches:YES]; | 206 [self setWantsRestingTouches:YES]; |
202 DEBUG_TOUCH(@"Initializing Cocoa Touch System...."); | 207 DEBUG_TOUCH(@"Initializing Cocoa Touch System...."); |
203 //DEBUG_TOUCH(@"Accepts Touch events? %@",[self acceptsTouchEvents]); | 208 |
204 } | 209 } |
205 return self; | 210 return self; |
206 } | 211 } |
207 | 212 |
213 //Not an API function | |
214 - (void)handleTouches:(cocoaTouchType)type WithEvent:(NSEvent *)event { | |
215 NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:self]; | |
216 | |
217 NSEnumerator *enumerator = [touches objectEnumerator]; | |
218 NSTouch *touch = (NSTouch*)[enumerator nextObject]; | |
219 while (touch) { | |
220 long touchId = (long)[touch device]; | |
221 if(!SDL_GetTouchIndex(touchId)) { | |
222 if(Cocoa_AddTouch(touch) < 0) continue; | |
223 } | |
224 float x = [touch normalizedPosition].x; | |
225 float y = [touch normalizedPosition].y; | |
226 long fingerId = (long)[touch identity]; | |
227 switch (type) { | |
228 case COCOA_TOUCH_DOWN: | |
229 SDL_SendFingerDown(touchId,fingerId, | |
230 SDL_TRUE,x,y,1); | |
231 break; | |
232 case COCOA_TOUCH_UP: | |
233 case COCOA_TOUCH_CANCELLED: | |
234 SDL_SendFingerDown(touchId,fingerId, | |
235 SDL_FALSE,x,y,1); | |
236 case COCOA_TOUCH_MOVE: | |
237 SDL_SendTouchMotion(touchId,fingerId, | |
238 SDL_FALSE,x,y,1); | |
239 } | |
240 | |
241 touch = (NSTouch*)[enumerator nextObject]; | |
242 } | |
243 } | |
244 | |
208 - (void)touchesBeganWithEvent:(NSEvent *)event { | 245 - (void)touchesBeganWithEvent:(NSEvent *)event { |
209 DEBUG_TOUCH(@"Finger Down"); | 246 DEBUG_TOUCH(@"Finger Down"); |
247 | |
248 [self handleTouches: COCOA_TOUCH_DOWN WithEvent: event]; | |
249 | |
250 //Documentation said to call super, but examples do not | |
251 //[super touchesBeganWithEvent:event] | |
210 } | 252 } |
211 - (void)touchesMovedWithEvent:(NSEvent *)event { | 253 - (void)touchesMovedWithEvent:(NSEvent *)event { |
212 DEBUG_TOUCH(@"Finger Moved"); | 254 DEBUG_TOUCH(@"Finger Moved"); |
255 | |
256 [self handleTouches: COCOA_TOUCH_MOVE WithEvent: event]; | |
257 | |
258 //[super touchesMovedWithEvent:event] | |
213 } | 259 } |
214 - (void)touchesEndedWithEvent:(NSEvent *)event { | 260 - (void)touchesEndedWithEvent:(NSEvent *)event { |
215 DEBUG_TOUCH(@"Finger Up"); | 261 DEBUG_TOUCH(@"Finger Up"); |
262 | |
263 [self handleTouches: COCOA_TOUCH_UP WithEvent: event]; | |
264 | |
265 //[super touchesEndedWithEvent:event] | |
216 } | 266 } |
217 - (void)touchesCancelledWithEvent:(NSEvent *)event { | 267 - (void)touchesCancelledWithEvent:(NSEvent *)event { |
218 DEBUG_TOUCH(@"Finger Cancelled"); | 268 DEBUG_TOUCH(@"Finger Cancelled"); |
269 | |
270 [self handleTouches: COCOA_TOUCH_CANCELLED WithEvent: event]; | |
271 | |
272 //[super touchesCancelledWithEvent:event] | |
219 } | 273 } |
220 | 274 |
221 //Touch Code Ends -------------- | 275 //Touch Code Ends -------------- |
222 | 276 |
223 | 277 |
656 * than one copy. When we switched to another window and requesting for | 710 * than one copy. When we switched to another window and requesting for |
657 * text input, simply remove the field editor from its superview then add | 711 * text input, simply remove the field editor from its superview then add |
658 * it to the front most window's content view */ | 712 * it to the front most window's content view */ |
659 if (!data->fieldEdit) { | 713 if (!data->fieldEdit) { |
660 data->fieldEdit = | 714 data->fieldEdit = |
661 [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)]; | 715 [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)]; |
716 DEBUG_TOUCH(@"Accepts Touch events? %i",[data->fieldEdit acceptsTouchEvents]); | |
662 } | 717 } |
663 | 718 |
664 if (![[data->fieldEdit superview] isEqual: parentView]) | 719 if (![[data->fieldEdit superview] isEqual: parentView]) |
665 { | 720 { |
666 // DEBUG_IME(@"add fieldEdit to window contentView"); | 721 // DEBUG_IME(@"add fieldEdit to window contentView"); |
667 [data->fieldEdit removeFromSuperview]; | 722 [data->fieldEdit removeFromSuperview]; |
668 [parentView addSubview: data->fieldEdit]; | 723 [parentView addSubview: data->fieldEdit]; |
669 [[NSApp keyWindow] makeFirstResponder: data->fieldEdit]; | 724 [[NSApp keyWindow] makeFirstResponder: data->fieldEdit]; |
670 } | 725 } |
671 | 726 |
672 [pool release]; | 727 [pool release]; |
751 default: /* just to avoid compiler warnings */ | 806 default: /* just to avoid compiler warnings */ |
752 break; | 807 break; |
753 } | 808 } |
754 } | 809 } |
755 | 810 |
811 Cocoa_AddTouch(NSTouch* finger) { | |
812 SDL_Touch touch; | |
813 touch.id = (long)[finger device]; | |
814 //NSSize size = [finger deviceSize]; | |
815 //touch.driverdata = SDL_malloc(sizeof(EventTouchData)); | |
816 //EventTouchData* data = (EventTouchData*)(touch.driverdata); | |
817 | |
818 touch.x_min = 0; | |
819 touch.x_max = 1; | |
820 touch.xres = touch.x_max - touch.x_min; | |
821 touch.y_min = 0; | |
822 touch.y_max = 1; | |
823 touch.yres = touch.y_max - touch.y_min; | |
824 touch.pressure_min = 0; | |
825 touch.pressure_max = 1; | |
826 touch.pressureres = touch.pressure_max - touch.pressure_min; | |
827 | |
828 | |
829 return SDL_AddTouch(&touch, ""); | |
830 | |
831 } | |
832 | |
833 | |
756 void | 834 void |
757 Cocoa_QuitKeyboard(_THIS) | 835 Cocoa_QuitKeyboard(_THIS) |
758 { | 836 { |
759 } | 837 } |
760 | 838 |