The Mac OS X Cocoa video driver is under construction...
Note that SDLmain is no longer necessary on Mac OS X. :)
1.1 --- a/configure.in Sun Jul 23 00:55:25 2006 +0000
1.2 +++ b/configure.in Sun Jul 23 09:11:10 2006 +0000
1.3 @@ -1046,36 +1046,11 @@
1.4 fi
1.5 }
1.6
1.7 -dnl Set up the Carbon/QuickDraw video driver for Mac OS X (but not Darwin)
1.8 -CheckCARBON()
1.9 -{
1.10 - AC_ARG_ENABLE(video-carbon,
1.11 -AC_HELP_STRING([--enable-video-carbon], [use Carbon/QuickDraw video driver [[default=no]]]),
1.12 - , enable_video_carbon=no)
1.13 - if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
1.14 - AC_MSG_CHECKING(for Carbon framework)
1.15 - have_carbon=no
1.16 - AC_TRY_COMPILE([
1.17 - #include <Carbon/Carbon.h>
1.18 - ],[
1.19 - ],[
1.20 - have_carbon=yes
1.21 - ])
1.22 - AC_MSG_RESULT($have_carbon)
1.23 - if test x$have_carbon = xyes; then
1.24 - AC_DEFINE(SDL_VIDEO_DRIVER_TOOLBOX)
1.25 - SOURCES="$SOURCES $srcdir/src/video/maccommon/*.c"
1.26 - SOURCES="$SOURCES $srcdir/src/video/macrom/*.c"
1.27 - have_video=yes
1.28 - fi
1.29 - fi
1.30 -}
1.31 -
1.32 -dnl Set up the Cocoa/Quartz video driver for Mac OS X (but not Darwin)
1.33 +dnl Set up the Cocoa video driver for Mac OS X (but not Darwin)
1.34 CheckCOCOA()
1.35 {
1.36 AC_ARG_ENABLE(video-cocoa,
1.37 -AC_HELP_STRING([--enable-video-cocoa], [use Cocoa/Quartz video driver [[default=yes]]]),
1.38 +AC_HELP_STRING([--enable-video-cocoa], [use Cocoa video driver [[default=yes]]]),
1.39 , enable_video_cocoa=yes)
1.40 if test x$enable_video = xyes -a x$enable_video_cocoa = xyes; then
1.41 save_CFLAGS="$CFLAGS"
1.42 @@ -1092,8 +1067,8 @@
1.43 AC_MSG_RESULT($have_cocoa)
1.44 CFLAGS="$save_CFLAGS"
1.45 if test x$have_cocoa = xyes; then
1.46 - AC_DEFINE(SDL_VIDEO_DRIVER_QUARTZ)
1.47 - SOURCES="$SOURCES $srcdir/src/video/quartz/*.m"
1.48 + AC_DEFINE(SDL_VIDEO_DRIVER_COCOA)
1.49 + SOURCES="$SOURCES $srcdir/src/video/cocoa/*.m"
1.50 have_video=yes
1.51 fi
1.52 fi
1.53 @@ -1526,9 +1501,6 @@
1.54 if test x$enable_video_cocoa = xyes; then
1.55 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGL"
1.56 fi
1.57 - if test x$enable_video_carbon = xyes; then
1.58 - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AGL"
1.59 - fi
1.60 esac
1.61 fi
1.62 }
1.63 @@ -2453,7 +2425,6 @@
1.64 fi
1.65
1.66 CheckCOCOA
1.67 - CheckCARBON
1.68 CheckX11
1.69 CheckMacGL
1.70 CheckOpenGLX11
1.71 @@ -2492,11 +2463,9 @@
1.72 have_timers=yes
1.73 fi
1.74 # The Mac OS X platform requires special setup.
1.75 - SDLMAIN_SOURCES="$srcdir/src/main/macosx/*.m"
1.76 EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings"
1.77 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Cocoa"
1.78 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Carbon"
1.79 - SDL_LIBS="-lSDLmain $SDL_LIBS"
1.80 # If either the audio or CD driver is used, add the AudioUnit framework
1.81 if test x$enable_audio = xyes -o x$enable_cdrom = xyes; then
1.82 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit"
1.83 @@ -2623,7 +2592,6 @@
1.84 OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.S,$(objects)/\1.lo,g'`
1.85
1.86 SDLMAIN_OBJECTS=`echo $SDLMAIN_SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.cc,$(objects)/\1.o,g'`
1.87 -SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.m,$(objects)/\1.o,g'`
1.88 SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.o,g'`
1.89
1.90 # Set runtime shared library paths as needed
1.91 @@ -2642,12 +2610,8 @@
1.92 case "$ARCH" in
1.93 macosx)
1.94 SDL_LIBS="$SDL_LIBS -Wl,-framework,Cocoa"
1.95 - # Is this still needed?
1.96 - #if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
1.97 - # SDL_LIBS="$SDL_LIBS -Wl,-framework,Carbon"
1.98 - #fi
1.99 # Evil hack to allow static linking on Mac OS X
1.100 - SDL_STATIC_LIBS="\${exec_prefix}/lib/libSDLmain.a \${exec_prefix}/lib/libSDL.a $EXTRA_LDFLAGS"
1.101 + SDL_STATIC_LIBS="\${exec_prefix}/lib/libSDL.a $EXTRA_LDFLAGS"
1.102 ;;
1.103 *)
1.104 SDL_STATIC_LIBS="$SDL_LIBS"
2.1 --- a/include/SDL_config.h.in Sun Jul 23 00:55:25 2006 +0000
2.2 +++ b/include/SDL_config.h.in Sun Jul 23 09:11:10 2006 +0000
2.3 @@ -251,6 +251,7 @@
2.4 /* Enable various video drivers */
2.5 #undef SDL_VIDEO_DRIVER_AALIB
2.6 #undef SDL_VIDEO_DRIVER_BWINDOW
2.7 +#undef SDL_VIDEO_DRIVER_COCOA
2.8 #undef SDL_VIDEO_DRIVER_CYBERGRAPHICS
2.9 #undef SDL_VIDEO_DRIVER_DC
2.10 #undef SDL_VIDEO_DRIVER_DGA
2.11 @@ -270,7 +271,6 @@
2.12 #undef SDL_VIDEO_DRIVER_PICOGUI
2.13 #undef SDL_VIDEO_DRIVER_PS2GS
2.14 #undef SDL_VIDEO_DRIVER_QTOPIA
2.15 -#undef SDL_VIDEO_DRIVER_QUARTZ
2.16 #undef SDL_VIDEO_DRIVER_RISCOS
2.17 #undef SDL_VIDEO_DRIVER_SVGALIB
2.18 #undef SDL_VIDEO_DRIVER_TOOLBOX
3.1 --- a/include/SDL_config_macosx.h Sun Jul 23 00:55:25 2006 +0000
3.2 +++ b/include/SDL_config_macosx.h Sun Jul 23 09:11:10 2006 +0000
3.3 @@ -113,12 +113,8 @@
3.4 #define SDL_TIMER_UNIX 1
3.5
3.6 /* Enable various video drivers */
3.7 +#define SDL_VIDEO_DRIVER_COCOA 1
3.8 #define SDL_VIDEO_DRIVER_DUMMY 1
3.9 -#if TARGET_API_MAC_CARBON
3.10 -#define SDL_VIDEO_DRIVER_TOOLBOX 1
3.11 -#else
3.12 -#define SDL_VIDEO_DRIVER_QUARTZ 1
3.13 -#endif
3.14
3.15 /* Enable OpenGL support */
3.16 #define SDL_VIDEO_OPENGL 1
4.1 --- a/include/SDL_main.h Sun Jul 23 00:55:25 2006 +0000
4.2 +++ b/include/SDL_main.h Sun Jul 23 09:11:10 2006 +0000
4.3 @@ -25,11 +25,11 @@
4.4
4.5 #include "SDL_stdinc.h"
4.6
4.7 -/* Redefine main() on Win32 and MacOS so that it is called by winmain.c */
4.8 +/* Redefine main() on some platforms so that it is called by SDL */
4.9
4.10 #if defined(__WIN32__) || \
4.11 (defined(__MWERKS__) && !defined(__BEOS__)) || \
4.12 - defined(__MACOS__) || defined(__MACOSX__) || \
4.13 + defined(__MACOS__) || \
4.14 defined(__SYMBIAN32__) || defined(QWS)
4.15
4.16 #ifdef __cplusplus
5.1 --- a/src/main/macosx/Info.plist.in Sun Jul 23 00:55:25 2006 +0000
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,24 +0,0 @@
5.4 -<?xml version="1.0" encoding="UTF-8"?>
5.5 -<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
5.6 -<plist version="0.9">
5.7 -<dict>
5.8 - <key>CFBundleDevelopmentRegion</key>
5.9 - <string>English</string>
5.10 - <key>CFBundleExecutable</key>
5.11 - <string>@EXECUTABLE_NAME@</string>
5.12 - <key>CFBundleInfoDictionaryVersion</key>
5.13 - <string>6.0</string>
5.14 - <key>CFBundleName</key>
5.15 - <string>@PACKAGE@</string>
5.16 - <key>CFBundlePackageType</key>
5.17 - <string>APPL</string>
5.18 - <key>CFBundleShortVersionString</key>
5.19 - <string>@VERSION@</string>
5.20 - <key>CFBundleSignature</key>
5.21 - <string>????</string>
5.22 - <key>NSMainNibFile</key>
5.23 - <string>SDLMain.nib</string>
5.24 - <key>NSPrincipalClass</key>
5.25 - <string>NSApplication</string>
5.26 -</dict>
5.27 -</plist>
6.1 --- a/src/main/macosx/SDLMain.h Sun Jul 23 00:55:25 2006 +0000
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,11 +0,0 @@
6.4 -/* SDLMain.m - main entry point for our Cocoa-ized SDL app
6.5 - Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
6.6 - Non-NIB-Code & other changes: Max Horn <max@quendi.de>
6.7 -
6.8 - Feel free to customize this file to suit your needs
6.9 -*/
6.10 -
6.11 -#import <Cocoa/Cocoa.h>
6.12 -
6.13 -@ interface SDLMain:NSObject @ end
6.14 -/* vi: set ts=4 sw=4 expandtab: */
7.1 --- a/src/main/macosx/SDLMain.m Sun Jul 23 00:55:25 2006 +0000
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,384 +0,0 @@
7.4 -/* SDLMain.m - main entry point for our Cocoa-ized SDL app
7.5 - Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
7.6 - Non-NIB-Code & other changes: Max Horn <max@quendi.de>
7.7 -
7.8 - Feel free to customize this file to suit your needs
7.9 -*/
7.10 -
7.11 -#import "SDL.h"
7.12 -#import "SDLMain.h"
7.13 -#import <sys/param.h> /* for MAXPATHLEN */
7.14 -#import <unistd.h>
7.15 -
7.16 -/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
7.17 - but the method still is there and works. To avoid warnings, we declare
7.18 - it ourselves here. */
7.19 -@interface NSApplication(SDL_Missing_Methods)
7.20 -- (void)setAppleMenu:(NSMenu *)menu;
7.21 -@end
7.22 -
7.23 -/* Use this flag to determine whether we use SDLMain.nib or not */
7.24 -#define SDL_USE_NIB_FILE 0
7.25 -
7.26 -/* Use this flag to determine whether we use CPS (docking) or not */
7.27 -#define SDL_USE_CPS 1
7.28 -#ifdef SDL_USE_CPS
7.29 -/* Portions of CPS.h */
7.30 -typedef struct CPSProcessSerNum
7.31 -{
7.32 - UInt32 lo;
7.33 - UInt32 hi;
7.34 -} CPSProcessSerNum;
7.35 -
7.36 -extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
7.37 -extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
7.38 -extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
7.39 -
7.40 -#endif /* SDL_USE_CPS */
7.41 -
7.42 -static int gArgc;
7.43 -static char **gArgv;
7.44 -static BOOL gFinderLaunch;
7.45 -static BOOL gCalledAppMainline = FALSE;
7.46 -
7.47 -static NSString *getApplicationName(void)
7.48 -{
7.49 - NSDictionary *dict;
7.50 - NSString *appName = 0;
7.51 -
7.52 - /* Determine the application name */
7.53 - dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
7.54 - if (dict)
7.55 - appName = [dict objectForKey: @"CFBundleName"];
7.56 -
7.57 - if (![appName length])
7.58 - appName = [[NSProcessInfo processInfo] processName];
7.59 -
7.60 - return appName;
7.61 -}
7.62 -
7.63 -#if SDL_USE_NIB_FILE
7.64 -/* A helper category for NSString */
7.65 -@interface NSString (ReplaceSubString)
7.66 -- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
7.67 -@end
7.68 -#endif
7.69 -
7.70 -@interface SDLApplication : NSApplication
7.71 -@end
7.72 -
7.73 -@implementation SDLApplication
7.74 -/* Invoked from the Quit menu item */
7.75 -- (void)terminate:(id)sender
7.76 -{
7.77 - /* Post a SDL_QUIT event */
7.78 - SDL_Event event;
7.79 - event.type = SDL_QUIT;
7.80 - SDL_PushEvent(&event);
7.81 -}
7.82 -@end
7.83 -
7.84 -/* The main class of the application, the application's delegate */
7.85 -@implementation SDLMain
7.86 -
7.87 -/* Set the working directory to the .app's parent directory */
7.88 -- (void) setupWorkingDirectory:(BOOL)shouldChdir
7.89 -{
7.90 - if (shouldChdir)
7.91 - {
7.92 - char parentdir[MAXPATHLEN];
7.93 - CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
7.94 - CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
7.95 - if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
7.96 - assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
7.97 - }
7.98 - CFRelease(url);
7.99 - CFRelease(url2);
7.100 - }
7.101 -
7.102 -}
7.103 -
7.104 -#if SDL_USE_NIB_FILE
7.105 -
7.106 -/* Fix menu to contain the real app name instead of "SDL App" */
7.107 -- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
7.108 -{
7.109 - NSRange aRange;
7.110 - NSEnumerator *enumerator;
7.111 - NSMenuItem *menuItem;
7.112 -
7.113 - aRange = [[aMenu title] rangeOfString:@"SDL App"];
7.114 - if (aRange.length != 0)
7.115 - [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
7.116 -
7.117 - enumerator = [[aMenu itemArray] objectEnumerator];
7.118 - while ((menuItem = [enumerator nextObject]))
7.119 - {
7.120 - aRange = [[menuItem title] rangeOfString:@"SDL App"];
7.121 - if (aRange.length != 0)
7.122 - [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
7.123 - if ([menuItem hasSubmenu])
7.124 - [self fixMenu:[menuItem submenu] withAppName:appName];
7.125 - }
7.126 - [ aMenu sizeToFit ];
7.127 -}
7.128 -
7.129 -#else
7.130 -
7.131 -static void setApplicationMenu(void)
7.132 -{
7.133 - /* warning: this code is very odd */
7.134 - NSMenu *appleMenu;
7.135 - NSMenuItem *menuItem;
7.136 - NSString *title;
7.137 - NSString *appName;
7.138 -
7.139 - appName = getApplicationName();
7.140 - appleMenu = [[NSMenu alloc] initWithTitle:@""];
7.141 -
7.142 - /* Add menu items */
7.143 - title = [@"About " stringByAppendingString:appName];
7.144 - [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
7.145 -
7.146 - [appleMenu addItem:[NSMenuItem separatorItem]];
7.147 -
7.148 - title = [@"Hide " stringByAppendingString:appName];
7.149 - [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
7.150 -
7.151 - menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
7.152 - [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
7.153 -
7.154 - [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
7.155 -
7.156 - [appleMenu addItem:[NSMenuItem separatorItem]];
7.157 -
7.158 - title = [@"Quit " stringByAppendingString:appName];
7.159 - [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
7.160 -
7.161 -
7.162 - /* Put menu into the menubar */
7.163 - menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
7.164 - [menuItem setSubmenu:appleMenu];
7.165 - [[NSApp mainMenu] addItem:menuItem];
7.166 -
7.167 - /* Tell the application object that this is now the application menu */
7.168 - [NSApp setAppleMenu:appleMenu];
7.169 -
7.170 - /* Finally give up our references to the objects */
7.171 - [appleMenu release];
7.172 - [menuItem release];
7.173 -}
7.174 -
7.175 -/* Create a window menu */
7.176 -static void setupWindowMenu(void)
7.177 -{
7.178 - NSMenu *windowMenu;
7.179 - NSMenuItem *windowMenuItem;
7.180 - NSMenuItem *menuItem;
7.181 -
7.182 - windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
7.183 -
7.184 - /* "Minimize" item */
7.185 - menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
7.186 - [windowMenu addItem:menuItem];
7.187 - [menuItem release];
7.188 -
7.189 - /* Put menu into the menubar */
7.190 - windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
7.191 - [windowMenuItem setSubmenu:windowMenu];
7.192 - [[NSApp mainMenu] addItem:windowMenuItem];
7.193 -
7.194 - /* Tell the application object that this is now the window menu */
7.195 - [NSApp setWindowsMenu:windowMenu];
7.196 -
7.197 - /* Finally give up our references to the objects */
7.198 - [windowMenu release];
7.199 - [windowMenuItem release];
7.200 -}
7.201 -
7.202 -/* Replacement for NSApplicationMain */
7.203 -static void CustomApplicationMain (int argc, char **argv)
7.204 -{
7.205 - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
7.206 - SDLMain *sdlMain;
7.207 -
7.208 - /* Ensure the application object is initialised */
7.209 - [SDLApplication sharedApplication];
7.210 -
7.211 -#ifdef SDL_USE_CPS
7.212 - {
7.213 - CPSProcessSerNum PSN;
7.214 - /* Tell the dock about us */
7.215 - if (!CPSGetCurrentProcess(&PSN))
7.216 - if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
7.217 - if (!CPSSetFrontProcess(&PSN))
7.218 - [SDLApplication sharedApplication];
7.219 - }
7.220 -#endif /* SDL_USE_CPS */
7.221 -
7.222 - /* Set up the menubar */
7.223 - [NSApp setMainMenu:[[NSMenu alloc] init]];
7.224 - setApplicationMenu();
7.225 - setupWindowMenu();
7.226 -
7.227 - /* Create SDLMain and make it the app delegate */
7.228 - sdlMain = [[SDLMain alloc] init];
7.229 - [NSApp setDelegate:sdlMain];
7.230 -
7.231 - /* Start the main event loop */
7.232 - [NSApp run];
7.233 -
7.234 - [sdlMain release];
7.235 - [pool release];
7.236 -}
7.237 -
7.238 -#endif
7.239 -
7.240 -
7.241 -/*
7.242 - * Catch document open requests...this lets us notice files when the app
7.243 - * was launched by double-clicking a document, or when a document was
7.244 - * dragged/dropped on the app's icon. You need to have a
7.245 - * CFBundleDocumentsType section in your Info.plist to get this message,
7.246 - * apparently.
7.247 - *
7.248 - * Files are added to gArgv, so to the app, they'll look like command line
7.249 - * arguments. Previously, apps launched from the finder had nothing but
7.250 - * an argv[0].
7.251 - *
7.252 - * This message may be received multiple times to open several docs on launch.
7.253 - *
7.254 - * This message is ignored once the app's mainline has been called.
7.255 - */
7.256 -- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
7.257 -{
7.258 - const char *temparg;
7.259 - size_t arglen;
7.260 - char *arg;
7.261 - char **newargv;
7.262 -
7.263 - if (!gFinderLaunch) /* MacOS is passing command line args. */
7.264 - return FALSE;
7.265 -
7.266 - if (gCalledAppMainline) /* app has started, ignore this document. */
7.267 - return FALSE;
7.268 -
7.269 - temparg = [filename UTF8String];
7.270 - arglen = SDL_strlen(temparg) + 1;
7.271 - arg = (char *) SDL_malloc(arglen);
7.272 - if (arg == NULL)
7.273 - return FALSE;
7.274 -
7.275 - newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
7.276 - if (newargv == NULL)
7.277 - {
7.278 - SDL_free(arg);
7.279 - return FALSE;
7.280 - }
7.281 - gArgv = newargv;
7.282 -
7.283 - SDL_strlcpy(arg, temparg, arglen);
7.284 - gArgv[gArgc++] = arg;
7.285 - gArgv[gArgc] = NULL;
7.286 - return TRUE;
7.287 -}
7.288 -
7.289 -
7.290 -/* Called when the internal event loop has just started running */
7.291 -- (void) applicationDidFinishLaunching: (NSNotification *) note
7.292 -{
7.293 - int status;
7.294 -
7.295 - /* Set the working directory to the .app's parent directory */
7.296 - [self setupWorkingDirectory:gFinderLaunch];
7.297 -
7.298 -#if SDL_USE_NIB_FILE
7.299 - /* Set the main menu to contain the real app name instead of "SDL App" */
7.300 - [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
7.301 -#endif
7.302 -
7.303 - /* Hand off to main application code */
7.304 - gCalledAppMainline = TRUE;
7.305 - status = SDL_main (gArgc, gArgv);
7.306 -
7.307 - /* We're done, thank you for playing */
7.308 - exit(status);
7.309 -}
7.310 -@end
7.311 -
7.312 -
7.313 -@implementation NSString (ReplaceSubString)
7.314 -
7.315 -- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
7.316 -{
7.317 - unsigned int bufferSize;
7.318 - unsigned int selfLen = [self length];
7.319 - unsigned int aStringLen = [aString length];
7.320 - unichar *buffer;
7.321 - NSRange localRange;
7.322 - NSString *result;
7.323 -
7.324 - bufferSize = selfLen + aStringLen - aRange.length;
7.325 - buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
7.326 -
7.327 - /* Get first part into buffer */
7.328 - localRange.location = 0;
7.329 - localRange.length = aRange.location;
7.330 - [self getCharacters:buffer range:localRange];
7.331 -
7.332 - /* Get middle part into buffer */
7.333 - localRange.location = 0;
7.334 - localRange.length = aStringLen;
7.335 - [aString getCharacters:(buffer+aRange.location) range:localRange];
7.336 -
7.337 - /* Get last part into buffer */
7.338 - localRange.location = aRange.location + aRange.length;
7.339 - localRange.length = selfLen - localRange.location;
7.340 - [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
7.341 -
7.342 - /* Build output string */
7.343 - result = [NSString stringWithCharacters:buffer length:bufferSize];
7.344 -
7.345 - NSDeallocateMemoryPages(buffer, bufferSize);
7.346 -
7.347 - return result;
7.348 -}
7.349 -
7.350 -@end
7.351 -
7.352 -
7.353 -
7.354 -#ifdef main
7.355 -# undef main
7.356 -#endif
7.357 -
7.358 -
7.359 -/* Main entry point to executable - should *not* be SDL_main! */
7.360 -int main (int argc, char **argv)
7.361 -{
7.362 - /* Copy the arguments into a global variable */
7.363 - /* This is passed if we are launched by double-clicking */
7.364 - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
7.365 - gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
7.366 - gArgv[0] = argv[0];
7.367 - gArgv[1] = NULL;
7.368 - gArgc = 1;
7.369 - gFinderLaunch = YES;
7.370 - } else {
7.371 - int i;
7.372 - gArgc = argc;
7.373 - gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
7.374 - for (i = 0; i <= argc; i++)
7.375 - gArgv[i] = argv[i];
7.376 - gFinderLaunch = NO;
7.377 - }
7.378 -
7.379 -#if SDL_USE_NIB_FILE
7.380 - [SDLApplication poseAsClass:[NSApplication class]];
7.381 - NSApplicationMain (argc, argv);
7.382 -#else
7.383 - CustomApplicationMain (argc, argv);
7.384 -#endif
7.385 - return 0;
7.386 -}
7.387 -
8.1 --- a/src/main/macosx/SDLMain.nib/classes.nib Sun Jul 23 00:55:25 2006 +0000
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,12 +0,0 @@
8.4 -{
8.5 - IBClasses = (
8.6 - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
8.7 - {
8.8 - ACTIONS = {makeFullscreen = id; quit = id; };
8.9 - CLASS = SDLMain;
8.10 - LANGUAGE = ObjC;
8.11 - SUPERCLASS = NSObject;
8.12 - }
8.13 - );
8.14 - IBVersion = 1;
8.15 -}
9.1 --- a/src/main/macosx/SDLMain.nib/info.nib Sun Jul 23 00:55:25 2006 +0000
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,12 +0,0 @@
9.4 -<?xml version="1.0" encoding="UTF-8"?>
9.5 -<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
9.6 -<plist version="0.9">
9.7 -<dict>
9.8 - <key>IBDocumentLocation</key>
9.9 - <string>49 97 356 240 0 0 987 746 </string>
9.10 - <key>IBMainMenuLocation</key>
9.11 - <string>20 515 195 44 0 46 800 532 </string>
9.12 - <key>IBUserGuides</key>
9.13 - <dict/>
9.14 -</dict>
9.15 -</plist>
10.1 Binary file src/main/macosx/SDLMain.nib/objects.nib has changed
11.1 --- a/src/main/macosx/info.nib Sun Jul 23 00:55:25 2006 +0000
11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3 @@ -1,1 +0,0 @@
11.4 -// This is just a stub file to force automake to create the install directory
12.1 --- a/src/video/SDL_sysvideo.h Sun Jul 23 00:55:25 2006 +0000
12.2 +++ b/src/video/SDL_sysvideo.h Sun Jul 23 09:11:10 2006 +0000
12.3 @@ -296,8 +296,8 @@
12.4 SDL_VideoDevice *(*create) (int devindex);
12.5 } VideoBootStrap;
12.6
12.7 -#if SDL_VIDEO_DRIVER_QUARTZ
12.8 -extern VideoBootStrap QZ_bootstrap;
12.9 +#if SDL_VIDEO_DRIVER_COCOA
12.10 +extern VideoBootStrap COCOA_bootstrap;
12.11 #endif
12.12 #if SDL_VIDEO_DRIVER_X11
12.13 extern VideoBootStrap X11_bootstrap;
13.1 --- a/src/video/SDL_video.c Sun Jul 23 00:55:25 2006 +0000
13.2 +++ b/src/video/SDL_video.c Sun Jul 23 09:11:10 2006 +0000
13.3 @@ -43,8 +43,8 @@
13.4
13.5 /* Available video drivers */
13.6 static VideoBootStrap *bootstrap[] = {
13.7 -#if SDL_VIDEO_DRIVER_QUARTZ
13.8 - &QZ_bootstrap,
13.9 +#if SDL_VIDEO_DRIVER_COCOA
13.10 + &COCOA_bootstrap,
13.11 #endif
13.12 #if SDL_VIDEO_DRIVER_X11
13.13 &X11_bootstrap,
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/src/video/cocoa/SDL_cocoaevents.h Sun Jul 23 09:11:10 2006 +0000
14.3 @@ -0,0 +1,32 @@
14.4 +/*
14.5 + SDL - Simple DirectMedia Layer
14.6 + Copyright (C) 1997-2006 Sam Lantinga
14.7 +
14.8 + This library is free software; you can redistribute it and/or
14.9 + modify it under the terms of the GNU Lesser General Public
14.10 + License as published by the Free Software Foundation; either
14.11 + version 2.1 of the License, or (at your option) any later version.
14.12 +
14.13 + This library is distributed in the hope that it will be useful,
14.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14.16 + Lesser General Public License for more details.
14.17 +
14.18 + You should have received a copy of the GNU Lesser General Public
14.19 + License along with this library; if not, write to the Free Software
14.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14.21 +
14.22 + Sam Lantinga
14.23 + slouken@libsdl.org
14.24 +*/
14.25 +#include "SDL_config.h"
14.26 +
14.27 +#ifndef _SDL_cocoaevents_h
14.28 +#define _SDL_cocoaevents_h
14.29 +
14.30 +extern void Cocoa_RegisterApp(void);
14.31 +extern void Cocoa_PumpEvents(_THIS);
14.32 +
14.33 +#endif /* _SDL_cocoaevents_h */
14.34 +
14.35 +/* vi: set ts=4 sw=4 expandtab: */
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/src/video/cocoa/SDL_cocoaevents.m Sun Jul 23 09:11:10 2006 +0000
15.3 @@ -0,0 +1,170 @@
15.4 +/*
15.5 + SDL - Simple DirectMedia Layer
15.6 + Copyright (C) 1997-2006 Sam Lantinga
15.7 +
15.8 + This library is free software; you can redistribute it and/or
15.9 + modify it under the terms of the GNU Lesser General Public
15.10 + License as published by the Free Software Foundation; either
15.11 + version 2.1 of the License, or (at your option) any later version.
15.12 +
15.13 + This library is distributed in the hope that it will be useful,
15.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
15.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15.16 + Lesser General Public License for more details.
15.17 +
15.18 + You should have received a copy of the GNU Lesser General Public
15.19 + License along with this library; if not, write to the Free Software
15.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15.21 +
15.22 + Sam Lantinga
15.23 + slouken@libsdl.org
15.24 +*/
15.25 +#include "SDL_config.h"
15.26 +
15.27 +#include "SDL_cocoavideo.h"
15.28 +
15.29 +/* setAppleMenu disappeared from the headers in 10.4 */
15.30 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
15.31 +@interface NSApplication(NSAppleMenu)
15.32 +- (void)setAppleMenu:(NSMenu *)menu;
15.33 +@end
15.34 +#endif
15.35 +
15.36 +@interface SDLApplication : NSApplication
15.37 +{
15.38 +}
15.39 +- (void)finishLaunching;
15.40 +@end
15.41 +
15.42 +@implementation SDLApplication
15.43 +
15.44 +- (void)finishLaunching
15.45 +{
15.46 + [super finishLaunching];
15.47 + _running = 1;
15.48 +}
15.49 +
15.50 +@end
15.51 +
15.52 +static NSString *
15.53 +GetApplicationName(void)
15.54 +{
15.55 + NSDictionary *dict;
15.56 + NSString *appName = 0;
15.57 +
15.58 + /* Determine the application name */
15.59 + dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
15.60 + if (dict)
15.61 + appName = [dict objectForKey: @"CFBundleName"];
15.62 +
15.63 + if (![appName length])
15.64 + appName = [[NSProcessInfo processInfo] processName];
15.65 +
15.66 + return appName;
15.67 +}
15.68 +
15.69 +static void
15.70 +CreateApplicationMenus(void)
15.71 +{
15.72 + NSString *appName;
15.73 + NSString *title;
15.74 + NSMenu *appleMenu;
15.75 + NSMenu *windowMenu;
15.76 + NSMenuItem *menuItem;
15.77 +
15.78 + /* Create the main menu bar */
15.79 + [NSApp setMainMenu:[[NSMenu alloc] init]];
15.80 +
15.81 + /* Create the application menu */
15.82 + appName = GetApplicationName();
15.83 + appleMenu = [[NSMenu alloc] initWithTitle:@""];
15.84 +
15.85 + /* Add menu items */
15.86 + title = [@"About " stringByAppendingString:appName];
15.87 + [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
15.88 +
15.89 + [appleMenu addItem:[NSMenuItem separatorItem]];
15.90 +
15.91 + title = [@"Hide " stringByAppendingString:appName];
15.92 + [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
15.93 +
15.94 + menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
15.95 + [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
15.96 +
15.97 + [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
15.98 +
15.99 + [appleMenu addItem:[NSMenuItem separatorItem]];
15.100 +
15.101 + title = [@"Quit " stringByAppendingString:appName];
15.102 + [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
15.103 +
15.104 + /* Put menu into the menubar */
15.105 + menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
15.106 + [menuItem setSubmenu:appleMenu];
15.107 + [[NSApp mainMenu] addItem:menuItem];
15.108 + [menuItem release];
15.109 +
15.110 + /* Tell the application object that this is now the application menu */
15.111 + [NSApp setAppleMenu:appleMenu];
15.112 + [appleMenu release];
15.113 +
15.114 +
15.115 + /* Create the window menu */
15.116 + windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
15.117 +
15.118 + /* "Minimize" item */
15.119 + menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
15.120 + [windowMenu addItem:menuItem];
15.121 + [menuItem release];
15.122 +
15.123 + /* Put menu into the menubar */
15.124 + menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
15.125 + [menuItem setSubmenu:windowMenu];
15.126 + [[NSApp mainMenu] addItem:menuItem];
15.127 + [menuItem release];
15.128 +
15.129 + /* Tell the application object that this is now the window menu */
15.130 + [NSApp setWindowsMenu:windowMenu];
15.131 + [windowMenu release];
15.132 +}
15.133 +
15.134 +void
15.135 +Cocoa_RegisterApp(void)
15.136 +{
15.137 + ProcessSerialNumber psn;
15.138 + NSAutoreleasePool *pool;
15.139 +
15.140 + if (!GetCurrentProcess(&psn)) {
15.141 + TransformProcessType(&psn, kProcessTransformToForegroundApplication);
15.142 + SetFrontProcess(&psn);
15.143 + }
15.144 +
15.145 + pool = [[NSAutoreleasePool alloc] init];
15.146 + if (NSApp == nil) {
15.147 + [SDLApplication sharedApplication];
15.148 +
15.149 + if ([NSApp mainMenu] == nil) {
15.150 + CreateApplicationMenus();
15.151 + }
15.152 + [NSApp finishLaunching];
15.153 + }
15.154 + [pool release];
15.155 +}
15.156 +
15.157 +void
15.158 +Cocoa_PumpEvents(_THIS)
15.159 +{
15.160 + NSAutoreleasePool *pool;
15.161 +
15.162 + pool = [[NSAutoreleasePool alloc] init];
15.163 + for ( ; [NSApp isRunning]; ) {
15.164 + NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
15.165 + if ( event == nil ) {
15.166 + break;
15.167 + }
15.168 + [NSApp sendEvent:event];
15.169 + }
15.170 + [pool release];
15.171 +}
15.172 +
15.173 +/* vi: set ts=4 sw=4 expandtab: */
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.h Sun Jul 23 09:11:10 2006 +0000
16.3 @@ -0,0 +1,32 @@
16.4 +/*
16.5 + SDL - Simple DirectMedia Layer
16.6 + Copyright (C) 1997-2006 Sam Lantinga
16.7 +
16.8 + This library is free software; you can redistribute it and/or
16.9 + modify it under the terms of the GNU Lesser General Public
16.10 + License as published by the Free Software Foundation; either
16.11 + version 2.1 of the License, or (at your option) any later version.
16.12 +
16.13 + This library is distributed in the hope that it will be useful,
16.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16.16 + Lesser General Public License for more details.
16.17 +
16.18 + You should have received a copy of the GNU Lesser General Public
16.19 + License along with this library; if not, write to the Free Software
16.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16.21 +
16.22 + Sam Lantinga
16.23 + slouken@libsdl.org
16.24 +*/
16.25 +#include "SDL_config.h"
16.26 +
16.27 +#ifndef _SDL_cocoakeyboard_h
16.28 +#define _SDL_cocoakeyboard_h
16.29 +
16.30 +extern void Cocoa_InitKeyboard(_THIS);
16.31 +extern void Cocoa_QuitKeyboard(_THIS);
16.32 +
16.33 +#endif /* _SDL_cocoakeyboard_h */
16.34 +
16.35 +/* vi: set ts=4 sw=4 expandtab: */
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m Sun Jul 23 09:11:10 2006 +0000
17.3 @@ -0,0 +1,46 @@
17.4 +/*
17.5 + SDL - Simple DirectMedia Layer
17.6 + Copyright (C) 1997-2006 Sam Lantinga
17.7 +
17.8 + This library is free software; you can redistribute it and/or
17.9 + modify it under the terms of the GNU Lesser General Public
17.10 + License as published by the Free Software Foundation; either
17.11 + version 2.1 of the License, or (at your option) any later version.
17.12 +
17.13 + This library is distributed in the hope that it will be useful,
17.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
17.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17.16 + Lesser General Public License for more details.
17.17 +
17.18 + You should have received a copy of the GNU Lesser General Public
17.19 + License along with this library; if not, write to the Free Software
17.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17.21 +
17.22 + Sam Lantinga
17.23 + slouken@libsdl.org
17.24 +*/
17.25 +#include "SDL_config.h"
17.26 +
17.27 +#include "SDL_cocoavideo.h"
17.28 +
17.29 +#include "../../events/SDL_keyboard_c.h"
17.30 +
17.31 +void
17.32 +Cocoa_InitKeyboard(_THIS)
17.33 +{
17.34 + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
17.35 + SDL_Keyboard keyboard;
17.36 +
17.37 + SDL_zero(keyboard);
17.38 + data->keyboard = SDL_AddKeyboard(&keyboard, -1);
17.39 +}
17.40 +
17.41 +void
17.42 +Cocoa_QuitKeyboard(_THIS)
17.43 +{
17.44 + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
17.45 +
17.46 + SDL_DelKeyboard(data->keyboard);
17.47 +}
17.48 +
17.49 +/* vi: set ts=4 sw=4 expandtab: */
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/src/video/cocoa/SDL_cocoamodes.h Sun Jul 23 09:11:10 2006 +0000
18.3 @@ -0,0 +1,34 @@
18.4 +/*
18.5 + SDL - Simple DirectMedia Layer
18.6 + Copyright (C) 1997-2006 Sam Lantinga
18.7 +
18.8 + This library is free software; you can redistribute it and/or
18.9 + modify it under the terms of the GNU Lesser General Public
18.10 + License as published by the Free Software Foundation; either
18.11 + version 2.1 of the License, or (at your option) any later version.
18.12 +
18.13 + This library is distributed in the hope that it will be useful,
18.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
18.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18.16 + Lesser General Public License for more details.
18.17 +
18.18 + You should have received a copy of the GNU Lesser General Public
18.19 + License along with this library; if not, write to the Free Software
18.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18.21 +
18.22 + Sam Lantinga
18.23 + slouken@libsdl.org
18.24 +*/
18.25 +#include "SDL_config.h"
18.26 +
18.27 +#ifndef _SDL_cocoamodes_h
18.28 +#define _SDL_cocoamodes_h
18.29 +
18.30 +extern void Cocoa_InitModes(_THIS);
18.31 +extern void Cocoa_GetDisplayModes(_THIS);
18.32 +extern int Cocoa_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
18.33 +extern void Cocoa_QuitModes(_THIS);
18.34 +
18.35 +#endif /* _SDL_cocoamodes_h */
18.36 +
18.37 +/* vi: set ts=4 sw=4 expandtab: */
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/src/video/cocoa/SDL_cocoamodes.m Sun Jul 23 09:11:10 2006 +0000
19.3 @@ -0,0 +1,56 @@
19.4 +/*
19.5 + SDL - Simple DirectMedia Layer
19.6 + Copyright (C) 1997-2006 Sam Lantinga
19.7 +
19.8 + This library is free software; you can redistribute it and/or
19.9 + modify it under the terms of the GNU Lesser General Public
19.10 + License as published by the Free Software Foundation; either
19.11 + version 2.1 of the License, or (at your option) any later version.
19.12 +
19.13 + This library is distributed in the hope that it will be useful,
19.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
19.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19.16 + Lesser General Public License for more details.
19.17 +
19.18 + You should have received a copy of the GNU Lesser General Public
19.19 + License along with this library; if not, write to the Free Software
19.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19.21 +
19.22 + Sam Lantinga
19.23 + slouken@libsdl.org
19.24 +*/
19.25 +#include "SDL_config.h"
19.26 +
19.27 +#include "SDL_cocoavideo.h"
19.28 +
19.29 +
19.30 +void
19.31 +Cocoa_InitModes(_THIS)
19.32 +{
19.33 + SDL_VideoDisplay display;
19.34 + SDL_DisplayMode mode;
19.35 +
19.36 + SDL_zero(display);
19.37 + SDL_zero(mode);
19.38 + display.desktop_mode = mode;
19.39 + display.current_mode = mode;
19.40 + SDL_AddVideoDisplay(&display);
19.41 +}
19.42 +
19.43 +void
19.44 +Cocoa_GetDisplayModes(_THIS)
19.45 +{
19.46 +}
19.47 +
19.48 +int
19.49 +Cocoa_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
19.50 +{
19.51 + return -1;
19.52 +}
19.53 +
19.54 +void
19.55 +Cocoa_QuitModes(_THIS)
19.56 +{
19.57 +}
19.58 +
19.59 +/* vi: set ts=4 sw=4 expandtab: */
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/src/video/cocoa/SDL_cocoamouse.h Sun Jul 23 09:11:10 2006 +0000
20.3 @@ -0,0 +1,32 @@
20.4 +/*
20.5 + SDL - Simple DirectMedia Layer
20.6 + Copyright (C) 1997-2006 Sam Lantinga
20.7 +
20.8 + This library is free software; you can redistribute it and/or
20.9 + modify it under the terms of the GNU Lesser General Public
20.10 + License as published by the Free Software Foundation; either
20.11 + version 2.1 of the License, or (at your option) any later version.
20.12 +
20.13 + This library is distributed in the hope that it will be useful,
20.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
20.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20.16 + Lesser General Public License for more details.
20.17 +
20.18 + You should have received a copy of the GNU Lesser General Public
20.19 + License along with this library; if not, write to the Free Software
20.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20.21 +
20.22 + Sam Lantinga
20.23 + slouken@libsdl.org
20.24 +*/
20.25 +#include "SDL_config.h"
20.26 +
20.27 +#ifndef _SDL_cocoamouse_h
20.28 +#define _SDL_cocoamouse_h
20.29 +
20.30 +extern void Cocoa_InitMouse(_THIS);
20.31 +extern void Cocoa_QuitMouse(_THIS);
20.32 +
20.33 +#endif /* _SDL_cocoamouse_h */
20.34 +
20.35 +/* vi: set ts=4 sw=4 expandtab: */
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/src/video/cocoa/SDL_cocoamouse.m Sun Jul 23 09:11:10 2006 +0000
21.3 @@ -0,0 +1,46 @@
21.4 +/*
21.5 + SDL - Simple DirectMedia Layer
21.6 + Copyright (C) 1997-2006 Sam Lantinga
21.7 +
21.8 + This library is free software; you can redistribute it and/or
21.9 + modify it under the terms of the GNU Lesser General Public
21.10 + License as published by the Free Software Foundation; either
21.11 + version 2.1 of the License, or (at your option) any later version.
21.12 +
21.13 + This library is distributed in the hope that it will be useful,
21.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21.16 + Lesser General Public License for more details.
21.17 +
21.18 + You should have received a copy of the GNU Lesser General Public
21.19 + License along with this library; if not, write to the Free Software
21.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21.21 +
21.22 + Sam Lantinga
21.23 + slouken@libsdl.org
21.24 +*/
21.25 +#include "SDL_config.h"
21.26 +
21.27 +#include "SDL_cocoavideo.h"
21.28 +
21.29 +#include "../../events/SDL_mouse_c.h"
21.30 +
21.31 +void
21.32 +Cocoa_InitMouse(_THIS)
21.33 +{
21.34 + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
21.35 + SDL_Mouse mouse;
21.36 +
21.37 + SDL_zero(mouse);
21.38 + data->mouse = SDL_AddMouse(&mouse, -1);
21.39 +}
21.40 +
21.41 +void
21.42 +Cocoa_QuitMouse(_THIS)
21.43 +{
21.44 + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
21.45 +
21.46 + SDL_DelMouse(data->mouse);
21.47 +}
21.48 +
21.49 +/* vi: set ts=4 sw=4 expandtab: */
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
22.2 +++ b/src/video/cocoa/SDL_cocoavideo.h Sun Jul 23 09:11:10 2006 +0000
22.3 @@ -0,0 +1,50 @@
22.4 +/*
22.5 + SDL - Simple DirectMedia Layer
22.6 + Copyright (C) 1997-2006 Sam Lantinga
22.7 +
22.8 + This library is free software; you can redistribute it and/or
22.9 + modify it under the terms of the GNU Lesser General Public
22.10 + License as published by the Free Software Foundation; either
22.11 + version 2.1 of the License, or (at your option) any later version.
22.12 +
22.13 + This library is distributed in the hope that it will be useful,
22.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
22.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22.16 + Lesser General Public License for more details.
22.17 +
22.18 + You should have received a copy of the GNU Lesser General Public
22.19 + License along with this library; if not, write to the Free Software
22.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22.21 +
22.22 + Sam Lantinga
22.23 + slouken@libsdl.org
22.24 +*/
22.25 +#include "SDL_config.h"
22.26 +
22.27 +#ifndef _SDL_cocoavideo_h
22.28 +#define _SDL_cocoavideo_h
22.29 +
22.30 +#include <Cocoa/Cocoa.h>
22.31 +
22.32 +#include "../SDL_sysvideo.h"
22.33 +
22.34 +#include "SDL_cocoaevents.h"
22.35 +#include "SDL_cocoakeyboard.h"
22.36 +#include "SDL_cocoamodes.h"
22.37 +#include "SDL_cocoamouse.h"
22.38 +/*
22.39 +#include "SDL_cocoaopengl.h"
22.40 +#include "SDL_cocoawindow.h"
22.41 +*/
22.42 +
22.43 +/* Private display data */
22.44 +
22.45 +typedef struct SDL_VideoData
22.46 +{
22.47 + int mouse;
22.48 + int keyboard;
22.49 +} SDL_VideoData;
22.50 +
22.51 +#endif /* _SDL_cocoavideo_h */
22.52 +
22.53 +/* vi: set ts=4 sw=4 expandtab: */
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/src/video/cocoa/SDL_cocoavideo.m Sun Jul 23 09:11:10 2006 +0000
23.3 @@ -0,0 +1,132 @@
23.4 +/*
23.5 + SDL - Simple DirectMedia Layer
23.6 + Copyright (C) 1997-2006 Sam Lantinga
23.7 +
23.8 + This library is free software; you can redistribute it and/or
23.9 + modify it under the terms of the GNU Lesser General Public
23.10 + License as published by the Free Software Foundation; either
23.11 + version 2.1 of the License, or (at your option) any later version.
23.12 +
23.13 + This library is distributed in the hope that it will be useful,
23.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
23.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23.16 + Lesser General Public License for more details.
23.17 +
23.18 + You should have received a copy of the GNU Lesser General Public
23.19 + License along with this library; if not, write to the Free Software
23.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23.21 +
23.22 + Sam Lantinga
23.23 + slouken@libsdl.org
23.24 +*/
23.25 +#include "SDL_config.h"
23.26 +
23.27 +#include "SDL_cocoavideo.h"
23.28 +
23.29 +/* Initialization/Query functions */
23.30 +static int Cocoa_VideoInit(_THIS);
23.31 +static void Cocoa_VideoQuit(_THIS);
23.32 +
23.33 +/* Cocoa driver bootstrap functions */
23.34 +
23.35 +static int
23.36 +Cocoa_Available(void)
23.37 +{
23.38 + return (1);
23.39 +}
23.40 +
23.41 +static void
23.42 +Cocoa_DeleteDevice(SDL_VideoDevice * device)
23.43 +{
23.44 + SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
23.45 +
23.46 + SDL_free(device->driverdata);
23.47 + SDL_free(device);
23.48 +}
23.49 +
23.50 +static SDL_VideoDevice *
23.51 +Cocoa_CreateDevice(int devindex)
23.52 +{
23.53 + SDL_VideoDevice *device;
23.54 + SDL_VideoData *data;
23.55 +
23.56 + Cocoa_RegisterApp();
23.57 +
23.58 + /* Initialize all variables that we clean on shutdown */
23.59 + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
23.60 + if (device) {
23.61 + data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
23.62 + }
23.63 + if (!device || !data) {
23.64 + SDL_OutOfMemory();
23.65 + if (device) {
23.66 + SDL_free(device);
23.67 + }
23.68 + return NULL;
23.69 + }
23.70 + device->driverdata = data;
23.71 +
23.72 + /* Set the function pointers */
23.73 + device->VideoInit = Cocoa_VideoInit;
23.74 + device->VideoQuit = Cocoa_VideoQuit;
23.75 + device->GetDisplayModes = Cocoa_GetDisplayModes;
23.76 + device->SetDisplayMode = Cocoa_SetDisplayMode;
23.77 + device->PumpEvents = Cocoa_PumpEvents;
23.78 +
23.79 + /*
23.80 + device->CreateWindow = Cocoa_CreateWindow;
23.81 + device->CreateWindowFrom = Cocoa_CreateWindowFrom;
23.82 + device->SetWindowTitle = Cocoa_SetWindowTitle;
23.83 + device->SetWindowPosition = Cocoa_SetWindowPosition;
23.84 + device->SetWindowSize = Cocoa_SetWindowSize;
23.85 + device->ShowWindow = Cocoa_ShowWindow;
23.86 + device->HideWindow = Cocoa_HideWindow;
23.87 + device->RaiseWindow = Cocoa_RaiseWindow;
23.88 + device->MaximizeWindow = Cocoa_MaximizeWindow;
23.89 + device->MinimizeWindow = Cocoa_MinimizeWindow;
23.90 + device->RestoreWindow = Cocoa_RestoreWindow;
23.91 + device->SetWindowGrab = Cocoa_SetWindowGrab;
23.92 + device->DestroyWindow = Cocoa_DestroyWindow;
23.93 + device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
23.94 +#ifdef SDL_VIDEO_OPENGL
23.95 + device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
23.96 + device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
23.97 + device->GL_GetWindowAttribute = Cocoa_GL_GetWindowAttribute;
23.98 + device->GL_CreateContext = Cocoa_GL_CreateContext;
23.99 + device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
23.100 + device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
23.101 + device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
23.102 + device->GL_SwapWindow = Cocoa_GL_SwapWindow;
23.103 + device->GL_DeleteContext = Cocoa_GL_DeleteContext;
23.104 +#endif
23.105 + */
23.106 +
23.107 + device->free = Cocoa_DeleteDevice;
23.108 +
23.109 + return device;
23.110 +}
23.111 +
23.112 +VideoBootStrap COCOA_bootstrap = {
23.113 + "cocoa", "SDL Cocoa video driver",
23.114 + Cocoa_Available, Cocoa_CreateDevice
23.115 +};
23.116 +
23.117 +
23.118 +int
23.119 +Cocoa_VideoInit(_THIS)
23.120 +{
23.121 + Cocoa_InitModes(_this);
23.122 + Cocoa_InitKeyboard(_this);
23.123 + Cocoa_InitMouse(_this);
23.124 + return 0;
23.125 +}
23.126 +
23.127 +void
23.128 +Cocoa_VideoQuit(_THIS)
23.129 +{
23.130 + Cocoa_QuitModes(_this);
23.131 + Cocoa_QuitKeyboard(_this);
23.132 + Cocoa_QuitMouse(_this);
23.133 +}
23.134 +
23.135 +/* vim: set ts=4 sw=4 expandtab: */
24.1 --- a/src/video/quartz/CGS.h Sun Jul 23 00:55:25 2006 +0000
24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
24.3 @@ -1,85 +0,0 @@
24.4 -/*
24.5 - SDL - Simple DirectMedia Layer
24.6 - Copyright (C) 1997-2003 Sam Lantinga
24.7 -
24.8 - This library is free software; you can redistribute it and/or
24.9 - modify it under the terms of the GNU Library General Public
24.10 - License as published by the Free Software Foundation; either
24.11 - version 2 of the License, or (at your option) any later version.
24.12 -
24.13 - This library is distributed in the hope that it will be useful,
24.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
24.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24.16 - Library General Public License for more details.
24.17 -
24.18 - You should have received a copy of the GNU Library General Public
24.19 - License along with this library; if not, write to the Free
24.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24.21 -
24.22 - Sam Lantinga
24.23 - slouken@libsdl.org
24.24 -*/
24.25 -#include "SDL_config.h"
24.26 -
24.27 -/*
24.28 - Obscuring code: maximum number of windows above ours (inclusive)
24.29 -
24.30 - Note: this doesn't work too well in practice and should be
24.31 - phased out when we add OpenGL 2D acceleration. It was never
24.32 - enabled in the first place, so this shouldn't be a problem ;-)
24.33 -*/
24.34 -#define kMaxWindows 256
24.35 -
24.36 -/* Some of the Core Graphics Server API for obscuring code */
24.37 -#define kCGSWindowLevelTop 2147483632
24.38 -#define kCGSWindowLevelDockIconDrag 500
24.39 -#define kCGSWindowLevelDockMenu 101
24.40 -#define kCGSWindowLevelMenuIgnore 21
24.41 -#define kCGSWindowLevelMenu 20
24.42 -#define kCGSWindowLevelDockLabel 12
24.43 -#define kCGSWindowLevelDockIcon 11
24.44 -#define kCGSWindowLevelDock 10
24.45 -#define kCGSWindowLevelUtility 3
24.46 -#define kCGSWindowLevelNormal 0
24.47 -
24.48 -/*
24.49 - For completeness; We never use these window levels, they are always below us
24.50 - #define kCGSWindowLevelMBarShadow -20
24.51 - #define kCGSWindowLevelDesktopPicture -2147483647
24.52 - #define kCGSWindowLevelDesktop -2147483648
24.53 -*/
24.54 -
24.55 -typedef CGError CGSError;
24.56 -typedef long CGSWindowCount;
24.57 -typedef void *CGSConnectionID;
24.58 -typedef int CGSWindowID;
24.59 -typedef CGSWindowID *CGSWindowIDList;
24.60 -typedef CGWindowLevel CGSWindowLevel;
24.61 -typedef NSRect CGSRect;
24.62 -
24.63 -extern CGSConnectionID _CGSDefaultConnection();
24.64 -
24.65 -extern CGSError CGSGetOnScreenWindowList(CGSConnectionID cid,
24.66 - CGSConnectionID owner,
24.67 - CGSWindowCount listCapacity,
24.68 - CGSWindowIDList list,
24.69 - CGSWindowCount * listCount);
24.70 -
24.71 -extern CGSError CGSGetScreenRectForWindow(CGSConnectionID cid,
24.72 - CGSWindowID wid, CGSRect * rect);
24.73 -
24.74 -extern CGWindowLevel CGSGetWindowLevel(CGSConnectionID cid,
24.75 - CGSWindowID wid,
24.76 - CGSWindowLevel * level);
24.77 -
24.78 -extern CGSError CGSDisplayHWFill(CGDirectDisplayID id, unsigned int x,
24.79 - unsigned int y, unsigned int w,
24.80 - unsigned int h, unsigned int color);
24.81 -
24.82 -extern CGSError CGSDisplayCanHWFill(CGDirectDisplayID id);
24.83 -
24.84 -extern CGSError CGSGetMouseEnabledFlags(CGSConnectionID cid, CGSWindowID wid,
24.85 - int *flags);
24.86 -
24.87 -int CGSDisplayHWSync(CGDirectDisplayID id);
24.88 -/* vi: set ts=4 sw=4 expandtab: */
25.1 --- a/src/video/quartz/SDL_QuartzEvents.m Sun Jul 23 00:55:25 2006 +0000
25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
25.3 @@ -1,1002 +0,0 @@
25.4 -/*
25.5 - SDL - Simple DirectMedia Layer
25.6 - Copyright (C) 1997-2003 Sam Lantinga
25.7 -
25.8 - This library is free software; you can redistribute it and/or
25.9 - modify it under the terms of the GNU Library General Public
25.10 - License as published by the Free Software Foundation; either
25.11 - version 2 of the License, or (at your option) any later version.
25.12 -
25.13 - This library is distributed in the hope that it will be useful,
25.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
25.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25.16 - Library General Public License for more details.
25.17 -
25.18 - You should have received a copy of the GNU Library General Public
25.19 - License along with this library; if not, write to the Free
25.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25.21 -
25.22 - Sam Lantinga
25.23 - slouken@libsdl.org
25.24 -*/
25.25 -#include "SDL_config.h"
25.26 -
25.27 -#include "SDL_QuartzVideo.h"
25.28 -
25.29 -#include <IOKit/IOMessage.h> /* For wake from sleep detection */
25.30 -#include <IOKit/pwr_mgt/IOPMLib.h> /* For wake from sleep detection */
25.31 -#include "SDL_QuartzKeys.h"
25.32 -
25.33 -/*
25.34 - * In Panther, this header defines device dependent masks for
25.35 - * right side keys. These definitions only exist in Panther, but
25.36 - * the header seems to exist at least in Jaguar and probably earlier
25.37 - * versions of the OS, so this should't break anything.
25.38 - */
25.39 -#include <IOKit/hidsystem/IOLLEvent.h>
25.40 -/*
25.41 - * These are not defined before Panther. To keep the code compiling
25.42 - * on systems without these, I will define if they don't exist.
25.43 - */
25.44 -#ifndef NX_DEVICERCTLKEYMASK
25.45 -#define NX_DEVICELCTLKEYMASK 0x00000001
25.46 -#endif
25.47 -#ifndef NX_DEVICELSHIFTKEYMASK
25.48 -#define NX_DEVICELSHIFTKEYMASK 0x00000002
25.49 -#endif
25.50 -#ifndef NX_DEVICERSHIFTKEYMASK
25.51 -#define NX_DEVICERSHIFTKEYMASK 0x00000004
25.52 -#endif
25.53 -#ifndef NX_DEVICELCMDKEYMASK
25.54 -#define NX_DEVICELCMDKEYMASK 0x00000008
25.55 -#endif
25.56 -#ifndef NX_DEVICERCMDKEYMASK
25.57 -#define NX_DEVICERCMDKEYMASK 0x00000010
25.58 -#endif
25.59 -#ifndef NX_DEVICELALTKEYMASK
25.60 -#define NX_DEVICELALTKEYMASK 0x00000020
25.61 -#endif
25.62 -#ifndef NX_DEVICERALTKEYMASK
25.63 -#define NX_DEVICERALTKEYMASK 0x00000040
25.64 -#endif
25.65 -#ifndef NX_DEVICERCTLKEYMASK
25.66 -#define NX_DEVICERCTLKEYMASK 0x00002000
25.67 -#endif
25.68 -
25.69 -void
25.70 -QZ_InitOSKeymap (_THIS)
25.71 -{
25.72 - const void *KCHRPtr;
25.73 - UInt32 state;
25.74 - UInt32 value;
25.75 - int i;
25.76 - int world = SDLK_WORLD_0;
25.77 -
25.78 - for (i = 0; i < SDL_TABLESIZE (keymap); ++i)
25.79 - keymap[i] = SDLK_UNKNOWN;
25.80 -
25.81 - /* This keymap is almost exactly the same as the OS 9 one */
25.82 - keymap[QZ_ESCAPE] = SDLK_ESCAPE;
25.83 - keymap[QZ_F1] = SDLK_F1;
25.84 - keymap[QZ_F2] = SDLK_F2;
25.85 - keymap[QZ_F3] = SDLK_F3;
25.86 - keymap[QZ_F4] = SDLK_F4;
25.87 - keymap[QZ_F5] = SDLK_F5;
25.88 - keymap[QZ_F6] = SDLK_F6;
25.89 - keymap[QZ_F7] = SDLK_F7;
25.90 - keymap[QZ_F8] = SDLK_F8;
25.91 - keymap[QZ_F9] = SDLK_F9;
25.92 - keymap[QZ_F10] = SDLK_F10;
25.93 - keymap[QZ_F11] = SDLK_F11;
25.94 - keymap[QZ_F12] = SDLK_F12;
25.95 - keymap[QZ_PRINT] = SDLK_PRINT;
25.96 - keymap[QZ_SCROLLOCK] = SDLK_SCROLLOCK;
25.97 - keymap[QZ_PAUSE] = SDLK_PAUSE;
25.98 - keymap[QZ_POWER] = SDLK_POWER;
25.99 - keymap[QZ_BACKQUOTE] = SDLK_BACKQUOTE;
25.100 - keymap[QZ_1] = SDLK_1;
25.101 - keymap[QZ_2] = SDLK_2;
25.102 - keymap[QZ_3] = SDLK_3;
25.103 - keymap[QZ_4] = SDLK_4;
25.104 - keymap[QZ_5] = SDLK_5;
25.105 - keymap[QZ_6] = SDLK_6;
25.106 - keymap[QZ_7] = SDLK_7;
25.107 - keymap[QZ_8] = SDLK_8;
25.108 - keymap[QZ_9] = SDLK_9;
25.109 - keymap[QZ_0] = SDLK_0;
25.110 - keymap[QZ_MINUS] = SDLK_MINUS;
25.111 - keymap[QZ_EQUALS] = SDLK_EQUALS;
25.112 - keymap[QZ_BACKSPACE] = SDLK_BACKSPACE;
25.113 - keymap[QZ_INSERT] = SDLK_INSERT;
25.114 - keymap[QZ_HOME] = SDLK_HOME;
25.115 - keymap[QZ_PAGEUP] = SDLK_PAGEUP;
25.116 - keymap[QZ_NUMLOCK] = SDLK_NUMLOCK;
25.117 - keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
25.118 - keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
25.119 - keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
25.120 - keymap[QZ_TAB] = SDLK_TAB;
25.121 - keymap[QZ_q] = SDLK_q;
25.122 - keymap[QZ_w] = SDLK_w;
25.123 - keymap[QZ_e] = SDLK_e;
25.124 - keymap[QZ_r] = SDLK_r;
25.125 - keymap[QZ_t] = SDLK_t;
25.126 - keymap[QZ_y] = SDLK_y;
25.127 - keymap[QZ_u] = SDLK_u;
25.128 - keymap[QZ_i] = SDLK_i;
25.129 - keymap[QZ_o] = SDLK_o;
25.130 - keymap[QZ_p] = SDLK_p;
25.131 - keymap[QZ_LEFTBRACKET] = SDLK_LEFTBRACKET;
25.132 - keymap[QZ_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
25.133 - keymap[QZ_BACKSLASH] = SDLK_BACKSLASH;
25.134 - keymap[QZ_DELETE] = SDLK_DELETE;
25.135 - keymap[QZ_END] = SDLK_END;
25.136 - keymap[QZ_PAGEDOWN] = SDLK_PAGEDOWN;
25.137 - keymap[QZ_KP7] = SDLK_KP7;
25.138 - keymap[QZ_KP8] = SDLK_KP8;
25.139 - keymap[QZ_KP9] = SDLK_KP9;
25.140 - keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
25.141 - keymap[QZ_CAPSLOCK] = SDLK_CAPSLOCK;
25.142 - keymap[QZ_a] = SDLK_a;
25.143 - keymap[QZ_s] = SDLK_s;
25.144 - keymap[QZ_d] = SDLK_d;
25.145 - keymap[QZ_f] = SDLK_f;
25.146 - keymap[QZ_g] = SDLK_g;
25.147 - keymap[QZ_h] = SDLK_h;
25.148 - keymap[QZ_j] = SDLK_j;
25.149 - keymap[QZ_k] = SDLK_k;
25.150 - keymap[QZ_l] = SDLK_l;
25.151 - keymap[QZ_SEMICOLON] = SDLK_SEMICOLON;
25.152 - keymap[QZ_QUOTE] = SDLK_QUOTE;
25.153 - keymap[QZ_RETURN] = SDLK_RETURN;
25.154 - keymap[QZ_KP4] = SDLK_KP4;
25.155 - keymap[QZ_KP5] = SDLK_KP5;
25.156 - keymap[QZ_KP6] = SDLK_KP6;
25.157 - keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
25.158 - keymap[QZ_LSHIFT] = SDLK_LSHIFT;
25.159 - keymap[QZ_RSHIFT] = SDLK_RSHIFT;
25.160 - keymap[QZ_z] = SDLK_z;
25.161 - keymap[QZ_x] = SDLK_x;
25.162 - keymap[QZ_c] = SDLK_c;
25.163 - keymap[QZ_v] = SDLK_v;
25.164 - keymap[QZ_b] = SDLK_b;
25.165 - keymap[QZ_n] = SDLK_n;
25.166 - keymap[QZ_m] = SDLK_m;
25.167 - keymap[QZ_COMMA] = SDLK_COMMA;
25.168 - keymap[QZ_PERIOD] = SDLK_PERIOD;
25.169 - keymap[QZ_SLASH] = SDLK_SLASH;
25.170 - keymap[QZ_UP] = SDLK_UP;
25.171 - keymap[QZ_KP1] = SDLK_KP1;
25.172 - keymap[QZ_KP2] = SDLK_KP2;
25.173 - keymap[QZ_KP3] = SDLK_KP3;
25.174 - keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
25.175 - keymap[QZ_LCTRL] = SDLK_LCTRL;
25.176 - keymap[QZ_LALT] = SDLK_LALT;
25.177 - keymap[QZ_LMETA] = SDLK_LMETA;
25.178 - keymap[QZ_RCTRL] = SDLK_RCTRL;
25.179 - keymap[QZ_RALT] = SDLK_RALT;
25.180 - keymap[QZ_RMETA] = SDLK_RMETA;
25.181 - keymap[QZ_SPACE] = SDLK_SPACE;
25.182 - keymap[QZ_LEFT] = SDLK_LEFT;
25.183 - keymap[QZ_DOWN] = SDLK_DOWN;
25.184 - keymap[QZ_RIGHT] = SDLK_RIGHT;
25.185 - keymap[QZ_KP0] = SDLK_KP0;
25.186 - keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
25.187 - keymap[QZ_IBOOK_ENTER] = SDLK_KP_ENTER;
25.188 - keymap[QZ_IBOOK_RIGHT] = SDLK_RIGHT;
25.189 - keymap[QZ_IBOOK_DOWN] = SDLK_DOWN;
25.190 - keymap[QZ_IBOOK_UP] = SDLK_UP;
25.191 - keymap[QZ_IBOOK_LEFT] = SDLK_LEFT;
25.192 -
25.193 - /*
25.194 - Up there we setup a static scancode->keysym map. However, it will not
25.195 - work very well on international keyboard. Hence we now query MacOS
25.196 - for its own keymap to adjust our own mapping table. However, this is
25.197 - basically only useful for ascii char keys. This is also the reason
25.198 - why we keep the static table, too.
25.199 - */
25.200 -
25.201 - /* Get a pointer to the systems cached KCHR */
25.202 - KCHRPtr = (void *) GetScriptManagerVariable (smKCHRCache);
25.203 - if (KCHRPtr) {
25.204 - /* Loop over all 127 possible scan codes */
25.205 - for (i = 0; i < 0x7F; i++) {
25.206 - /* We pretend a clean start to begin with (i.e. no dead keys active */
25.207 - state = 0;
25.208 -
25.209 - /* Now translate the key code to a key value */
25.210 - value = KeyTranslate (KCHRPtr, i, &state) & 0xff;
25.211 -
25.212 - /* If the state become 0, it was a dead key. We need to translate again,
25.213 - passing in the new state, to get the actual key value */
25.214 - if (state != 0)
25.215 - value = KeyTranslate (KCHRPtr, i, &state) & 0xff;
25.216 -
25.217 - /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
25.218 - if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */
25.219 - keymap[i] = world++;
25.220 - else if (value >= 32) /* non-control ASCII char */
25.221 - keymap[i] = value;
25.222 - }
25.223 - }
25.224 -
25.225 - /*
25.226 - The keypad codes are re-setup here, because the loop above cannot
25.227 - distinguish between a key on the keypad and a regular key. We maybe
25.228 - could get around this problem in another fashion: NSEvent's flags
25.229 - include a "NSNumericPadKeyMask" bit; we could check that and modify
25.230 - the symbol we return on the fly. However, this flag seems to exhibit
25.231 - some weird behaviour related to the num lock key
25.232 - */
25.233 - keymap[QZ_KP0] = SDLK_KP0;
25.234 - keymap[QZ_KP1] = SDLK_KP1;
25.235 - keymap[QZ_KP2] = SDLK_KP2;
25.236 - keymap[QZ_KP3] = SDLK_KP3;
25.237 - keymap[QZ_KP4] = SDLK_KP4;
25.238 - keymap[QZ_KP5] = SDLK_KP5;
25.239 - keymap[QZ_KP6] = SDLK_KP6;
25.240 - keymap[QZ_KP7] = SDLK_KP7;
25.241 - keymap[QZ_KP8] = SDLK_KP8;
25.242 - keymap[QZ_KP9] = SDLK_KP9;
25.243 - keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
25.244 - keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
25.245 - keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
25.246 - keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
25.247 - keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
25.248 - keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
25.249 - keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
25.250 -}
25.251 -
25.252 -static void
25.253 -QZ_DoKey (_THIS, int state, NSEvent * event)
25.254 -{
25.255 -
25.256 - NSString *chars;
25.257 - unsigned int numChars;
25.258 - SDL_keysym key;
25.259 -
25.260 - /*
25.261 - A key event can contain multiple characters,
25.262 - or no characters at all. In most cases, it
25.263 - will contain a single character. If it contains
25.264 - 0 characters, we'll use 0 as the unicode. If it
25.265 - contains multiple characters, we'll use 0 as
25.266 - the scancode/keysym.
25.267 - */
25.268 - chars =[event characters];
25.269 - numChars =[chars length];
25.270 -
25.271 - if (numChars == 1) {
25.272 -
25.273 - key.scancode =[event keyCode];
25.274 - key.sym = keymap[key.scancode];
25.275 - key.unicode =[chars characterAtIndex:0];
25.276 - key.mod = KMOD_NONE;
25.277 -
25.278 - SDL_PrivateKeyboard (state, &key);
25.279 - } else if (numChars == 0) {
25.280 -
25.281 - key.scancode =[event keyCode];
25.282 - key.sym = keymap[key.scancode];
25.283 - key.unicode = 0;
25.284 - key.mod = KMOD_NONE;
25.285 -
25.286 - SDL_PrivateKeyboard (state, &key);
25.287 - } else { /* (numChars > 1) */
25.288 -
25.289 -
25.290 - int i;
25.291 - for (i = 0; i < numChars; i++) {
25.292 -
25.293 - key.scancode = 0;
25.294 - key.sym = 0;
25.295 - key.unicode =[chars characterAtIndex:i];
25.296 - key.mod = KMOD_NONE;
25.297 -
25.298 - SDL_PrivateKeyboard (state, &key);
25.299 - }
25.300 - }
25.301 -
25.302 - if (SDL_getenv ("SDL_ENABLEAPPEVENTS"))
25.303 - [NSApp sendEvent:event];
25.304 -}
25.305 -
25.306 -/* This is the original behavior, before support was added for
25.307 - * differentiating between left and right versions of the keys.
25.308 - */
25.309 -static void
25.310 -QZ_DoUnsidedModifiers (_THIS, unsigned int newMods)
25.311 -{
25.312 -
25.313 - const int mapping[] =
25.314 - { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA };
25.315 -
25.316 - int i;
25.317 - int bit;
25.318 - SDL_keysym key;
25.319 -
25.320 - key.scancode = 0;
25.321 - key.sym = SDLK_UNKNOWN;
25.322 - key.unicode = 0;
25.323 - key.mod = KMOD_NONE;
25.324 -
25.325 - /* Iterate through the bits, testing each against the current modifiers */
25.326 - for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask;
25.327 - bit <<= 1, ++i) {
25.328 -
25.329 - unsigned int currentMask, newMask;
25.330 -
25.331 - currentMask = current_mods & bit;
25.332 - newMask = newMods & bit;
25.333 -
25.334 - if (currentMask && currentMask != newMask) { /* modifier up event */
25.335 -
25.336 - key.sym = mapping[i];
25.337 - /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
25.338 - if (bit == NSAlphaShiftKeyMask)
25.339 - SDL_PrivateKeyboard (SDL_PRESSED, &key);
25.340 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.341 - } else if (newMask && currentMask != newMask) { /* modifier down event */
25.342 -
25.343 - key.sym = mapping[i];
25.344 - SDL_PrivateKeyboard (SDL_PRESSED, &key);
25.345 - /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
25.346 - if (bit == NSAlphaShiftKeyMask)
25.347 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.348 - }
25.349 - }
25.350 -}
25.351 -
25.352 -/* This is a helper function for QZ_HandleModifierSide. This
25.353 - * function reverts back to behavior before the distinction between
25.354 - * sides was made.
25.355 - */
25.356 -static void
25.357 -QZ_HandleNonDeviceModifier (_THIS, unsigned int device_independent_mask,
25.358 - unsigned int newMods, unsigned int key_sym)
25.359 -{
25.360 - unsigned int currentMask, newMask;
25.361 - SDL_keysym key;
25.362 -
25.363 - key.scancode = 0;
25.364 - key.sym = key_sym;
25.365 - key.unicode = 0;
25.366 - key.mod = KMOD_NONE;
25.367 -
25.368 - /* Isolate just the bits we care about in the depedent bits so we can
25.369 - * figure out what changed
25.370 - */
25.371 - currentMask = current_mods & device_independent_mask;
25.372 - newMask = newMods & device_independent_mask;
25.373 -
25.374 - if (currentMask && currentMask != newMask) { /* modifier up event */
25.375 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.376 - } else if (newMask && currentMask != newMask) { /* modifier down event */
25.377 - SDL_PrivateKeyboard (SDL_PRESSED, &key);
25.378 - }
25.379 -}
25.380 -
25.381 -/* This is a helper function for QZ_HandleModifierSide.
25.382 - * This function sets the actual SDL_PrivateKeyboard event.
25.383 - */
25.384 -static void
25.385 -QZ_HandleModifierOneSide (_THIS, unsigned int newMods,
25.386 - unsigned int key_sym,
25.387 - unsigned int sided_device_dependent_mask)
25.388 -{
25.389 -
25.390 - SDL_keysym key;
25.391 - unsigned int current_dep_mask, new_dep_mask;
25.392 -
25.393 - key.scancode = 0;
25.394 - key.sym = key_sym;
25.395 - key.unicode = 0;
25.396 - key.mod = KMOD_NONE;
25.397 -
25.398 - /* Isolate just the bits we care about in the depedent bits so we can
25.399 - * figure out what changed
25.400 - */
25.401 - current_dep_mask = current_mods & sided_device_dependent_mask;
25.402 - new_dep_mask = newMods & sided_device_dependent_mask;
25.403 -
25.404 - /* We now know that this side bit flipped. But we don't know if
25.405 - * it went pressed to released or released to pressed, so we must
25.406 - * find out which it is.
25.407 - */
25.408 - if (new_dep_mask && current_dep_mask != new_dep_mask) {
25.409 - /* Modifier down event */
25.410 - SDL_PrivateKeyboard (SDL_PRESSED, &key);
25.411 - } else { /* Modifier up event */
25.412 -
25.413 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.414 - }
25.415 -}
25.416 -
25.417 -/* This is a helper function for QZ_DoSidedModifiers.
25.418 - * This function will figure out if the modifier key is the left or right side,
25.419 - * e.g. left-shift vs right-shift.
25.420 - */
25.421 -static void
25.422 -QZ_HandleModifierSide (_THIS, int device_independent_mask,
25.423 - unsigned int newMods,
25.424 - unsigned int left_key_sym,
25.425 - unsigned int right_key_sym,
25.426 - unsigned int left_device_dependent_mask,
25.427 - unsigned int right_device_dependent_mask)
25.428 -{
25.429 - unsigned int device_dependent_mask = 0;
25.430 - unsigned int diff_mod = 0;
25.431 -
25.432 - device_dependent_mask =
25.433 - left_device_dependent_mask | right_device_dependent_mask;
25.434 - /* On the basis that the device independent mask is set, but there are
25.435 - * no device dependent flags set, we'll assume that we can't detect this
25.436 - * keyboard and revert to the unsided behavior.
25.437 - */
25.438 - if ((device_dependent_mask & newMods) == 0) {
25.439 - /* Revert to the old behavior */
25.440 - QZ_HandleNonDeviceModifier (this, device_independent_mask, newMods,
25.441 - left_key_sym);
25.442 - return;
25.443 - }
25.444 -
25.445 - /* XOR the previous state against the new state to see if there's a change */
25.446 - diff_mod = (device_dependent_mask & current_mods)
25.447 - ^ (device_dependent_mask & newMods);
25.448 -
25.449 - if (diff_mod) {
25.450 - /* A change in state was found. Isolate the left and right bits
25.451 - * to handle them separately just in case the values can simulataneously
25.452 - * change or if the bits don't both exist.
25.453 - */
25.454 - if (left_device_dependent_mask & diff_mod) {
25.455 - QZ_HandleModifierOneSide (this, newMods, left_key_sym,
25.456 - left_device_dependent_mask);
25.457 - }
25.458 - if (right_device_dependent_mask & diff_mod) {
25.459 - QZ_HandleModifierOneSide (this, newMods, right_key_sym,
25.460 - right_device_dependent_mask);
25.461 - }
25.462 - }
25.463 -}
25.464 -
25.465 -/* This is a helper function for QZ_DoSidedModifiers.
25.466 - * This function will release a key press in the case that
25.467 - * it is clear that the modifier has been released (i.e. one side
25.468 - * can't still be down).
25.469 - */
25.470 -static void
25.471 -QZ_ReleaseModifierSide (_THIS,
25.472 - unsigned int device_independent_mask,
25.473 - unsigned int newMods,
25.474 - unsigned int left_key_sym,
25.475 - unsigned int right_key_sym,
25.476 - unsigned int left_device_dependent_mask,
25.477 - unsigned int right_device_dependent_mask)
25.478 -{
25.479 - unsigned int device_dependent_mask = 0;
25.480 - SDL_keysym key;
25.481 -
25.482 - key.scancode = 0;
25.483 - key.sym = SDLK_UNKNOWN;
25.484 - key.unicode = 0;
25.485 - key.mod = KMOD_NONE;
25.486 -
25.487 - device_dependent_mask =
25.488 - left_device_dependent_mask | right_device_dependent_mask;
25.489 - /* On the basis that the device independent mask is set, but there are
25.490 - * no device dependent flags set, we'll assume that we can't detect this
25.491 - * keyboard and revert to the unsided behavior.
25.492 - */
25.493 - if ((device_dependent_mask & current_mods) == 0) {
25.494 - /* In this case, we can't detect the keyboard, so use the left side
25.495 - * to represent both, and release it.
25.496 - */
25.497 - key.sym = left_key_sym;
25.498 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.499 -
25.500 - return;
25.501 - }
25.502 -
25.503 -
25.504 - /*
25.505 - * This could have been done in an if-else case because at this point,
25.506 - * we know that all keys have been released when calling this function.
25.507 - * But I'm being paranoid so I want to handle each separately,
25.508 - * so I hope this doesn't cause other problems.
25.509 - */
25.510 - if (left_device_dependent_mask & current_mods) {
25.511 - key.sym = left_key_sym;
25.512 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.513 - }
25.514 - if (right_device_dependent_mask & current_mods) {
25.515 - key.sym = right_key_sym;
25.516 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.517 - }
25.518 -}
25.519 -
25.520 -/* This is a helper function for QZ_DoSidedModifiers.
25.521 - * This function handles the CapsLock case.
25.522 - */
25.523 -static void
25.524 -QZ_HandleCapsLock (_THIS, unsigned int newMods)
25.525 -{
25.526 - unsigned int currentMask, newMask;
25.527 - SDL_keysym key;
25.528 -
25.529 - key.scancode = 0;
25.530 - key.sym = SDLK_CAPSLOCK;
25.531 - key.unicode = 0;
25.532 - key.mod = KMOD_NONE;
25.533 -
25.534 - currentMask = current_mods & NSAlphaShiftKeyMask;
25.535 - newMask = newMods & NSAlphaShiftKeyMask;
25.536 -
25.537 - if (currentMask && currentMask != newMask) { /* modifier up event */
25.538 - /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
25.539 - SDL_PrivateKeyboard (SDL_PRESSED, &key);
25.540 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.541 - } else if (newMask && currentMask != newMask) { /* modifier down event */
25.542 - /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
25.543 - SDL_PrivateKeyboard (SDL_PRESSED, &key);
25.544 - SDL_PrivateKeyboard (SDL_RELEASED, &key);
25.545 - }
25.546 -}
25.547 -
25.548 -/* This function will handle the modifier keys and also determine the
25.549 - * correct side of the key.
25.550 - */
25.551 -static void
25.552 -QZ_DoSidedModifiers (_THIS, unsigned int newMods)
25.553 -{
25.554 - /* Set up arrays for the key syms for the left and right side. */
25.555 - const unsigned int left_mapping[] =
25.556 - { SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA };
25.557 - const unsigned int right_mapping[] =
25.558 - { SDLK_RSHIFT, SDLK_RCTRL, SDLK_RALT, SDLK_RMETA };
25.559 - /* Set up arrays for the device dependent masks with indices that
25.560 - * correspond to the _mapping arrays
25.561 - */
25.562 - const unsigned int left_device_mapping[] =
25.563 - { NX_DEVICELSHIFTKEYMASK, NX_DEVICELCTLKEYMASK, NX_DEVICELALTKEYMASK,
25.564 - NX_DEVICELCMDKEYMASK
25.565 - };
25.566 - const unsigned int right_device_mapping[] =
25.567 - { NX_DEVICERSHIFTKEYMASK, NX_DEVICERCTLKEYMASK, NX_DEVICERALTKEYMASK,
25.568 - NX_DEVICERCMDKEYMASK
25.569 - };
25.570 -
25.571 - unsigned int i;
25.572 - unsigned int bit;
25.573 -
25.574 - /* Handle CAPSLOCK separately because it doesn't have a left/right side */
25.575 - QZ_HandleCapsLock (this, newMods);
25.576 -
25.577 - /* Iterate through the bits, testing each against the current modifiers */
25.578 - for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
25.579 -
25.580 - unsigned int currentMask, newMask;
25.581 -
25.582 - currentMask = current_mods & bit;
25.583 - newMask = newMods & bit;
25.584 -
25.585 - /* If the bit is set, we must always examine it because the left
25.586 - * and right side keys may alternate or both may be pressed.
25.587 - */
25.588 - if (newMask) {
25.589 - QZ_HandleModifierSide (this, bit, newMods,
25.590 - left_mapping[i],
25.591 - right_mapping[i],
25.592 - left_device_mapping[i],
25.593 - right_device_mapping[i]);
25.594 - }
25.595 - /* If the state changed from pressed to unpressed, we must examine
25.596 - * the device dependent bits to release the correct keys.
25.597 - */
25.598 - else if (currentMask && currentMask != newMask) { /* modifier up event */
25.599 - QZ_ReleaseModifierSide (this, bit, newMods,
25.600 - left_mapping[i],
25.601 - right_mapping[i],
25.602 - left_device_mapping[i],
25.603 - right_device_mapping[i]);
25.604 - }
25.605 - }
25.606 -}
25.607 -
25.608 -/* This function is called to handle the modifiers.
25.609 - * It will try to distinguish between the left side and right side
25.610 - * of the keyboard for those modifiers that qualify if the
25.611 - * operating system version supports it. Otherwise, the code
25.612 - * will not try to make the distinction.
25.613 - */
25.614 -static void
25.615 -QZ_DoModifiers (_THIS, unsigned int newMods)
25.616 -{
25.617 -
25.618 - if (current_mods == newMods)
25.619 - return;
25.620 -
25.621 - /*
25.622 - * Starting with Panther (10.3.0), the ability to distinguish between
25.623 - * left side and right side modifiers is available.
25.624 - */
25.625 - if (system_version >= 0x1030) {
25.626 - QZ_DoSidedModifiers (this, newMods);
25.627 - } else {
25.628 - QZ_DoUnsidedModifiers (this, newMods);
25.629 - }
25.630 -
25.631 - current_mods = newMods;
25.632 -}
25.633 -
25.634 -static void
25.635 -QZ_GetMouseLocation (_THIS, NSPoint * p)
25.636 -{
25.637 - *p =[NSEvent mouseLocation]; /* global coordinates */
25.638 - if (qz_window)
25.639 - QZ_PrivateGlobalToLocal (this, p);
25.640 - QZ_PrivateCocoaToSDL (this, p);
25.641 -}
25.642 -
25.643 -void
25.644 -QZ_DoActivate (_THIS)
25.645 -{
25.646 -
25.647 - SDL_PrivateAppActive (1,
25.648 - SDL_APPINPUTFOCUS | (QZ_IsMouseInWindow (this) ?
25.649 - SDL_APPMOUSEFOCUS : 0));
25.650 -
25.651 - /* Hide the cursor if it was hidden by SDL_ShowCursor() */
25.652 - if (!cursor_should_be_visible)
25.653 - QZ_HideMouse (this);
25.654 -
25.655 - /* Regrab input, only if it was previously grabbed */
25.656 - if (current_grab_mode == SDL_GRAB_ON) {
25.657 -
25.658 - /* Restore cursor location if input was grabbed */
25.659 - QZ_PrivateWarpCursor (this, cursor_loc.x, cursor_loc.y);
25.660 - QZ_ChangeGrabState (this, QZ_ENABLE_GRAB);
25.661 - } else {
25.662 - /* Update SDL's mouse location */
25.663 - NSPoint p;
25.664 - QZ_GetMouseLocation (this, &p);
25.665 - SDL_PrivateMouseMotion (0, 0, p.x, p.y);
25.666 - }
25.667 -}
25.668 -
25.669 -void
25.670 -QZ_DoDeactivate (_THIS)
25.671 -{
25.672 -
25.673 - SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS);
25.674 -
25.675 - /* Get the current cursor location, for restore on activate */
25.676 - QZ_GetMouseLocation (this, &cursor_loc);
25.677 -
25.678 - /* Reassociate mouse and cursor */
25.679 - CGAssociateMouseAndMouseCursorPosition (1);
25.680 -
25.681 - /* Show the cursor if it was hidden by SDL_ShowCursor() */
25.682 - if (!cursor_should_be_visible)
25.683 - QZ_ShowMouse (this);
25.684 -}
25.685 -
25.686 -void
25.687 -QZ_SleepNotificationHandler (void *refcon,
25.688 - io_service_t service,
25.689 - natural_t messageType, void *messageArgument)
25.690 -{
25.691 - SDL_VideoDevice *this = (SDL_VideoDevice *) refcon;
25.692 -
25.693 - switch (messageType) {
25.694 - case kIOMessageSystemWillSleep:
25.695 - IOAllowPowerChange (power_connection, (long) messageArgument);
25.696 - break;
25.697 - case kIOMessageCanSystemSleep:
25.698 - IOAllowPowerChange (power_connection, (long) messageArgument);
25.699 - break;
25.700 - case kIOMessageSystemHasPoweredOn:
25.701 - /* awake */
25.702 - SDL_PrivateExpose ();
25.703 - break;
25.704 - }
25.705 -}
25.706 -
25.707 -void
25.708 -QZ_RegisterForSleepNotifications (_THIS)
25.709 -{
25.710 - CFRunLoopSourceRef rls;
25.711 - IONotificationPortRef thePortRef;
25.712 - io_object_t notifier;
25.713 -
25.714 - power_connection =
25.715 - IORegisterForSystemPower (this, &thePortRef,
25.716 - QZ_SleepNotificationHandler, ¬ifier);
25.717 -
25.718 - if (power_connection == 0)
25.719 - NSLog
25.720 - (@"SDL: QZ_SleepNotificationHandler() IORegisterForSystemPower failed.");
25.721 -
25.722 - rls = IONotificationPortGetRunLoopSource (thePortRef);
25.723 - CFRunLoopAddSource (CFRunLoopGetCurrent (), rls, kCFRunLoopDefaultMode);
25.724 - CFRelease (rls);
25.725 -}
25.726 -
25.727 -
25.728 -/* Try to map Quartz mouse buttons to SDL's lingo... */
25.729 -static int
25.730 -QZ_OtherMouseButtonToSDL (int button)
25.731 -{
25.732 - switch (button) {
25.733 - case 0:
25.734 - return (SDL_BUTTON_LEFT); /* 1 */
25.735 - case 1:
25.736 - return (SDL_BUTTON_RIGHT); /* 3 */
25.737 - case 2:
25.738 - return (SDL_BUTTON_MIDDLE); /* 2 */
25.739 - }
25.740 -
25.741 - /* >= 3: skip 4 & 5, since those are the SDL mousewheel buttons. */
25.742 - return (button + 3);
25.743 -}
25.744 -
25.745 -
25.746 -void
25.747 -QZ_PumpEvents (_THIS)
25.748 -{
25.749 - static Uint32 screensaverTicks = 0;
25.750 - Uint32 nowTicks;
25.751 - int firstMouseEvent;
25.752 - CGMouseDelta dx, dy;
25.753 -
25.754 - NSDate *distantPast;
25.755 - NSEvent *event;
25.756 - NSRect winRect;
25.757 - NSAutoreleasePool *pool;
25.758 -
25.759 - if (!SDL_VideoSurface)
25.760 - return; /* don't do anything if there's no screen surface. */
25.761 -
25.762 - /* Update activity every five seconds to prevent screensaver. --ryan. */
25.763 - nowTicks = SDL_GetTicks ();
25.764 - if ((nowTicks - screensaverTicks) > 5000) {
25.765 - UpdateSystemActivity (UsrActivity);
25.766 - screensaverTicks = nowTicks;
25.767 - }
25.768 -
25.769 - pool =[[NSAutoreleasePool alloc] init];
25.770 - distantPast =[NSDate distantPast];
25.771 -
25.772 - winRect = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
25.773 -
25.774 - /* send the first mouse event in absolute coordinates */
25.775 - firstMouseEvent = 1;
25.776 -
25.777 - /* accumulate any additional mouse moved events into one SDL mouse event */
25.778 - dx = 0;
25.779 - dy = 0;
25.780 -
25.781 - do {
25.782 -
25.783 - /* Poll for an event. This will not block */
25.784 - event =[NSApp nextEventMatchingMask: NSAnyEventMask untilDate: distantPast inMode: NSDefaultRunLoopMode dequeue:YES];
25.785 - if (event != nil) {
25.786 -
25.787 - int button;
25.788 - unsigned int type;
25.789 - BOOL isInGameWin;
25.790 -
25.791 -#define DO_MOUSE_DOWN(button) do { \
25.792 - if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { \
25.793 - SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \
25.794 - expect_mouse_up |= 1<<button; \
25.795 - } \
25.796 - [ NSApp sendEvent:event ]; \
25.797 - } while(0)
25.798 -
25.799 -#define DO_MOUSE_UP(button) do { \
25.800 - if ( expect_mouse_up & (1<<button) ) { \
25.801 - SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); \
25.802 - expect_mouse_up &= ~(1<<button); \
25.803 - } \
25.804 - [ NSApp sendEvent:event ]; \
25.805 - } while(0)
25.806 -
25.807 - type =[event type];
25.808 - isInGameWin = QZ_IsMouseInWindow (this);
25.809 -
25.810 - QZ_DoModifiers (this,[event modifierFlags]);
25.811 -
25.812 - switch (type) {
25.813 - case NSLeftMouseDown:
25.814 - if (SDL_getenv ("SDL_HAS3BUTTONMOUSE")) {
25.815 - DO_MOUSE_DOWN (SDL_BUTTON_LEFT);
25.816 - } else {
25.817 - if (NSCommandKeyMask & current_mods) {
25.818 - last_virtual_button = SDL_BUTTON_RIGHT;
25.819 - DO_MOUSE_DOWN (SDL_BUTTON_RIGHT);
25.820 - } else if (NSAlternateKeyMask & current_mods) {
25.821 - last_virtual_button = SDL_BUTTON_MIDDLE;
25.822 - DO_MOUSE_DOWN (SDL_BUTTON_MIDDLE);
25.823 - } else {
25.824 - DO_MOUSE_DOWN (SDL_BUTTON_LEFT);
25.825 - }
25.826 - }
25.827 - break;
25.828 -
25.829 - case NSLeftMouseUp:
25.830 - if (last_virtual_button != 0) {
25.831 - DO_MOUSE_UP (last_virtual_button);
25.832 - last_virtual_button = 0;
25.833 - } else {
25.834 - DO_MOUSE_UP (SDL_BUTTON_LEFT);
25.835 - }
25.836 - break;
25.837 -
25.838 - case NSOtherMouseDown:
25.839 - case NSRightMouseDown:
25.840 - button = QZ_OtherMouseButtonToSDL ([event buttonNumber]);
25.841 - DO_MOUSE_DOWN (button);
25.842 - break;
25.843 -
25.844 - case NSOtherMouseUp:
25.845 - case NSRightMouseUp:
25.846 - button = QZ_OtherMouseButtonToSDL ([event buttonNumber]);
25.847 - DO_MOUSE_UP (button);
25.848 - break;
25.849 -
25.850 - case NSSystemDefined:
25.851 - /*
25.852 - Future: up to 32 "mouse" buttons can be handled.
25.853 - if ([event subtype] == 7) {
25.854 - unsigned int buttons;
25.855 - buttons = [ event data2 ];
25.856 - */
25.857 - break;
25.858 - case NSLeftMouseDragged:
25.859 - case NSRightMouseDragged:
25.860 - case NSOtherMouseDragged: /* usually middle mouse dragged */
25.861 - case NSMouseMoved:
25.862 - if (grab_state == QZ_INVISIBLE_GRAB) {
25.863 -
25.864 - /*
25.865 - If input is grabbed+hidden, the cursor doesn't move,
25.866 - so we have to call the lowlevel window server
25.867 - function. This is less accurate but works OK.
25.868 - */
25.869 - CGMouseDelta dx1, dy1;
25.870 - CGGetLastMouseDelta (&dx1, &dy1);
25.871 - dx += dx1;
25.872 - dy += dy1;
25.873 - } else if (firstMouseEvent) {
25.874 -
25.875 - /*
25.876 - Get the first mouse event in a possible
25.877 - sequence of mouse moved events. Since we
25.878 - use absolute coordinates, this serves to
25.879 - compensate any inaccuracy in deltas, and
25.880 - provides the first known mouse position,
25.881 - since everything after this uses deltas
25.882 - */
25.883 - NSPoint p;
25.884 - QZ_GetMouseLocation (this, &p);
25.885 - SDL_PrivateMouseMotion (0, 0, p.x, p.y);
25.886 - firstMouseEvent = 0;
25.887 - } else {
25.888 -
25.889 - /*
25.890 - Get the amount moved since the last drag or move event,
25.891 - add it on for one big move event at the end.
25.892 - */
25.893 - dx +=[event deltaX];
25.894 - dy +=[event deltaY];
25.895 - }
25.896 -
25.897 - /*
25.898 - Handle grab input+cursor visible by warping the cursor back
25.899 - into the game window. This still generates a mouse moved event,
25.900 - but not as a result of the warp (so it's in the right direction).
25.901 - */
25.902 - if (grab_state == QZ_VISIBLE_GRAB && !isInGameWin) {
25.903 -
25.904 - NSPoint p;
25.905 - QZ_GetMouseLocation (this, &p);
25.906 -
25.907 - if (p.x < 0.0)
25.908 - p.x = 0.0;
25.909 -
25.910 - if (p.y < 0.0)
25.911 - p.y = 0.0;
25.912 -
25.913 - if (p.x >= winRect.size.width)
25.914 - p.x = winRect.size.width - 1;
25.915 -
25.916 - if (p.y >= winRect.size.height)
25.917 - p.y = winRect.size.height - 1;
25.918 -
25.919 - QZ_PrivateWarpCursor (this, p.x, p.y);
25.920 - } else if (!isInGameWin
25.921 - && (SDL_GetAppState () & SDL_APPMOUSEFOCUS)) {
25.922 -
25.923 - SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
25.924 - if (grab_state == QZ_INVISIBLE_GRAB)
25.925 - /*The cursor has left the window even though it is
25.926 - disassociated from the mouse (and therefore
25.927 - shouldn't move): this can happen with Wacom
25.928 - tablets, and it effectively breaks the grab, since
25.929 - mouse down events now go to background
25.930 - applications. The only possibility to avoid this
25.931 - seems to be talking to the tablet driver
25.932 - (AppleEvents) to constrain its mapped area to the
25.933 - window, which may not be worth the effort. For
25.934 - now, handle the condition more gracefully than
25.935 - before by reassociating cursor and mouse until the
25.936 - cursor enters the window again, making it obvious
25.937 - to the user that the grab is broken. */
25.938 - CGAssociateMouseAndMouseCursorPosition (1);
25.939 - if (!cursor_should_be_visible)
25.940 - QZ_ShowMouse (this);
25.941 - } else if (isInGameWin
25.942 - && (SDL_GetAppState () &
25.943 - (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) ==
25.944 - SDL_APPINPUTFOCUS) {
25.945 -
25.946 - SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
25.947 - if (!cursor_should_be_visible)
25.948 - QZ_HideMouse (this);
25.949 - if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above */
25.950 - QZ_PrivateWarpCursor (this,
25.951 - SDL_VideoSurface->w /
25.952 - 2, SDL_VideoSurface->h / 2);
25.953 - CGAssociateMouseAndMouseCursorPosition (0);
25.954 - }
25.955 - }
25.956 - break;
25.957 - case NSScrollWheel:
25.958 - if (isInGameWin) {
25.959 - float dy, dx;
25.960 - Uint8 button;
25.961 - dy =[event deltaY];
25.962 - dx =[event deltaX];
25.963 - if (dy > 0.0 || dx > 0.0) /* Scroll up */
25.964 - button = SDL_BUTTON_WHEELUP;
25.965 - else /* Scroll down */
25.966 - button = SDL_BUTTON_WHEELDOWN;
25.967 - /* For now, wheel is sent as a quick down+up */
25.968 - SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);
25.969 - SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0);
25.970 - }
25.971 - break;
25.972 - case NSKeyUp:
25.973 - QZ_DoKey (this, SDL_RELEASED, event);
25.974 - break;
25.975 - case NSKeyDown:
25.976 - QZ_DoKey (this, SDL_PRESSED, event);
25.977 - break;
25.978 - case NSFlagsChanged:
25.979 - break;
25.980 - /* case NSAppKitDefined: break; */
25.981 - /* case NSApplicationDefined: break; */
25.982 - /* case NSPeriodic: break; */
25.983 - /* case NSCursorUpdate: break; */
25.984 - default:
25.985 - [NSApp sendEvent:event];
25.986 - }
25.987 - }
25.988 - }
25.989 - while (event != nil);
25.990 -
25.991 - /* handle accumulated mouse moved events */
25.992 - if (dx != 0 || dy != 0)
25.993 - SDL_PrivateMouseMotion (0, 1, dx, dy);
25.994 -
25.995 - [pool release];
25.996 -}
25.997 -
25.998 -void
25.999 -QZ_UpdateMouse (_THIS)
25.1000 -{
25.1001 - NSPoint p;
25.1002 - QZ_GetMouseLocation (this, &p);
25.1003 - SDL_PrivateAppActive (QZ_IsMouseInWindow (this), SDL_APPMOUSEFOCUS);
25.1004 - SDL_PrivateMouseMotion (0, 0, p.x, p.y);
25.1005 -}
26.1 --- a/src/video/quartz/SDL_QuartzGL.m Sun Jul 23 00:55:25 2006 +0000
26.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
26.3 @@ -1,329 +0,0 @@
26.4 -/*
26.5 - SDL - Simple DirectMedia Layer
26.6 - Copyright (C) 1997-2003 Sam Lantinga
26.7 -
26.8 - This library is free software; you can redistribute it and/or
26.9 - modify it under the terms of the GNU Library General Public
26.10 - License as published by the Free Software Foundation; either
26.11 - version 2 of the License, or (at your option) any later version.
26.12 -
26.13 - This library is distributed in the hope that it will be useful,
26.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
26.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26.16 - Library General Public License for more details.
26.17 -
26.18 - You should have received a copy of the GNU Library General Public
26.19 - License along with this library; if not, write to the Free
26.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26.21 -
26.22 - Sam Lantinga
26.23 - slouken@libsdl.org
26.24 -*/
26.25 -#include "SDL_config.h"
26.26 -
26.27 -#include "SDL_QuartzVideo.h"
26.28 -
26.29 -/*
26.30 - * GL_ARB_Multisample is supposed to be available in 10.1, according to Apple:
26.31 - *
26.32 - * http://developer.apple.com/opengl/extensions.html#GL_ARB_multisample
26.33 - *
26.34 - * ...but it isn't in the system headers, according to Sam:
26.35 - *
26.36 - * http://www.libsdl.org/pipermail/sdl/2003-December/058335.html
26.37 - *
26.38 - * These are normally enums and not #defines in the system headers.
26.39 - *
26.40 - * --ryan.
26.41 - */
26.42 -#if (MAC_OS_X_VERSION_MAX_ALLOWED < 1020)
26.43 -#define NSOpenGLPFASampleBuffers ((NSOpenGLPixelFormatAttribute) 55)
26.44 -#define NSOpenGLPFASamples ((NSOpenGLPixelFormatAttribute) 56)
26.45 -#endif
26.46 -
26.47 -
26.48 -@ implementation NSOpenGLContext (CGLContextAccess)
26.49 - - (CGLContextObj) cglContext;
26.50 -{
26.51 - return _contextAuxiliary;
26.52 -}
26.53 -
26.54 -@end
26.55 -/* OpenGL helper functions (used internally) */
26.56 - int
26.57 -QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags)
26.58 -{
26.59 -
26.60 - NSOpenGLPixelFormatAttribute attr[32];
26.61 - NSOpenGLPixelFormat *fmt;
26.62 - int i = 0;
26.63 - int colorBits = bpp;
26.64 -
26.65 - /* if a GL library hasn't been loaded at this point, load the default. */
26.66 - if (!this->gl_config.driver_loaded) {
26.67 - if (QZ_GL_LoadLibrary (this, NULL) == -1)
26.68 - return 0;
26.69 - }
26.70 -
26.71 - if (flags & SDL_FULLSCREEN) {
26.72 -
26.73 - attr[i++] = NSOpenGLPFAFullScreen;
26.74 - }
26.75 - /* In windowed mode, the OpenGL pixel depth must match device pixel depth */
26.76 - else if (colorBits != device_bpp) {
26.77 -
26.78 - colorBits = device_bpp;
26.79 - }
26.80 -
26.81 - attr[i++] = NSOpenGLPFAColorSize;
26.82 - attr[i++] = colorBits;
26.83 -
26.84 - attr[i++] = NSOpenGLPFADepthSize;
26.85 - attr[i++] = this->gl_config.depth_size;
26.86 -
26.87 - if (this->gl_config.double_buffer) {
26.88 - attr[i++] = NSOpenGLPFADoubleBuffer;
26.89 - }
26.90 -
26.91 - if (this->gl_config.stereo) {
26.92 - attr[i++] = NSOpenGLPFAStereo;
26.93 - }
26.94 -
26.95 - if (this->gl_config.stencil_size != 0) {
26.96 - attr[i++] = NSOpenGLPFAStencilSize;
26.97 - attr[i++] = this->gl_config.stencil_size;
26.98 - }
26.99 -
26.100 - if ((this->gl_config.accum_red_size +
26.101 - this->gl_config.accum_green_size +
26.102 - this->gl_config.accum_blue_size +
26.103 - this->gl_config.accum_alpha_size) > 0) {
26.104 - attr[i++] = NSOpenGLPFAAccumSize;
26.105 - attr[i++] =
26.106 - this->gl_config.accum_red_size +
26.107 - this->gl_config.accum_green_size +
26.108 - this->gl_config.accum_blue_size +
26.109 - this->gl_config.accum_alpha_size;
26.110 - }
26.111 -
26.112 - if (this->gl_config.multisamplebuffers != 0) {
26.113 - attr[i++] = NSOpenGLPFASampleBuffers;
26.114 - attr[i++] = this->gl_config.multisamplebuffers;
26.115 - }
26.116 -
26.117 - if (this->gl_config.multisamplesamples != 0) {
26.118 - attr[i++] = NSOpenGLPFASamples;
26.119 - attr[i++] = this->gl_config.multisamplesamples;
26.120 - attr[i++] = NSOpenGLPFANoRecovery;
26.121 - }
26.122 -
26.123 - if (this->gl_config.accelerated > 0) {
26.124 - attr[i++] = NSOpenGLPFAAccelerated;
26.125 - }
26.126 -
26.127 - attr[i++] = NSOpenGLPFAScreenMask;
26.128 - attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
26.129 - attr[i] = 0;
26.130 -
26.131 - fmt =[[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
26.132 - if (fmt == nil) {
26.133 - SDL_SetError ("Failed creating OpenGL pixel format");
26.134 - return 0;
26.135 - }
26.136 -
26.137 - gl_context =[[NSOpenGLContext alloc] initWithFormat: fmt shareContext:nil];
26.138 -
26.139 - [fmt release];
26.140 -
26.141 - if (gl_context == nil) {
26.142 - SDL_SetError ("Failed creating OpenGL context");
26.143 - return 0;
26.144 - }
26.145 -
26.146 - /* Synchronize QZ_GL_SwapBuffers() to vertical retrace.
26.147 - * (Apple's documentation is not completely clear about what this setting
26.148 - * exactly does, IMHO - for a detailed explanation see
26.149 - * http://lists.apple.com/archives/mac-opengl/2006/Jan/msg00080.html )
26.150 - */
26.151 - if (this->gl_config.swap_control >= 0) {
26.152 - long value;
26.153 - value = this->gl_config.swap_control;
26.154 - [gl_context setValues: &value forParameter:NSOpenGLCPSwapInterval];
26.155 - }
26.156 -
26.157 - /*
26.158 - * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
26.159 - * "You are blowing a couple of the internal OpenGL function caches. This
26.160 - * appears to be happening in the VAO case. You can tell OpenGL to up
26.161 - * the cache size by issuing the following calls right after you create
26.162 - * the OpenGL context. The default cache size is 16." --ryan.
26.163 - */
26.164 -
26.165 -#ifndef GLI_ARRAY_FUNC_CACHE_MAX
26.166 -#define GLI_ARRAY_FUNC_CACHE_MAX 284
26.167 -#endif
26.168 -
26.169 -#ifndef GLI_SUBMIT_FUNC_CACHE_MAX
26.170 -#define GLI_SUBMIT_FUNC_CACHE_MAX 280
26.171 -#endif
26.172 -
26.173 - {
26.174 - long cache_max = 64;
26.175 - CGLContextObj ctx =[gl_context cglContext];
26.176 - CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
26.177 - CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
26.178 - }
26.179 -
26.180 - /* End Wisdom from Apple Engineer section. --ryan. */
26.181 -
26.182 - return 1;
26.183 -}
26.184 -
26.185 -void
26.186 -QZ_TearDownOpenGL (_THIS)
26.187 -{
26.188 -
26.189 - [NSOpenGLContext clearCurrentContext];
26.190 - [gl_context clearDrawable];
26.191 - [gl_context release];
26.192 -}
26.193 -
26.194 -
26.195 -/* SDL OpenGL functions */
26.196 -static const char *DEFAULT_OPENGL_LIB_NAME =
26.197 - "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib";
26.198 -
26.199 -int
26.200 -QZ_GL_LoadLibrary (_THIS, const char *location)
26.201 -{
26.202 - if (gl_context != NULL) {
26.203 - SDL_SetError ("OpenGL context already created");
26.204 - return -1;
26.205 - }
26.206 -
26.207 - if (opengl_library != NULL)
26.208 - SDL_UnloadObject (opengl_library);
26.209 -
26.210 - if (location == NULL)
26.211 - location = DEFAULT_OPENGL_LIB_NAME;
26.212 -
26.213 - opengl_library = SDL_LoadObject (location);
26.214 - if (opengl_library != NULL) {
26.215 - this->gl_config.driver_loaded = 1;
26.216 - return 0;
26.217 - }
26.218 -
26.219 - this->gl_config.driver_loaded = 0;
26.220 - return -1;
26.221 -}
26.222 -
26.223 -void *
26.224 -QZ_GL_GetProcAddress (_THIS, const char *proc)
26.225 -{
26.226 - return SDL_LoadFunction (opengl_library, proc);
26.227 -}
26.228 -
26.229 -int
26.230 -QZ_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value)
26.231 -{
26.232 -
26.233 - GLenum attr = 0;
26.234 -
26.235 - QZ_GL_MakeCurrent (this);
26.236 -
26.237 - switch (attrib) {
26.238 - case SDL_GL_RED_SIZE:
26.239 - attr = GL_RED_BITS;
26.240 - break;
26.241 - case SDL_GL_BLUE_SIZE:
26.242 - attr = GL_BLUE_BITS;
26.243 - break;
26.244 - case SDL_GL_GREEN_SIZE:
26.245 - attr = GL_GREEN_BITS;
26.246 - break;
26.247 - case SDL_GL_ALPHA_SIZE:
26.248 - attr = GL_ALPHA_BITS;
26.249 - break;
26.250 - case SDL_GL_DOUBLEBUFFER:
26.251 - attr = GL_DOUBLEBUFFER;
26.252 - break;
26.253 - case SDL_GL_DEPTH_SIZE:
26.254 - attr = GL_DEPTH_BITS;
26.255 - break;
26.256 - case SDL_GL_STENCIL_SIZE:
26.257 - attr = GL_STENCIL_BITS;
26.258 - break;
26.259 - case SDL_GL_ACCUM_RED_SIZE:
26.260 - attr = GL_ACCUM_RED_BITS;
26.261 - break;
26.262 - case SDL_GL_ACCUM_GREEN_SIZE:
26.263 - attr = GL_ACCUM_GREEN_BITS;
26.264 - break;
26.265 - case SDL_GL_ACCUM_BLUE_SIZE:
26.266 - attr = GL_ACCUM_BLUE_BITS;
26.267 - break;
26.268 - case SDL_GL_ACCUM_ALPHA_SIZE:
26.269 - attr = GL_ACCUM_ALPHA_BITS;
26.270 - break;
26.271 - case SDL_GL_STEREO:
26.272 - attr = GL_STEREO;
26.273 - break;
26.274 - case SDL_GL_MULTISAMPLEBUFFERS:
26.275 - attr = GL_SAMPLE_BUFFERS_ARB;
26.276 - break;
26.277 - case SDL_GL_MULTISAMPLESAMPLES:
26.278 - attr = GL_SAMPLES_ARB;
26.279 - break;
26.280 - case SDL_GL_BUFFER_SIZE:
26.281 - {
26.282 - GLint bits = 0;
26.283 - GLint component;
26.284 -
26.285 - /* there doesn't seem to be a single flag in OpenGL for this! */
26.286 - glGetIntegerv (GL_RED_BITS, &component);
26.287 - bits += component;
26.288 - glGetIntegerv (GL_GREEN_BITS, &component);
26.289 - bits += component;
26.290 - glGetIntegerv (GL_BLUE_BITS, &component);
26.291 - bits += component;
26.292 - glGetIntegerv (GL_ALPHA_BITS, &component);
26.293 - bits += component;
26.294 -
26.295 - *value = bits;
26.296 - return 0;
26.297 - }
26.298 - case SDL_GL_ACCELERATED_VISUAL:
26.299 - {
26.300 - long val;
26.301 - /* FIXME: How do we get this information here?
26.302 - [fmt getValues: &val forAttribute: NSOpenGLPFAAccelerated attr forVirtualScreen: 0];
26.303 - */
26.304 - val = (this->gl_config.accelerated != 0);;
26.305 - *value = val;
26.306 - return 0;
26.307 - }
26.308 - case SDL_GL_SWAP_CONTROL:
26.309 - {
26.310 - long val;
26.311 - [gl_context getValues: &val forParameter:NSOpenGLCPSwapInterval];
26.312 - *value = val;
26.313 - return 0;
26.314 - }
26.315 - }
26.316 -
26.317 - glGetIntegerv (attr, (GLint *) value);
26.318 - return 0;
26.319 -}
26.320 -
26.321 -int
26.322 -QZ_GL_MakeCurrent (_THIS)
26.323 -{
26.324 - [gl_context makeCurrentContext];
26.325 - return 0;
26.326 -}
26.327 -
26.328 -void
26.329 -QZ_GL_SwapBuffers (_THIS)
26.330 -{
26.331 - [gl_context flushBuffer];
26.332 -}
27.1 --- a/src/video/quartz/SDL_QuartzKeys.h Sun Jul 23 00:55:25 2006 +0000
27.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
27.3 @@ -1,142 +0,0 @@
27.4 -/*
27.5 - SDL - Simple DirectMedia Layer
27.6 - Copyright (C) 1997-2003 Sam Lantinga
27.7 -
27.8 - This library is free software; you can redistribute it and/or
27.9 - modify it under the terms of the GNU Library General Public
27.10 - License as published by the Free Software Foundation; either
27.11 - version 2 of the License, or (at your option) any later version.
27.12 -
27.13 - This library is distributed in the hope that it will be useful,
27.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
27.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27.16 - Library General Public License for more details.
27.17 -
27.18 - You should have received a copy of the GNU Library General Public
27.19 - License along with this library; if not, write to the Free
27.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27.21 -
27.22 - Sam Lantinga
27.23 - slouken@libsdl.org
27.24 -*/
27.25 -#include "SDL_config.h"
27.26 -
27.27 -/* These are the Macintosh key scancode constants -- from Inside Macintosh */
27.28 -
27.29 -#define QZ_ESCAPE 0x35
27.30 -#define QZ_F1 0x7A
27.31 -#define QZ_F2 0x78
27.32 -#define QZ_F3 0x63
27.33 -#define QZ_F4 0x76
27.34 -#define QZ_F5 0x60
27.35 -#define QZ_F6 0x61
27.36 -#define QZ_F7 0x62
27.37 -#define QZ_F8 0x64
27.38 -#define QZ_F9 0x65
27.39 -#define QZ_F10 0x6D
27.40 -#define QZ_F11 0x67
27.41 -#define QZ_F12 0x6F
27.42 -#define QZ_PRINT 0x69
27.43 -#define QZ_SCROLLOCK 0x6B
27.44 -#define QZ_PAUSE 0x71
27.45 -#define QZ_POWER 0x7F
27.46 -#define QZ_BACKQUOTE 0x32
27.47 -#define QZ_1 0x12
27.48 -#define QZ_2 0x13
27.49 -#define QZ_3 0x14
27.50 -#define QZ_4 0x15
27.51 -#define QZ_5 0x17
27.52 -#define QZ_6 0x16
27.53 -#define QZ_7 0x1A
27.54 -#define QZ_8 0x1C
27.55 -#define QZ_9 0x19
27.56 -#define QZ_0 0x1D
27.57 -#define QZ_MINUS 0x1B
27.58 -#define QZ_EQUALS 0x18
27.59 -#define QZ_BACKSPACE 0x33
27.60 -#define QZ_INSERT 0x72
27.61 -#define QZ_HOME 0x73
27.62 -#define QZ_PAGEUP 0x74
27.63 -#define QZ_NUMLOCK 0x47
27.64 -#define QZ_KP_EQUALS 0x51
27.65 -#define QZ_KP_DIVIDE 0x4B
27.66 -#define QZ_KP_MULTIPLY 0x43
27.67 -#define QZ_TAB 0x30
27.68 -#define QZ_q 0x0C
27.69 -#define QZ_w 0x0D
27.70 -#define QZ_e 0x0E
27.71 -#define QZ_r 0x0F
27.72 -#define QZ_t 0x11
27.73 -#define QZ_y 0x10
27.74 -#define QZ_u 0x20
27.75 -#define QZ_i 0x22
27.76 -#define QZ_o 0x1F
27.77 -#define QZ_p 0x23
27.78 -#define QZ_LEFTBRACKET 0x21
27.79 -#define QZ_RIGHTBRACKET 0x1E
27.80 -#define QZ_BACKSLASH 0x2A
27.81 -#define QZ_DELETE 0x75
27.82 -#define QZ_END 0x77
27.83 -#define QZ_PAGEDOWN 0x79
27.84 -#define QZ_KP7 0x59
27.85 -#define QZ_KP8 0x5B
27.86 -#define QZ_KP9 0x5C
27.87 -#define QZ_KP_MINUS 0x4E
27.88 -#define QZ_CAPSLOCK 0x39
27.89 -#define QZ_a 0x00
27.90 -#define QZ_s 0x01
27.91 -#define QZ_d 0x02
27.92 -#define QZ_f 0x03
27.93 -#define QZ_g 0x05
27.94 -#define QZ_h 0x04
27.95 -#define QZ_j 0x26
27.96 -#define QZ_k 0x28
27.97 -#define QZ_l 0x25
27.98 -#define QZ_SEMICOLON 0x29
27.99 -#define QZ_QUOTE 0x27
27.100 -#define QZ_RETURN 0x24
27.101 -#define QZ_KP4 0x56
27.102 -#define QZ_KP5 0x57
27.103 -#define QZ_KP6 0x58
27.104 -#define QZ_KP_PLUS 0x45
27.105 -#define QZ_LSHIFT 0x38
27.106 -#define QZ_z 0x06
27.107 -#define QZ_x 0x07
27.108 -#define QZ_c 0x08
27.109 -#define QZ_v 0x09
27.110 -#define QZ_b 0x0B
27.111 -#define QZ_n 0x2D
27.112 -#define QZ_m 0x2E
27.113 -#define QZ_COMMA 0x2B
27.114 -#define QZ_PERIOD 0x2F
27.115 -#define QZ_SLASH 0x2C
27.116 -#if 1 /* Panther now defines right side keys */
27.117 -#define QZ_RSHIFT 0x3C
27.118 -#endif
27.119 -#define QZ_UP 0x7E
27.120 -#define QZ_KP1 0x53
27.121 -#define QZ_KP2 0x54
27.122 -#define QZ_KP3 0x55
27.123 -#define QZ_KP_ENTER 0x4C
27.124 -#define QZ_LCTRL 0x3B
27.125 -#define QZ_LALT 0x3A
27.126 -#define QZ_LMETA 0x37
27.127 -#define QZ_SPACE 0x31
27.128 -#if 1 /* Panther now defines right side keys */
27.129 -#define QZ_RMETA 0x36
27.130 -#define QZ_RALT 0x3D
27.131 -#define QZ_RCTRL 0x3E
27.132 -#endif
27.133 -#define QZ_LEFT 0x7B
27.134 -#define QZ_DOWN 0x7D
27.135 -#define QZ_RIGHT 0x7C
27.136 -#define QZ_KP0 0x52
27.137 -#define QZ_KP_PERIOD 0x41
27.138 -
27.139 -/* Wierd, these keys are on my iBook under Mac OS X */
27.140 -#define QZ_IBOOK_ENTER 0x34
27.141 -#define QZ_IBOOK_LEFT 0x3B
27.142 -#define QZ_IBOOK_RIGHT 0x3C
27.143 -#define QZ_IBOOK_DOWN 0x3D
27.144 -#define QZ_IBOOK_UP 0x3E
27.145 -/* vi: set ts=4 sw=4 expandtab: */
28.1 --- a/src/video/quartz/SDL_QuartzVideo.h Sun Jul 23 00:55:25 2006 +0000
28.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
28.3 @@ -1,298 +0,0 @@
28.4 -/*
28.5 - SDL - Simple DirectMedia Layer
28.6 - Copyright (C) 1997-2003 Sam Lantinga
28.7 -
28.8 - This library is free software; you can redistribute it and/or
28.9 - modify it under the terms of the GNU Library General Public
28.10 - License as published by the Free Software Foundation; either
28.11 - version 2 of the License, or (at your option) any later version.
28.12 -
28.13 - This library is distributed in the hope that it will be useful,
28.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
28.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28.16 - Library General Public License for more details.
28.17 -
28.18 - You should have received a copy of the GNU Library General Public
28.19 - License along with this library; if not, write to the Free
28.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28.21 -
28.22 - Sam Lantinga
28.23 - slouken@libsdl.org
28.24 -*/
28.25 -#include "SDL_config.h"
28.26 -
28.27 -/*
28.28 - @file SDL_QuartzVideo.h
28.29 - @author Darrell Walisser, Max Horn, et al.
28.30 -
28.31 - @abstract SDL video driver for Mac OS X.
28.32 -
28.33 - @discussion
28.34 -
28.35 - TODO
28.36 - - Hardware Cursor support with NSCursor instead of Carbon
28.37 - - Keyboard repeat/mouse speed adjust (if needed)
28.38 - - Multiple monitor support (currently only main display)
28.39 - - Accelerated blitting support
28.40 - - Fix white OpenGL window on minimize (fixed) (update: broken again on 10.2)
28.41 - - Find out what events should be sent/ignored if window is minimized
28.42 - - Find a way to deal with external resolution/depth switch while app is running
28.43 - - Check accuracy of QZ_SetGamma()
28.44 - Problems:
28.45 - - OGL not working in full screen with software renderer
28.46 - - SetColors sets palette correctly but clears framebuffer
28.47 - - Crash in CG after several mode switches (I think this has been fixed)
28.48 - - Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
28.49 - - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug) (update: not just Radeon)
28.50 - - Warping cursor delays mouse events for a fraction of a second,
28.51 - there is a hack around this that helps a bit
28.52 -*/
28.53 -
28.54 -/* Needs to be first, so QuickTime.h doesn't include glext.h (10.4) */
28.55 -#include "SDL_opengl.h"
28.56 -
28.57 -#include <Cocoa/Cocoa.h>
28.58 -#include <Carbon/Carbon.h>
28.59 -#include <QuickTime/QuickTime.h>
28.60 -#include <OpenGL/CGLTypes.h> /* For CGLContextObj */
28.61 -#include <IOKit/IOKitLib.h> /* For powersave handling */
28.62 -#include <pthread.h>
28.63 -
28.64 -#include "SDL_thread.h"
28.65 -#include "SDL_video.h"
28.66 -#include "SDL_error.h"
28.67 -#include "SDL_timer.h"
28.68 -#include "SDL_loadso.h"
28.69 -#include "SDL_syswm.h"
28.70 -#include "../SDL_sysvideo.h"
28.71 -#include "../SDL_pixels_c.h"
28.72 -#include "../../events/SDL_events_c.h"
28.73 -
28.74 -/*
28.75 - This is a workaround to directly access NSOpenGLContext's CGL context
28.76 - We need this to check for errors NSOpenGLContext doesn't support
28.77 -*/
28.78 -@ interface NSOpenGLContext(CGLContextAccess) - (CGLContextObj) cglContext;
28.79 -@end
28.80 -/* Main driver structure to store required state information */
28.81 - typedef struct SDL_PrivateVideoData
28.82 - {
28.83 -
28.84 - CGDirectDisplayID
28.85 - display; /* 0 == main display (only support single display) */
28.86 - CFDictionaryRef
28.87 - mode; /* current mode of the display */
28.88 - CFDictionaryRef
28.89 - save_mode; /* original mode of the display */
28.90 - CFArrayRef
28.91 - mode_list; /* list of available fullscreen modes */
28.92 - CGDirectPaletteRef
28.93 - palette; /* palette of an 8-bit display */
28.94 - NSOpenGLContext *
28.95 - gl_context; /* OpenGL rendering context */
28.96 - Uint32
28.97 - width,
28.98 - height,
28.99 - bpp; /* frequently used data about the display */
28.100 - Uint32
28.101 - flags; /* flags for current mode, for teardown purposes */
28.102 - Uint32
28.103 - video_set; /* boolean; indicates if video was set correctly */
28.104 - Uint32
28.105 - warp_flag; /* boolean; notify to event loop that a warp just occured */
28.106 - Uint32
28.107 - warp_ticks; /* timestamp when the warp occured */
28.108 - NSWindow *
28.109 - window; /* Cocoa window to implement the SDL window */
28.110 - NSQuickDrawView *
28.111 - view; /* the window's view; draw 2D and OpenGL into this view */
28.112 - SDL_Surface *
28.113 - resize_icon; /* icon for the resize badge, we have to draw it by hand */
28.114 - SDL_GrabMode
28.115 - current_grab_mode; /* default value is SDL_GRAB_OFF */
28.116 - SDL_Rect **
28.117 - client_mode_list; /* resolution list to pass back to client */
28.118 - SDLKey
28.119 - keymap[256]; /* Mac OS X to SDL key mapping */
28.120 - Uint32
28.121 - current_mods; /* current keyboard modifiers, to track modifier state */
28.122 - Uint32
28.123 - last_virtual_button; /* last virtual mouse button pressed */
28.124 - io_connect_t
28.125 - power_connection; /* used with IOKit to detect wake from sleep */
28.126 - Uint8
28.127 - expect_mouse_up; /* used to determine when to send mouse up events */
28.128 - Uint8
28.129 - grab_state; /* used to manage grab behavior */
28.130 - NSPoint
28.131 - cursor_loc; /* saved cursor coords, for activate/deactivate when grabbed */
28.132 - BOOL
28.133 - cursor_should_be_visible; /* tells if cursor is supposed to be visible (SDL_ShowCursor) */
28.134 - BOOL
28.135 - cursor_visible; /* tells if cursor is *actually* visible or not */
28.136 - Uint8 *
28.137 - sw_buffers[2]; /* pointers to the two software buffers for double-buffer emulation */
28.138 - SDL_Thread *
28.139 - thread; /* thread for async updates to the screen */
28.140 - SDL_sem *
28.141 - sem1, *
28.142 - sem2; /* synchronization for async screen updates */
28.143 - Uint8 *
28.144 - current_buffer; /* the buffer being copied to the screen */
28.145 - BOOL
28.146 - quit_thread; /* used to quit the async blitting thread */
28.147 - SInt32
28.148 - system_version; /* used to dis-/enable workarounds depending on the system version */
28.149 -
28.150 - ImageDescriptionHandle
28.151 - yuv_idh;
28.152 - MatrixRecordPtr
28.153 - yuv_matrix;
28.154 - DecompressorComponent
28.155 - yuv_codec;
28.156 - ImageSequence
28.157 - yuv_seq;
28.158 - PlanarPixmapInfoYUV420 *
28.159 - yuv_pixmap;
28.160 - Sint16
28.161 - yuv_width,
28.162 - yuv_height;
28.163 - CGrafPtr
28.164 - yuv_port;
28.165 -
28.166 - void *
28.167 - opengl_library; /* dynamically loaded OpenGL library. */
28.168 - } SDL_PrivateVideoData;
28.169 -
28.170 -#define _THIS SDL_VideoDevice *this
28.171 -#define display_id (this->hidden->display)
28.172 -#define mode (this->hidden->mode)
28.173 -#define save_mode (this->hidden->save_mode)
28.174 -#define mode_list (this->hidden->mode_list)
28.175 -#define palette (this->hidden->palette)
28.176 -#define gl_context (this->hidden->gl_context)
28.177 -#define device_width (this->hidden->width)
28.178 -#define device_height (this->hidden->height)
28.179 -#define device_bpp (this->hidden->bpp)
28.180 -#define mode_flags (this->hidden->flags)
28.181 -#define qz_window (this->hidden->window)
28.182 -#define window_view (this->hidden->view)
28.183 -#define video_set (this->hidden->video_set)
28.184 -#define warp_ticks (this->hidden->warp_ticks)
28.185 -#define warp_flag (this->hidden->warp_flag)
28.186 -#define resize_icon (this->hidden->resize_icon)
28.187 -#define current_grab_mode (this->hidden->current_grab_mode)
28.188 -#define client_mode_list (this->hidden->client_mode_list)
28.189 -#define keymap (this->hidden->keymap)
28.190 -#define current_mods (this->hidden->current_mods)
28.191 -#define last_virtual_button (this->hidden->last_virtual_button)
28.192 -#define power_connection (this->hidden->power_connection)
28.193 -#define expect_mouse_up (this->hidden->expect_mouse_up)
28.194 -#define grab_state (this->hidden->grab_state)
28.195 -#define cursor_loc (this->hidden->cursor_loc)
28.196 -#define cursor_should_be_visible (this->hidden->cursor_should_be_visible)
28.197 -#define cursor_visible (this->hidden->cursor_visible)
28.198 -#define sw_buffers (this->hidden->sw_buffers)
28.199 -#define thread (this->hidden->thread)
28.200 -#define sem1 (this->hidden->sem1)
28.201 -#define sem2 (this->hidden->sem2)
28.202 -#define current_buffer (this->hidden->current_buffer)
28.203 -#define quit_thread (this->hidden->quit_thread)
28.204 -#define system_version (this->hidden->system_version)
28.205 -#define opengl_library (this->hidden->opengl_library)
28.206 -
28.207 -/* grab states - the input is in one of these states */
28.208 - enum
28.209 - {
28.210 - QZ_UNGRABBED = 0,
28.211 - QZ_VISIBLE_GRAB,
28.212 - QZ_INVISIBLE_GRAB
28.213 - };
28.214 -
28.215 -/* grab actions - these can change the grabbed state */
28.216 - enum
28.217 - {
28.218 - QZ_ENABLE_GRAB = 0,
28.219 - QZ_DISABLE_GRAB,
28.220 - QZ_HIDECURSOR,
28.221 - QZ_SHOWCURSOR
28.222 - };
28.223 -
28.224 -/* Gamma Functions */
28.225 - int
28.226 - QZ_SetGamma(_THIS, float red, float green, float blue);
28.227 - int
28.228 - QZ_GetGamma(_THIS, float *red, float *green, float *blue);
28.229 - int
28.230 - QZ_SetGammaRamp(_THIS, Uint16 * ramp);
28.231 - int
28.232 - QZ_GetGammaRamp(_THIS, Uint16 * ramp);
28.233 -
28.234 -/* OpenGL functions */
28.235 - int
28.236 - QZ_SetupOpenGL(_THIS, int bpp, Uint32 flags);
28.237 - void
28.238 - QZ_TearDownOpenGL(_THIS);
28.239 - void *
28.240 - QZ_GL_GetProcAddress(_THIS, const char *proc);
28.241 - int
28.242 - QZ_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
28.243 - int
28.244 - QZ_GL_MakeCurrent(_THIS);
28.245 - void
28.246 - QZ_GL_SwapBuffers(_THIS);
28.247 - int
28.248 - QZ_GL_LoadLibrary(_THIS, const char *location);
28.249 -
28.250 -/* Cursor and Mouse functions */
28.251 - void
28.252 - QZ_FreeWMCursor(_THIS, WMcursor * cursor);
28.253 - WMcursor *
28.254 - QZ_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
28.255 - int w, int h, int hot_x, int hot_y);
28.256 - int
28.257 - QZ_ShowWMCursor(_THIS, WMcursor * cursor);
28.258 - void
28.259 - QZ_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
28.260 - void
28.261 - QZ_MoveWMCursor(_THIS, int x, int y);
28.262 - void
28.263 - QZ_CheckMouseMode(_THIS);
28.264 - void
28.265 - QZ_UpdateMouse(_THIS);
28.266 -
28.267 -/* Event functions */
28.268 - void
28.269 - QZ_InitOSKeymap(_THIS);
28.270 - void
28.271 - QZ_PumpEvents(_THIS);
28.272 -
28.273 -/* Window Manager functions */
28.274 - void
28.275 - QZ_SetCaption(_THIS, const char *title, const char *icon);
28.276 - void
28.277 - QZ_SetIcon(_THIS, SDL_Surface * icon, Uint8 * mask);
28.278 - int
28.279 - QZ_IconifyWindow(_THIS);
28.280 -SDL_GrabMode
28.281 -QZ_GrabInput(_THIS, SDL_GrabMode grab_mode);
28.282 -/*int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info);*/
28.283 -
28.284 -/* YUV functions */
28.285 - SDL_Overlay *QZ_CreateYUVOverlay(_THIS, int width, int height,
28.286 - Uint32 format, SDL_Surface * display);
28.287 -
28.288 -
28.289 -/* Private functions (used internally) */
28.290 - void QZ_PrivateWarpCursor(_THIS, int x, int y);
28.291 - void QZ_ChangeGrabState(_THIS, int action);
28.292 - void QZ_RegisterForSleepNotifications(_THIS);
28.293 - void QZ_ShowMouse(_THIS);
28.294 - void QZ_HideMouse(_THIS);
28.295 - void QZ_PrivateGlobalToLocal(_THIS, NSPoint * p);
28.296 - void QZ_PrivateCocoaToSDL(_THIS, NSPoint * p);
28.297 -BOOL
28.298 -QZ_IsMouseInWindow(_THIS);
28.299 - void QZ_DoActivate(_THIS);
28.300 - void QZ_DoDeactivate(_THIS);
28.301 -/* vi: set ts=4 sw=4 expandtab: */
29.1 --- a/src/video/quartz/SDL_QuartzVideo.m Sun Jul 23 00:55:25 2006 +0000
29.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
29.3 @@ -1,1721 +0,0 @@
29.4 -/*
29.5 - SDL - Simple DirectMedia Layer
29.6 - Copyright (C) 1997-2003 Sam Lantinga
29.7 -
29.8 - This library is free software; you can redistribute it and/or
29.9 - modify it under the terms of the GNU Library General Public
29.10 - License as published by the Free Software Foundation; either
29.11 - version 2 of the License, or (at your option) any later version.
29.12 -
29.13 - This library is distributed in the hope that it will be useful,
29.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
29.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29.16 - Library General Public License for more details.
29.17 -
29.18 - You should have received a copy of the GNU Library General Public
29.19 - License along with this library; if not, write to the Free
29.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29.21 -
29.22 - Sam Lantinga
29.23 - slouken@libsdl.org
29.24 -*/
29.25 -#include "SDL_config.h"
29.26 -
29.27 -#include "SDL_QuartzVideo.h"
29.28 -#include "SDL_QuartzWindow.h"
29.29 -
29.30 -/*
29.31 - Add methods to get at private members of NSScreen.
29.32 - Since there is a bug in Apple's screen switching code
29.33 - that does not update this variable when switching
29.34 - to fullscreen, we'll set it manually (but only for the
29.35 - main screen).
29.36 -*/
29.37 -@ interface NSScreen (NSScreenAccess) - (void) setFrame:(NSRect) frame;
29.38 -@end @ implementation NSScreen (NSScreenAccess) - (void) setFrame:(NSRect)
29.39 - frame;
29.40 -{
29.41 - _frame = frame;
29.42 -}
29.43 -
29.44 -@end
29.45 -/*
29.46 - Structure for rez switch gamma fades
29.47 - We can hide the monitor flicker by setting the gamma tables to 0
29.48 -*/
29.49 -#define QZ_GAMMA_TABLE_SIZE 256
29.50 - typedef struct
29.51 -{
29.52 -
29.53 - CGGammaValue red[QZ_GAMMA_TABLE_SIZE];
29.54 - CGGammaValue green[QZ_GAMMA_TABLE_SIZE];
29.55 - CGGammaValue blue[QZ_GAMMA_TABLE_SIZE];
29.56 -
29.57 -} SDL_QuartzGammaTable;
29.58 -
29.59 -
29.60 -/* Bootstrap functions */
29.61 -static int QZ_Available ();
29.62 -static SDL_VideoDevice *QZ_CreateDevice (int device_index);
29.63 -static void QZ_DeleteDevice (SDL_VideoDevice * device);
29.64 -
29.65 -/* Initialization, Query, Setup, and Redrawing functions */
29.66 -static int QZ_VideoInit (_THIS, SDL_PixelFormat * video_format);
29.67 -
29.68 -static SDL_Rect **QZ_ListModes (_THIS, SDL_PixelFormat * format,
29.69 - Uint32 flags);
29.70 -static void QZ_UnsetVideoMode (_THIS, BOOL to_desktop);
29.71 -
29.72 -static SDL_Surface *QZ_SetVideoMode (_THIS, SDL_Surface * current,
29.73 - int width, int height, int bpp,
29.74 - Uint32 flags);
29.75 -static int QZ_ToggleFullScreen (_THIS, int on);
29.76 -static int QZ_SetColors (_THIS, int first_color,
29.77 - int num_colors, SDL_Color * colors);
29.78 -
29.79 -static int QZ_LockDoubleBuffer (_THIS, SDL_Surface * surface);
29.80 -static void QZ_UnlockDoubleBuffer (_THIS, SDL_Surface * surface);
29.81 -static int QZ_ThreadFlip (_THIS);
29.82 -static int QZ_FlipDoubleBuffer (_THIS, SDL_Surface * surface);
29.83 -static void QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect * rects);
29.84 -
29.85 -static void QZ_DirectUpdate (_THIS, int num_rects, SDL_Rect * rects);
29.86 -static int QZ_LockWindow (_THIS, SDL_Surface * surface);
29.87 -static void QZ_UnlockWindow (_THIS, SDL_Surface * surface);
29.88 -static void QZ_UpdateRects (_THIS, int num_rects, SDL_Rect * rects);
29.89 -static void QZ_VideoQuit (_THIS);
29.90 -
29.91 -/* Hardware surface functions (for fullscreen mode only) */
29.92 -#if 0 /* Not used (apparently, it's really slow) */
29.93 -static int QZ_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * rect,
29.94 - Uint32 color);
29.95 -#endif
29.96 -static int QZ_LockHWSurface (_THIS, SDL_Surface * surface);
29.97 -static void QZ_UnlockHWSurface (_THIS, SDL_Surface * surface);
29.98 -static int QZ_AllocHWSurface (_THIS, SDL_Surface * surface);
29.99 -static void QZ_FreeHWSurface (_THIS, SDL_Surface * surface);
29.100 -/* static int QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
29.101 -
29.102 -/* Bootstrap binding, enables entry point into the driver */
29.103 -VideoBootStrap QZ_bootstrap = {
29.104 - "Quartz", "Mac OS X CoreGraphics", QZ_Available, QZ_CreateDevice
29.105 -};
29.106 -
29.107 -
29.108 -/* Bootstrap functions */
29.109 -static int
29.110 -QZ_Available ()
29.111 -{
29.112 - return 1;
29.113 -}
29.114 -
29.115 -static SDL_VideoDevice *
29.116 -QZ_CreateDevice (int device_index)
29.117 -{
29.118 -
29.119 -#pragma unused (device_index)
29.120 -
29.121 - SDL_VideoDevice *device;
29.122 - SDL_PrivateVideoData *hidden;
29.123 -
29.124 - device = (SDL_VideoDevice *) SDL_malloc (sizeof (*device));
29.125 - hidden = (SDL_PrivateVideoData *) SDL_malloc (sizeof (*hidden));
29.126 -
29.127 - if (device == NULL || hidden == NULL)
29.128 - SDL_OutOfMemory ();
29.129 -
29.130 - SDL_memset (device, 0, sizeof (*device));
29.131 - SDL_memset (hidden, 0, sizeof (*hidden));
29.132 -
29.133 - device->hidden = hidden;
29.134 -
29.135 - device->VideoInit = QZ_VideoInit;
29.136 - device->ListModes = QZ_ListModes;
29.137 - device->SetVideoMode = QZ_SetVideoMode;
29.138 - device->ToggleFullScreen = QZ_ToggleFullScreen;
29.139 - device->UpdateMouse = QZ_UpdateMouse;
29.140 - device->SetColors = QZ_SetColors;
29.141 - /* device->UpdateRects = QZ_UpdateRects; this is determined by SetVideoMode() */
29.142 - device->VideoQuit = QZ_VideoQuit;
29.143 -
29.144 - device->LockHWSurface = QZ_LockHWSurface;
29.145 - device->UnlockHWSurface = QZ_UnlockHWSurface;
29.146 - device->AllocHWSurface = QZ_AllocHWSurface;
29.147 - device->FreeHWSurface = QZ_FreeHWSurface;
29.148 - /* device->FlipHWSurface = QZ_FlipHWSurface */ ;
29.149 -
29.150 - device->SetGamma = QZ_SetGamma;
29.151 - device->GetGamma = QZ_GetGamma;
29.152 - device->SetGammaRamp = QZ_SetGammaRamp;
29.153 - device->GetGammaRamp = QZ_GetGammaRamp;
29.154 -
29.155 - device->GL_GetProcAddress = QZ_GL_GetProcAddress;
29.156 - device->GL_GetAttribute = QZ_GL_GetAttribute;
29.157 - device->GL_MakeCurrent = QZ_GL_MakeCurrent;
29.158 - device->GL_SwapBuffers = QZ_GL_SwapBuffers;
29.159 - device->GL_LoadLibrary = QZ_GL_LoadLibrary;
29.160 -
29.161 - device->FreeWMCursor = QZ_FreeWMCursor;
29.162 - device->CreateWMCursor = QZ_CreateWMCursor;
29.163 - device->ShowWMCursor = QZ_ShowWMCursor;
29.164 - device->WarpWMCursor = QZ_WarpWMCursor;
29.165 - device->MoveWMCursor = QZ_MoveWMCursor;
29.166 - device->CheckMouseMode = QZ_CheckMouseMode;
29.167 - device->InitOSKeymap = QZ_InitOSKeymap;
29.168 - device->PumpEvents = QZ_PumpEvents;
29.169 -
29.170 - device->SetCaption = QZ_SetCaption;
29.171 - device->SetIcon = QZ_SetIcon;
29.172 - device->IconifyWindow = QZ_IconifyWindow;
29.173 - /*device->GetWMInfo = QZ_GetWMInfo; */
29.174 - device->GrabInput = QZ_GrabInput;
29.175 -
29.176 - device->CreateYUVOverlay = QZ_CreateYUVOverlay;
29.177 -
29.178 - device->free = QZ_DeleteDevice;
29.179 -
29.180 - return device;
29.181 -}
29.182 -
29.183 -static void
29.184 -QZ_DeleteDevice (SDL_VideoDevice * device)
29.185 -{
29.186 -
29.187 - SDL_free (device->hidden);
29.188 - SDL_free (device);
29.189 -}
29.190 -
29.191 -static int
29.192 -QZ_VideoInit (_THIS, SDL_PixelFormat * video_format)
29.193 -{
29.194 -
29.195 - /* Initialize the video settings; this data persists between mode switches */
29.196 - display_id = kCGDirectMainDisplay;
29.197 - save_mode = CGDisplayCurrentMode (display_id);
29.198 - mode_list = CGDisplayAvailableModes (display_id);
29.199 - palette = CGPaletteCreateDefaultColorPalette ();
29.200 -
29.201 - /* Gather some information that is useful to know about the display */
29.202 - CFNumberGetValue (CFDictionaryGetValue
29.203 - (save_mode, kCGDisplayBitsPerPixel),
29.204 - kCFNumberSInt32Type, &device_bpp);
29.205 -
29.206 - CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayWidth),
29.207 - kCFNumberSInt32Type, &device_width);
29.208 -
29.209 - CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayHeight),
29.210 - kCFNumberSInt32Type, &device_height);
29.211 -
29.212 - /* Determine the current screen size */
29.213 - this->info.current_w = device_width;
29.214 - this->info.current_h = device_height;
29.215 -
29.216 - /* Determine the default screen depth */
29.217 - video_format->BitsPerPixel = device_bpp;
29.218 -
29.219 - /* Set misc globals */
29.220 - current_grab_mode = SDL_GRAB_OFF;
29.221 - cursor_should_be_visible = YES;
29.222 - cursor_visible = YES;
29.223 - current_mods = 0;
29.224 -
29.225 - if (Gestalt (gestaltSystemVersion, &system_version) != noErr)
29.226 - system_version = 0;
29.227 -
29.228 - /* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
29.229 - QZ_RegisterForSleepNotifications (this);
29.230 -
29.231 - /* Fill in some window manager capabilities */
29.232 - this->info.wm_available = 1;
29.233 -
29.234 - return 0;
29.235 -}
29.236 -
29.237 -static SDL_Rect **
29.238 -QZ_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
29.239 -{
29.240 -
29.241 - CFIndex num_modes;
29.242 - CFIndex i;
29.243 -
29.244 - int list_size = 0;
29.245 -
29.246 - /* Any windowed mode is acceptable */
29.247 - if ((flags & SDL_FULLSCREEN) == 0)
29.248 - return (SDL_Rect **) - 1;
29.249 -
29.250 - /* Free memory from previous call, if any */
29.251 - if (client_mode_list != NULL) {
29.252 -
29.253 - int i;
29.254 -
29.255 - for (i = 0; client_mode_list[i] != NULL; i++)
29.256 - SDL_free (client_mode_list[i]);
29.257 -
29.258 - SDL_free (client_mode_list);
29.259 - client_mode_list = NULL;
29.260 - }
29.261 -
29.262 - num_modes = CFArrayGetCount (mode_list);
29.263 -
29.264 - /* Build list of modes with the requested bpp */
29.265 - for (i = 0; i < num_modes; i++) {
29.266 -
29.267 - CFDictionaryRef onemode;
29.268 - CFNumberRef number;
29.269 - int bpp;
29.270 -
29.271 - onemode = CFArrayGetValueAtIndex (mode_list, i);
29.272 - number = CFDictionaryGetValue (onemode, kCGDisplayBitsPerPixel);
29.273 - CFNumberGetValue (number, kCFNumberSInt32Type, &bpp);
29.274 -
29.275 - if (bpp == format->BitsPerPixel) {
29.276 -
29.277 - int intvalue;
29.278 - int hasMode;
29.279 - int width, height;
29.280 -
29.281 - number = CFDictionaryGetValue (onemode, kCGDisplayWidth);
29.282 - CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
29.283 - width = (Uint16) intvalue;
29.284 -
29.285 - number = CFDictionaryGetValue (onemode, kCGDisplayHeight);
29.286 - CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
29.287 - height = (Uint16) intvalue;
29.288 -
29.289 - /* Check if mode is already in the list */
29.290 - {
29.291 - int i;
29.292 - hasMode = SDL_FALSE;
29.293 - for (i = 0; i < list_size; i++) {
29.294 - if (client_mode_list[i]->w == width &&
29.295 - client_mode_list[i]->h == height) {
29.296 - hasMode = SDL_TRUE;
29.297 - break;
29.298 - }
29.299 - }
29.300 - }
29.301 -
29.302 - /* Grow the list and add mode to the list */
29.303 - if (!hasMode) {
29.304 -
29.305 - SDL_Rect *rect;
29.306 -
29.307 - list_size++;
29.308 -
29.309 - if (client_mode_list == NULL)
29.310 - client_mode_list = (SDL_Rect **)
29.311 - SDL_malloc (sizeof (*client_mode_list) *
29.312 - (list_size + 1));
29.313 - else
29.314 - client_mode_list = (SDL_Rect **)
29.315 - SDL_realloc (client_mode_list,
29.316 - sizeof (*client_mode_list) *
29.317 - (list_size + 1));
29.318 -
29.319 - rect = (SDL_Rect *)
29.320 - SDL_malloc (sizeof (**client_mode_list));
29.321 -
29.322 - if (client_mode_list == NULL || rect == NULL) {
29.323 - SDL_OutOfMemory ();
29.324 - return NULL;
29.325 - }
29.326 -
29.327 - rect->x = rect->y = 0;
29.328 - rect->w = width;
29.329 - rect->h = height;
29.330 -
29.331 - client_mode_list[list_size - 1] = rect;
29.332 - client_mode_list[list_size] = NULL;
29.333 - }
29.334 - }
29.335 - }
29.336 -
29.337 - /* Sort list largest to smallest (by area) */
29.338 - {
29.339 - int i, j;
29.340 - for (i = 0; i < list_size; i++) {
29.341 - for (j = 0; j < list_size - 1; j++) {
29.342 -
29.343 - int area1, area2;
29.344 - area1 = client_mode_list[j]->w * client_mode_list[j]->h;
29.345 - area2 =
29.346 - client_mode_list[j + 1]->w * client_mode_list[j + 1]->h;
29.347 -
29.348 - if (area1 < area2) {
29.349 - SDL_Rect *tmp = client_mode_list[j];
29.350 - client_mode_list[j] = client_mode_list[j + 1];
29.351 - client_mode_list[j + 1] = tmp;
29.352 - }
29.353 - }
29.354 - }
29.355 - }
29.356 - return client_mode_list;
29.357 -}
29.358 -
29.359 -static SDL_bool
29.360 -QZ_WindowPosition (_THIS, int *x, int *y)
29.361 -{
29.362 - const char *window = getenv ("SDL_VIDEO_WINDOW_POS");
29.363 - if (window) {
29.364 - if (sscanf (window, "%d,%d", x, y) == 2) {
29.365 - return SDL_TRUE;
29.366 - }
29.367 - }
29.368 - return SDL_FALSE;
29.369 -}
29.370 -
29.371 -static void
29.372 -QZ_UnsetVideoMode (_THIS, BOOL to_desktop)
29.373 -{
29.374 -
29.375 - /* Reset values that may change between switches */
29.376 - this->info.blit_fill = 0;
29.377 - this->FillHWRect = NULL;
29.378 - this->UpdateRects = NULL;
29.379 - this->LockHWSurface = NULL;
29.380 - this->UnlockHWSurface = NULL;
29.381 -
29.382 - /* Release fullscreen resources */
29.383 - if (mode_flags & SDL_FULLSCREEN) {
29.384 -
29.385 - NSRect screen_rect;
29.386 -
29.387 - /* Release double buffer stuff */
29.388 - if (mode_flags & SDL_DOUBLEBUF) {
29.389 - quit_thread = YES;
29.390 - SDL_SemPost (sem1);
29.391 - SDL_WaitThread (thread, NULL);
29.392 - SDL_DestroySemaphore (sem1);
29.393 - SDL_DestroySemaphore (sem2);
29.394 - SDL_free (sw_buffers[0]);
29.395 - }
29.396 -
29.397 - /*
29.398 - Release the OpenGL context
29.399 - Do this first to avoid trash on the display before fade
29.400 - */
29.401 - if (mode_flags & SDL_INTERNALOPENGL) {
29.402 -
29.403 - QZ_TearDownOpenGL (this);
29.404 - CGLSetFullScreen (NULL);
29.405 - }
29.406 - if (to_desktop) {
29.407 - /* Restore original screen resolution/bpp */
29.408 - CGDisplaySwitchToMode (display_id, save_mode);
29.409 - CGReleaseAllDisplays ();
29.410 - ShowMenuBar ();
29.411 - /*
29.412 - Reset the main screen's rectangle
29.413 - See comment in QZ_SetVideoFullscreen for why we do this
29.414 - */
29.415 - screen_rect = NSMakeRect (0, 0, device_width, device_height);
29.416 - [[NSScreen mainScreen] setFrame:screen_rect];
29.417 - }
29.418 - }
29.419 - /* Release window mode resources */
29.420 - else {
29.421 -
29.422 - [qz_window close];
29.423 - [qz_window release];
29.424 - qz_window = nil;
29.425 - window_view = nil;
29.426 -
29.427 - /* Release the OpenGL context */
29.428 - if (mode_flags & SDL_INTERNALOPENGL)
29.429 - QZ_TearDownOpenGL (this);
29.430 - }
29.431 -
29.432 - /* Signal successful teardown */
29.433 - video_set = SDL_FALSE;
29.434 -}
29.435 -
29.436 -static SDL_Surface *
29.437 -QZ_SetVideoFullScreen (_THIS, SDL_Surface * current, int width,
29.438 - int height, int bpp, Uint32 flags)
29.439 -{
29.440 - boolean_t exact_match = 0;
29.441 - NSRect screen_rect;
29.442 - CGError error;
29.443 - CGDisplayFadeReservationToken fade_token =
29.444 - kCGDisplayFadeReservationInvalidToken;
29.445 -
29.446 - /* Fade to black to hide resolution-switching flicker (and garbage
29.447 - that is displayed by a destroyed OpenGL context, if applicable) */
29.448 - if (CGAcquireDisplayFadeReservation (5, &fade_token) == kCGErrorSuccess) {
29.449 - CGDisplayFade (fade_token, 0.3, kCGDisplayBlendNormal,
29.450 - kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
29.451 - }
29.452 -
29.453 - /* Destroy any previous mode */
29.454 - if (video_set == SDL_TRUE)
29.455 - QZ_UnsetVideoMode (this, FALSE);
29.456 -
29.457 - /* See if requested mode exists */
29.458 - mode = CGDisplayBestModeForParameters (display_id, bpp, width,
29.459 - height, &exact_match);
29.460 -
29.461 - /* Require an exact match to the requested mode */
29.462 - if (!exact_match) {
29.463 - SDL_SetError ("Failed to find display resolution: %dx%dx%d", width,
29.464 - height, bpp);
29.465 - goto ERR_NO_MATCH;
29.466 - }
29.467 -
29.468 - /* Put up the blanking window (a window above all other windows) */
29.469 - if (getenv ("SDL_SINGLEDISPLAY"))
29.470 - error = CGDisplayCapture (display_id);
29.471 - else
29.472 - error = CGCaptureAllDisplays ();
29.473 -
29.474 - if (CGDisplayNoErr != error) {
29.475 - SDL_SetError ("Failed capturing display");
29.476 - goto ERR_NO_CAPTURE;
29.477 - }
29.478 -
29.479 - /* Do the physical switch */
29.480 - if (CGDisplayNoErr != CGDisplaySwitchToMode (display_id, mode)) {
29.481 - SDL_SetError ("Failed switching display resolution");
29.482 - goto ERR_NO_SWITCH;
29.483 - }
29.484 -
29.485 - current->pixels = (Uint32 *) CGDisplayBaseAddress (display_id);
29.486 - current->pitch = CGDisplayBytesPerRow (display_id);
29.487 -
29.488 - current->flags = 0;
29.489 - current->w = width;
29.490 - current->h = height;
29.491 - current->flags |= SDL_FULLSCREEN;
29.492 - current->flags |= SDL_HWSURFACE;
29.493 - current->flags |= SDL_PREALLOC;
29.494 -
29.495 - this->UpdateRects = QZ_DirectUpdate;
29.496 - this->LockHWSurface = QZ_LockHWSurface;
29.497 - this->UnlockHWSurface = QZ_UnlockHWSurface;
29.498 -
29.499 - /* Setup double-buffer emulation */
29.500 - if (flags & SDL_DOUBLEBUF) {
29.501 -
29.502 - /*
29.503 - Setup a software backing store for reasonable results when
29.504 - double buffering is requested (since a single-buffered hardware
29.505 - surface looks hideous).
29.506 -
29.507 - The actual screen blit occurs in a separate thread to allow
29.508 - other blitting while waiting on the VBL (and hence results in higher framerates).
29.509 - */
29.510 - this->LockHWSurface = NULL;
29.511 - this->UnlockHWSurface = NULL;
29.512 - this->UpdateRects = NULL;
29.513 -
29.514 - current->flags |= (SDL_HWSURFACE | SDL_DOUBLEBUF);
29.515 - this->UpdateRects = QZ_DoubleBufferUpdate;
29.516 - this->LockHWSurface = QZ_LockDoubleBuffer;
29.517 - this->UnlockHWSurface = QZ_UnlockDoubleBuffer;
29.518 - this->FlipHWSurface = QZ_FlipDoubleBuffer;
29.519 -
29.520 - current->pixels = SDL_malloc (current->pitch * current->h * 2);
29.521 - if (current->pixels == NULL) {
29.522 - SDL_OutOfMemory ();
29.523 - goto ERR_DOUBLEBUF;
29.524 - }
29.525 -
29.526 - sw_buffers[0] = current->pixels;
29.527 - sw_buffers[1] =
29.528 - (Uint8 *) current->pixels + current->pitch * current->h;
29.529 -
29.530 - quit_thread = NO;
29.531 - sem1 = SDL_CreateSemaphore (0);
29.532 - sem2 = SDL_CreateSemaphore (1);
29.533 - thread = SDL_CreateThread ((int (*)(void *)) QZ_ThreadFlip, this);
29.534 - }
29.535 -
29.536 - if (CGDisplayCanSetPalette (display_id))
29.537 - current->flags |= SDL_HWPALETTE;
29.538 -
29.539 - /* Setup OpenGL for a fullscreen context */
29.540 - if (flags & SDL_INTERNALOPENGL) {
29.541 -
29.542 - CGLError err;
29.543 - CGLContextObj ctx;
29.544 -
29.545 - if (!QZ_SetupOpenGL (this, bpp, flags)) {
29.546 - goto ERR_NO_GL;
29.547 - }
29.548 -
29.549 - ctx =[gl_context cglContext];
29.550 - err = CGLSetFullScreen (ctx);
29.551 -
29.552 - if (err) {
29.553 - SDL_SetError ("Error setting OpenGL fullscreen: %s",
29.554 - CGLErrorString (err));
29.555 - goto ERR_NO_GL;
29.556 - }
29.557 -
29.558 - [gl_context makeCurrentContext];
29.559 -
29.560 - glClear (GL_COLOR_BUFFER_BIT);
29.561 -
29.562 - [gl_context flushBuffer];
29.563 -
29.564 - current->flags |= SDL_INTERNALOPENGL;
29.565 - }
29.566 -
29.567 - /* If we don't hide menu bar, it will get events and interrupt the program */
29.568 - HideMenuBar ();
29.569 -
29.570 - /* Fade in again (asynchronously) */
29.571 - if (fade_token != kCGDisplayFadeReservationInvalidToken) {
29.572 - CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor,
29.573 - kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
29.574 - CGReleaseDisplayFadeReservation (fade_token);
29.575 - }
29.576 -
29.577 - /*
29.578 - There is a bug in Cocoa where NSScreen doesn't synchronize
29.579 - with CGDirectDisplay, so the main screen's frame is wrong.
29.580 - As a result, coordinate translation produces incorrect results.
29.581 - We can hack around this bug by setting the screen rect
29.582 - ourselves. This hack should be removed if/when the bug is fixed.
29.583 - */
29.584 - screen_rect = NSMakeRect (0, 0, width, height);
29.585 - [[NSScreen mainScreen] setFrame:screen_rect];
29.586 -
29.587 - /* Save the flags to ensure correct tear-down */
29.588 - mode_flags = current->flags;
29.589 -
29.590 - /* Set app state, hide cursor if necessary, ... */
29.591 - QZ_DoActivate (this);
29.592 -
29.593 - return current;
29.594 -
29.595 - /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
29.596 - ERR_NO_GL:
29.597 - ERR_DOUBLEBUF:CGDisplaySwitchToMode (display_id, save_mode);
29.598 - ERR_NO_SWITCH:CGReleaseAllDisplays ();
29.599 - ERR_NO_CAPTURE:
29.600 - ERR_NO_MATCH:if (fade_token != kCGDisplayFadeReservationInvalidToken) {
29.601 - CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor,
29.602 - kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
29.603 - CGReleaseDisplayFadeReservation (fade_token);
29.604 - }
29.605 - return NULL;
29.606 -}
29.607 -
29.608 -static SDL_Surface *
29.609 -QZ_SetVideoWindowed (_THIS, SDL_Surface * current, int width,
29.610 - int height, int *bpp, Uint32 flags)
29.611 -{
29.612 - unsigned int style;
29.613 - NSRect contentRect;
29.614 - BOOL isCustom = NO;
29.615 - int center_window = 1;
29.616 - int origin_x, origin_y;
29.617 - CGDisplayFadeReservationToken fade_token =
29.618 - kCGDisplayFadeReservationInvalidToken;
29.619 -
29.620 - current->flags = 0;
29.621 - current->w = width;
29.622 - current->h = height;
29.623 -
29.624 - contentRect = NSMakeRect (0, 0, width, height);
29.625 -
29.626 - /*
29.627 - Check if we should completely destroy the previous mode
29.628 - - If it is fullscreen
29.629 - - If it has different noframe or resizable attribute
29.630 - - If it is OpenGL (since gl attributes could be different)
29.631 - - If new mode is OpenGL, but previous mode wasn't
29.632 - */
29.633 - if (video_set == SDL_TRUE) {
29.634 - if (mode_flags & SDL_FULLSCREEN) {
29.635 - /* Fade to black to hide resolution-switching flicker (and garbage
29.636 - that is displayed by a destroyed OpenGL context, if applicable) */
29.637 - if (CGAcquireDisplayFadeReservation (5, &fade_token) ==
29.638 - kCGErrorSuccess) {
29.639 - CGDisplayFade (fade_token, 0.3, kCGDisplayBlendNormal,
29.640 - kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0,
29.641 - TRUE);
29.642 - }
29.643 - QZ_UnsetVideoMode (this, TRUE);
29.644 - } else if (((mode_flags ^ flags) & (SDL_NOFRAME | SDL_RESIZABLE)) ||
29.645 - (mode_flags & SDL_INTERNALOPENGL) ||
29.646 - (flags & SDL_INTERNALOPENGL)) {
29.647 - QZ_UnsetVideoMode (this, TRUE);
29.648 - }
29.649 - }
29.650 -
29.651 - /* Check for user-specified window and view */
29.652 - {
29.653 - char *windowPtrString = getenv ("SDL_NSWindowPointer");
29.654 - char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer");
29.655 -
29.656 - if (windowPtrString && viewPtrString) {
29.657 -
29.658 - /* Release any previous window */
29.659 - if (qz_window) {
29.660 - [qz_window release];
29.661 - qz_window = nil;
29.662 - }
29.663 -
29.664 - qz_window = (NSWindow *) atoi (windowPtrString);
29.665 - window_view = (NSQuickDrawView *) atoi (viewPtrString);
29.666 - isCustom = YES;
29.667 -
29.668 - /*
29.669 - Retain reference to window because we
29.670 - might release it in QZ_UnsetVideoMode
29.671 - */
29.672 - [qz_window retain];
29.673 -
29.674 - style =[qz_window styleMask];
29.675 - /* Check resizability */
29.676 - if (style & NSResizableWindowMask)
29.677 - current->flags |= SDL_RESIZABLE;
29.678 -
29.679 - /* Check frame */
29.680 - if (style & NSBorderlessWindowMask)
29.681 - current->flags |= SDL_NOFRAME;
29.682 - }
29.683 - }
29.684 -
29.685 - /* Check if we should recreate the window */
29.686 - if (qz_window == nil) {
29.687 -
29.688 - /* Set the window style based on input flags */
29.689 - if (flags & SDL_NOFRAME) {
29.690 - style = NSBorderlessWindowMask;
29.691 - current->flags |= SDL_NOFRAME;
29.692 - } else {
29.693 - style = NSTitledWindowMask;
29.694 - style |= (NSMiniaturizableWindowMask | NSClosableWindowMask);
29.695 - if (flags & SDL_RESIZABLE) {
29.696 - style |= NSResizableWindowMask;
29.697 - current->flags |= SDL_RESIZABLE;
29.698 - }
29.699 - }
29.700 -
29.701 - if (QZ_WindowPosition (this, &origin_x, &origin_y)) {
29.702 - center_window = 0;
29.703 - contentRect.origin.x = (float) origin_x;
29.704 - contentRect.origin.y = (float) origin_y;
29.705 - }
29.706 -
29.707 - /* Manually create a window, avoids having a nib file resource */
29.708 - qz_window =[[SDL_QuartzWindow alloc] initWithContentRect: contentRect styleMask: style backing: NSBackingStoreBuffered defer:NO];
29.709 -
29.710 - if (qz_window == nil) {
29.711 - SDL_SetError ("Could not create the Cocoa window");
29.712 - if (fade_token != kCGDisplayFadeReservationInvalidToken) {
29.713 - CGDisplayFade (fade_token, 0.5,
29.714 - kCGDisplayBlendSolidColor,
29.715 - kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
29.716 - CGReleaseDisplayFadeReservation (fade_token);
29.717 - }
29.718 - return NULL;
29.719 - }
29.720 -
29.721 - /*[ qz_window setReleasedWhenClosed:YES ]; */
29.722 - QZ_SetCaption (this, this->wm_title, this->wm_icon);
29.723 - [qz_window setAcceptsMouseMovedEvents:YES];
29.724 - [qz_window setViewsNeedDisplay:NO];
29.725 - if (center_window) {
29.726 - [qz_window center];
29.727 - }
29.728 - [qz_window setDelegate:
29.729 -[[[SDL_QuartzWindowDelegate alloc] init] autorelease]];
29.730 - }
29.731 - /* We already have a window, just change its size */
29.732 - else {
29.733 -
29.734 - if (!isCustom) {
29.735 - [qz_window setContentSize:contentRect.size];
29.736 - current->flags |= (SDL_NOFRAME | SDL_RESIZABLE) & mode_flags;
29.737 - [window_view setFrameSize:contentRect.size];
29.738 - }
29.739 - }
29.740 -
29.741 - /* For OpenGL, we bind the context to a subview */
29.742 - if (flags & SDL_INTERNALOPENGL) {
29.743 -
29.744 - if (!QZ_SetupOpenGL (this, *bpp, flags)) {
29.745 - if (fade_token != kCGDisplayFadeReservationInvalidToken) {
29.746 - CGDisplayFade (fade_token, 0.5,
29.747 - kCGDisplayBlendSolidColor,
29.748 - kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
29.749 - CGReleaseDisplayFadeReservation (fade_token);
29.750 - }
29.751 - return NULL;
29.752 - }
29.753 -
29.754 - window_view =[[NSView alloc] initWithFrame:contentRect];
29.755 - [window_view setAutoresizingMask:NSViewWidthSizable |
29.756 - NSViewHeightSizable];
29.757 - [[qz_window contentView] addSubview:window_view];
29.758 - [gl_context setView:window_view];
29.759 - [window_view release];
29.760 - [gl_context makeCurrentContext];
29.761 - [qz_window makeKeyAndOrderFront:nil];
29.762 - current->flags |= SDL_INTERNALOPENGL;
29.763 - }
29.764 - /* For 2D, we set the subview to an NSQuickDrawView */
29.765 - else {
29.766 - short qdbpp = 0;
29.767 -
29.768 - /* Only recreate the view if it doesn't already exist */
29.769 - if (window_view == nil) {
29.770 -
29.771 - window_view =[[NSQuickDrawView alloc] initWithFrame:contentRect];
29.772 - [window_view setAutoresizingMask:NSViewWidthSizable |
29.773 - NSViewHeightSizable];
29.774 - [[qz_window contentView] addSubview:window_view];
29.775 - [window_view release];
29.776 - [qz_window makeKeyAndOrderFront:nil];
29.777 - }
29.778 -
29.779 - LockPortBits ([window_view qdPort]);
29.780 - current->pixels =
29.781 - GetPixBaseAddr (GetPortPixMap ([window_view qdPort]));
29.782 - current->pitch =
29.783 - GetPixRowBytes (GetPortPixMap ([window_view qdPort]));
29.784 - qdbpp = GetPixDepth (GetPortPixMap ([window_view qdPort]));
29.785 - UnlockPortBits ([window_view qdPort]);
29.786 -
29.787 - /* QuickDraw may give a 16-bit shadow surface on 8-bit displays! */
29.788 - *bpp = qdbpp;
29.789 -
29.790 - current->flags |= SDL_SWSURFACE;
29.791 - current->flags |= SDL_PREALLOC;
29.792 - current->flags |= SDL_ASYNCBLIT;
29.793 -
29.794 - /*
29.795 - current->pixels now points to the window's pixels
29.796 - We want it to point to the *view's* pixels
29.797 - */
29.798 - {
29.799 - int vOffset =[qz_window frame].size.height -
29.800 - [window_view frame].size.height -[window_view frame].origin.y;
29.801 -
29.802 - int hOffset =[window_view frame].origin.x;
29.803 -
29.804 - current->pixels =
29.805 - (Uint8 *) current->pixels + (vOffset * current->pitch) +
29.806 - hOffset * (qdbpp / 8);
29.807 - }
29.808 - this->UpdateRects = QZ_UpdateRects;
29.809 - this->LockHWSurface = QZ_LockWindow;
29.810 - this->UnlockHWSurface = QZ_UnlockWindow;
29.811 - }
29.812 -
29.813 - /* Save flags to ensure correct teardown */
29.814 - mode_flags = current->flags;
29.815 -
29.816 - /* Fade in again (asynchronously) if we came from a fullscreen mode and faded to black */
29.817 - if (fade_token != kCGDisplayFadeReservationInvalidToken) {
29.818 - CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor,
29.819 - kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
29.820 - CGReleaseDisplayFadeReservation (fade_token);
29.821 - }
29.822 -
29.823 - return current;
29.824 -}
29.825 -
29.826 -static SDL_Surface *
29.827 -QZ_SetVideoMode (_THIS, SDL_Surface * current, int width,
29.828 - int height, int bpp, Uint32 flags)
29.829 -{
29.830 -
29.831 - current->flags = 0;
29.832 - current->pixels = NULL;
29.833 -
29.834 - /* Setup full screen video */
29.835 - if (flags & SDL_FULLSCREEN) {
29.836 - current =
29.837 - QZ_SetVideoFullScreen (this, current, width, height, bpp, flags);
29.838 - if (current == NULL)
29.839 - return NULL;
29.840 - }
29.841 - /* Setup windowed video */
29.842 - else {
29.843 - /* Force bpp to the device's bpp */
29.844 - bpp = device_bpp;
29.845 - current =
29.846 - QZ_SetVideoWindowed (this, current, width, height, &bpp, flags);
29.847 - if (current == NULL)
29.848 - return NULL;
29.849 - }
29.850 -
29.851 - /* Setup the new pixel format */
29.852 - {
29.853 - int amask = 0, rmask = 0, gmask = 0, bmask = 0;
29.854 -
29.855 - switch (bpp) {
29.856 - case 16: /* (1)-5-5-5 RGB */
29.857 - amask = 0;
29.858 - rmask = 0x7C00;
29.859 - gmask = 0x03E0;
29.860 - bmask = 0x001F;
29.861 - break;
29.862 - case 24:
29.863 - SDL_SetError ("24bpp is not available");
29.864 - return NULL;
29.865 - case 32: /* (8)-8-8-8 ARGB */
29.866 - amask = 0x00000000;
29.867 - rmask = 0x00FF0000;
29.868 - gmask = 0x0000FF00;
29.869 - bmask = 0x000000FF;
29.870 - break;
29.871 - }
29.872 -
29.873 - if (!SDL_ReallocFormat (current, bpp, rmask, gmask, bmask, amask)) {
29.874 - SDL_SetError ("Couldn't reallocate pixel format");
29.875 - return NULL;
29.876 - }
29.877 - }
29.878 -
29.879 - /* Signal successful completion (used internally) */
29.880 - video_set = SDL_TRUE;
29.881 -
29.882 - return current;
29.883 -}
29.884 -
29.885 -static int
29.886 -QZ_ToggleFullScreen (_THIS, int on)
29.887 -{
29.888 - return 0;
29.889 -}
29.890 -
29.891 -static int
29.892 -QZ_SetColors (_THIS, int first_color, int num_colors, SDL_Color * colors)
29.893 -{
29.894 -
29.895 - CGTableCount index;
29.896 - CGDeviceColor color;
29.897 -
29.898 - for (index = first_color; index < first_color + num_colors; index++) {
29.899 -
29.900 - /* Clamp colors between 0.0 and 1.0 */
29.901 - color.red = colors->r / 255.0;
29.902 - color.blue = colors->b / 255.0;
29.903 - color.green = colors->g / 255.0;
29.904 -
29.905 - colors++;
29.906 -
29.907 - CGPaletteSetColorAtIndex (palette, color, index);
29.908 - }
29.909 -
29.910 - if (CGDisplayNoErr != CGDisplaySetPalette (display_id, palette))
29.911 - return 0;
29.912 -
29.913 - return 1;
29.914 -}
29.915 -
29.916 -static int
29.917 -QZ_LockDoubleBuffer (_THIS, SDL_Surface * surface)
29.918 -{
29.919 -
29.920 - return 1;
29.921 -}
29.922 -
29.923 -static void
29.924 -QZ_UnlockDoubleBuffer (_THIS, SDL_Surface * surface)
29.925 -{
29.926 -
29.927 -}
29.928 -
29.929 - /* The VBL delay is based on code by Ian R Ollmann's RezLib <iano@cco.caltech.edu> */
29.930 -static AbsoluteTime
29.931 -QZ_SecondsToAbsolute (double seconds)
29.932 -{
29.933 -
29.934 - union
29.935 - {
29.936 - UInt64 i;
29.937 - Nanoseconds ns;
29.938 - } temp;
29.939 -
29.940 - temp.i = seconds * 1000000000.0;
29.941 -
29.942 - return NanosecondsToAbsolute (temp.ns);
29.943 -}
29.944 -
29.945 -static int
29.946 -QZ_ThreadFlip (_THIS)
29.947 -{
29.948 -
29.949 - Uint8 *src, *dst;
29.950 - int skip, len, h;
29.951 -
29.952 - /*
29.953 - Give this thread the highest scheduling priority possible,
29.954 - in the hopes that it will immediately run after the VBL delay
29.955 - */
29.956 - {
29.957 - pthread_t current_thread;
29.958 - int policy;
29.959 - struct sched_param param;
29.960 -
29.961 - current_thread = pthread_self ();
29.962 - pthread_getschedparam (current_thread, &policy, ¶m);
29.963 - policy = SCHED_RR;
29.964 - param.sched_priority = sched_get_priority_max (policy);
29.965 - pthread_setschedparam (current_thread, policy, ¶m);
29.966 - }
29.967 -
29.968 - while (1) {
29.969 -
29.970 - SDL_SemWait (sem1);
29.971 - if (quit_thread)
29.972 - return 0;
29.973 -
29.974 - /*
29.975 - * We have to add SDL_VideoSurface->offset here, since we might be a
29.976 - * smaller surface in the center of the framebuffer (you asked for
29.977 - * a fullscreen resolution smaller than the hardware could supply
29.978 - * so SDL is centering it in a bigger resolution)...
29.979 - */
29.980 - dst =
29.981 - (Uint8 *) CGDisplayBaseAddress (display_id) +
29.982 - SDL_VideoSurface->offset;
29.983 - src = current_buffer + SDL_VideoSurface->offset;
29.984 - len = SDL_VideoSurface->w * SDL_VideoSurface->format->BytesPerPixel;
29.985 - h = SDL_VideoSurface->h;
29.986 - skip = SDL_VideoSurface->pitch;
29.987 -
29.988 - /* Wait for the VBL to occur (estimated since we don't have a hardware interrupt) */
29.989 - {
29.990 -
29.991 - /* The VBL delay is based on Ian Ollmann's RezLib <iano@cco.caltech.edu> */
29.992 - double refreshRate;
29.993 - double linesPerSecond;
29.994 - double target;
29.995 - double position;
29.996 - double adjustment;
29.997 - AbsoluteTime nextTime;
29.998 - CFNumberRef refreshRateCFNumber;
29.999 -
29.1000 - refreshRateCFNumber =
29.1001 - CFDictionaryGetValue (mode, kCGDisplayRefreshRate);
29.1002 - if (NULL == refreshRateCFNumber) {
29.1003 - SDL_SetError ("Mode has no refresh rate");
29.1004 - goto ERROR;
29.1005 - }
29.1006 -
29.1007 - if (0 ==
29.1008 - CFNumberGetValue (refreshRateCFNumber, kCFNumberDoubleType,
29.1009 - &refreshRate)) {
29.1010 - SDL_SetError ("Error getting refresh rate");
29.1011 - goto ERROR;
29.1012 - }
29.1013 -
29.1014 - if (0 == refreshRate) {
29.1015 -
29.1016 - SDL_SetError ("Display has no refresh rate, using 60hz");
29.1017 -
29.1018 - /* ok, for LCD's we'll emulate a 60hz refresh, which may or may not look right */
29.1019 - refreshRate = 60.0;
29.1020 - }
29.1021 -
29.1022 - linesPerSecond = refreshRate * h;
29.1023 - target = h;
29.1024 -
29.1025 - /* Figure out the first delay so we start off about right */
29.1026 - position = CGDisplayBeamPosition (display_id);
29.1027 - if (position > target)
29.1028 - position = 0;
29.1029 -
29.1030 - adjustment = (target - position) / linesPerSecond;
29.1031 -
29.1032 - nextTime =
29.1033 - AddAbsoluteToAbsolute (UpTime (),
29.1034 - QZ_SecondsToAbsolute (adjustment));
29.1035 -
29.1036 - MPDelayUntil (&nextTime);
29.1037 - }
29.1038 -
29.1039 -
29.1040 - /* On error, skip VBL delay */
29.1041 - ERROR:
29.1042 -
29.1043 - while (h--) {
29.1044 -
29.1045 - SDL_memcpy (dst, src, len);
29.1046 - src += skip;
29.1047 - dst += skip;
29.1048 - }
29.1049 -
29.1050 - /* signal flip completion */
29.1051 - SDL_SemPost (sem2);
29.1052 - }
29.1053 -
29.1054 - return 0;
29.1055 -}
29.1056 -
29.1057 -static int
29.1058 -QZ_FlipDoubleBuffer (_THIS, SDL_Surface * surface)
29.1059 -{
29.1060 -
29.1061 - /* wait for previous flip to complete */
29.1062 - SDL_SemWait (sem2);
29.1063 -
29.1064 - current_buffer = surface->pixels;
29.1065 -
29.1066 - if (surface->pixels == sw_buffers[0])
29.1067 - surface->pixels = sw_buffers[1];
29.1068 - else
29.1069 - surface->pixels = sw_buffers[0];
29.1070 -
29.1071 - /* signal worker thread to do the flip */
29.1072 - SDL_SemPost (sem1);
29.1073 -
29.1074 - return 0;
29.1075 -}
29.1076 -
29.1077 -
29.1078 -static void
29.1079 -QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect * rects)
29.1080 -{
29.1081 -
29.1082 - /* perform a flip if someone calls updaterects on a doublebuferred surface */
29.1083 - this->FlipHWSurface (this, SDL_VideoSurface);
29.1084 -}
29.1085 -
29.1086 -static void
29.1087 -QZ_DirectUpdate (_THIS, int num_rects, SDL_Rect * rects)
29.1088 -{
29.1089 -#pragma unused(this,num_rects,rects)
29.1090 -}
29.1091 -
29.1092 -/*
29.1093 - The obscured code is based on work by Matt Slot fprefect@ambrosiasw.com,
29.1094 - who supplied sample code for Carbon.
29.1095 -*/
29.1096 -
29.1097 -/*#define TEST_OBSCURED 1*/
29.1098 -
29.1099 -#if TEST_OBSCURED
29.1100 -#include "CGS.h"
29.1101 -#endif
29.1102 -
29.1103 -static int
29.1104 -QZ_IsWindowObscured (NSWindow * window)
29.1105 -{
29.1106 -
29.1107 -
29.1108 -#if TEST_OBSCURED
29.1109 -
29.1110 - /*
29.1111 - In order to determine if a direct copy to the screen is possible,
29.1112 - we must figure out if there are any windows covering ours (including shadows).
29.1113 - This can be done by querying the window server about the on screen
29.1114 - windows for their screen rectangle and window level.
29.1115 - The procedure used below is puts accuracy before speed; however, it aims to call
29.1116 - the window server the fewest number of times possible to keep things reasonable.
29.1117 - In my testing on a 300mhz G3, this routine typically takes < 2 ms. -DW
29.1118 -
29.1119 - Notes:
29.1120 - -Calls into the Window Server involve IPC which is slow.
29.1121 - -Getting a rectangle seems slower than getting the window level
29.1122 - -The window list we get back is in sorted order, top to bottom
29.1123 - -On average, I suspect, most windows above ours are dock icon windows (hence optimization)
29.1124 - -Some windows above ours are always there, and cannot move or obscure us (menu bar)
29.1125 -
29.1126 - Bugs:
29.1127 - -no way (yet) to deactivate direct drawing when a window is dragged,
29.1128 - or suddenly obscured, so drawing continues and can produce garbage
29.1129 - We need some kind of locking mechanism on window movement to prevent this
29.1130 -
29.1131 - -deactivated normal windows use activated normal
29.1132 - window shadows (slight inaccuraccy)
29.1133 - */
29.1134 -
29.1135 - /* Cache the connection to the window server */
29.1136 - static CGSConnectionID cgsConnection = (CGSConnectionID) - 1;
29.1137 -
29.1138 - /* Cache the dock icon windows */
29.1139 - static CGSWindowID dockIcons[kMaxWindows];
29.1140 - static int numCachedDockIcons = 0;
29.1141 -
29.1142 - CGSWindowID windows[kMaxWindows];
29.1143 - CGSWindowCount i, count;
29.1144 - CGSWindowLevel winLevel;
29.1145 - CGSRect winRect;
29.1146 -
29.1147 - CGSRect contentRect;
29.1148 - int windowNumber;
29.1149 - int firstDockIcon;
29.1150 - int dockIconCacheMiss;
29.1151 - int windowContentOffset;
29.1152 -
29.1153 - int obscured = SDL_TRUE;
29.1154 -
29.1155 - if ([window isVisible]) {
29.1156 -
29.1157 - /*
29.1158 - walk the window list looking for windows over top of
29.1159 - (or casting a shadow on) ours
29.1160 - */
29.1161 -
29.1162 - /*
29.1163 - Get a connection to the window server
29.1164 - Should probably be moved out into SetVideoMode() or InitVideo()
29.1165 - */
29.1166 - if (cgsConnection == (CGSConnectionID) - 1) {
29.1167 - cgsConnection = (CGSConnectionID) 0;
29.1168 - cgsConnection = _CGSDefaultConnection ();
29.1169 - }
29.1170 -
29.1171 - if (cgsConnection) {
29.1172 -
29.1173 - if (![window styleMask] & NSBorderlessWindowMask)
29.1174 - windowContentOffset = 22;
29.1175 - else
29.1176 - windowContentOffset = 0;
29.1177 -
29.1178 - windowNumber =[window windowNumber];
29.1179 -
29.1180 - /* The window list is sorted according to order on the screen */
29.1181 - count = 0;
29.1182 - CGSGetOnScreenWindowList (cgsConnection, 0, kMaxWindows,
29.1183 - windows, &count);
29.1184 - CGSGetScreenRectForWindow (cgsConnection, windowNumber,
29.1185 - &contentRect);
29.1186 -
29.1187 - /* adjust rect for window title bar (if present) */
29.1188 - contentRect.origin.y += windowContentOffset;
29.1189 - contentRect.size.height -= windowContentOffset;
29.1190 -
29.1191 - firstDockIcon = -1;
29.1192 - dockIconCacheMiss = SDL_FALSE;
29.1193 -
29.1194 - /*
29.1195 - The first window is always an empty window with level kCGSWindowLevelTop
29.1196 - so start at index 1
29.1197 - */
29.1198 - for (i = 1; i < count; i++) {
29.1199 -
29.1200 - /* If we reach our window in the list, it cannot be obscured */
29.1201 - if (windows[i] == windowNumber) {
29.1202 -
29.1203 - obscured = SDL_FALSE;
29.1204 - break;
29.1205 - } else {
29.1206 -
29.1207 - float shadowSide;
29.1208 - float shadowTop;
29.1209 - float shadowBottom;
29.1210 -
29.1211 - CGSGetWindowLevel (cgsConnection, windows[i], &winLevel);
29.1212 -
29.1213 - if (winLevel == kCGSWindowLevelDockIcon) {
29.1214 -
29.1215 - int j;
29.1216 -
29.1217 - if (firstDockIcon < 0) {
29.1218 -
29.1219 - firstDockIcon = i;
29.1220 -
29.1221 - if (numCachedDockIcons > 0) {
29.1222 -
29.1223 - for (j = 0; j < numCachedDockIcons; j++) {
29.1224 -
29.1225 - if (windows[i] == dockIcons[j])
29.1226 - i++;
29.1227 - else
29.1228 - break;
29.1229 - }
29.1230 -
29.1231 - if (j != 0) {
29.1232 -
29.1233 - i--;
29.1234 -
29.1235 - if (j < numCachedDockIcons) {
29.1236 -
29.1237 - dockIconCacheMiss = SDL_TRUE;
29.1238 - }
29.1239 - }
29.1240 -
29.1241 - }
29.1242 - }
29.1243 -
29.1244 - continue;
29.1245 - } else if (winLevel == kCGSWindowLevelMenuIgnore
29.1246 - /* winLevel == kCGSWindowLevelTop */ ) {
29.1247 -
29.1248 - continue; /* cannot obscure window */
29.1249 - } else if (winLevel == kCGSWindowLevelDockMenu ||
29.1250 - winLevel == kCGSWindowLevelMenu) {
29.1251 -
29.1252 - shadowSide = 18;
29.1253 - shadowTop = 4;
29.1254 - shadowBottom = 22;
29.1255 - } else if (winLevel == kCGSWindowLevelUtility) {
29.1256 -
29.1257 - shadowSide = 8;
29.1258 - shadowTop = 4;
29.1259 - shadowBottom = 12;
29.1260 - } else if (winLevel == kCGSWindowLevelNormal) {
29.1261 -
29.1262 - /*
29.1263 - These numbers are for foreground windows,
29.1264 - they are too big (but will work) for background windows
29.1265 - */
29.1266 - shadowSide = 20;
29.1267 - shadowTop = 10;
29.1268 - shadowBottom = 24;
29.1269 - } else if (winLevel == kCGSWindowLevelDock) {
29.1270 -
29.1271 - /* Create dock icon cache */
29.1272 - if (numCachedDockIcons != (i - firstDockIcon)
29.1273 - || dockIconCacheMiss) {
29.1274 -
29.1275 - numCachedDockIcons = i - firstDockIcon;
29.1276 - SDL_memcpy (dockIcons,
29.1277 - &(windows[firstDockIcon]),
29.1278 - numCachedDockIcons *
29.1279 - sizeof (*windows));
29.1280 - }
29.1281 -
29.1282 - /* no shadow */
29.1283 - shadowSide = 0;
29.1284 - shadowTop = 0;
29.1285 - shadowBottom = 0;
29.1286 - } else {
29.1287 -
29.1288 - /*
29.1289 - kCGSWindowLevelDockLabel,
29.1290 - kCGSWindowLevelDock,
29.1291 - kOther???
29.1292 - */
29.1293 -
29.1294 - /* no shadow */
29.1295 - shadowSide = 0;
29.1296 - shadowTop = 0;
29.1297 - shadowBottom = 0;
29.1298 - }
29.1299 -
29.1300 - CGSGetScreenRectForWindow (cgsConnection,
29.1301 - windows[i], &winRect);
29.1302 -
29.1303 - winRect.origin.x -= shadowSide;
29.1304 - winRect.origin.y -= shadowTop;
29.1305 - winRect.size.width += shadowSide;
29.1306 - winRect.size.height += shadowBottom;
29.1307 -
29.1308 - if (NSIntersectsRect (contentRect, winRect)) {
29.1309 -
29.1310 - obscured = SDL_TRUE;
29.1311 - break;
29.1312 - }
29.1313 -
29.1314 - } /* window was not our window */
29.1315 -
29.1316 - } /* iterate over windows */
29.1317 -
29.1318 - }
29.1319 - /* get cgsConnection */
29.1320 - }
29.1321 - /* window is visible */
29.1322 - return obscured;
29.1323 -#else
29.1324 - return SDL_TRUE;
29.1325 -#endif
29.1326 -}
29.1327 -
29.1328 -
29.1329 -/* Locking functions for the software window buffer */
29.1330 -static int
29.1331 -QZ_LockWindow (_THIS, SDL_Surface * surface)
29.1332 -{
29.1333 -
29.1334 - return LockPortBits ([window_view qdPort]);
29.1335 -}
29.1336 -
29.1337 -static void
29.1338 -QZ_UnlockWindow (_THIS, SDL_Surface * surface)
29.1339 -{
29.1340 -
29.1341 - UnlockPortBits ([window_view qdPort]);
29.1342 -}
29.1343 -
29.1344 -/* Resize icon, BMP format */
29.1345 -static const unsigned char QZ_ResizeIcon[] = {
29.1346 - 0x42, 0x4d, 0x31, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00,
29.1347 - 0x00, 0x00, 0x28, 0x00,
29.1348 - 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00,
29.1349 - 0x18, 0x00, 0x00, 0x00,
29.1350 - 0x00, 0x00, 0xfb, 0x01, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b,
29.1351 - 0x00, 0x00, 0x00, 0x00,
29.1352 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1353 - 0xff, 0xff, 0xff, 0xff,
29.1354 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1355 - 0xff, 0xff, 0xff, 0xff,
29.1356 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1357 - 0xff, 0x0b, 0xff, 0xff,
29.1358 - 0xff, 0xda, 0xda, 0xda, 0x87, 0x87, 0x87, 0xe8, 0xe8, 0xe8, 0xff, 0xff,
29.1359 - 0xff, 0xda, 0xda, 0xda,
29.1360 - 0x87, 0x87, 0x87, 0xe8, 0xe8, 0xe8, 0xff, 0xff, 0xff, 0xda, 0xda, 0xda,
29.1361 - 0x87, 0x87, 0x87, 0xe8,
29.1362 - 0xe8, 0xe8, 0xff, 0xff, 0xff, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1363 - 0xda, 0xda, 0xda, 0x87,
29.1364 - 0x87, 0x87, 0xe8, 0xe8, 0xe8, 0xff, 0xff, 0xff, 0xda, 0xda, 0xda, 0x87,
29.1365 - 0x87, 0x87, 0xe8, 0xe8,
29.1366 - 0xe8, 0xff, 0xff, 0xff, 0xda, 0xda, 0xda, 0x87, 0x87, 0x87, 0xff, 0xff,
29.1367 - 0xff, 0x0b, 0xff, 0xff,
29.1368 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd5, 0xd5, 0xd5, 0x87, 0x87,
29.1369 - 0x87, 0xe8, 0xe8, 0xe8,
29.1370 - 0xff, 0xff, 0xff, 0xda, 0xda, 0xda, 0x87, 0x87, 0x87, 0xe8, 0xe8, 0xe8,
29.1371 - 0xff, 0xff, 0xff, 0xda,
29.1372 - 0xda, 0xda, 0xff, 0xff, 0xff, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1373 - 0xff, 0xff, 0xff, 0xff,
29.1374 - 0xff, 0xff, 0xd7, 0xd7, 0xd7, 0x87, 0x87, 0x87, 0xe8, 0xe8, 0xe8, 0xff,
29.1375 - 0xff, 0xff, 0xda, 0xda,
29.1376 - 0xda, 0x87, 0x87, 0x87, 0xe8, 0xe8, 0xe8, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1377 - 0xff, 0x0b, 0xff, 0xff,
29.1378 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1379 - 0xff, 0xd7, 0xd7, 0xd7,
29.1380 - 0x87, 0x87, 0x87, 0xe8, 0xe8, 0xe8, 0xff, 0xff, 0xff, 0xda, 0xda, 0xda,
29.1381 - 0x87, 0x87, 0x87, 0xe8,
29.1382 - 0xe8, 0xe8, 0xff, 0xff, 0xff, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1383 - 0xff, 0xff, 0xff, 0xff,
29.1384 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd7, 0xd7, 0xd7, 0x87,
29.1385 - 0x87, 0x87, 0xe8, 0xe8,
29.1386 - 0xe8, 0xff, 0xff, 0xff, 0xdc, 0xdc, 0xdc, 0x87, 0x87, 0x87, 0xff, 0xff,
29.1387 - 0xff, 0x0b, 0xff, 0xff,
29.1388 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1389 - 0xff, 0xff, 0xff, 0xff,
29.1390 - 0xff, 0xff, 0xff, 0xd9, 0xd9, 0xd9, 0x87, 0x87, 0x87, 0xe8, 0xe8, 0xe8,
29.1391 - 0xff, 0xff, 0xff, 0xdc,
29.1392 - 0xdc, 0xdc, 0xff, 0xff, 0xff, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1393 - 0xff, 0xff, 0xff, 0xff,
29.1394 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1395 - 0xff, 0xff, 0xdb, 0xdb,
29.1396 - 0xdb, 0x87, 0x87, 0x87, 0xe8, 0xe8, 0xe8, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1397 - 0xff, 0x0b, 0xff, 0xff,
29.1398 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1399 - 0xff, 0xff, 0xff, 0xff,
29.1400 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdb, 0xdb, 0xdb,
29.1401 - 0x87, 0x87, 0x87, 0xe8,
29.1402 - 0xe8, 0xe8, 0xff, 0xff, 0xff, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1403 - 0xff, 0xff, 0xff, 0xff,
29.1404 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1405 - 0xff, 0xff, 0xff, 0xff,
29.1406 - 0xff, 0xff, 0xff, 0xff, 0xdc, 0xdc, 0xdc, 0x87, 0x87, 0x87, 0xff, 0xff,
29.1407 - 0xff, 0x0b, 0xff, 0xff,
29.1408 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1409 - 0xff, 0xff, 0xff, 0xff,
29.1410 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1411 - 0xff, 0xff, 0xff, 0xdc,
29.1412 - 0xdc, 0xdc, 0xff, 0xff, 0xff, 0x0b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1413 - 0xff, 0xff, 0xff, 0xff,
29.1414 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1415 - 0xff, 0xff, 0xff, 0xff,
29.1416 - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
29.1417 - 0xff, 0x0b
29.1418 -};
29.1419 -
29.1420 -static void
29.1421 -QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion)
29.1422 -{
29.1423 -
29.1424 - /* Check if we should draw the resize icon */
29.1425 - if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
29.1426 -
29.1427 - Rect icon;
29.1428 - SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13,
29.1429 - SDL_VideoSurface->w, SDL_VideoSurface->h);
29.1430 -
29.1431 - if (RectInRgn (&icon, dirtyRegion)) {
29.1432 -
29.1433 - SDL_Rect icon_rect;
29.1434 -
29.1435 - /* Create the icon image */
29.1436 - if (resize_icon == NULL) {
29.1437 -
29.1438 - SDL_RWops *rw;
29.1439 - SDL_Surface *tmp;
29.1440 -
29.1441 - rw = SDL_RWFromConstMem (QZ_ResizeIcon,
29.1442 - sizeof (QZ_ResizeIcon));
29.1443 - tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
29.1444 -
29.1445 - resize_icon =
29.1446 - SDL_ConvertSurface (tmp, SDL_VideoSurface->format,
29.1447 - SDL_SRCCOLORKEY);
29.1448 - SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
29.1449 -
29.1450 - SDL_FreeSurface (tmp);
29.1451 - }
29.1452 -
29.1453 - icon_rect.x = SDL_VideoSurface->w - 13;
29.1454 - icon_rect.y = SDL_VideoSurface->h - 13;
29.1455 - icon_rect.w = 13;
29.1456 - icon_rect.h = 13;
29.1457 -
29.1458 - SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
29.1459 - }
29.1460 - }
29.1461 -}
29.1462 -
29.1463 -static void
29.1464 -QZ_UpdateRects (_THIS, int numRects, SDL_Rect * rects)
29.1465 -{
29.1466 -
29.1467 - if ([qz_window isMiniaturized]) {
29.1468 -
29.1469 - /* Do nothing if miniaturized */
29.1470 - }
29.1471 -
29.1472 - else if (!QZ_IsWindowObscured (qz_window)) {
29.1473 -
29.1474 - /* Use direct copy to flush contents to the display */
29.1475 - CGrafPtr savePort;
29.1476 - CGrafPtr dstPort, srcPort;
29.1477 - const BitMap *dstBits, *srcBits;
29.1478 - Rect dstRect, srcRect;
29.1479 - Point offset;
29.1480 - int i;
29.1481 -
29.1482 - GetPort (&savePort);
29.1483 -
29.1484 - dstPort = CreateNewPortForCGDisplayID ((UInt32) display_id);
29.1485 - srcPort =[window_view qdPort];
29.1486 -
29.1487 - offset.h = 0;
29.1488 - offset.v = 0;
29.1489 - SetPort (srcPort);
29.1490 - LocalToGlobal (&offset);
29.1491 -
29.1492 - SetPort (dstPort);
29.1493 -
29.1494 - LockPortBits (dstPort);
29.1495 - LockPortBits (srcPort);
29.1496 -
29.1497 - dstBits = GetPortBitMapForCopyBits (dstPort);
29.1498 - srcBits = GetPortBitMapForCopyBits (srcPort);
29.1499 -
29.1500 - for (i = 0; i < numRects; i++) {
29.1501 -
29.1502 - SetRect (&srcRect, rects[i].x, rects[i].y,
29.1503 - rects[i].x + rects[i].w, rects[i].y + rects[i].h);
29.1504 -
29.1505 - SetRect (&dstRect,
29.1506 - rects[i].x + offset.h,
29.1507 - rects[i].y + offset.v,
29.1508 - rects[i].x + rects[i].w + offset.h,
29.1509 - rects[i].y + rects[i].h + offset.v);
29.1510 -
29.1511 - CopyBits (srcBits, dstBits, &srcRect, &dstRect, srcCopy, NULL);
29.1512 -
29.1513 - }
29.1514 -
29.1515 - SetPort (savePort);
29.1516 - } else {
29.1517 - /* Use QDFlushPortBuffer() to flush content to display */
29.1518 - int i;
29.1519 - RgnHandle dirty = NewRgn ();
29.1520 - RgnHandle temp = NewRgn ();
29.1521 -
29.1522 - SetEmptyRgn (dirty);
29.1523 -
29.1524 - /* Build the region of dirty rectangles */
29.1525 - for (i = 0; i < numRects; i++) {
29.1526 -
29.1527 - MacSetRectRgn (temp, rects[i].x, rects[i].y,
29.1528 - rects[i].x + rects[i].w, rects[i].y + rects[i].h);
29.1529 - MacUnionRgn (dirty, temp, dirty);
29.1530 - }
29.1531 -
29.1532 - QZ_DrawResizeIcon (this, dirty);
29.1533 -
29.1534 - /* Flush the dirty region */
29.1535 - QDFlushPortBuffer ([window_view qdPort], dirty);
29.1536 - DisposeRgn (dirty);
29.1537 - DisposeRgn (temp);
29.1538 - }
29.1539 -}
29.1540 -
29.1541 -static void
29.1542 -QZ_VideoQuit (_THIS)
29.1543 -{
29.1544 -
29.1545 - CGDisplayFadeReservationToken fade_token =
29.1546 - kCGDisplayFadeReservationInvalidToken;
29.1547 -
29.1548 - /* Restore gamma settings */
29.1549 - CGDisplayRestoreColorSyncSettings ();
29.1550 -
29.1551 - /* Ensure the cursor will be visible and working when we quit */
29.1552 - CGDisplayShowCursor (display_id);
29.1553 - CGAssociateMouseAndMouseCursorPosition (1);
29.1554 -
29.1555 - if (mode_flags & SDL_FULLSCREEN) {
29.1556 - /* Fade to black to hide resolution-switching flicker (and garbage
29.1557 - that is displayed by a destroyed OpenGL context, if applicable) */
29.1558 - if (CGAcquireDisplayFadeReservation (5, &fade_token) ==
29.1559 - kCGErrorSuccess) {
29.1560 - CGDisplayFade (fade_token, 0.3, kCGDisplayBlendNormal,
29.1561 - kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
29.1562 - }
29.1563 - QZ_UnsetVideoMode (this, TRUE);
29.1564 - if (fade_token != kCGDisplayFadeReservationInvalidToken) {
29.1565 - CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor,
29.1566 - kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
29.1567 - CGReleaseDisplayFadeReservation (fade_token);
29.1568 - }
29.1569 - } else
29.1570 - QZ_UnsetVideoMode (this, TRUE);
29.1571 -
29.1572 - CGPaletteRelease (palette);
29.1573 -
29.1574 - if (opengl_library) {
29.1575 - SDL_UnloadObject (opengl_library);
29.1576 - opengl_library = NULL;
29.1577 - }
29.1578 - this->gl_config.driver_loaded = 0;
29.1579 -}
29.1580 -
29.1581 -#if 0 /* Not used (apparently, it's really slow) */
29.1582 -static int
29.1583 -QZ_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * rect, Uint32 color)
29.1584 -{
29.1585 -
29.1586 - CGSDisplayHWFill (display_id, rect->x, rect->y, rect->w, rect->h, color);
29.1587 -
29.1588 - return 0;
29.1589 -}
29.1590 -#endif
29.1591 -
29.1592 -static int
29.1593 -QZ_LockHWSurface (_THIS, SDL_Surface * surface)
29.1594 -{
29.1595 -
29.1596 - return 1;
29.1597 -}
29.1598 -
29.1599 -static void
29.1600 -QZ_UnlockHWSurface (_THIS, SDL_Surface * surface)
29.1601 -{
29.1602 -
29.1603 -}
29.1604 -
29.1605 -static int
29.1606 -QZ_AllocHWSurface (_THIS, SDL_Surface * surface)
29.1607 -{
29.1608 - return (-1); /* unallowed (no HWSURFACE support here). */
29.1609 -}
29.1610 -
29.1611 -static void
29.1612 -QZ_FreeHWSurface (_THIS, SDL_Surface * surface)
29.1613 -{
29.1614 -}
29.1615 -
29.1616 -/*
29.1617 - int QZ_FlipHWSurface (_THIS, SDL_Surface *surface) {
29.1618 - return 0;
29.1619 - }
29.1620 - */
29.1621 -
29.1622 -/* Gamma functions */
29.1623 -int
29.1624 -QZ_SetGamma (_THIS, float red, float green, float blue)
29.1625 -{
29.1626 -
29.1627 - const CGGammaValue min = 0.0, max = 1.0;
29.1628 -
29.1629 - if (red == 0.0)
29.1630 - red = FLT_MAX;
29.1631 - else
29.1632 - red = 1.0 / red;
29.1633 -
29.1634 - if (green == 0.0)
29.1635 - green = FLT_MAX;
29.1636 - else
29.1637 - green = 1.0 / green;
29.1638 -
29.1639 - if (blue == 0.0)
29.1640 - blue = FLT_MAX;
29.1641 - else
29.1642 - blue = 1.0 / blue;
29.1643 -
29.1644 - if (CGDisplayNoErr == CGSetDisplayTransferByFormula
29.1645 - (display_id, min, max, red, min, max, green, min, max, blue)) {
29.1646 -
29.1647 - return 0;
29.1648 - } else {
29.1649 -
29.1650 - return -1;
29.1651 - }
29.1652 -}
29.1653 -
29.1654 -int
29.1655 -QZ_GetGamma (_THIS, float *red, float *green, float *blue)
29.1656 -{
29.1657 -
29.1658 - CGGammaValue dummy;
29.1659 - if (CGDisplayNoErr == CGGetDisplayTransferByFormula
29.1660 - (display_id, &dummy, &dummy, red,
29.1661 - &dummy, &dummy, green, &dummy, &dummy, blue))
29.1662 -
29.1663 - return 0;
29.1664 - else
29.1665 - return -1;
29.1666 -}
29.1667 -
29.1668 -int
29.1669 -QZ_SetGammaRamp (_THIS, Uint16 * ramp)
29.1670 -{
29.1671 -
29.1672 - const CGTableCount tableSize = 255;
29.1673 - CGGammaValue redTable[tableSize];
29.1674 - CGGammaValue greenTable[tableSize];
29.1675 - CGGammaValue blueTable[tableSize];
29.1676 -
29.1677 - int i;
29.1678 -
29.1679 - /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
29.1680 - for (i = 0; i < 256; i++)
29.1681 - redTable[i % 256] = ramp[i] / 65535.0;
29.1682 -
29.1683 - for (i = 256; i < 512; i++)
29.1684 - greenTable[i % 256] = ramp[i] / 65535.0;
29.1685 -
29.1686 - for (i = 512; i < 768; i++)
29.1687 - blueTable[i % 256] = ramp[i] / 65535.0;
29.1688 -
29.1689 - if (CGDisplayNoErr == CGSetDisplayTransferByTable
29.1690 - (display_id, tableSize, redTable, greenTable, blueTable))
29.1691 - return 0;
29.1692 - else
29.1693 - return -1;
29.1694 -}
29.1695 -
29.1696 -int
29.1697 -QZ_GetGammaRamp (_THIS, Uint16 * ramp)
29.1698 -{
29.1699 -
29.1700 - const CGTableCount tableSize = 255;
29.1701 - CGGammaValue redTable[tableSize];
29.1702 - CGGammaValue greenTable[tableSize];
29.1703 - CGGammaValue blueTable[tableSize];
29.1704 - CGTableCount actual;
29.1705 - int i;
29.1706 -
29.1707 - if (CGDisplayNoErr != CGGetDisplayTransferByTable
29.1708 - (display_id, tableSize, redTable, greenTable, blueTable, &actual) ||
29.1709 - actual != tableSize)
29.1710 -
29.1711 - return -1;
29.1712 -
29.1713 - /* Pack tables into one array, with values from 0 to 65535 */
29.1714 - for (i = 0; i < 256; i++)
29.1715 - ramp[i] = redTable[i % 256] * 65535.0;
29.1716 -
29.1717 - for (i = 256; i < 512; i++)
29.1718 - ramp[i] = greenTable[i % 256] * 65535.0;
29.1719 -
29.1720 - for (i = 512; i < 768; i++)
29.1721 - ramp[i] = blueTable[i % 256] * 65535.0;
29.1722 -
29.1723 - return 0;
29.1724 -}
30.1 --- a/src/video/quartz/SDL_QuartzWM.m Sun Jul 23 00:55:25 2006 +0000
30.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
30.3 @@ -1,492 +0,0 @@
30.4 -/*
30.5 - SDL - Simple DirectMedia Layer
30.6 - Copyright (C) 1997-2003 Sam Lantinga
30.7 -
30.8 - This library is free software; you can redistribute it and/or
30.9 - modify it under the terms of the GNU Library General Public
30.10 - License as published by the Free Software Foundation; either
30.11 - version 2 of the License, or (at your option) any later version.
30.12 -
30.13 - This library is distributed in the hope that it will be useful,
30.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
30.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30.16 - Library General Public License for more details.
30.17 -
30.18 - You should have received a copy of the GNU Library General Public
30.19 - License along with this library; if not, write to the Free
30.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30.21 -
30.22 - Sam Lantinga
30.23 - slouken@libsdl.org
30.24 -*/
30.25 -#include "SDL_config.h"
30.26 -
30.27 -#include "SDL_QuartzVideo.h"
30.28 -
30.29 -
30.30 -struct WMcursor
30.31 -{
30.32 - NSCursor *nscursor;
30.33 -};
30.34 -
30.35 -void
30.36 -QZ_FreeWMCursor(_THIS, WMcursor * cursor)
30.37 -{
30.38 -
30.39 - if (cursor != NULL) {
30.40 - [cursor->nscursor release];
30.41 - free(cursor);
30.42 - }
30.43 -}
30.44 -
30.45 -WMcursor *
30.46 -QZ_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
30.47 - int w, int h, int hot_x, int hot_y)
30.48 -{
30.49 - WMcursor *cursor;
30.50 - NSBitmapImageRep *imgrep;
30.51 - NSImage *img;
30.52 - unsigned char *planes[5];
30.53 - int i;
30.54 - NSAutoreleasePool *pool;
30.55 -
30.56 - pool =[[NSAutoreleasePool alloc] init];
30.57 -
30.58 - /* Allocate the cursor memory */
30.59 - cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
30.60 - if (cursor == NULL)
30.61 - goto outOfMemory;
30.62 -
30.63 - /* create the image representation and get the pointers to its storage */
30.64 - 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];
30.65 - if (imgrep == nil)
30.66 - goto outOfMemory;
30.67 - [imgrep getBitmapDataPlanes:planes];
30.68 -
30.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 */
30.70 - for (i = 0; i < (w + 7) / 8 * h; i++) {
30.71 - planes[0][i] = data[i];
30.72 - planes[1][i] = mask[i] | data[i];
30.73 - }
30.74 -
30.75 - /* create image and cursor */
30.76 - img =[[[NSImage alloc] initWithSize:NSMakeSize(w, h)] autorelease];
30.77 - if (img == nil)
30.78 - goto outOfMemory;
30.79 - [img addRepresentation:imgrep];
30.80 - if (system_version < 0x1030) { /* on 10.2, cursors must be 16*16 */
30.81 - if (w > 16 || h > 16) { /* too big: scale it down */
30.82 - [img setScalesWhenResized:YES];
30.83 - hot_x = hot_x * 16 / w;
30.84 - hot_y = hot_y * 16 / h;
30.85 - } else { /* too small (or just right): extend it (from the bottom left corner, so hot_y must be adjusted) */
30.86 - hot_y += 16 - h;
30.87 - }
30.88 - [img setSize:NSMakeSize(16, 16)];
30.89 - }
30.90 - cursor->nscursor =[[NSCursor alloc] initWithImage: img hotSpot:NSMakePoint(hot_x,
30.91 - hot_y)];
30.92 - if (cursor->nscursor == nil)
30.93 - goto outOfMemory;
30.94 -
30.95 - [pool release];
30.96 - return (cursor);
30.97 -
30.98 - outOfMemory:
30.99 - [pool release];
30.100 - if (cursor != NULL)
30.101 - SDL_free(cursor);
30.102 - SDL_OutOfMemory();
30.103 - return (NULL);
30.104 -}
30.105 -
30.106 -void
30.107 -QZ_ShowMouse(_THIS)
30.108 -{
30.109 - if (!cursor_visible) {
30.110 - [NSCursor unhide];
30.111 - cursor_visible = YES;
30.112 - }
30.113 -}
30.114 -
30.115 -void
30.116 -QZ_HideMouse(_THIS)
30.117 -{
30.118 - if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) {
30.119 - [NSCursor hide];
30.120 - cursor_visible = NO;
30.121 - }
30.122 -}
30.123 -
30.124 -BOOL
30.125 -QZ_IsMouseInWindow(_THIS)
30.126 -{
30.127 - if (qz_window == nil)
30.128 - return YES; /*fullscreen */
30.129 - else {
30.130 - NSPoint p =[qz_window mouseLocationOutsideOfEventStream];
30.131 - 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" */
30.132 - return NSPointInRect(p,[window_view frame]);
30.133 - }
30.134 -}
30.135 -
30.136 -int
30.137 -QZ_ShowWMCursor(_THIS, WMcursor * cursor)
30.138 -{
30.139 -
30.140 - if (cursor == NULL) {
30.141 - if (cursor_should_be_visible) {
30.142 - QZ_HideMouse(this);
30.143 - cursor_should_be_visible = NO;
30.144 - QZ_ChangeGrabState(this, QZ_HIDECURSOR);
30.145 - }
30.146 - } else {
30.147 - [cursor->nscursor set];
30.148 - if (!cursor_should_be_visible) {
30.149 - QZ_ShowMouse(this);
30.150 - cursor_should_be_visible = YES;
30.151 - QZ_ChangeGrabState(this, QZ_SHOWCURSOR);
30.152 - }
30.153 - }
30.154 -
30.155 - return 1;
30.156 -}
30.157 -
30.158 -/*
30.159 - Coordinate conversion functions, for convenience
30.160 - Cocoa sets the origin at the lower left corner of the window/screen
30.161 - SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
30.162 - The routines were written so they could be called before SetVideoMode() has finished;
30.163 - this might have limited usefulness at the moment, but the extra cost is trivial.
30.164 -*/
30.165 -
30.166 -/* Convert Cocoa screen coordinate to Cocoa window coordinate */
30.167 -void
30.168 -QZ_PrivateGlobalToLocal(_THIS, NSPoint * p)
30.169 -{
30.170 -
30.171 - *p =[qz_window convertScreenToBase:*p];
30.172 -}
30.173 -
30.174 -
30.175 -/* Convert Cocoa window coordinate to Cocoa screen coordinate */
30.176 -void
30.177 -QZ_PrivateLocalToGlobal(_THIS, NSPoint * p)
30.178 -{
30.179 -
30.180 - *p =[qz_window convertBaseToScreen:*p];
30.181 -}
30.182 -
30.183 -/* Convert SDL coordinate to Cocoa coordinate */
30.184 -void
30.185 -QZ_PrivateSDLToCocoa(_THIS, NSPoint * p)
30.186 -{
30.187 -
30.188 - if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
30.189 -
30.190 - p->y = CGDisplayPixelsHigh(display_id) - p->y;
30.191 - } else {
30.192 -
30.193 - *p =[window_view convertPoint: *p toView:nil];
30.194 -
30.195 - /* We need a workaround in OpenGL mode */
30.196 - if (SDL_VideoSurface->flags & SDL_OPENGL) {
30.197 - p->y =[window_view frame].size.height - p->y;
30.198 - }
30.199 - }
30.200 -}
30.201 -
30.202 -/* Convert Cocoa coordinate to SDL coordinate */
30.203 -void
30.204 -QZ_PrivateCocoaToSDL(_THIS, NSPoint * p)
30.205 -{
30.206 -
30.207 - if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
30.208 -
30.209 - p->y = CGDisplayPixelsHigh(display_id) - p->y;
30.210 - } else {
30.211 -
30.212 - *p =[window_view convertPoint: *p fromView:nil];
30.213 -
30.214 - /* We need a workaround in OpenGL mode */
30.215 - if (SDL_VideoSurface != NULL
30.216 - && (SDL_VideoSurface->flags & SDL_OPENGL)) {
30.217 - p->y =[window_view frame].size.height - p->y;
30.218 - }
30.219 - }
30.220 -}
30.221 -
30.222 -/* Convert SDL coordinate to window server (CoreGraphics) coordinate */
30.223 -CGPoint
30.224 -QZ_PrivateSDLToCG(_THIS, NSPoint * p)
30.225 -{
30.226 -
30.227 - CGPoint cgp;
30.228 -
30.229 - if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
30.230 -
30.231 - int height;
30.232 -
30.233 - QZ_PrivateSDLToCocoa(this, p);
30.234 - QZ_PrivateLocalToGlobal(this, p);
30.235 -
30.236 - height = CGDisplayPixelsHigh(display_id);
30.237 - p->y = height - p->y;
30.238 - }
30.239 -
30.240 - cgp.x = p->x;
30.241 - cgp.y = p->y;
30.242 -
30.243 - return cgp;
30.244 -}
30.245 -
30.246 -#if 0 /* Dead code */
30.247 -/* Convert window server (CoreGraphics) coordinate to SDL coordinate */
30.248 -void
30.249 -QZ_PrivateCGToSDL(_THIS, NSPoint * p)
30.250 -{
30.251 -
30.252 - if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
30.253 -
30.254 - int height;
30.255 -
30.256 - /* Convert CG Global to Cocoa Global */
30.257 - height = CGDisplayPixelsHigh(display_id);
30.258 - p->y = height - p->y;
30.259 -
30.260 - QZ_PrivateGlobalToLocal(this, p);
30.261 - QZ_PrivateCocoaToSDL(this, p);
30.262 - }
30.263 -}
30.264 -#endif /* Dead code */
30.265 -
30.266 -void
30.267 -QZ_PrivateWarpCursor(_THIS, int x, int y)
30.268 -{
30.269 -
30.270 - NSPoint p;
30.271 - CGPoint cgp;
30.272 -
30.273 - p = NSMakePoint(x, y);
30.274 - cgp = QZ_PrivateSDLToCG(this, &p);
30.275 -
30.276 - /* this is the magic call that fixes cursor "freezing" after warp */
30.277 - CGSetLocalEventsSuppressionInterval(0.0);
30.278 - CGWarpMouseCursorPosition(cgp);
30.279 -}
30.280 -
30.281 -void
30.282 -QZ_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
30.283 -{
30.284 -
30.285 - /* Only allow warping when in foreground */
30.286 - if (![NSApp isActive])
30.287 - return;
30.288 -
30.289 - /* Do the actual warp */
30.290 - if (grab_state != QZ_INVISIBLE_GRAB)
30.291 - QZ_PrivateWarpCursor(this, x, y);
30.292 -
30.293 - /* Generate the mouse moved event */
30.294 - SDL_PrivateMouseMotion(0, 0, x, y);
30.295 -}
30.296 -
30.297 -void
30.298 -QZ_MoveWMCursor(_THIS, int x, int y)
30.299 -{
30.300 -}
30.301 -void
30.302 -QZ_CheckMouseMode(_THIS)
30.303 -{
30.304 -}
30.305 -
30.306 -void
30.307 -QZ_SetCaption(_THIS, const char *title, const char *icon)
30.308 -{
30.309 -
30.310 - if (qz_window != nil) {
30.311 - NSString *string;
30.312 - if (title != NULL) {
30.313 - string =[[NSString alloc] initWithUTF8String:title];
30.314 - [qz_window setTitle:string];
30.315 - [string release];
30.316 - }
30.317 - if (icon != NULL) {
30.318 - string =[[NSString alloc] initWithUTF8String:icon];
30.319 - [qz_window setMiniwindowTitle:string];
30.320 - [string release];
30.321 - }
30.322 - }
30.323 -}
30.324 -
30.325 -void
30.326 -QZ_SetIcon(_THIS, SDL_Surface * icon, Uint8 * mask)
30.327 -{
30.328 - NSBitmapImageRep *imgrep;
30.329 - NSImage *img;
30.330 - SDL_Surface *mergedSurface;
30.331 - NSAutoreleasePool *pool;
30.332 - Uint8 *pixels;
30.333 - SDL_bool iconSrcAlpha;
30.334 - Uint8 iconAlphaValue;
30.335 - int i, j, maskPitch, index;
30.336 -
30.337 - pool =[[NSAutoreleasePool alloc] init];
30.338 -
30.339 - 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];
30.340 - if (imgrep == nil)
30.341 - goto freePool;
30.342 - pixels =[imgrep bitmapData];
30.343 - SDL_memset(pixels, 0, 4 * icon->w * icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
30.344 -
30.345 -#if SDL_BYTEORDER == SDL_BIG_ENDIAN
30.346 -#define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
30.347 -#else
30.348 -#define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
30.349 -#endif
30.350 - mergedSurface =
30.351 - SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4 * icon->w,
30.352 - BYTEORDER_DEPENDENT_RGBA_MASKS);
30.353 - if (mergedSurface == NULL)
30.354 - goto freePool;
30.355 -
30.356 - /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
30.357 - iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
30.358 - iconAlphaValue = icon->format->alpha;
30.359 - SDL_SetAlpha(icon, 0, 255);
30.360 - SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
30.361 - if (iconSrcAlpha)
30.362 - SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
30.363 -
30.364 - SDL_FreeSurface(mergedSurface);
30.365 -
30.366 - /* apply mask, source alpha, and premultiply color values by alpha */
30.367 - maskPitch = (icon->w + 7) / 8;
30.368 - for (i = 0; i < icon->h; i++) {
30.369 - for (j = 0; j < icon->w; j++) {
30.370 - index = i * 4 * icon->w + j * 4;
30.371 - if (!(mask[i * maskPitch + j / 8] & (128 >> j % 8))) {
30.372 - pixels[index + 3] = 0;
30.373 - } else {
30.374 - if (iconSrcAlpha) {
30.375 - if (icon->format->Amask == 0)
30.376 - pixels[index + 3] = icon->format->alpha;
30.377 - } else {
30.378 - pixels[index + 3] = 255;
30.379 - }
30.380 - }
30.381 - if (pixels[index + 3] < 255) {
30.382 - pixels[index + 0] =
30.383 - (Uint16) pixels[index + 0] * pixels[index + 3] / 255;
30.384 - pixels[index + 1] =
30.385 - (Uint16) pixels[index + 1] * pixels[index + 3] / 255;
30.386 - pixels[index + 2] =
30.387 - (Uint16) pixels[index + 2] * pixels[index + 3] / 255;
30.388 - }
30.389 - }
30.390 - }
30.391 -
30.392 - img =[[[NSImage alloc] initWithSize:NSMakeSize(icon->w,
30.393 - icon->h)] autorelease];
30.394 - if (img == nil)
30.395 - goto freePool;
30.396 - [img addRepresentation:imgrep];
30.397 - [NSApp setApplicationIconImage:img];
30.398 -
30.399 - freePool:
30.400 - [pool release];
30.401 -}
30.402 -
30.403 -int
30.404 -QZ_IconifyWindow(_THIS)
30.405 -{
30.406 -
30.407 - if (![qz_window isMiniaturized]) {
30.408 - [qz_window miniaturize:nil];
30.409 - return 1;
30.410 - } else {
30.411 - SDL_SetError("window already iconified");
30.412 - return 0;
30.413 - }
30.414 -}
30.415 -
30.416 -/*
30.417 -int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) {
30.418 - info->nsWindowPtr = qz_window;
30.419 - return 0;
30.420 -}*/
30.421 -
30.422 -void
30.423 -QZ_ChangeGrabState(_THIS, int action)
30.424 -{
30.425 -
30.426 - /*
30.427 - Figure out what the next state should be based on the action.
30.428 - Ignore actions that can't change the current state.
30.429 - */
30.430 - if (grab_state == QZ_UNGRABBED) {
30.431 - if (action == QZ_ENABLE_GRAB) {
30.432 - if (cursor_should_be_visible)
30.433 - grab_state = QZ_VISIBLE_GRAB;
30.434 - else
30.435 - grab_state = QZ_INVISIBLE_GRAB;
30.436 - }
30.437 - } else if (grab_state == QZ_VISIBLE_GRAB) {
30.438 - if (action == QZ_DISABLE_GRAB)
30.439 - grab_state = QZ_UNGRABBED;
30.440 - else if (action == QZ_HIDECURSOR)
30.441 - grab_state = QZ_INVISIBLE_GRAB;
30.442 - } else {
30.443 - assert(grab_state == QZ_INVISIBLE_GRAB);
30.444 -
30.445 - if (action == QZ_DISABLE_GRAB)
30.446 - grab_state = QZ_UNGRABBED;
30.447 - else if (action == QZ_SHOWCURSOR)
30.448 - grab_state = QZ_VISIBLE_GRAB;
30.449 - }
30.450 -
30.451 - /* now apply the new state */
30.452 - if (grab_state == QZ_UNGRABBED) {
30.453 -
30.454 - CGAssociateMouseAndMouseCursorPosition(1);
30.455 - } else if (grab_state == QZ_VISIBLE_GRAB) {
30.456 -
30.457 - CGAssociateMouseAndMouseCursorPosition(1);
30.458 - } else {
30.459 - assert(grab_state == QZ_INVISIBLE_GRAB);
30.460 -
30.461 - QZ_PrivateWarpCursor(this, SDL_VideoSurface->w / 2,
30.462 - SDL_VideoSurface->h / 2);
30.463 - CGAssociateMouseAndMouseCursorPosition(0);
30.464 - }
30.465 -}
30.466 -
30.467 -SDL_GrabMode
30.468 -QZ_GrabInput(_THIS, SDL_GrabMode grab_mode)
30.469 -{
30.470 -
30.471 - int doGrab = grab_mode & SDL_GRAB_ON;
30.472 - /*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN; */
30.473 -
30.474 - if (this->screen == NULL) {
30.475 - SDL_SetError("QZ_GrabInput: screen is NULL");
30.476 - return SDL_GRAB_OFF;
30.477 - }
30.478 -
30.479 - if (!video_set) {
30.480 - /*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */
30.481 - current_grab_mode = grab_mode;
30.482 - return grab_mode; /* Will be set later on mode switch */
30.483 - }
30.484 -
30.485 - if (grab_mode != SDL_GRAB_QUERY) {
30.486 - if (doGrab)
30.487 - QZ_ChangeGrabState(this, QZ_ENABLE_GRAB);
30.488 - else
30.489 - QZ_ChangeGrabState(this, QZ_DISABLE_GRAB);
30.490 -
30.491 - current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF;
30.492 - }
30.493 -
30.494 - return current_grab_mode;
30.495 -}
31.1 --- a/src/video/quartz/SDL_QuartzWindow.h Sun Jul 23 00:55:25 2006 +0000
31.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
31.3 @@ -1,41 +0,0 @@
31.4 -/*
31.5 - SDL - Simple DirectMedia Layer
31.6 - Copyright (C) 1997-2003 Sam Lantinga
31.7 -
31.8 - This library is free software; you can redistribute it and/or
31.9 - modify it under the terms of the GNU Library General Public
31.10 - License as published by the Free Software Foundation; either
31.11 - version 2 of the License, or (at your option) any later version.
31.12 -
31.13 - This library is distributed in the hope that it will be useful,
31.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
31.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31.16 - Library General Public License for more details.
31.17 -
31.18 - You should have received a copy of the GNU Library General Public
31.19 - License along with this library; if not, write to the Free
31.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31.21 -
31.22 - Sam Lantinga
31.23 - slouken@libsdl.org
31.24 -*/
31.25 -#include "SDL_config.h"
31.26 -
31.27 -/* Subclass of NSWindow to fix genie effect and support resize events */
31.28 -@ interface SDL_QuartzWindow: NSWindow - (void) miniaturize:(id) sender;
31.29 --(void) display;
31.30 --(void) setFrame:(NSRect)
31.31 - frameRect display:(BOOL) flag;
31.32 --(void) appDidHide:(NSNotification *) note;
31.33 --(void) appWillUnhide:(NSNotification *) note;
31.34 --(void) appDidUnhide:(NSNotification *) note;
31.35 --(id) initWithContentRect:(NSRect)
31.36 - contentRect styleMask:(unsigned int)
31.37 - styleMask backing:(NSBackingStoreType)
31.38 - backingType defer:(BOOL) flag;
31.39 -@end
31.40 -/* Delegate for our NSWindow to send SDLQuit() on close */
31.41 -@ interface SDL_QuartzWindowDelegate: NSObject - (BOOL) windowShouldClose:(id)
31.42 - sender;
31.43 -@end
31.44 -/* vi: set ts=4 sw=4 expandtab: */
32.1 --- a/src/video/quartz/SDL_QuartzWindow.m Sun Jul 23 00:55:25 2006 +0000
32.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
32.3 @@ -1,214 +0,0 @@
32.4 -/*
32.5 - SDL - Simple DirectMedia Layer
32.6 - Copyright (C) 1997-2003 Sam Lantinga
32.7 -
32.8 - This library is free software; you can redistribute it and/or
32.9 - modify it under the terms of the GNU Library General Public
32.10 - License as published by the Free Software Foundation; either
32.11 - version 2 of the License, or (at your option) any later version.
32.12 -
32.13 - This library is distributed in the hope that it will be useful,
32.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
32.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32.16 - Library General Public License for more details.
32.17 -
32.18 - You should have received a copy of the GNU Library General Public
32.19 - License along with this library; if not, write to the Free
32.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32.21 -
32.22 - Sam Lantinga
32.23 - slouken@libsdl.org
32.24 -*/
32.25 -#include "SDL_config.h"
32.26 -
32.27 -#include "SDL_QuartzVideo.h"
32.28 -#include "SDL_QuartzWindow.h"
32.29 -
32.30 -/*
32.31 - This function makes the *SDL region* of the window 100% opaque.
32.32 - The genie effect uses the alpha component. Otherwise,
32.33 - it doesn't seem to matter what value it has.
32.34 -*/
32.35 -static void
32.36 -QZ_SetPortAlphaOpaque ()
32.37 -{
32.38 -
32.39 - SDL_Surface *surface = current_video->screen;
32.40 - int bpp;
32.41 -
32.42 - bpp = surface->format->BitsPerPixel;
32.43 -
32.44 - if (bpp == 32) {
32.45 -
32.46 - Uint32 *pixels = (Uint32 *) surface->pixels;
32.47 - Uint32 rowPixels = surface->pitch / 4;
32.48 - Uint32 i, j;
32.49 -
32.50 - for (i = 0; i < surface->h; i++)
32.51 - for (j = 0; j < surface->w; j++) {
32.52 -
32.53 - pixels[(i * rowPixels) + j] |= 0xFF000000;
32.54 - }
32.55 - }
32.56 -}
32.57 -
32.58 -@implementation SDL_QuartzWindow
32.59 -/* we override these methods to fix the miniaturize animation/dock icon bug */
32.60 -- (void) miniaturize:(id) sender {
32.61 - if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
32.62 -
32.63 - /*
32.64 - Future: Grab framebuffer and put into NSImage
32.65 - [ qz_window setMiniwindowImage:image ];
32.66 - */
32.67 - } else {
32.68 -
32.69 - /* make the alpha channel opaque so anim won't have holes in it */
32.70 - QZ_SetPortAlphaOpaque ();
32.71 - }
32.72 -
32.73 - /* window is hidden now */
32.74 - SDL_PrivateAppActive (0, SDL_APPACTIVE);
32.75 -
32.76 - [super miniaturize:sender];
32.77 -}
32.78 -
32.79 --(void) display {
32.80 - /*
32.81 - This method fires just before the window deminaturizes from the Dock.
32.82 -
32.83 - We'll save the current visible surface, let the window manager redraw any
32.84 - UI elements, and restore the SDL surface. This way, no expose event
32.85 - is required, and the deminiaturize works perfectly.
32.86 - */
32.87 - SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
32.88 -
32.89 - /* make sure pixels are fully opaque */
32.90 - if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL))
32.91 - QZ_SetPortAlphaOpaque ();
32.92 -
32.93 - /* save current visible SDL surface */
32.94 - [self cacheImageInRect:[window_view frame]];
32.95 -
32.96 - /* let the window manager redraw controls, border, etc */
32.97 - [super display];
32.98 -
32.99 - /* restore visible SDL surface */
32.100 - [self restoreCachedImage];
32.101 -
32.102 - /* window is visible again */
32.103 - SDL_PrivateAppActive (1, SDL_APPACTIVE);
32.104 -}
32.105 -
32.106 --(void) setFrame:(NSRect)
32.107 - frameRect display:(BOOL) flag
32.108 -{
32.109 -
32.110 - /*
32.111 - If the video surface is NULL, this originated from QZ_SetVideoMode,
32.112 - so don't send the resize event.
32.113 - */
32.114 - SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
32.115 -
32.116 - if (this && SDL_VideoSurface == NULL) {
32.117 -
32.118 - [super setFrame: frameRect display:flag];
32.119 - } else if (this && qz_window) {
32.120 -
32.121 - NSRect newViewFrame;
32.122 -
32.123 - [super setFrame: frameRect display:flag];
32.124 -
32.125 - newViewFrame =[window_view frame];
32.126 -
32.127 - SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height);
32.128 -
32.129 - /* If not OpenGL, we have to update the pixels and pitch */
32.130 - if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL)) {
32.131 -
32.132 - CGrafPtr thePort =[window_view qdPort];
32.133 - LockPortBits (thePort);
32.134 -
32.135 - SDL_VideoSurface->pixels =
32.136 - GetPixBaseAddr (GetPortPixMap (thePort));
32.137 - SDL_VideoSurface->pitch =
32.138 - GetPixRowBytes (GetPortPixMap (thePort));
32.139 -
32.140 - /*
32.141 - SDL_VideoSurface->pixels now points to the window's pixels
32.142 - We want it to point to the *view's* pixels
32.143 - */
32.144 - {
32.145 - int vOffset =[qz_window frame].size.height -
32.146 - newViewFrame.size.height - newViewFrame.origin.y;
32.147 -
32.148 - int hOffset = newViewFrame.origin.x;
32.149 -
32.150 - SDL_VideoSurface->pixels =
32.151 - (Uint8 *) SDL_VideoSurface->pixels +
32.152 - (vOffset * SDL_VideoSurface->pitch) +
32.153 - hOffset * (device_bpp / 8);
32.154 - }
32.155 -
32.156 - UnlockPortBits (thePort);
32.157 - }
32.158 - }
32.159 -}
32.160 -
32.161 --(void) appDidHide:(NSNotification *) note {
32.162 - SDL_PrivateAppActive (0, SDL_APPACTIVE);
32.163 -}
32.164 -
32.165 --(void) appWillUnhide:(NSNotification *) note {
32.166 - SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
32.167 -
32.168 - if (this) {
32.169 -
32.170 - /* make sure pixels are fully opaque */
32.171 - if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL))
32.172 - QZ_SetPortAlphaOpaque ();
32.173 -
32.174 - /* save current visible SDL surface */
32.175 - [self cacheImageInRect:[window_view frame]];
32.176 - }
32.177 -}
32.178 -
32.179 --(void) appDidUnhide:(NSNotification *) note {
32.180 - /* restore cached image, since it may not be current, post expose event too */
32.181 - [self restoreCachedImage];
32.182 -
32.183 - /*SDL_PrivateExpose (); */
32.184 -
32.185 - SDL_PrivateAppActive (1, SDL_APPACTIVE);
32.186 -}
32.187 -
32.188 --(id) initWithContentRect:(NSRect)
32.189 - contentRect styleMask:(unsigned int)
32.190 - styleMask backing:(NSBackingStoreType)
32.191 - backingType defer:(BOOL) flag
32.192 -{
32.193 - /* Make our window subclass receive these application notifications */
32.194 - [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appDidHide: )name: NSApplicationDidHideNotification object:NSApp];
32.195 -
32.196 - [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appDidUnhide: )name: NSApplicationDidUnhideNotification object:NSApp];
32.197 -
32.198 - [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appWillUnhide: )name: NSApplicationWillUnhideNotification object:NSApp];
32.199 -
32.200 - return[super initWithContentRect: contentRect styleMask: styleMask backing: backingType defer:flag];
32.201 -}
32.202 -
32.203 -@end @ implementation SDL_QuartzWindowDelegate - (BOOL) windowShouldClose:(id) sender
32.204 -{
32.205 - SDL_PrivateQuit ();
32.206 - return NO;
32.207 -}
32.208 -
32.209 --(void) windowDidBecomeKey:(NSNotification *) aNotification {
32.210 - QZ_DoActivate (current_video);
32.211 -}
32.212 -
32.213 --(void) windowDidResignKey:(NSNotification *) aNotification {
32.214 - QZ_DoDeactivate (current_video);
32.215 -}
32.216 -
32.217 -@end
33.1 --- a/src/video/quartz/SDL_QuartzYUV.m Sun Jul 23 00:55:25 2006 +0000
33.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
33.3 @@ -1,330 +0,0 @@
33.4 -/*
33.5 - SDL - Simple DirectMedia Layer
33.6 - Copyright (C) 1997-2003 Sam Lantinga
33.7 -
33.8 - This library is free software; you can redistribute it and/or
33.9 - modify it under the terms of the GNU Library General Public
33.10 - License as published by the Free Software Foundation; either
33.11 - version 2 of the License, or (at your option) any later version.
33.12 -
33.13 - This library is distributed in the hope that it will be useful,
33.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
33.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33.16 - Library General Public License for more details.
33.17 -
33.18 - You should have received a copy of the GNU Library General Public
33.19 - License along with this library; if not, write to the Free
33.20 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33.21 -
33.22 - Sam Lantinga
33.23 - slouken@libsdl.org
33.24 -*/
33.25 -#include "SDL_config.h"
33.26 -
33.27 -#include "SDL_QuartzVideo.h"
33.28 -#include "SDL_QuartzWindow.h"
33.29 -#include "../SDL_yuvfuncs.h"
33.30 -
33.31 -
33.32 -#define yuv_idh (this->hidden->yuv_idh)
33.33 -#define yuv_matrix (this->hidden->yuv_matrix)
33.34 -#define yuv_codec (this->hidden->yuv_codec)
33.35 -#define yuv_seq (this->hidden->yuv_seq)
33.36 -#define yuv_pixmap (this->hidden->yuv_pixmap)
33.37 -#define yuv_data (this->hidden->yuv_data)
33.38 -#define yuv_width (this->hidden->yuv_width)
33.39 -#define yuv_height (this->hidden->yuv_height)
33.40 -#define yuv_port (this->hidden->yuv_port)
33.41 -
33.42 -
33.43 -static int
33.44 -QZ_LockYUV (_THIS, SDL_Overlay * overlay)
33.45 -{
33.46 -
33.47 - return 0;
33.48 -}
33.49 -
33.50 -static void
33.51 -QZ_UnlockYUV (_THIS, SDL_Overlay * overlay)
33.52 -{
33.53 -
33.54 - ;
33.55 -}
33.56 -
33.57 -static int
33.58 -QZ_DisplayYUV (_THIS, SDL_Overlay * overlay, SDL_Rect * src, SDL_Rect * dst)
33.59 -{
33.60 -
33.61 - OSErr err;
33.62 - CodecFlags flags;
33.63 -
33.64 - if (dst->x != 0 || dst->y != 0) {
33.65 -
33.66 - SDL_SetError ("Need a dst at (0,0)");
33.67 - return -1;
33.68 - }
33.69 -
33.70 - if (dst->w != yuv_width || dst->h != yuv_height) {
33.71 -
33.72 - Fixed scale_x, scale_y;
33.73 -
33.74 - scale_x = FixDiv (Long2Fix (dst->w), Long2Fix (overlay->w));
33.75 - scale_y = FixDiv (Long2Fix (dst->h), Long2Fix (overlay->h));
33.76 -
33.77 - SetIdentityMatrix (yuv_matrix);
33.78 - ScaleMatrix (yuv_matrix, scale_x, scale_y, Long2Fix (0),
33.79 - Long2Fix (0));
33.80 -
33.81 - SetDSequenceMatrix (yuv_seq, yuv_matrix);
33.82 -
33.83 - yuv_width = dst->w;
33.84 - yuv_height = dst->h;
33.85 - }
33.86 -
33.87 - if ((err = DecompressSequenceFrameS (yuv_seq,
33.88 - (void *) yuv_pixmap,
33.89 - sizeof (PlanarPixmapInfoYUV420),
33.90 - codecFlagUseImageBuffer, &flags,
33.91 - nil) != noErr)) {
33.92 - SDL_SetError ("DecompressSequenceFrameS failed");
33.93 - }
33.94 -
33.95 - return err != noErr;
33.96 -}
33.97 -
33.98 -static void
33.99 -QZ_FreeHWYUV (_THIS, SDL_Overlay * overlay)
33.100 -{
33.101 -
33.102 - CDSequenceEnd (yuv_seq);
33.103 - ExitMovies ();
33.104 -
33.105 - SDL_free (overlay->hwfuncs);
33.106 - SDL_free (overlay->pitches);
33.107 - SDL_free (overlay->pixels);
33.108 -
33.109 - if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
33.110 - [qz_window close];
33.111 - qz_window = nil;
33.112 - }
33.113 -
33.114 - SDL_free (yuv_matrix);
33.115 - DisposeHandle ((Handle) yuv_idh);
33.116 -}
33.117 -
33.118 -/* check for 16 byte alignment, bail otherwise */
33.119 -#define CHECK_ALIGN(x) do { if ((Uint32)x & 15) { SDL_SetError("Alignment error"); return NULL; } } while(0)
33.120 -
33.121 -/* align a byte offset, return how much to add to make it a multiple of 16 */
33.122 -#define ALIGN(x) ((16 - (x & 15)) & 15)
33.123 -
33.124 -SDL_Overlay *
33.125 -QZ_CreateYUVOverlay (_THIS, int width, int height,
33.126 - Uint32 format, SDL_Surface * display)
33.127 -{
33.128 -
33.129 - Uint32 codec;
33.130 - OSStatus err;
33.131 - CGrafPtr port;
33.132 - SDL_Overlay *overlay;
33.133 -
33.134 - if (format == SDL_YV12_OVERLAY || format == SDL_IYUV_OVERLAY) {
33.135 -
33.136 - codec = kYUV420CodecType;
33.137 - } else {
33.138 - SDL_SetError ("Hardware: unsupported video format");
33.139 - return NULL;
33.140 - }
33.141 -
33.142 - yuv_idh =
33.143 - (ImageDescriptionHandle) NewHandleClear (sizeof (ImageDescription));
33.144 - if (yuv_idh == NULL) {
33.145 - SDL_OutOfMemory ();
33.146 - return NULL;
33.147 - }
33.148 -
33.149 - yuv_matrix = (MatrixRecordPtr) SDL_malloc (sizeof (MatrixRecord));
33.150 - if (yuv_matrix == NULL) {
33.151 - SDL_OutOfMemory ();
33.152 - return NULL;
33.153 - }
33.154 -
33.155 - if (EnterMovies () != noErr) {
33.156 - SDL_SetError ("Could not init QuickTime for YUV playback");
33.157 - return NULL;
33.158 - }
33.159 -
33.160 - err = FindCodec (codec, bestSpeedCodec, nil, &yuv_codec);
33.161 - if (err != noErr) {
33.162 - SDL_SetError ("Could not find QuickTime codec for format");
33.163 - return NULL;
33.164 - }
33.165 -
33.166 - if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
33.167 -
33.168 - /*
33.169 - Acceleration requires a window to be present.
33.170 - A CGrafPtr that points to the screen isn't good enough
33.171 - */
33.172 - NSRect content =
33.173 - NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
33.174 -
33.175 - qz_window =[[SDL_QuartzWindow alloc] initWithContentRect: content styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer:NO];
33.176 -
33.177 - if (qz_window == nil) {
33.178 - SDL_SetError ("Could not create the Cocoa window");
33.179 - return NULL;
33.180 - }
33.181 -
33.182 - [qz_window setContentView:[[NSQuickDrawView alloc] init]];
33.183 - [qz_window setReleasedWhenClosed:YES];
33.184 - [qz_window center];
33.185 - [qz_window setAcceptsMouseMovedEvents:YES];
33.186 - [qz_window setLevel:CGShieldingWindowLevel ()];
33.187 - [qz_window makeKeyAndOrderFront:nil];
33.188 -
33.189 - port =[[qz_window contentView] qdPort];
33.190 - SetPort (port);
33.191 -
33.192 - /*
33.193 - BUG: would like to remove white flash when window kicks in
33.194 - {
33.195 - Rect r;
33.196 - SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
33.197 - PaintRect (&r);
33.198 - QDFlushPortBuffer (port, nil);
33.199 - }
33.200 - */
33.201 - } else {
33.202 - port =[window_view qdPort];
33.203 - SetPort (port);
33.204 - }
33.205 -
33.206 - SetIdentityMatrix (yuv_matrix);
33.207 -
33.208 - HLock ((Handle) yuv_idh);
33.209 -
33.210 - (**yuv_idh).idSize = sizeof (ImageDescription);
33.211 - (**yuv_idh).cType = codec;
33.212 - (**yuv_idh).version = 1;
33.213 - (**yuv_idh).revisionLevel = 0;
33.214 - (**yuv_idh).width = width;
33.215 - (**yuv_idh).height = height;
33.216 - (**yuv_idh).hRes = Long2Fix (72);
33.217 - (**yuv_idh).vRes = Long2Fix (72);
33.218 - (**yuv_idh).spatialQuality = codecLosslessQuality;
33.219 - (**yuv_idh).frameCount = 1;
33.220 - (**yuv_idh).clutID = -1;
33.221 - (**yuv_idh).dataSize = 0;
33.222 - (**yuv_idh).depth = 24;
33.223 -
33.224 - HUnlock ((Handle) yuv_idh);
33.225 -
33.226 - err = DecompressSequenceBeginS (&yuv_seq,
33.227 - yuv_idh,
33.228 - NULL,
33.229 - 0,
33.230 - port,
33.231 - NULL,
33.232 - NULL,
33.233 - yuv_matrix,
33.234 - 0,
33.235 - NULL,
33.236 - codecFlagUseImageBuffer,
33.237 - codecLosslessQuality, yuv_codec);
33.238 -
33.239 - if (err != noErr) {
33.240 - SDL_SetError ("Error trying to start YUV codec.");
33.241 - return NULL;
33.242 - }
33.243 -
33.244 - overlay = (SDL_Overlay *) SDL_malloc (sizeof (*overlay));
33.245 - if (overlay == NULL) {
33.246 - SDL_OutOfMemory ();
33.247 - return NULL;
33.248 - }
33.249 -
33.250 - overlay->format = format;
33.251 - overlay->w = width;
33.252 - overlay->h = height;
33.253 - overlay->planes = 3;
33.254 - overlay->hw_overlay = 1;
33.255 - {
33.256 - int offset;
33.257 - Uint8 **pixels;
33.258 - Uint16 *pitches;
33.259 - int plane2, plane3;
33.260 -
33.261 - if (format == SDL_IYUV_OVERLAY) {
33.262 -
33.263 - plane2 = 1; /* Native codec format */
33.264 - plane3 = 2;
33.265 - } else if (format == SDL_YV12_OVERLAY) {
33.266 -
33.267 - /* switch the U and V planes */
33.268 - plane2 = 2; /* U plane maps to plane 3 */
33.269 - plane3 = 1; /* V plane maps to plane 2 */
33.270 - } else {
33.271 - SDL_SetError ("Unsupported YUV format");
33.272 - return NULL;
33.273 - }
33.274 -
33.275 - pixels = (Uint8 **) SDL_malloc (sizeof (*pixels) * 3);
33.276 - pitches = (Uint16 *) SDL_malloc (sizeof (*pitches) * 3);
33.277 - if (pixels == NULL || pitches == NULL) {
33.278 - SDL_OutOfMemory ();
33.279 - return NULL;
33.280 - }
33.281 -
33.282 - yuv_pixmap = (PlanarPixmapInfoYUV420 *)
33.283 - SDL_malloc (sizeof (PlanarPixmapInfoYUV420) +
33.284 - (width * height * 2));
33.285 - if (yuv_pixmap == NULL) {
33.286 - SDL_OutOfMemory ();
33.287 - return NULL;
33.288 - }
33.289 -
33.290 - /* CHECK_ALIGN(yuv_pixmap); */
33.291 - offset = sizeof (PlanarPixmapInfoYUV420);
33.292 - /* offset += ALIGN(offset); */
33.293 - /* CHECK_ALIGN(offset); */
33.294 -
33.295 - pixels[0] = (Uint8 *) yuv_pixmap + offset;
33.296 - /* CHECK_ALIGN(pixels[0]); */
33.297 -
33.298 - pitches[0] = width;
33.299 - yuv_pixmap->componentInfoY.offset = offset;
33.300 - yuv_pixmap->componentInfoY.rowBytes = width;
33.301 -
33.302 - offset += width * height;
33.303 - pixels[plane2] = (Uint8 *) yuv_pixmap + offset;
33.304 - pitches[plane2] = width / 2;
33.305 - yuv_pixmap->componentInfoCb.offset = offset;
33.306 - yuv_pixmap->componentInfoCb.rowBytes = width / 2;
33.307 -
33.308 - offset += (width * height / 4);
33.309 - pixels[plane3] = (Uint8 *) yuv_pixmap + offset;
33.310 - pitches[plane3] = width / 2;
33.311 - yuv_pixmap->componentInfoCr.offset = offset;
33.312 - yuv_pixmap->componentInfoCr.rowBytes = width / 2;
33.313 -
33.314 - overlay->pixels = pixels;
33.315 - overlay->pitches = pitches;
33.316 - }
33.317 -
33.318 - overlay->hwfuncs = SDL_malloc (sizeof (*overlay->hwfuncs));
33.319 - if (overlay->hwfuncs == NULL) {
33.320 - SDL_OutOfMemory ();
33.321 - return NULL;
33.322 - }
33.323 -
33.324 - overlay->hwfuncs->Lock = QZ_LockYUV;
33.325 - overlay->hwfuncs->Unlock = QZ_UnlockYUV;
33.326 - overlay->hwfuncs->Display = QZ_DisplayYUV;
33.327 - overlay->hwfuncs->FreeHW = QZ_FreeHWYUV;
33.328 -
33.329 - yuv_width = overlay->w;
33.330 - yuv_height = overlay->h;
33.331 -
33.332 - return overlay;
33.333 -}
34.1 --- a/test/testsprite.c Sun Jul 23 00:55:25 2006 +0000
34.2 +++ b/test/testsprite.c Sun Jul 23 09:11:10 2006 +0000
34.3 @@ -3,6 +3,7 @@
34.4 #include <stdlib.h>
34.5 #include <stdio.h>
34.6 #include <time.h>
34.7 +#include <math.h>
34.8
34.9 #include "SDL.h"
34.10