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