Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
492 lines (403 loc) · 13.5 KB

SDL_QuartzWM.m

File metadata and controls

492 lines (403 loc) · 13.5 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 4, 2004
Jan 4, 2004
3
Copyright (C) 1997-2003 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.
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.
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
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Jan 4, 2004
Jan 4, 2004
24
25
#include "SDL_QuartzVideo.h"
Dec 27, 2002
Dec 27, 2002
26
May 28, 2006
May 28, 2006
27
28
struct WMcursor
{
Jun 24, 2006
Jun 24, 2006
29
NSCursor *nscursor;
May 28, 2006
May 28, 2006
32
void
Jun 24, 2006
Jun 24, 2006
33
QZ_FreeWMCursor(_THIS, WMcursor * cursor)
May 28, 2006
May 28, 2006
34
{
Jun 24, 2006
Jun 24, 2006
36
37
38
39
if (cursor != NULL) {
[cursor->nscursor release];
free(cursor);
}
May 28, 2006
May 28, 2006
42
WMcursor *
Jun 24, 2006
Jun 24, 2006
43
44
QZ_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
int w, int h, int hot_x, int hot_y)
May 28, 2006
May 28, 2006
45
{
Jun 1, 2002
Jun 1, 2002
46
WMcursor *cursor;
Jun 24, 2006
Jun 24, 2006
47
48
49
50
51
NSBitmapImageRep *imgrep;
NSImage *img;
unsigned char *planes[5];
int i;
NSAutoreleasePool *pool;
May 28, 2006
May 28, 2006
52
Jun 24, 2006
Jun 24, 2006
53
pool =[[NSAutoreleasePool alloc] init];
May 28, 2006
May 28, 2006
54
Jun 24, 2006
Jun 24, 2006
55
56
57
58
/* Allocate the cursor memory */
cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
if (cursor == NULL)
goto outOfMemory;
Jun 1, 2002
Jun 1, 2002
59
Jun 24, 2006
Jun 24, 2006
60
61
62
63
64
/* create the image representation and get the pointers to its storage */
imgrep =[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: w pixelsHigh: h bitsPerSample: 1 samplesPerPixel: 2 hasAlpha: YES isPlanar: YES colorSpaceName: NSDeviceBlackColorSpace bytesPerRow: (w + 7) / 8 bitsPerPixel:0] autorelease];
if (imgrep == nil)
goto outOfMemory;
[imgrep getBitmapDataPlanes:planes];
May 28, 2006
May 28, 2006
65
Jun 24, 2006
Jun 24, 2006
66
67
68
69
/* copy data and mask, extending the mask to all black pixels because the inversion effect doesn't work with Cocoa's alpha-blended cursors */
for (i = 0; i < (w + 7) / 8 * h; i++) {
planes[0][i] = data[i];
planes[1][i] = mask[i] | data[i];
Jun 1, 2002
Jun 1, 2002
70
}
Jun 24, 2006
Jun 24, 2006
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* create image and cursor */
img =[[[NSImage alloc] initWithSize:NSMakeSize(w, h)] autorelease];
if (img == nil)
goto outOfMemory;
[img addRepresentation:imgrep];
if (system_version < 0x1030) { /* on 10.2, cursors must be 16*16 */
if (w > 16 || h > 16) { /* too big: scale it down */
[img setScalesWhenResized:YES];
hot_x = hot_x * 16 / w;
hot_y = hot_y * 16 / h;
} else { /* too small (or just right): extend it (from the bottom left corner, so hot_y must be adjusted) */
hot_y += 16 - h;
}
[img setSize:NSMakeSize(16, 16)];
Jun 1, 2002
Jun 1, 2002
86
}
Jun 24, 2006
Jun 24, 2006
87
88
89
90
cursor->nscursor =[[NSCursor alloc] initWithImage: img hotSpot:NSMakePoint(hot_x,
hot_y)];
if (cursor->nscursor == nil)
goto outOfMemory;
May 28, 2006
May 28, 2006
91
Jun 24, 2006
Jun 24, 2006
92
[pool release];
May 28, 2006
May 28, 2006
93
return (cursor);
Jun 24, 2006
Jun 24, 2006
94
95
96
97
98
99
100
outOfMemory:
[pool release];
if (cursor != NULL)
SDL_free(cursor);
SDL_OutOfMemory();
return (NULL);
May 28, 2006
May 28, 2006
103
void
Jun 24, 2006
Jun 24, 2006
104
QZ_ShowMouse(_THIS)
May 28, 2006
May 28, 2006
105
{
Jan 4, 2004
Jan 4, 2004
106
if (!cursor_visible) {
May 28, 2006
May 28, 2006
107
[NSCursor unhide];
Jan 4, 2004
Jan 4, 2004
108
109
110
111
cursor_visible = YES;
}
}
May 28, 2006
May 28, 2006
112
void
Jun 24, 2006
Jun 24, 2006
113
QZ_HideMouse(_THIS)
May 28, 2006
May 28, 2006
114
{
Jun 24, 2006
Jun 24, 2006
115
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) {
May 28, 2006
May 28, 2006
116
[NSCursor hide];
Jan 4, 2004
Jan 4, 2004
117
118
119
120
cursor_visible = NO;
}
}
May 28, 2006
May 28, 2006
121
BOOL
Jun 24, 2006
Jun 24, 2006
122
QZ_IsMouseInWindow(_THIS)
May 28, 2006
May 28, 2006
123
124
125
{
if (qz_window == nil)
return YES; /*fullscreen */
Nov 28, 2005
Nov 28, 2005
126
else {
May 28, 2006
May 28, 2006
127
128
NSPoint p =[qz_window mouseLocationOutsideOfEventStream];
p.y -= 1.0f; /* Apparently y goes from 1 to h, not from 0 to h-1 (i.e. the "location of the mouse" seems to be defined as "the location of the top left corner of the mouse pointer's hot pixel" */
Jun 24, 2006
Jun 24, 2006
129
return NSPointInRect(p,[window_view frame]);
Nov 28, 2005
Nov 28, 2005
130
}
Jan 7, 2004
Jan 7, 2004
131
132
}
May 28, 2006
May 28, 2006
133
int
Jun 24, 2006
Jun 24, 2006
134
QZ_ShowWMCursor(_THIS, WMcursor * cursor)
May 28, 2006
May 28, 2006
135
{
May 28, 2006
May 28, 2006
137
138
if (cursor == NULL) {
if (cursor_should_be_visible) {
Jun 24, 2006
Jun 24, 2006
139
QZ_HideMouse(this);
Jan 4, 2004
Jan 4, 2004
140
cursor_should_be_visible = NO;
Jun 24, 2006
Jun 24, 2006
141
QZ_ChangeGrabState(this, QZ_HIDECURSOR);
May 28, 2006
May 28, 2006
143
} else {
Jun 24, 2006
Jun 24, 2006
144
[cursor->nscursor set];
May 28, 2006
May 28, 2006
145
if (!cursor_should_be_visible) {
Jun 24, 2006
Jun 24, 2006
146
QZ_ShowMouse(this);
Jan 4, 2004
Jan 4, 2004
147
cursor_should_be_visible = YES;
Jun 24, 2006
Jun 24, 2006
148
QZ_ChangeGrabState(this, QZ_SHOWCURSOR);
149
150
151
152
153
154
}
}
return 1;
}
Oct 5, 2002
Oct 5, 2002
155
156
157
158
159
160
161
/*
Coordinate conversion functions, for convenience
Cocoa sets the origin at the lower left corner of the window/screen
SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
The routines were written so they could be called before SetVideoMode() has finished;
this might have limited usefulness at the moment, but the extra cost is trivial.
*/
Jan 22, 2002
Jan 22, 2002
163
/* Convert Cocoa screen coordinate to Cocoa window coordinate */
May 28, 2006
May 28, 2006
164
void
Jun 24, 2006
Jun 24, 2006
165
QZ_PrivateGlobalToLocal(_THIS, NSPoint * p)
May 28, 2006
May 28, 2006
166
{
Jan 22, 2002
Jan 22, 2002
167
May 28, 2006
May 28, 2006
168
*p =[qz_window convertScreenToBase:*p];
Jan 22, 2002
Jan 22, 2002
169
170
171
172
}
/* Convert Cocoa window coordinate to Cocoa screen coordinate */
May 28, 2006
May 28, 2006
173
void
Jun 24, 2006
Jun 24, 2006
174
QZ_PrivateLocalToGlobal(_THIS, NSPoint * p)
May 28, 2006
May 28, 2006
175
{
Jan 22, 2002
Jan 22, 2002
176
May 28, 2006
May 28, 2006
177
*p =[qz_window convertBaseToScreen:*p];
Jan 22, 2002
Jan 22, 2002
178
179
180
}
/* Convert SDL coordinate to Cocoa coordinate */
May 28, 2006
May 28, 2006
181
void
Jun 24, 2006
Jun 24, 2006
182
QZ_PrivateSDLToCocoa(_THIS, NSPoint * p)
May 28, 2006
May 28, 2006
183
184
{
Jun 24, 2006
Jun 24, 2006
185
if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
Jan 22, 2002
Jan 22, 2002
186
Jun 24, 2006
Jun 24, 2006
187
p->y = CGDisplayPixelsHigh(display_id) - p->y;
May 28, 2006
May 28, 2006
188
189
190
191
} else {
*p =[window_view convertPoint: *p toView:nil];
Nov 28, 2005
Nov 28, 2005
192
/* We need a workaround in OpenGL mode */
Jun 24, 2006
Jun 24, 2006
193
if (SDL_VideoSurface->flags & SDL_OPENGL) {
May 28, 2006
May 28, 2006
194
p->y =[window_view frame].size.height - p->y;
Nov 28, 2005
Nov 28, 2005
195
}
Jan 22, 2002
Jan 22, 2002
199
/* Convert Cocoa coordinate to SDL coordinate */
May 28, 2006
May 28, 2006
200
void
Jun 24, 2006
Jun 24, 2006
201
QZ_PrivateCocoaToSDL(_THIS, NSPoint * p)
May 28, 2006
May 28, 2006
202
203
{
Jun 24, 2006
Jun 24, 2006
204
if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
Jan 22, 2002
Jan 22, 2002
205
Jun 24, 2006
Jun 24, 2006
206
p->y = CGDisplayPixelsHigh(display_id) - p->y;
May 28, 2006
May 28, 2006
207
208
209
} else {
*p =[window_view convertPoint: *p fromView:nil];
Mar 22, 2004
Mar 22, 2004
210
Nov 21, 2004
Nov 21, 2004
211
/* We need a workaround in OpenGL mode */
May 28, 2006
May 28, 2006
212
if (SDL_VideoSurface != NULL
Jun 24, 2006
Jun 24, 2006
213
&& (SDL_VideoSurface->flags & SDL_OPENGL)) {
May 28, 2006
May 28, 2006
214
p->y =[window_view frame].size.height - p->y;
Aug 31, 2004
Aug 31, 2004
215
}
Aug 10, 2003
Aug 10, 2003
216
}
Jan 22, 2002
Jan 22, 2002
217
218
219
}
/* Convert SDL coordinate to window server (CoreGraphics) coordinate */
May 28, 2006
May 28, 2006
220
CGPoint
Jun 24, 2006
Jun 24, 2006
221
QZ_PrivateSDLToCG(_THIS, NSPoint * p)
May 28, 2006
May 28, 2006
222
223
{
Jan 22, 2002
Jan 22, 2002
224
CGPoint cgp;
May 28, 2006
May 28, 2006
225
Jun 24, 2006
Jun 24, 2006
226
if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
May 28, 2006
May 28, 2006
227
Jan 22, 2002
Jan 22, 2002
228
int height;
May 28, 2006
May 28, 2006
229
Jun 24, 2006
Jun 24, 2006
230
231
QZ_PrivateSDLToCocoa(this, p);
QZ_PrivateLocalToGlobal(this, p);
May 28, 2006
May 28, 2006
232
Jun 24, 2006
Jun 24, 2006
233
height = CGDisplayPixelsHigh(display_id);
Jan 22, 2002
Jan 22, 2002
234
235
p->y = height - p->y;
}
May 28, 2006
May 28, 2006
236
Jan 22, 2002
Jan 22, 2002
237
238
cgp.x = p->x;
cgp.y = p->y;
May 28, 2006
May 28, 2006
239
Jan 22, 2002
Jan 22, 2002
240
241
242
return cgp;
}
May 28, 2006
May 28, 2006
243
#if 0 /* Dead code */
Jan 22, 2002
Jan 22, 2002
244
/* Convert window server (CoreGraphics) coordinate to SDL coordinate */
May 28, 2006
May 28, 2006
245
void
Jun 24, 2006
Jun 24, 2006
246
QZ_PrivateCGToSDL(_THIS, NSPoint * p)
May 28, 2006
May 28, 2006
247
248
{
Jun 24, 2006
Jun 24, 2006
249
if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
May 28, 2006
May 28, 2006
250
Jan 22, 2002
Jan 22, 2002
251
252
253
int height;
/* Convert CG Global to Cocoa Global */
Jun 24, 2006
Jun 24, 2006
254
height = CGDisplayPixelsHigh(display_id);
Jan 22, 2002
Jan 22, 2002
255
256
p->y = height - p->y;
Jun 24, 2006
Jun 24, 2006
257
258
QZ_PrivateGlobalToLocal(this, p);
QZ_PrivateCocoaToSDL(this, p);
Jan 22, 2002
Jan 22, 2002
259
260
}
}
Aug 10, 2003
Aug 10, 2003
261
#endif /* Dead code */
Jan 22, 2002
Jan 22, 2002
262
May 28, 2006
May 28, 2006
263
void
Jun 24, 2006
Jun 24, 2006
264
QZ_PrivateWarpCursor(_THIS, int x, int y)
May 28, 2006
May 28, 2006
265
266
{
Jan 22, 2002
Jan 22, 2002
267
268
NSPoint p;
CGPoint cgp;
May 28, 2006
May 28, 2006
269
Jun 24, 2006
Jun 24, 2006
270
271
p = NSMakePoint(x, y);
cgp = QZ_PrivateSDLToCG(this, &p);
May 28, 2006
May 28, 2006
272
Dec 27, 2002
Dec 27, 2002
273
/* this is the magic call that fixes cursor "freezing" after warp */
Jun 24, 2006
Jun 24, 2006
274
275
CGSetLocalEventsSuppressionInterval(0.0);
CGWarpMouseCursorPosition(cgp);
Jan 22, 2002
Jan 22, 2002
276
277
}
May 28, 2006
May 28, 2006
278
void
Jun 24, 2006
Jun 24, 2006
279
QZ_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
May 28, 2006
May 28, 2006
280
{
Jan 22, 2002
Jan 22, 2002
281
282
/* Only allow warping when in foreground */
May 28, 2006
May 28, 2006
283
if (![NSApp isActive])
May 28, 2006
May 28, 2006
285
286
/* Do the actual warp */
May 28, 2006
May 28, 2006
287
if (grab_state != QZ_INVISIBLE_GRAB)
Jun 24, 2006
Jun 24, 2006
288
QZ_PrivateWarpCursor(this, x, y);
Dec 27, 2002
Dec 27, 2002
289
290
/* Generate the mouse moved event */
Jun 24, 2006
Jun 24, 2006
291
SDL_PrivateMouseMotion(0, 0, x, y);
May 28, 2006
May 28, 2006
294
void
Jun 24, 2006
Jun 24, 2006
295
QZ_MoveWMCursor(_THIS, int x, int y)
May 28, 2006
May 28, 2006
296
297
298
{
}
void
Jun 24, 2006
Jun 24, 2006
299
QZ_CheckMouseMode(_THIS)
May 28, 2006
May 28, 2006
300
301
{
}
May 28, 2006
May 28, 2006
303
void
Jun 24, 2006
Jun 24, 2006
304
QZ_SetCaption(_THIS, const char *title, const char *icon)
May 28, 2006
May 28, 2006
305
{
May 28, 2006
May 28, 2006
307
if (qz_window != nil) {
Jun 11, 2001
Jun 11, 2001
308
NSString *string;
May 28, 2006
May 28, 2006
309
310
311
312
if (title != NULL) {
string =[[NSString alloc] initWithUTF8String:title];
[qz_window setTitle:string];
[string release];
Jun 11, 2001
Jun 11, 2001
313
}
May 28, 2006
May 28, 2006
314
315
316
317
if (icon != NULL) {
string =[[NSString alloc] initWithUTF8String:icon];
[qz_window setMiniwindowTitle:string];
[string release];
Jun 11, 2001
Jun 11, 2001
318
319
}
}
May 28, 2006
May 28, 2006
322
void
Jun 24, 2006
Jun 24, 2006
323
QZ_SetIcon(_THIS, SDL_Surface * icon, Uint8 * mask)
Jan 18, 2002
Jan 18, 2002
324
{
Oct 5, 2002
Oct 5, 2002
325
326
327
328
NSBitmapImageRep *imgrep;
NSImage *img;
SDL_Surface *mergedSurface;
NSAutoreleasePool *pool;
May 17, 2006
May 17, 2006
329
330
331
332
Uint8 *pixels;
SDL_bool iconSrcAlpha;
Uint8 iconAlphaValue;
int i, j, maskPitch, index;
May 28, 2006
May 28, 2006
333
334
335
336
337
338
339
pool =[[NSAutoreleasePool alloc] init];
imgrep =[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4 * icon->w bitsPerPixel:32] autorelease];
if (imgrep == nil)
goto freePool;
pixels =[imgrep bitmapData];
Jun 24, 2006
Jun 24, 2006
340
SDL_memset(pixels, 0, 4 * icon->w * icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
May 28, 2006
May 28, 2006
341
May 17, 2006
May 17, 2006
342
343
344
345
346
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
#else
#define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
#endif
May 28, 2006
May 28, 2006
347
mergedSurface =
Jun 24, 2006
Jun 24, 2006
348
349
SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4 * icon->w,
BYTEORDER_DEPENDENT_RGBA_MASKS);
May 28, 2006
May 28, 2006
350
351
352
if (mergedSurface == NULL)
goto freePool;
May 17, 2006
May 17, 2006
353
354
355
/* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
iconAlphaValue = icon->format->alpha;
Jun 24, 2006
Jun 24, 2006
356
357
SDL_SetAlpha(icon, 0, 255);
SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
May 28, 2006
May 28, 2006
358
if (iconSrcAlpha)
Jun 24, 2006
Jun 24, 2006
359
SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
May 28, 2006
May 28, 2006
360
Jun 24, 2006
Jun 24, 2006
361
SDL_FreeSurface(mergedSurface);
May 28, 2006
May 28, 2006
362
May 17, 2006
May 17, 2006
363
/* apply mask, source alpha, and premultiply color values by alpha */
May 28, 2006
May 28, 2006
364
maskPitch = (icon->w + 7) / 8;
May 17, 2006
May 17, 2006
365
366
for (i = 0; i < icon->h; i++) {
for (j = 0; j < icon->w; j++) {
May 28, 2006
May 28, 2006
367
368
index = i * 4 * icon->w + j * 4;
if (!(mask[i * maskPitch + j / 8] & (128 >> j % 8))) {
May 17, 2006
May 17, 2006
369
pixels[index + 3] = 0;
May 28, 2006
May 28, 2006
370
} else {
May 17, 2006
May 17, 2006
371
if (iconSrcAlpha) {
May 28, 2006
May 28, 2006
372
373
374
if (icon->format->Amask == 0)
pixels[index + 3] = icon->format->alpha;
} else {
May 17, 2006
May 17, 2006
375
376
377
378
pixels[index + 3] = 255;
}
}
if (pixels[index + 3] < 255) {
May 28, 2006
May 28, 2006
379
380
381
382
383
384
pixels[index + 0] =
(Uint16) pixels[index + 0] * pixels[index + 3] / 255;
pixels[index + 1] =
(Uint16) pixels[index + 1] * pixels[index + 3] / 255;
pixels[index + 2] =
(Uint16) pixels[index + 2] * pixels[index + 3] / 255;
Feb 1, 2003
Feb 1, 2003
385
386
}
}
Oct 5, 2002
Oct 5, 2002
387
}
May 28, 2006
May 28, 2006
388
Jun 24, 2006
Jun 24, 2006
389
390
img =[[[NSImage alloc] initWithSize:NSMakeSize(icon->w,
icon->h)] autorelease];
May 28, 2006
May 28, 2006
391
392
393
394
395
396
397
if (img == nil)
goto freePool;
[img addRepresentation:imgrep];
[NSApp setApplicationIconImage:img];
freePool:
[pool release];
May 28, 2006
May 28, 2006
400
int
Jun 24, 2006
Jun 24, 2006
401
QZ_IconifyWindow(_THIS)
May 28, 2006
May 28, 2006
402
{
May 28, 2006
May 28, 2006
404
405
if (![qz_window isMiniaturized]) {
[qz_window miniaturize:nil];
May 28, 2006
May 28, 2006
407
} else {
Jun 24, 2006
Jun 24, 2006
408
SDL_SetError("window already iconified");
409
410
411
412
413
return 0;
}
}
/*
Jan 4, 2004
Jan 4, 2004
414
int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) {
Aug 21, 2001
Aug 21, 2001
415
info->nsWindowPtr = qz_window;
416
417
418
return 0;
}*/
May 28, 2006
May 28, 2006
419
void
Jun 24, 2006
Jun 24, 2006
420
QZ_ChangeGrabState(_THIS, int action)
May 28, 2006
May 28, 2006
421
{
Dec 27, 2002
Dec 27, 2002
422
423
/*
May 28, 2006
May 28, 2006
424
425
426
427
428
429
Figure out what the next state should be based on the action.
Ignore actions that can't change the current state.
*/
if (grab_state == QZ_UNGRABBED) {
if (action == QZ_ENABLE_GRAB) {
if (cursor_should_be_visible)
Dec 27, 2002
Dec 27, 2002
430
431
432
433
grab_state = QZ_VISIBLE_GRAB;
else
grab_state = QZ_INVISIBLE_GRAB;
}
May 28, 2006
May 28, 2006
434
435
} else if (grab_state == QZ_VISIBLE_GRAB) {
if (action == QZ_DISABLE_GRAB)
Dec 27, 2002
Dec 27, 2002
436
grab_state = QZ_UNGRABBED;
May 28, 2006
May 28, 2006
437
else if (action == QZ_HIDECURSOR)
Dec 27, 2002
Dec 27, 2002
438
grab_state = QZ_INVISIBLE_GRAB;
May 28, 2006
May 28, 2006
439
} else {
Jun 24, 2006
Jun 24, 2006
440
assert(grab_state == QZ_INVISIBLE_GRAB);
May 28, 2006
May 28, 2006
441
442
if (action == QZ_DISABLE_GRAB)
Dec 27, 2002
Dec 27, 2002
443
grab_state = QZ_UNGRABBED;
May 28, 2006
May 28, 2006
444
else if (action == QZ_SHOWCURSOR)
Dec 27, 2002
Dec 27, 2002
445
446
grab_state = QZ_VISIBLE_GRAB;
}
May 28, 2006
May 28, 2006
447
Dec 27, 2002
Dec 27, 2002
448
449
/* now apply the new state */
if (grab_state == QZ_UNGRABBED) {
May 28, 2006
May 28, 2006
450
Jun 24, 2006
Jun 24, 2006
451
CGAssociateMouseAndMouseCursorPosition(1);
May 28, 2006
May 28, 2006
452
453
} else if (grab_state == QZ_VISIBLE_GRAB) {
Jun 24, 2006
Jun 24, 2006
454
CGAssociateMouseAndMouseCursorPosition(1);
May 28, 2006
May 28, 2006
455
} else {
Jun 24, 2006
Jun 24, 2006
456
assert(grab_state == QZ_INVISIBLE_GRAB);
Dec 27, 2002
Dec 27, 2002
457
Jun 24, 2006
Jun 24, 2006
458
459
460
QZ_PrivateWarpCursor(this, SDL_VideoSurface->w / 2,
SDL_VideoSurface->h / 2);
CGAssociateMouseAndMouseCursorPosition(0);
Dec 27, 2002
Dec 27, 2002
461
462
463
}
}
May 28, 2006
May 28, 2006
464
SDL_GrabMode
Jun 24, 2006
Jun 24, 2006
465
QZ_GrabInput(_THIS, SDL_GrabMode grab_mode)
May 28, 2006
May 28, 2006
466
{
Dec 27, 2002
Dec 27, 2002
468
int doGrab = grab_mode & SDL_GRAB_ON;
May 28, 2006
May 28, 2006
469
/*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN; */
Dec 27, 2002
Dec 27, 2002
470
May 28, 2006
May 28, 2006
471
if (this->screen == NULL) {
Jun 24, 2006
Jun 24, 2006
472
SDL_SetError("QZ_GrabInput: screen is NULL");
Dec 27, 2002
Dec 27, 2002
473
474
return SDL_GRAB_OFF;
}
May 28, 2006
May 28, 2006
475
476
if (!video_set) {
Dec 27, 2002
Dec 27, 2002
477
478
479
/*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */
current_grab_mode = grab_mode;
return grab_mode; /* Will be set later on mode switch */
Dec 27, 2002
Dec 27, 2002
481
May 28, 2006
May 28, 2006
482
483
if (grab_mode != SDL_GRAB_QUERY) {
if (doGrab)
Jun 24, 2006
Jun 24, 2006
484
QZ_ChangeGrabState(this, QZ_ENABLE_GRAB);
Dec 27, 2002
Dec 27, 2002
485
else
Jun 24, 2006
Jun 24, 2006
486
QZ_ChangeGrabState(this, QZ_DISABLE_GRAB);
May 28, 2006
May 28, 2006
487
Dec 27, 2002
Dec 27, 2002
488
489
490
current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF;
}
Oct 5, 2002
Oct 5, 2002
491
return current_grab_mode;