Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoamouse.m @ 4465:3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Plus, this lets me start implementing cursor support.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 09 May 2010 20:47:22 -0700 |
parents | 64ce267332c6 |
children | 9322f7db8603 |
comparison
equal
deleted
inserted
replaced
4464:fa77a6429698 | 4465:3e69e077cb95 |
---|---|
27 #include "../../events/SDL_mouse_c.h" | 27 #include "../../events/SDL_mouse_c.h" |
28 | 28 |
29 void | 29 void |
30 Cocoa_InitMouse(_THIS) | 30 Cocoa_InitMouse(_THIS) |
31 { | 31 { |
32 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
33 SDL_Mouse mouse; | |
34 | |
35 SDL_zero(mouse); | |
36 data->mouse = SDL_AddMouse(&mouse, "Mouse", 0, 0, 1); | |
37 } | 32 } |
38 | 33 |
39 static int | 34 static int |
40 ConvertMouseButtonToSDL(int button) | 35 ConvertMouseButtonToSDL(int button) |
41 { | 36 { |
52 } | 47 } |
53 | 48 |
54 void | 49 void |
55 Cocoa_HandleMouseEvent(_THIS, NSEvent *event) | 50 Cocoa_HandleMouseEvent(_THIS, NSEvent *event) |
56 { | 51 { |
57 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
58 SDL_Mouse *mouse = SDL_GetMouse(data->mouse); | |
59 int i; | 52 int i; |
60 NSPoint point; | 53 NSPoint point = { 0, 0 }; |
61 SDL_Window *window; | 54 SDL_Window *window; |
62 | 55 |
63 /* See if there are any fullscreen windows that might handle this event */ | 56 /* See if there are any fullscreen windows that might handle this event */ |
64 window = NULL; | 57 window = NULL; |
65 for (i = 0; i < _this->num_displays; ++i) { | 58 for (i = 0; i < _this->num_displays; ++i) { |
71 | 64 |
72 Cocoa_GetDisplayBounds(_this, display, &bounds); | 65 Cocoa_GetDisplayBounds(_this, display, &bounds); |
73 point = [NSEvent mouseLocation]; | 66 point = [NSEvent mouseLocation]; |
74 point.x = point.x - bounds.x; | 67 point.x = point.x - bounds.x; |
75 point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - bounds.y; | 68 point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - bounds.y; |
76 if (point.x < 0 || point.x >= candidate->w || | 69 if ((point.x >= 0 && point.x < candidate->w) || |
77 point.y < 0 || point.y >= candidate->h) { | 70 (point.y >= 0 && point.y < candidate->h)) { |
78 /* The mouse is out of this fullscreen display */ | |
79 if (mouse->focus == candidate) { | |
80 SDL_SetMouseFocus(data->mouse, 0); | |
81 } | |
82 } else { | |
83 /* This is it! */ | 71 /* This is it! */ |
84 window = candidate; | 72 window = candidate; |
85 break; | 73 break; |
86 } | 74 } |
87 } | 75 } |
88 } | 76 } |
89 if (!window) { | |
90 return; | |
91 } | |
92 | 77 |
93 /* Set the focus appropriately */ | 78 /* Set the focus appropriately */ |
94 if (mouse->focus != window) { | 79 SDL_SetMouseFocus(window); |
95 SDL_SetMouseFocus(data->mouse, window); | 80 |
81 if (window) { | |
82 return; | |
96 } | 83 } |
97 | 84 |
98 switch ([event type]) { | 85 switch ([event type]) { |
99 case NSLeftMouseDown: | 86 case NSLeftMouseDown: |
100 case NSOtherMouseDown: | 87 case NSOtherMouseDown: |
101 case NSRightMouseDown: | 88 case NSRightMouseDown: |
102 SDL_SendMouseButton(data->mouse, SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber])); | 89 SDL_SendMouseButton(SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber])); |
103 break; | 90 break; |
104 case NSLeftMouseUp: | 91 case NSLeftMouseUp: |
105 case NSOtherMouseUp: | 92 case NSOtherMouseUp: |
106 case NSRightMouseUp: | 93 case NSRightMouseUp: |
107 SDL_SendMouseButton(data->mouse, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber])); | 94 SDL_SendMouseButton(SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber])); |
108 break; | 95 break; |
109 case NSLeftMouseDragged: | 96 case NSLeftMouseDragged: |
110 case NSRightMouseDragged: | 97 case NSRightMouseDragged: |
111 case NSOtherMouseDragged: /* usually middle mouse dragged */ | 98 case NSOtherMouseDragged: /* usually middle mouse dragged */ |
112 case NSMouseMoved: | 99 case NSMouseMoved: |
113 SDL_SendMouseMotion(data->mouse, 0, (int)point.x, (int)point.y, 0); | 100 SDL_SendMouseMotion(0, (int)point.x, (int)point.y); |
114 break; | 101 break; |
115 default: /* just to avoid compiler warnings */ | 102 default: /* just to avoid compiler warnings */ |
116 break; | 103 break; |
117 } | 104 } |
118 } | 105 } |
119 | 106 |
120 void | 107 void |
121 Cocoa_QuitMouse(_THIS) | 108 Cocoa_QuitMouse(_THIS) |
122 { | 109 { |
123 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
124 | |
125 SDL_DelMouse(data->mouse); | |
126 } | 110 } |
127 | 111 |
128 /* vi: set ts=4 sw=4 expandtab: */ | 112 /* vi: set ts=4 sw=4 expandtab: */ |