Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoamouse.m @ 3517:e7eec78e4b92
Fixed mouse events for fullscreen windows on Mac OS X
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 03 Dec 2009 08:33:39 +0000 |
parents | b93965a16fe0 |
children | 455a6c47d2c6 |
comparison
equal
deleted
inserted
replaced
3516:72e70a8c30d5 | 3517:e7eec78e4b92 |
---|---|
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | 23 |
24 #include "SDL_events.h" | |
24 #include "SDL_cocoavideo.h" | 25 #include "SDL_cocoavideo.h" |
25 | 26 |
26 #include "../../events/SDL_mouse_c.h" | 27 #include "../../events/SDL_mouse_c.h" |
27 | 28 |
28 void | 29 void |
33 | 34 |
34 SDL_zero(mouse); | 35 SDL_zero(mouse); |
35 data->mouse = SDL_AddMouse(&mouse, "Mouse", 0, 0, 1); | 36 data->mouse = SDL_AddMouse(&mouse, "Mouse", 0, 0, 1); |
36 } | 37 } |
37 | 38 |
39 static int | |
40 ConvertMouseButtonToSDL(int button) | |
41 { | |
42 switch (button) | |
43 { | |
44 case 0: | |
45 return(SDL_BUTTON_LEFT); /* 1 */ | |
46 case 1: | |
47 return(SDL_BUTTON_RIGHT); /* 3 */ | |
48 case 2: | |
49 return(SDL_BUTTON_MIDDLE); /* 2 */ | |
50 } | |
51 return button; | |
52 } | |
53 | |
54 void | |
55 Cocoa_HandleMouseEvent(_THIS, NSEvent *event) | |
56 { | |
57 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
58 SDL_Mouse *mouse = SDL_GetMouse(data->mouse); | |
59 int i; | |
60 NSPoint point; | |
61 SDL_Window *window; | |
62 | |
63 /* See if there are any fullscreen windows that might handle this event */ | |
64 window = NULL; | |
65 for (i = 0; i < _this->num_displays; ++i) { | |
66 SDL_VideoDisplay *display = &_this->displays[i]; | |
67 SDL_Window *candidate = display->fullscreen_window; | |
68 | |
69 if (candidate) { | |
70 SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; | |
71 NSRect rect = CGDisplayBounds(displaydata->display); | |
72 | |
73 point = [NSEvent mouseLocation]; | |
74 point.x = point.x - rect.origin.x; | |
75 point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - rect.origin.y; | |
76 if (point.x < 0 || point.x >= candidate->w || | |
77 point.y < 0 || point.y >= candidate->h) { | |
78 /* The mouse is out of this fullscreen display */ | |
79 if (mouse->focus == candidate->id) { | |
80 SDL_SetMouseFocus(data->mouse, 0); | |
81 } | |
82 } else { | |
83 /* This is it! */ | |
84 window = candidate; | |
85 break; | |
86 } | |
87 } | |
88 } | |
89 if (!window) { | |
90 return; | |
91 } | |
92 | |
93 /* Set the focus appropriately */ | |
94 if (mouse->focus != window->id) { | |
95 SDL_SetMouseFocus(data->mouse, window->id); | |
96 } | |
97 | |
98 switch ([event type]) { | |
99 case NSLeftMouseDown: | |
100 case NSOtherMouseDown: | |
101 case NSRightMouseDown: | |
102 SDL_SendMouseButton(data->mouse, SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber])); | |
103 break; | |
104 case NSLeftMouseUp: | |
105 case NSOtherMouseUp: | |
106 case NSRightMouseUp: | |
107 SDL_SendMouseButton(data->mouse, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber])); | |
108 break; | |
109 case NSLeftMouseDragged: | |
110 case NSRightMouseDragged: | |
111 case NSOtherMouseDragged: /* usually middle mouse dragged */ | |
112 case NSMouseMoved: | |
113 SDL_SendMouseMotion(data->mouse, 0, (int)point.x, (int)point.y, 0); | |
114 break; | |
115 default: /* just to avoid compiler warnings */ | |
116 break; | |
117 } | |
118 } | |
119 | |
38 void | 120 void |
39 Cocoa_QuitMouse(_THIS) | 121 Cocoa_QuitMouse(_THIS) |
40 { | 122 { |
41 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 123 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
42 | 124 |