Skip to content

Latest commit

 

History

History
640 lines (554 loc) · 23.1 KB

SDL_QuartzEvents.m

File metadata and controls

640 lines (554 loc) · 23.1 KB
 
Jun 1, 2002
Jun 1, 2002
2
SDL - Simple DirectMedia Layer
Jan 4, 2004
Jan 4, 2004
3
Copyright (C) 1997-2003 Sam Lantinga
Jun 1, 2002
Jun 1, 2002
5
6
7
8
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
Jun 1, 2002
Jun 1, 2002
10
11
12
13
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
Jun 1, 2002
Jun 1, 2002
15
16
17
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Jun 1, 2002
Jun 1, 2002
19
20
Sam Lantinga
slouken@libsdl.org
Jan 4, 2004
Jan 4, 2004
22
23
24
25
#include "SDL_QuartzVideo.h"
#include <stdlib.h> // For getenv()
Dec 7, 2002
Dec 7, 2002
26
27
#include <IOKit/IOMessage.h> // For wake from sleep detection
#include <IOKit/pwr_mgt/IOPMLib.h> // For wake from sleep detection
28
29
#include "SDL_QuartzKeys.h"
Jan 4, 2004
Jan 4, 2004
30
void QZ_InitOSKeymap (_THIS) {
Jun 1, 2002
Jun 1, 2002
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const void *KCHRPtr;
UInt32 state;
UInt32 value;
int i;
int world = SDLK_WORLD_0;
for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
keymap[i] = SDLK_UNKNOWN;
/* This keymap is almost exactly the same as the OS 9 one */
keymap[QZ_ESCAPE] = SDLK_ESCAPE;
keymap[QZ_F1] = SDLK_F1;
keymap[QZ_F2] = SDLK_F2;
keymap[QZ_F3] = SDLK_F3;
keymap[QZ_F4] = SDLK_F4;
keymap[QZ_F5] = SDLK_F5;
keymap[QZ_F6] = SDLK_F6;
keymap[QZ_F7] = SDLK_F7;
keymap[QZ_F8] = SDLK_F8;
keymap[QZ_F9] = SDLK_F9;
keymap[QZ_F10] = SDLK_F10;
keymap[QZ_F11] = SDLK_F11;
keymap[QZ_F12] = SDLK_F12;
keymap[QZ_PRINT] = SDLK_PRINT;
keymap[QZ_SCROLLOCK] = SDLK_SCROLLOCK;
keymap[QZ_PAUSE] = SDLK_PAUSE;
keymap[QZ_POWER] = SDLK_POWER;
keymap[QZ_BACKQUOTE] = SDLK_BACKQUOTE;
keymap[QZ_1] = SDLK_1;
keymap[QZ_2] = SDLK_2;
keymap[QZ_3] = SDLK_3;
keymap[QZ_4] = SDLK_4;
keymap[QZ_5] = SDLK_5;
keymap[QZ_6] = SDLK_6;
keymap[QZ_7] = SDLK_7;
keymap[QZ_8] = SDLK_8;
keymap[QZ_9] = SDLK_9;
keymap[QZ_0] = SDLK_0;
keymap[QZ_MINUS] = SDLK_MINUS;
keymap[QZ_EQUALS] = SDLK_EQUALS;
keymap[QZ_BACKSPACE] = SDLK_BACKSPACE;
keymap[QZ_INSERT] = SDLK_INSERT;
keymap[QZ_HOME] = SDLK_HOME;
keymap[QZ_PAGEUP] = SDLK_PAGEUP;
keymap[QZ_NUMLOCK] = SDLK_NUMLOCK;
keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
keymap[QZ_TAB] = SDLK_TAB;
keymap[QZ_q] = SDLK_q;
keymap[QZ_w] = SDLK_w;
keymap[QZ_e] = SDLK_e;
keymap[QZ_r] = SDLK_r;
keymap[QZ_t] = SDLK_t;
keymap[QZ_y] = SDLK_y;
keymap[QZ_u] = SDLK_u;
keymap[QZ_i] = SDLK_i;
keymap[QZ_o] = SDLK_o;
keymap[QZ_p] = SDLK_p;
keymap[QZ_LEFTBRACKET] = SDLK_LEFTBRACKET;
keymap[QZ_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
keymap[QZ_BACKSLASH] = SDLK_BACKSLASH;
keymap[QZ_DELETE] = SDLK_DELETE;
keymap[QZ_END] = SDLK_END;
keymap[QZ_PAGEDOWN] = SDLK_PAGEDOWN;
keymap[QZ_KP7] = SDLK_KP7;
keymap[QZ_KP8] = SDLK_KP8;
keymap[QZ_KP9] = SDLK_KP9;
keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
keymap[QZ_CAPSLOCK] = SDLK_CAPSLOCK;
keymap[QZ_a] = SDLK_a;
keymap[QZ_s] = SDLK_s;
keymap[QZ_d] = SDLK_d;
keymap[QZ_f] = SDLK_f;
keymap[QZ_g] = SDLK_g;
keymap[QZ_h] = SDLK_h;
keymap[QZ_j] = SDLK_j;
keymap[QZ_k] = SDLK_k;
keymap[QZ_l] = SDLK_l;
keymap[QZ_SEMICOLON] = SDLK_SEMICOLON;
keymap[QZ_QUOTE] = SDLK_QUOTE;
keymap[QZ_RETURN] = SDLK_RETURN;
keymap[QZ_KP4] = SDLK_KP4;
keymap[QZ_KP5] = SDLK_KP5;
keymap[QZ_KP6] = SDLK_KP6;
keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
keymap[QZ_LSHIFT] = SDLK_LSHIFT;
keymap[QZ_z] = SDLK_z;
keymap[QZ_x] = SDLK_x;
keymap[QZ_c] = SDLK_c;
keymap[QZ_v] = SDLK_v;
keymap[QZ_b] = SDLK_b;
keymap[QZ_n] = SDLK_n;
keymap[QZ_m] = SDLK_m;
keymap[QZ_COMMA] = SDLK_COMMA;
keymap[QZ_PERIOD] = SDLK_PERIOD;
keymap[QZ_SLASH] = SDLK_SLASH;
keymap[QZ_UP] = SDLK_UP;
keymap[QZ_KP1] = SDLK_KP1;
keymap[QZ_KP2] = SDLK_KP2;
keymap[QZ_KP3] = SDLK_KP3;
keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
keymap[QZ_LCTRL] = SDLK_LCTRL;
keymap[QZ_LALT] = SDLK_LALT;
keymap[QZ_LMETA] = SDLK_LMETA;
keymap[QZ_SPACE] = SDLK_SPACE;
keymap[QZ_LEFT] = SDLK_LEFT;
keymap[QZ_DOWN] = SDLK_DOWN;
keymap[QZ_RIGHT] = SDLK_RIGHT;
keymap[QZ_KP0] = SDLK_KP0;
keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
keymap[QZ_IBOOK_ENTER] = SDLK_KP_ENTER;
keymap[QZ_IBOOK_RIGHT] = SDLK_RIGHT;
keymap[QZ_IBOOK_DOWN] = SDLK_DOWN;
keymap[QZ_IBOOK_UP] = SDLK_UP;
keymap[QZ_IBOOK_LEFT] = SDLK_LEFT;
Oct 5, 2002
Oct 5, 2002
148
149
150
151
152
153
/*
Up there we setup a static scancode->keysym map. However, it will not
work very well on international keyboard. Hence we now query MacOS
for its own keymap to adjust our own mapping table. However, this is
basically only useful for ascii char keys. This is also the reason
why we keep the static table, too.
Jun 1, 2002
Jun 1, 2002
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
*/
/* Get a pointer to the systems cached KCHR */
KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
if (KCHRPtr)
{
/* Loop over all 127 possible scan codes */
for (i = 0; i < 0x7F; i++)
{
/* We pretend a clean start to begin with (i.e. no dead keys active */
state = 0;
/* Now translate the key code to a key value */
value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
/* If the state become 0, it was a dead key. We need to translate again,
passing in the new state, to get the actual key value */
if (state != 0)
value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
/* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */
keymap[i] = world++;
else if (value >= 32) /* non-control ASCII char */
keymap[i] = value;
}
}
Oct 5, 2002
Oct 5, 2002
182
183
184
185
186
187
188
189
/*
The keypad codes are re-setup here, because the loop above cannot
distinguish between a key on the keypad and a regular key. We maybe
could get around this problem in another fashion: NSEvent's flags
include a "NSNumericPadKeyMask" bit; we could check that and modify
the symbol we return on the fly. However, this flag seems to exhibit
some weird behaviour related to the num lock key
*/
Jun 1, 2002
Jun 1, 2002
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
keymap[QZ_KP0] = SDLK_KP0;
keymap[QZ_KP1] = SDLK_KP1;
keymap[QZ_KP2] = SDLK_KP2;
keymap[QZ_KP3] = SDLK_KP3;
keymap[QZ_KP4] = SDLK_KP4;
keymap[QZ_KP5] = SDLK_KP5;
keymap[QZ_KP6] = SDLK_KP6;
keymap[QZ_KP7] = SDLK_KP7;
keymap[QZ_KP8] = SDLK_KP8;
keymap[QZ_KP9] = SDLK_KP9;
keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
Oct 5, 2002
Oct 5, 2002
209
static void QZ_DoKey (_THIS, int state, NSEvent *event) {
Jun 1, 2002
Jun 1, 2002
211
NSString *chars;
Dec 15, 2002
Dec 15, 2002
212
unsigned int numChars;
Jun 1, 2002
Jun 1, 2002
213
SDL_keysym key;
Dec 15, 2002
Dec 15, 2002
214
Oct 5, 2002
Oct 5, 2002
215
/*
Dec 15, 2002
Dec 15, 2002
216
217
218
219
220
221
A key event can contain multiple characters,
or no characters at all. In most cases, it
will contain a single character. If it contains
0 characters, we'll use 0 as the unicode. If it
contains multiple characters, we'll use 0 as
the scancode/keysym.
Oct 5, 2002
Oct 5, 2002
222
*/
Jun 1, 2002
Jun 1, 2002
223
chars = [ event characters ];
Dec 15, 2002
Dec 15, 2002
224
225
226
numChars = [ chars length ];
if (numChars == 1) {
Jun 1, 2002
Jun 1, 2002
227
228
key.scancode = [ event keyCode ];
Dec 15, 2002
Dec 15, 2002
229
230
231
key.sym = keymap [ key.scancode ];
key.unicode = [ chars characterAtIndex:0 ];
key.mod = KMOD_NONE;
Jun 1, 2002
Jun 1, 2002
232
233
234
SDL_PrivateKeyboard (state, &key);
}
Dec 15, 2002
Dec 15, 2002
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
else if (numChars == 0) {
key.scancode = [ event keyCode ];
key.sym = keymap [ key.scancode ];
key.unicode = 0;
key.mod = KMOD_NONE;
SDL_PrivateKeyboard (state, &key);
}
else /* (numChars > 1) */ {
int i;
for (i = 0; i < numChars; i++) {
key.scancode = 0;
key.sym = 0;
key.unicode = [ chars characterAtIndex:i];
key.mod = KMOD_NONE;
SDL_PrivateKeyboard (state, &key);
}
}
Aug 10, 2003
Aug 10, 2003
257
258
259
if (getenv ("SDL_ENABLEAPPEVENTS"))
[ NSApp sendEvent:event ];
Oct 5, 2002
Oct 5, 2002
262
static void QZ_DoModifiers (_THIS, unsigned int newMods) {
Aug 4, 2003
Aug 4, 2003
264
const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA };
Jun 1, 2002
Jun 1, 2002
265
266
267
268
269
int i;
int bit;
SDL_keysym key;
Aug 4, 2003
Aug 4, 2003
270
key.scancode = 0;
Jun 1, 2002
Jun 1, 2002
271
272
273
274
275
276
277
278
279
key.sym = SDLK_UNKNOWN;
key.unicode = 0;
key.mod = KMOD_NONE;
/* Iterate through the bits, testing each against the current modifiers */
for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
unsigned int currentMask, newMask;
Oct 5, 2002
Oct 5, 2002
280
281
currentMask = current_mods & bit;
newMask = newMods & bit;
Jun 1, 2002
Jun 1, 2002
282
283
284
285
286
287
288
if ( currentMask &&
currentMask != newMask ) { /* modifier up event */
key.sym = mapping[i];
/* If this was Caps Lock, we need some additional voodoo to make SDL happy */
if (bit == NSAlphaShiftKeyMask)
Jan 4, 2004
Jan 4, 2004
289
SDL_PrivateKeyboard (SDL_PRESSED, &key);
Jun 1, 2002
Jun 1, 2002
290
291
292
293
294
295
296
297
298
299
300
301
302
SDL_PrivateKeyboard (SDL_RELEASED, &key);
}
else if ( newMask &&
currentMask != newMask ) { /* modifier down event */
key.sym = mapping[i];
SDL_PrivateKeyboard (SDL_PRESSED, &key);
/* If this was Caps Lock, we need some additional voodoo to make SDL happy */
if (bit == NSAlphaShiftKeyMask)
SDL_PrivateKeyboard (SDL_RELEASED, &key);
}
}
Oct 5, 2002
Oct 5, 2002
303
current_mods = newMods;
Jul 22, 2001
Jul 22, 2001
306
307
static void QZ_DoActivate (_THIS)
{
Apr 20, 2003
Apr 20, 2003
308
/* Hide the cursor if it was hidden by SDL_ShowCursor() */
Jan 4, 2004
Jan 4, 2004
309
310
if (!cursor_should_be_visible)
QZ_HideMouse (this);
Jun 1, 2002
Jun 1, 2002
311
Dec 27, 2002
Dec 27, 2002
312
313
314
315
316
317
/* Regrab input, only if it was previously grabbed */
if ( current_grab_mode == SDL_GRAB_ON ) {
/* Restore cursor location if input was grabbed */
QZ_PrivateWarpCursor (this, cursor_loc.x, cursor_loc.y);
QZ_ChangeGrabState (this, QZ_ENABLE_GRAB);
Jun 1, 2002
Jun 1, 2002
318
}
319
320
321
}
static void QZ_DoDeactivate (_THIS) {
Jun 1, 2002
Jun 1, 2002
322
Dec 27, 2002
Dec 27, 2002
323
324
325
326
327
328
329
330
/* Get the current cursor location, for restore on activate */
cursor_loc = [ NSEvent mouseLocation ]; /* global coordinates */
if (qz_window)
QZ_PrivateGlobalToLocal (this, &cursor_loc);
QZ_PrivateCocoaToSDL (this, &cursor_loc);
/* Reassociate mouse and cursor */
CGAssociateMouseAndMouseCursorPosition (1);
Jun 1, 2002
Jun 1, 2002
331
Apr 20, 2003
Apr 20, 2003
332
/* Show the cursor if it was hidden by SDL_ShowCursor() */
Jan 4, 2004
Jan 4, 2004
333
334
if (!cursor_should_be_visible)
QZ_ShowMouse (this);
Dec 7, 2002
Dec 7, 2002
337
338
339
340
341
342
343
344
345
346
void QZ_SleepNotificationHandler (void * refcon,
io_service_t service,
natural_t messageType,
void * messageArgument )
{
SDL_VideoDevice *this = (SDL_VideoDevice*)refcon;
switch(messageType)
{
case kIOMessageSystemWillSleep:
Dec 27, 2002
Dec 27, 2002
347
IOAllowPowerChange(power_connection, (long) messageArgument);
Dec 7, 2002
Dec 7, 2002
348
349
break;
case kIOMessageCanSystemSleep:
Dec 27, 2002
Dec 27, 2002
350
IOAllowPowerChange(power_connection, (long) messageArgument);
Dec 7, 2002
Dec 7, 2002
351
352
break;
case kIOMessageSystemHasPoweredOn:
Jan 4, 2004
Jan 4, 2004
353
/* awake */
Dec 7, 2002
Dec 7, 2002
354
355
356
357
358
SDL_PrivateExpose();
break;
}
}
Jan 4, 2004
Jan 4, 2004
359
void QZ_RegisterForSleepNotifications (_THIS)
Dec 7, 2002
Dec 7, 2002
360
361
362
363
364
{
CFRunLoopSourceRef rls;
IONotificationPortRef thePortRef;
io_object_t notifier;
Dec 27, 2002
Dec 27, 2002
365
power_connection = IORegisterForSystemPower (this, &thePortRef, QZ_SleepNotificationHandler, &notifier);
Dec 7, 2002
Dec 7, 2002
366
Dec 27, 2002
Dec 27, 2002
367
if (power_connection == 0)
Dec 7, 2002
Dec 7, 2002
368
369
370
371
372
373
374
NSLog(@"SDL: QZ_SleepNotificationHandler() IORegisterForSystemPower failed.");
rls = IONotificationPortGetRunLoopSource (thePortRef);
CFRunLoopAddSource (CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
CFRelease (rls);
}
May 27, 2003
May 27, 2003
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// Try to map Quartz mouse buttons to SDL's lingo...
static int QZ_OtherMouseButtonToSDL(int button)
{
switch (button)
{
case 0:
return(SDL_BUTTON_LEFT); // 1
case 1:
return(SDL_BUTTON_RIGHT); // 3
case 2:
return(SDL_BUTTON_MIDDLE); // 2
}
// >= 3: skip 4 & 5, since those are the SDL mousewheel buttons.
return(button + 3);
}
Jan 4, 2004
Jan 4, 2004
394
void QZ_PumpEvents (_THIS)
Aug 21, 2001
Aug 21, 2001
395
{
Aug 12, 2002
Aug 12, 2002
396
int firstMouseEvent;
Jun 1, 2002
Jun 1, 2002
397
398
399
400
401
402
403
CGMouseDelta dx, dy;
NSDate *distantPast;
NSEvent *event;
NSRect winRect;
NSAutoreleasePool *pool;
May 22, 2003
May 22, 2003
404
405
406
407
408
409
410
411
412
/* Update activity every five seconds to prevent screensaver. --ryan. */
static Uint32 screensaverTicks = 0;
Uint32 nowTicks = SDL_GetTicks();
if ((nowTicks - screensaverTicks) > 5000)
{
UpdateSystemActivity(UsrActivity);
screensaverTicks = nowTicks;
}
Jun 1, 2002
Jun 1, 2002
413
414
415
416
pool = [ [ NSAutoreleasePool alloc ] init ];
distantPast = [ NSDate distantPast ];
winRect = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
Aug 12, 2002
Aug 12, 2002
417
418
419
420
421
/* send the first mouse event in absolute coordinates */
firstMouseEvent = 1;
/* accumulate any additional mouse moved events into one SDL mouse event */
Jun 1, 2002
Jun 1, 2002
422
423
424
425
426
427
428
429
430
431
432
dx = 0;
dy = 0;
do {
/* Poll for an event. This will not block */
event = [ NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:distantPast
inMode: NSDefaultRunLoopMode dequeue:YES ];
if (event != nil) {
May 27, 2003
May 27, 2003
433
int button;
Jun 1, 2002
Jun 1, 2002
434
435
unsigned int type;
BOOL isForGameWin;
Dec 27, 2002
Dec 27, 2002
436
437
438
BOOL isInGameWin;
#define DO_MOUSE_DOWN(button) do { \
Jan 4, 2004
Jan 4, 2004
439
if ( [ NSApp isActive ] ) { \
Dec 27, 2002
Dec 27, 2002
440
441
442
443
if ( isInGameWin ) { \
SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \
expect_mouse_up |= 1<<button; \
} \
Jun 1, 2002
Jun 1, 2002
444
445
446
447
448
449
450
} \
else { \
QZ_DoActivate (this); \
} \
[ NSApp sendEvent:event ]; \
} while(0)
Dec 27, 2002
Dec 27, 2002
451
452
453
454
455
456
#define DO_MOUSE_UP(button) do { \
if ( expect_mouse_up & (1<<button) ) { \
SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); \
expect_mouse_up &= ~(1<<button); \
} \
[ NSApp sendEvent:event ]; \
Jun 1, 2002
Jun 1, 2002
457
} while(0)
Jan 22, 2002
Jan 22, 2002
458
Jun 1, 2002
Jun 1, 2002
459
460
type = [ event type ];
isForGameWin = (qz_window == [ event window ]);
Jan 7, 2004
Jan 7, 2004
461
isInGameWin = QZ_IsMouseInWindow (this);
Jun 1, 2002
Jun 1, 2002
462
463
switch (type) {
case NSLeftMouseDown:
Oct 5, 2002
Oct 5, 2002
464
if ( getenv("SDL_HAS3BUTTONMOUSE") ) {
Dec 27, 2002
Dec 27, 2002
465
DO_MOUSE_DOWN (SDL_BUTTON_LEFT);
Oct 5, 2002
Oct 5, 2002
466
467
} else {
if ( NSCommandKeyMask & current_mods ) {
Dec 27, 2002
Dec 27, 2002
468
469
last_virtual_button = SDL_BUTTON_RIGHT;
DO_MOUSE_DOWN (SDL_BUTTON_RIGHT);
Oct 5, 2002
Oct 5, 2002
470
471
}
else if ( NSAlternateKeyMask & current_mods ) {
Dec 27, 2002
Dec 27, 2002
472
473
last_virtual_button = SDL_BUTTON_MIDDLE;
DO_MOUSE_DOWN (SDL_BUTTON_MIDDLE);
Oct 5, 2002
Oct 5, 2002
474
475
}
else {
Dec 27, 2002
Dec 27, 2002
476
DO_MOUSE_DOWN (SDL_BUTTON_LEFT);
Oct 5, 2002
Oct 5, 2002
477
}
Jun 1, 2002
Jun 1, 2002
478
479
}
break;
May 27, 2003
May 27, 2003
480
Jun 1, 2002
Jun 1, 2002
481
482
case NSLeftMouseUp:
if ( last_virtual_button != 0 ) {
Dec 27, 2002
Dec 27, 2002
483
DO_MOUSE_UP (last_virtual_button);
Jun 1, 2002
Jun 1, 2002
484
485
486
last_virtual_button = 0;
}
else {
Dec 27, 2002
Dec 27, 2002
487
DO_MOUSE_UP (SDL_BUTTON_LEFT);
Jun 1, 2002
Jun 1, 2002
488
489
}
break;
May 27, 2003
May 27, 2003
490
491
492
493
494
495
496
497
498
499
500
501
502
case NSOtherMouseDown:
case NSRightMouseDown:
button = QZ_OtherMouseButtonToSDL([ event buttonNumber ]);
DO_MOUSE_DOWN (button);
break;
case NSOtherMouseUp:
case NSRightMouseUp:
button = QZ_OtherMouseButtonToSDL([ event buttonNumber ]);
DO_MOUSE_UP (button);
break;
Jun 1, 2002
Jun 1, 2002
503
case NSSystemDefined:
Oct 5, 2002
Oct 5, 2002
504
505
506
507
508
509
/*
Future: up to 32 "mouse" buttons can be handled.
if ([event subtype] == 7) {
unsigned int buttons;
buttons = [ event data2 ];
*/
Jun 1, 2002
Jun 1, 2002
510
511
512
break;
case NSLeftMouseDragged:
case NSRightMouseDragged:
Aug 12, 2002
Aug 12, 2002
513
case NSOtherMouseDragged: /* usually middle mouse dragged */
Jun 1, 2002
Jun 1, 2002
514
case NSMouseMoved:
Dec 27, 2002
Dec 27, 2002
515
if ( grab_state == QZ_INVISIBLE_GRAB ) {
Jun 1, 2002
Jun 1, 2002
516
Oct 5, 2002
Oct 5, 2002
517
/*
Dec 27, 2002
Dec 27, 2002
518
If input is grabbed+hidden, the cursor doesn't move,
Oct 5, 2002
Oct 5, 2002
519
520
521
so we have to call the lowlevel window server
function. This is less accurate but works OK.
*/
Jun 1, 2002
Jun 1, 2002
522
523
524
525
526
CGMouseDelta dx1, dy1;
CGGetLastMouseDelta (&dx1, &dy1);
dx += dx1;
dy += dy1;
}
Aug 12, 2002
Aug 12, 2002
527
528
else if (firstMouseEvent) {
Oct 5, 2002
Oct 5, 2002
529
530
531
532
533
534
535
536
/*
Get the first mouse event in a possible
sequence of mouse moved events. Since we
use absolute coordinates, this serves to
compensate any inaccuracy in deltas, and
provides the first known mouse position,
since everything after this uses deltas
*/
Jan 7, 2004
Jan 7, 2004
537
NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ];
Dec 27, 2002
Dec 27, 2002
538
QZ_PrivateCocoaToSDL (this, &p);
Aug 20, 2002
Aug 20, 2002
539
SDL_PrivateMouseMotion (0, 0, p.x, p.y);
Aug 12, 2002
Aug 12, 2002
540
541
542
543
firstMouseEvent = 0;
}
else {
Oct 5, 2002
Oct 5, 2002
544
545
546
547
548
549
/*
Get the amount moved since the last drag or move event,
add it on for one big move event at the end.
*/
dx += [ event deltaX ];
dy += [ event deltaY ];
Aug 12, 2002
Aug 12, 2002
550
}
Dec 27, 2002
Dec 27, 2002
551
552
553
554
555
556
557
558
559
/*
Handle grab input+cursor visible by warping the cursor back
into the game window. This still generates a mouse moved event,
but not as a result of the warp (so it's in the right direction).
*/
if ( grab_state == QZ_VISIBLE_GRAB &&
!isInGameWin ) {
Jan 7, 2004
Jan 7, 2004
560
NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ];
Dec 27, 2002
Dec 27, 2002
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
QZ_PrivateCocoaToSDL (this, &p);
if ( p.x < 0.0 )
p.x = 0.0;
if ( p.y < 0.0 )
p.y = 0.0;
if ( p.x >= winRect.size.width )
p.x = winRect.size.width-1;
if ( p.y >= winRect.size.height )
p.y = winRect.size.height-1;
QZ_PrivateWarpCursor (this, p.x, p.y);
}
May 29, 2003
May 29, 2003
577
578
579
580
else
if ( !isInGameWin && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
Jan 7, 2004
Jan 7, 2004
581
582
if (!cursor_should_be_visible)
QZ_ShowMouse (this);
May 29, 2003
May 29, 2003
583
584
585
586
587
}
else
if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
Jan 7, 2004
Jan 7, 2004
588
589
if (!cursor_should_be_visible)
QZ_HideMouse (this);
May 29, 2003
May 29, 2003
590
}
Jun 1, 2002
Jun 1, 2002
591
592
break;
case NSScrollWheel:
Dec 27, 2002
Dec 27, 2002
593
if ( isInGameWin ) {
Jun 1, 2002
Jun 1, 2002
594
float dy;
Oct 5, 2002
Oct 5, 2002
595
Uint8 button;
Jun 1, 2002
Jun 1, 2002
596
597
dy = [ event deltaY ];
if ( dy > 0.0 ) /* Scroll up */
Oct 5, 2002
Oct 5, 2002
598
button = SDL_BUTTON_WHEELUP;
Jun 1, 2002
Jun 1, 2002
599
else /* Scroll down */
Oct 5, 2002
Oct 5, 2002
600
button = SDL_BUTTON_WHEELDOWN;
Dec 27, 2002
Dec 27, 2002
601
/* For now, wheel is sent as a quick down+up */
Oct 5, 2002
Oct 5, 2002
602
603
SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);
SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0);
Jun 1, 2002
Jun 1, 2002
604
605
606
}
break;
case NSKeyUp:
Oct 5, 2002
Oct 5, 2002
607
QZ_DoKey (this, SDL_RELEASED, event);
Jun 1, 2002
Jun 1, 2002
608
609
break;
case NSKeyDown:
Oct 5, 2002
Oct 5, 2002
610
QZ_DoKey (this, SDL_PRESSED, event);
Jun 1, 2002
Jun 1, 2002
611
612
break;
case NSFlagsChanged:
Oct 5, 2002
Oct 5, 2002
613
QZ_DoModifiers(this, [ event modifierFlags ] );
Jun 1, 2002
Jun 1, 2002
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
break;
case NSAppKitDefined:
switch ( [ event subtype ] ) {
case NSApplicationActivatedEventType:
QZ_DoActivate (this);
break;
case NSApplicationDeactivatedEventType:
QZ_DoDeactivate (this);
break;
}
[ NSApp sendEvent:event ];
break;
/* case NSApplicationDefined: break; */
/* case NSPeriodic: break; */
/* case NSCursorUpdate: break; */
default:
[ NSApp sendEvent:event ];
Jan 22, 2002
Jan 22, 2002
631
632
}
}
Jun 1, 2002
Jun 1, 2002
633
634
} while (event != nil);
Aug 12, 2002
Aug 12, 2002
635
/* handle accumulated mouse moved events */
Jun 1, 2002
Jun 1, 2002
636
if (dx != 0 || dy != 0)
Aug 12, 2002
Aug 12, 2002
637
SDL_PrivateMouseMotion (0, 1, dx, dy);
Jun 1, 2002
Jun 1, 2002
638
639
[ pool release ];
Oct 5, 2002
Oct 5, 2002
640
}