Mercurial > sdl-ios-xcode
annotate src/video/macrom/SDL_romvideo.c @ 3914:4fd12011d8d6 SDL-1.2
Quartz code should use F13, F14, and F15 keys instead of PrintScreen,
ScrollLock, and Pause, since that's what's on the standard Apple keyboards
(minus the laptops, which have neither set). Ideally we'll find a better way
to distinguish this...the keys being replaced would be correct on a USB
keyboard for Windows. Sigh.
Fixes Bugzilla #301.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 14 Feb 2007 10:23:23 +0000 |
parents | e6de7e5fd451 |
children | c121d94672cb 70dac8976f94 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
47
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
24 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
25 #include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
26 #if USE_QUICKTIME |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
27 #include <QuickTime/Movies.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
28 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
29 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 30 #include <Carbon.h> |
31 /* The fullscreen code requires the QuickTime framework, and the window | |
1621 | 32 is still at the back on Mac OS X, which is where this code is needed. |
0 | 33 */ |
34 #if USE_QUICKTIME | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
35 #include <Movies.h> |
0 | 36 #endif |
37 #else | |
1811 | 38 #include <Quickdraw.h> |
0 | 39 #include <LowMem.h> |
40 #include <Gestalt.h> | |
41 #include <Devices.h> | |
42 #include <DiskInit.h> | |
43 #include <QDOffscreen.h> | |
44 #endif | |
45 | |
46 #include "SDL_video.h" | |
47 #include "SDL_syswm.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
48 #include "../SDL_sysvideo.h" |
0 | 49 #include "SDL_romvideo.h" |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
50 #include "../maccommon/SDL_macgl_c.h" |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
51 #include "../maccommon/SDL_macwm_c.h" |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
52 #include "../maccommon/SDL_macmouse_c.h" |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
53 #include "../maccommon/SDL_macevents_c.h" |
0 | 54 |
55 /* Initialization/Query functions */ | |
56 static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
57 static SDL_Rect **ROM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
58 static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
59 static int ROM_SetColors(_THIS, int firstcolor, int ncolors, | |
60 SDL_Color *colors); | |
61 static void ROM_VideoQuit(_THIS); | |
62 | |
63 /* Hardware surface functions */ | |
64 static int ROM_AllocHWSurface(_THIS, SDL_Surface *surface); | |
65 static int ROM_LockHWSurface(_THIS, SDL_Surface *surface); | |
66 static void ROM_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
67 static void ROM_FreeHWSurface(_THIS, SDL_Surface *surface); | |
68 | |
69 #if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */ | |
70 /* Saved state for the menu bar */ | |
71 static RgnHandle gSaveGrayRgn = nil; | |
72 static short gSaveMenuBar = 0; | |
73 static Boolean gSaveCSVis = true; | |
74 | |
75 #if powerc | |
76 /* Mixed mode glue to activate the 68K emulator and twiddle a register */ | |
77 #define ONEWORDSTUB(p1) \ | |
78 { 0x41FA, 0x0010, 0x209F, (p1), 0x41FA, \ | |
79 0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 } | |
80 | |
81 #define TWOWORDSTUB(p1,p2) \ | |
82 { 0x41FA, 0x0012, 0x209F, (p1), (p2), 0x41FA, \ | |
83 0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 } | |
84 | |
85 #define THREEWORDSTUB(p1,p2,p3) \ | |
86 { 0x41FA, 0x0014, 0x209F, (p1), (p2), (p3), 0x41FA, \ | |
87 0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 } | |
88 | |
89 /* ControlStrip inline glue for PowerPC */ | |
90 static pascal Boolean SBIsControlStripVisible(void) | |
91 { | |
92 static short procData[] = TWOWORDSTUB(0x7000, 0xAAF2); | |
93 ProcInfoType procInfo = kD0DispatchedPascalStackBased | |
94 | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) | |
95 | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode); | |
96 | |
97 return((Boolean) CallUniversalProc((UniversalProcPtr) procData, procInfo, 0x00)); | |
98 } | |
99 | |
100 static pascal void SBShowHideControlStrip(Boolean showIt) | |
101 { | |
102 static short procData[] = THREEWORDSTUB(0x303C, 0x0101, 0xAAF2); | |
103 ProcInfoType procInfo = kD0DispatchedPascalStackBased | |
104 | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode) | |
105 | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Boolean))); | |
106 | |
107 CallUniversalProc((UniversalProcPtr) procData, procInfo, 0x01, showIt); | |
108 } | |
109 #endif /* powerc */ | |
110 #endif /* !TARGET_API_MAC_CARBON */ | |
111 | |
112 /* Macintosh toolbox driver bootstrap functions */ | |
113 | |
114 static int ROM_Available(void) | |
115 { | |
116 return(1); | |
117 } | |
118 | |
119 static void ROM_DeleteDevice(SDL_VideoDevice *device) | |
120 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
121 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
122 SDL_free(device); |
0 | 123 } |
124 | |
125 static SDL_VideoDevice *ROM_CreateDevice(int devindex) | |
126 { | |
127 SDL_VideoDevice *device; | |
128 | |
129 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
130 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
0 | 131 if ( device ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
132 SDL_memset(device, 0, (sizeof *device)); |
0 | 133 device->hidden = (struct SDL_PrivateVideoData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
134 SDL_malloc((sizeof *device->hidden)); |
0 | 135 } |
136 if ( (device == NULL) || (device->hidden == NULL) ) { | |
137 SDL_OutOfMemory(); | |
138 if ( device ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
139 SDL_free(device); |
0 | 140 } |
141 return(0); | |
142 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
143 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
0 | 144 |
145 /* Set the function pointers */ | |
146 device->VideoInit = ROM_VideoInit; | |
147 device->ListModes = ROM_ListModes; | |
148 device->SetVideoMode = ROM_SetVideoMode; | |
149 device->SetColors = ROM_SetColors; | |
150 device->UpdateRects = NULL; | |
151 device->VideoQuit = ROM_VideoQuit; | |
152 device->AllocHWSurface = ROM_AllocHWSurface; | |
153 device->CheckHWBlit = NULL; | |
154 device->FillHWRect = NULL; | |
155 device->SetHWColorKey = NULL; | |
156 device->SetHWAlpha = NULL; | |
157 device->LockHWSurface = ROM_LockHWSurface; | |
158 device->UnlockHWSurface = ROM_UnlockHWSurface; | |
159 device->FlipHWSurface = NULL; | |
160 device->FreeHWSurface = ROM_FreeHWSurface; | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
161 #if SDL_VIDEO_OPENGL |
0 | 162 device->GL_MakeCurrent = Mac_GL_MakeCurrent; |
163 device->GL_SwapBuffers = Mac_GL_SwapBuffers; | |
774
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
164 device->GL_LoadLibrary = Mac_GL_LoadLibrary; |
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
165 device->GL_GetProcAddress = Mac_GL_GetProcAddress; |
916
46916168361d
Date: Sun, 25 Jul 2004 23:10:03 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
774
diff
changeset
|
166 #endif // Have OpenGL |
0 | 167 device->SetCaption = Mac_SetCaption; |
168 device->SetIcon = NULL; | |
169 device->IconifyWindow = NULL; | |
170 device->GrabInput = NULL; | |
171 device->GetWMInfo = NULL; | |
172 device->FreeWMCursor = Mac_FreeWMCursor; | |
173 device->CreateWMCursor = Mac_CreateWMCursor; | |
174 device->ShowWMCursor = Mac_ShowWMCursor; | |
175 device->WarpWMCursor = Mac_WarpWMCursor; | |
176 device->InitOSKeymap = Mac_InitOSKeymap; | |
177 device->PumpEvents = Mac_PumpEvents; | |
178 | |
179 device->free = ROM_DeleteDevice; | |
180 | |
181 return device; | |
182 } | |
183 | |
184 VideoBootStrap TOOLBOX_bootstrap = { | |
185 "toolbox", "MacOS ROM Toolbox", | |
186 ROM_Available, ROM_CreateDevice | |
187 }; | |
188 | |
189 | |
190 static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
191 { | |
192 long info; | |
193 | |
194 /* Check out some things about the system */ | |
195 Gestalt(gestaltQuickdrawVersion, &info); | |
196 if ( info == gestaltOriginalQD ) { | |
197 SDL_SetError("Color Quickdraw not available"); | |
198 return(-1); | |
199 } | |
200 | |
201 /* Start ROMintosh events */ | |
202 Mac_InitEvents(this); | |
203 | |
204 /* Get a handle to the main monitor */ | |
205 SDL_Display = GetMainDevice(); | |
206 | |
1545
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
207 /* Determine the current screen size */ |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
208 this->info.current_w = (**SDL_Display).gdRect.right; |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
209 this->info.current_h = (**SDL_Display).gdRect.bottom; |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1424
diff
changeset
|
210 |
0 | 211 /* Determine pixel format */ |
212 vformat->BitsPerPixel = (**(**SDL_Display).gdPMap).pixelSize; | |
213 switch (vformat->BitsPerPixel) { | |
214 case 16: /* 5-5-5 RGB */ | |
215 vformat->Rmask = 0x00007c00; | |
216 vformat->Gmask = 0x000003e0; | |
217 vformat->Bmask = 0x0000001f; | |
218 break; | |
219 default: | |
220 break; | |
221 } | |
222 | |
223 /* Create our palette */ | |
224 SDL_CTab = (CTabHandle)NewHandle(sizeof(ColorSpec)*256 + 8); | |
225 if ( SDL_CTab == nil ) { | |
226 SDL_OutOfMemory(); | |
227 return(-1); | |
228 } | |
229 (**SDL_CTab).ctSeed = GetCTSeed(); | |
230 (**SDL_CTab).ctFlags = 0; | |
231 (**SDL_CTab).ctSize = 255; | |
232 CTabChanged(SDL_CTab); | |
233 SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit+pmTolerant, 0); | |
234 | |
235 /* Get a list of available fullscreen modes */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
236 SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *)); |
0 | 237 if ( SDL_modelist ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
238 SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
0 | 239 if ( SDL_modelist[0] ) { |
240 SDL_modelist[0]->x = 0; | |
241 SDL_modelist[0]->y = 0; | |
242 SDL_modelist[0]->w = (**SDL_Display).gdRect.right; | |
243 SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom; | |
244 } | |
245 SDL_modelist[1] = NULL; | |
246 } | |
247 | |
248 /* Fill in some window manager capabilities */ | |
249 this->info.wm_available = 1; | |
250 | |
251 /* We're done! */ | |
252 return(0); | |
253 } | |
254 | |
255 static SDL_Rect **ROM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
256 { | |
257 if ( this->screen->format->BitsPerPixel == format->BitsPerPixel ) { | |
258 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
259 return(SDL_modelist); | |
260 } else { | |
261 return((SDL_Rect **)-1); | |
262 } | |
263 } else { | |
264 return((SDL_Rect **)0); | |
265 } | |
266 } | |
267 | |
268 static void ROM_HideMenuBar(_THIS) | |
269 { | |
270 #if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */ | |
271 RgnHandle drawRgn = nil; | |
272 RgnHandle tempRgn = nil; | |
273 RgnHandle grayRgn = nil; | |
274 WindowPtr window = nil; | |
275 GDHandle gd = nil; | |
276 GrafPtr savePort; | |
277 long response; | |
278 short height; | |
279 EventRecord theEvent; | |
280 | |
281 height = GetMBarHeight(); | |
282 | |
283 if ( height > 0 ) { | |
284 tempRgn = NewRgn(); | |
285 drawRgn = NewRgn(); | |
286 gSaveGrayRgn = NewRgn(); | |
287 if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) { | |
288 goto CLEANUP; | |
289 } | |
290 grayRgn = GetGrayRgn(); /* No need to check for this */ | |
291 | |
292 GetPort(&savePort); | |
293 | |
294 /* Hide the control strip if it's present, and record its | |
295 previous position into the dirty region for redrawing. | |
296 This isn't necessary, but may help catch stray bits. */ | |
297 CopyRgn(grayRgn, tempRgn); | |
298 if (!Gestalt(gestaltControlStripAttr, &response) && | |
299 (response & (1L << gestaltControlStripExists))) { | |
300 gSaveCSVis = SBIsControlStripVisible(); | |
301 if (gSaveCSVis) | |
302 SBShowHideControlStrip(false); | |
303 } | |
304 DiffRgn(grayRgn, tempRgn, drawRgn); | |
305 | |
306 /* Save the gray region once the control strip is hidden*/ | |
307 CopyRgn(grayRgn, gSaveGrayRgn); | |
308 | |
309 /* Change the menu height in lowmem */ | |
310 gSaveMenuBar = height; | |
311 LMSetMBarHeight(0); | |
312 | |
313 /* Walk the monitor rectangles, and combine any pieces that | |
314 aren't in GrayRgn: menubar, round corners, fake floaters. */ | |
315 for(gd = GetDeviceList(); gd; gd = GetNextDevice(gd)) | |
316 { | |
317 if (!TestDeviceAttribute(gd, screenDevice)) continue; | |
318 if (!TestDeviceAttribute(gd, screenActive)) continue; | |
319 | |
320 RectRgn(tempRgn, &(*gd)->gdRect); /* Get the whole screen */ | |
321 DiffRgn(tempRgn, grayRgn, tempRgn); /* Subtract out GrayRgn */ | |
322 UnionRgn(tempRgn, drawRgn, drawRgn);/* Combine all the bits */ | |
323 } | |
324 | |
325 /* Add the bits into the GrayRgn */ | |
326 UnionRgn(drawRgn, grayRgn, grayRgn); | |
327 | |
328 /* Modify the vis regions of exposed windows */ | |
329 window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L; | |
330 PaintBehind(window, drawRgn); | |
331 CalcVisBehind(window, drawRgn); | |
332 | |
333 SetPort(savePort); | |
334 | |
335 /* Yield time so that floaters can catch up */ | |
336 EventAvail(0, &theEvent); | |
337 EventAvail(0, &theEvent); | |
338 EventAvail(0, &theEvent); | |
339 EventAvail(0, &theEvent); | |
340 } | |
341 | |
342 CLEANUP: | |
343 | |
344 if (tempRgn) DisposeRgn(tempRgn); | |
345 if (drawRgn) DisposeRgn(drawRgn); | |
346 #endif /* !TARGET_API_MAC_CARBON */ | |
347 } | |
348 | |
349 static void ROM_ShowMenuBar(_THIS) | |
350 { | |
351 #if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */ | |
352 RgnHandle drawRgn = nil; | |
353 RgnHandle menuRgn = nil; | |
354 RgnHandle tempRgn = nil; | |
355 RgnHandle grayRgn = nil; | |
356 WindowPtr window = nil; | |
357 GrafPtr wMgrPort; | |
358 GrafPtr savePort; | |
359 Rect menuRect; | |
360 long response; | |
361 short height; | |
362 EventRecord theEvent; | |
363 RGBColor saveRGB; | |
364 RGBColor blackRGB = { 0, 0, 0 }; | |
365 | |
366 height = GetMBarHeight(); | |
367 | |
368 if ((height <= 0) && (gSaveMenuBar > 0)) { | |
369 drawRgn = NewRgn(); | |
370 menuRgn = NewRgn(); | |
371 tempRgn = NewRgn(); | |
372 if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) { | |
373 goto CLEANUP; | |
374 } | |
375 grayRgn = GetGrayRgn(); /* No need to check for this */ | |
376 | |
377 GetPort(&savePort); | |
378 GetWMgrPort(&wMgrPort); | |
379 | |
380 /* Set the height properly */ | |
381 LMSetMBarHeight(gSaveMenuBar); | |
382 | |
383 /* Restore the old GrayRgn: rounded corners, etc, but not | |
384 the menubar -- subtract that out first! */ | |
385 if (gSaveGrayRgn) | |
386 { | |
387 menuRect = (*GetMainDevice())->gdRect; | |
388 menuRect.bottom = menuRect.top + gSaveMenuBar; | |
389 RectRgn(menuRgn, &menuRect); | |
390 | |
391 DiffRgn(grayRgn, gSaveGrayRgn, drawRgn); /* What do we inval? */ | |
392 DiffRgn(drawRgn, menuRgn, drawRgn); /* Clip out the menu */ | |
393 | |
394 /* Now redraw the corners and other bits black */ | |
395 SetPort(wMgrPort); | |
396 GetClip(tempRgn); | |
397 SetClip(drawRgn); | |
398 GetForeColor(&saveRGB); | |
399 RGBForeColor(&blackRGB); | |
400 PaintRgn(drawRgn); | |
401 RGBForeColor(&saveRGB); | |
402 SetClip(tempRgn); | |
403 SetPort(savePort); | |
404 | |
405 UnionRgn(drawRgn, menuRgn, drawRgn); /* Put back the menu */ | |
406 | |
407 /* Now actually restore the GrayRgn */ | |
408 CopyRgn(gSaveGrayRgn, grayRgn); | |
409 DisposeRgn(gSaveGrayRgn); | |
410 gSaveGrayRgn = nil; | |
411 } | |
412 | |
413 /* Modify the vis regions of exposed windows and draw menubar */ | |
414 window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L; | |
415 PaintBehind(window, drawRgn); | |
416 CalcVisBehind(window, drawRgn); | |
417 DrawMenuBar(); | |
418 | |
419 SetPort(savePort); | |
420 gSaveMenuBar = 0; | |
421 | |
422 /* Now show the control strip if it's present */ | |
423 if (!Gestalt(gestaltControlStripAttr, &response) && | |
424 (response & (1L << gestaltControlStripExists))) | |
425 { | |
426 if (gSaveCSVis && !SBIsControlStripVisible()) | |
427 SBShowHideControlStrip(true); | |
428 gSaveCSVis = true; | |
429 } | |
430 | |
431 /* Yield time so that floaters can catch up */ | |
432 EventAvail(0, &theEvent); | |
433 EventAvail(0, &theEvent); | |
434 EventAvail(0, &theEvent); | |
435 EventAvail(0, &theEvent); | |
436 } | |
437 | |
438 CLEANUP: | |
439 | |
440 if (drawRgn) DisposeRgn(drawRgn); | |
441 if (menuRgn) DisposeRgn(menuRgn); | |
442 if (tempRgn) DisposeRgn(tempRgn); | |
443 #endif /* !TARGET_API_MAC_CARBON */ | |
444 } | |
445 | |
446 /* Various screen update functions available */ | |
447 static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | |
448 static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects); | |
449 | |
450 static void ROM_UnsetVideoMode(_THIS, SDL_Surface *current) | |
451 { | |
452 /* Free the current window, if any */ | |
453 if ( SDL_Window != nil ) { | |
454 GWorldPtr memworld; | |
455 | |
456 /* Handle OpenGL support */ | |
457 Mac_GL_Quit(this); | |
458 | |
459 memworld = (GWorldPtr)GetWRefCon(SDL_Window); | |
460 if ( memworld != nil ) { | |
461 UnlockPixels(GetGWorldPixMap(memworld)); | |
462 DisposeGWorld(memworld); | |
463 } | |
464 if ( (current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
465 #if USE_QUICKTIME | |
466 EndFullScreen(fullscreen_ctx, nil); | |
467 SDL_Window = nil; | |
468 #else | |
469 ROM_ShowMenuBar(this); | |
470 #endif | |
471 } | |
472 } | |
473 current->pixels = NULL; | |
474 current->flags &= ~(SDL_HWSURFACE|SDL_FULLSCREEN); | |
475 } | |
476 | |
477 static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface *current, | |
478 int width, int height, int bpp, Uint32 flags) | |
479 { | |
480 Rect wrect, orect; | |
481 #if TARGET_API_MAC_CARBON | |
482 Rect tmprect; | |
483 #endif | |
484 | |
485 /* Free any previous video mode */ | |
486 ROM_UnsetVideoMode(this, current); | |
487 | |
488 /* Create the ROM window and SDL video surface */ | |
489 current->flags = 0; /* Clear flags */ | |
490 current->w = width; | |
491 current->h = height; | |
492 SetRect(&wrect, 0, 0, width, height); | |
493 if ( SDL_Window ) { | |
494 /* If we recreate the window, don't move it around */ | |
495 #if TARGET_API_MAC_CARBON | |
496 orect = *GetWindowPortBounds(SDL_Window, &tmprect); | |
497 #else | |
498 orect = SDL_Window->portRect; | |
499 #endif | |
500 OffsetRect(&wrect, orect.left, orect.top); | |
501 } else { | |
502 /* Center the window the first time we show it */ | |
503 OffsetRect(&wrect, | |
504 (SDL_modelist[0]->w-width)/2, (SDL_modelist[0]->h-height)/2); | |
505 } | |
506 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
507 #if defined(__MACOSX__) && !USE_QUICKTIME |
0 | 508 /* Hum.. fullscreen mode is broken */ |
509 flags &= ~SDL_FULLSCREEN; | |
510 #endif | |
511 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
512 /* Create the fullscreen window and use screen bits */ | |
513 current->flags |= SDL_HWSURFACE|SDL_FULLSCREEN; | |
514 if ( SDL_Window ) { | |
515 DisposeWindow(SDL_Window); | |
516 } | |
517 #if USE_QUICKTIME | |
518 BeginFullScreen(&fullscreen_ctx, nil, 0,0, &SDL_Window, nil, 0); | |
519 #else | |
520 SDL_Window = NewCWindow(nil, &wrect, "\p", true, plainDBox, | |
521 (WindowPtr)-1, false, 0); | |
522 ROM_HideMenuBar(this); | |
523 #endif | |
524 current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF; | |
525 current->pixels = (**(**SDL_Display).gdPMap).baseAddr; | |
526 this->UpdateRects = ROM_DirectUpdate; | |
527 } else { | |
528 GWorldPtr memworld; | |
529 PixMapHandle pixmap; | |
530 int style; | |
531 | |
532 style = noGrowDocProc; | |
533 if ( flags & SDL_NOFRAME ) { | |
534 style = plainDBox; | |
535 current->flags |= SDL_NOFRAME; | |
536 } else | |
537 if ( flags & SDL_RESIZABLE ) { | |
538 style = zoomDocProc; | |
539 current->flags |= SDL_RESIZABLE; | |
540 } | |
541 if ( SDL_Window && (style == current_style) ) { | |
542 /* Resize existing window, if necessary */ | |
543 if ( ((orect.right-orect.left) != width) || | |
544 ((orect.bottom-orect.top) != height) ) { | |
545 SizeWindow(SDL_Window, width, height, false); | |
546 } | |
547 } else { | |
548 /* Recreate the window in the new style */ | |
549 if ( SDL_Window ) { | |
550 DisposeWindow(SDL_Window); | |
551 } | |
552 SDL_Window = NewCWindow(nil, &wrect, "\p", true, | |
553 style, (WindowPtr)-1, true, 0); | |
554 | |
555 /* Set the window title, if any */ | |
556 { char *title; | |
557 SDL_WM_GetCaption(&title, NULL); | |
558 if ( title ) { | |
559 Mac_SetCaption(this, title, NULL); | |
560 } | |
561 } | |
562 } | |
563 current_style = style; | |
564 SetPalette(SDL_Window, SDL_CPal, false); | |
565 ActivatePalette(SDL_Window); | |
566 if ( NewGWorld(&memworld, 0, | |
567 #if TARGET_API_MAC_CARBON | |
568 GetWindowPortBounds(SDL_Window, &tmprect), | |
569 #else | |
570 &SDL_Window->portRect, | |
571 #endif | |
572 SDL_CTab, nil, 0) != noErr ) { | |
573 SDL_SetError("NewGWorld() failed"); | |
574 return(NULL); | |
575 } | |
576 SetWRefCon(SDL_Window, (long)memworld); | |
577 pixmap = GetGWorldPixMap(memworld); | |
578 LockPixels(pixmap); | |
579 current->pitch = (**pixmap).rowBytes & 0x3FFF; | |
580 current->pixels = GetPixBaseAddr(pixmap); | |
581 this->UpdateRects = ROM_WindowUpdate; | |
582 } | |
583 SetPortWindowPort(SDL_Window); | |
584 SelectWindow(SDL_Window); | |
585 | |
586 /* Handle OpenGL support */ | |
587 if ( flags & SDL_OPENGL ) { | |
588 if ( Mac_GL_Init(this) == 0 ) { | |
589 current->flags |= SDL_OPENGL; | |
590 } else { | |
591 current = NULL; | |
592 } | |
593 } | |
594 | |
595 if ( (flags & SDL_HWPALETTE) && (flags & SDL_FULLSCREEN) ) | |
596 current->flags |= SDL_HWPALETTE; | |
597 | |
598 /* We're live! */ | |
599 return(current); | |
600 } | |
601 | |
602 /* We don't actually allow hardware surfaces other than the main one */ | |
603 static int ROM_AllocHWSurface(_THIS, SDL_Surface *surface) | |
604 { | |
605 return(-1); | |
606 } | |
607 static void ROM_FreeHWSurface(_THIS, SDL_Surface *surface) | |
608 { | |
609 return; | |
610 } | |
611 static int ROM_LockHWSurface(_THIS, SDL_Surface *surface) | |
612 { | |
613 return(0); | |
614 } | |
615 static void ROM_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
616 { | |
617 return; | |
618 } | |
619 | |
620 static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | |
621 { | |
622 /* The application is already updating the visible video memory */ | |
623 return; | |
624 } | |
625 | |
626 static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects) | |
627 { | |
628 GWorldPtr memworld; | |
629 GrafPtr saveport; | |
630 CGrafPtr thePort; | |
631 const BitMap *memBits; | |
632 const BitMap *winBits; | |
633 int i; | |
634 Rect update; | |
635 | |
636 /* Copy from the offscreen GWorld to the window port */ | |
637 GetPort(&saveport); | |
638 SetPortWindowPort(SDL_Window); | |
639 thePort = GetWindowPort(SDL_Window); | |
640 memworld = (GWorldPtr)GetWRefCon(SDL_Window); | |
1811 | 641 #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS |
0 | 642 memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld); |
643 #else | |
644 memBits = &((GrafPtr)memworld)->portBits; | |
645 #endif | |
1811 | 646 #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS |
0 | 647 winBits = GetPortBitMapForCopyBits(thePort); |
648 #else | |
649 winBits = &SDL_Window->portBits; | |
650 #endif | |
651 for ( i=0; i<numrects; ++i ) { | |
652 update.left = rects[i].x; | |
653 update.right = rects[i].x+rects[i].w; | |
654 update.top = rects[i].y; | |
655 update.bottom = rects[i].y+rects[i].h; | |
656 CopyBits(memBits, winBits, | |
657 &update, &update, srcCopy, nil); | |
658 } | |
659 #if TARGET_API_MAC_CARBON | |
660 if ( QDIsPortBuffered(thePort) ) { | |
661 QDFlushPortBuffer(thePort, NULL); | |
662 } | |
663 #endif | |
664 SetPort(saveport); | |
665 } | |
666 | |
667 static int ROM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
668 { | |
669 CTabHandle cTab; | |
670 int i; | |
671 | |
672 /* Get the colortable from the either the display or window */ | |
673 if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
674 cTab = (**(**SDL_Display).gdPMap).pmTable; | |
675 } else { | |
676 cTab = SDL_CTab; | |
677 } | |
678 | |
679 /* Verify the range of colors */ | |
680 if ( (firstcolor+ncolors) > ((**cTab).ctSize+1) ) { | |
681 return(0); | |
682 } | |
683 | |
684 /* Set the screen palette and update the display */ | |
685 for ( i=0; i< ncolors; ++i ) { | |
686 int j = firstcolor + i; | |
687 (**cTab).ctTable[j].value = j; | |
688 (**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r; | |
689 (**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g; | |
690 (**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b; | |
691 } | |
692 // if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) | |
693 { | |
694 GDevice **odisplay; | |
695 odisplay = GetGDevice(); | |
696 SetGDevice(SDL_Display); | |
697 SetEntries(0, (**cTab).ctSize, (ColorSpec *)&(**cTab).ctTable); | |
698 SetGDevice(odisplay); | |
699 } | |
700 return(1); | |
701 } | |
702 | |
703 void ROM_VideoQuit(_THIS) | |
704 { | |
705 int i; | |
706 | |
707 /* Free current video mode */ | |
708 ROM_UnsetVideoMode(this, this->screen); | |
709 if ( SDL_Window ) { | |
710 DisposeWindow(SDL_Window); | |
711 SDL_Window = nil; | |
712 } | |
713 | |
714 /* Free palette and restore original one */ | |
715 if ( SDL_CTab != nil ) { | |
716 DisposeHandle((Handle)SDL_CTab); | |
717 SDL_CTab = nil; | |
718 } | |
719 if ( SDL_CPal != nil ) { | |
720 DisposePalette(SDL_CPal); | |
721 SDL_CPal = nil; | |
722 } | |
723 RestoreDeviceClut(GetMainDevice()); | |
724 | |
725 /* Free list of video modes */ | |
726 if ( SDL_modelist != NULL ) { | |
727 for ( i=0; SDL_modelist[i]; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
728 SDL_free(SDL_modelist[i]); |
0 | 729 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
730 SDL_free(SDL_modelist); |
0 | 731 SDL_modelist = NULL; |
732 } | |
733 } | |
734 |