Added initial support for Quartz video (thanks Darrell!)
authorSam Lantinga <slouken@lokigames.com>
Thu, 07 Jun 2001 14:28:11 +0000
changeset 4745b1c4303f87
parent 46 3dcf26fa9d15
child 48 f97decee03a9
Added initial support for Quartz video (thanks Darrell!)
BUGS
README.MacOSX
configure.in
docs.html
include/SDL_main.h
include/SDL_video.h
src/audio/macrom/SDL_romaudio.c
src/main/macosx/SDLMain.h
src/main/macosx/SDLMain.m
src/main/macosx/exports/Makefile
src/main/macosx/exports/SDL.x
src/main/macosx/exports/gendef.pl
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/macrom/SDL_romvideo.c
src/video/quartz/Makefile.am
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzKeys.h
src/video/quartz/SDL_QuartzVideo.h
src/video/quartz/SDL_QuartzVideo.m
src/video/quartz/SDL_QuartzWM.m
src/video/quartz/SDL_QuartzWindow.m
test/testtypes.c
     1.1 --- a/BUGS	Thu Jun 07 13:53:51 2001 +0000
     1.2 +++ b/BUGS	Thu Jun 07 14:28:11 2001 +0000
     1.3 @@ -70,22 +70,35 @@
     1.4  	Not all of the keys are properly recognized on the keyboard.
     1.5  
     1.6  MacOS X:
     1.7 -	Fullscreen mode doesn't work - it requires the QuickTime framework
     1.8 -	and that the new SDL window gets raised to the top of the Z order.
     1.9 +	Joystick and CD-ROM functions are not implemented yet.
    1.10  
    1.11 +	Closing window from window's close widget not implemented yet.
    1.12 +	
    1.13 +	Minimizing the window erases the framebuffer to the pinstripe pattern.
    1.14 +	
    1.15 +	Window may not close when unsetting video mode and resetting.
    1.16 +	
    1.17 +	Depth switching for windowed mode isn't implemented yet.
    1.18 +	
    1.19  	Palette handling isn't implemented in windowed mode yet.
    1.20 +	
    1.21 +	Command-line arguments Dialog is not implemented yet.
    1.22  
    1.23 -	Native sound and video routines are not finished, though Carbon
    1.24 -	seems to work fairly well.
    1.25 +	Fullscreen drawing has some artifacts.
    1.26 +	
    1.27 +	Fullscreen window covers *all* other windows - even force quit.
    1.28 +	
    1.29 +	Fullscreen OpenGL for the software renderer is broken.
    1.30  
    1.31 -	Joysticks and CD-ROM functions are not implemented yet.
    1.32 +	Some OpenGL parameters are not accounted for, for example color bits customization.
    1.33 +	
    1.34 +	Getting OpenGL context parameters is not implemented.
    1.35 +	
    1.36 +	Continuous mouse motion perhaps is not as smooth as it should be.
    1.37  
    1.38 -	SDL_WM_GrabInput() is not implemented.
    1.39 -	Does anyone know how to do this?  SDL_WM_GrabInput() is designed
    1.40 -	to prevent the user from switching input and mouse focus away from
    1.41 -	the SDL application.
    1.42 -
    1.43 -	Continuous relative mouse motion is not implemented.
    1.44 +	SDL_WM_GrabInput() is implemented, but it "freezes" the hardware
    1.45 +	cursor in the center of the window/screen.  Also, mouse moved events
    1.46 +	are not generated, and the keyboard cannot be grabbed.
    1.47  
    1.48  	Not all of the keys are properly recognized on the keyboard.
    1.49  
     2.1 --- a/README.MacOSX	Thu Jun 07 13:53:51 2001 +0000
     2.2 +++ b/README.MacOSX	Thu Jun 07 14:28:11 2001 +0000
     2.3 @@ -34,11 +34,80 @@
     2.4  sdl-config knows about the linking path and -framework, so it's
     2.5  recommended to use it to fill in your Makefile variables.
     2.6  
     2.7 -[Add instructions for how to build using PB]
     2.8 +==============================================================================
     2.9 +Using the Simple DirectMedia Layer with Project Builder
    2.10 +==============================================================================
    2.11  
    2.12 -As of this writing (Sep 2000), OS X is in public beta.  This means
    2.13 -that while most of the APIs are frozen, things are still subject to
    2.14 -change, and many of the known problems will be resolved before the
    2.15 -final release comes out.
    2.16 +These instructions are for using Apple's Project Builder IDE to build SDL applications.
    2.17  
    2.18 +- Building the Framework
    2.19 +
    2.20 +The SDL Library is packaged as a framework bundle, an organized
    2.21 +relocatable folder heirarchy of executible code, interface headers, 
    2.22 +and additional resources. For practical purposes, you can think of a 
    2.23 +framework as a more user and system-friendly shared library, whose library
    2.24 +file behaves more or less like a standard UNIX shared library.
    2.25 +
    2.26 +To build the framework, simply open the framework project and build it. 
    2.27 +By default, the framework bundle "SDL.framework" is installed in 
    2.28 +~/Library/Frameworks. Therefore, the testers and project stationary expect
    2.29 +it to be located there. However, it will function the same in any of the
    2.30 +following locations:
    2.31 +
    2.32 +    ~/Library/Frameworks
    2.33 +    /Local/Library/Frameworks
    2.34 +    /System/Library/Frameworks
    2.35 +
    2.36 +- Build Options
    2.37 +    There are two "Build Styles" (See the "Targets" tab) for SDL.
    2.38 +    "Deployment" should be used if you aren't tweaking the SDL library.
    2.39 +    "Development" should be used to debug SDL apps or the library itself.
    2.40 +
    2.41 +- Building the Testers
    2.42 +    Open the SDLTest project and build away!
    2.43 +
    2.44 +- Using the Project Stationary
    2.45 +    Copy the stationary to the indicated folders to access it from
    2.46 +    the "New Project" and "Add target" menus. What could be easier?
    2.47 +
    2.48 +- Setting up a new project by hand
    2.49 +    Some of you won't want to use the Stationary so I'll give some tips:
    2.50 +    * Create a new "Cocoa Application"
    2.51 +    * Add src/main/macosx/SDLMain.m , .h and .nib to your project
    2.52 +    * Remove "main.c" from your project
    2.53 +    * Remove "MainMenu.nib" from your project
    2.54 +    * Add "$(HOME)/Library/Frameworks/SDL.framework/Headers" to include path
    2.55 +    * Add "$(HOME)/Library/Frameworks" to the frameworks search path
    2.56 +    * Add "-framework SDL" to the "OTHER_LDFLAGS" variable
    2.57 +    * Set the "Main Nib File" under "Application Settings" to "SDLMain.nib"
    2.58 +    * Add your files
    2.59 +    * Clean and build
    2.60 +
    2.61 +- Building from command line
    2.62 +    Use pbxbuild in the same directory as your .pbproj file
    2.63 +         
    2.64 +- Running your app
    2.65 +    You can send command line args to your app by either invoking it from
    2.66 +    the command line (in *.app/Contents/MacOS) or by entering them in the
    2.67 +    "Executibles" panel of the target settings.
    2.68 +    
    2.69 +- Implementation Notes
    2.70 +    Some things that may be of interest about how it all works...
    2.71 +    * Working directory
    2.72 +        As defined in the SDLMain.m file, the working directory of your SDL app
    2.73 +        is by default set to its parent. You may wish to change this to better
    2.74 +        suit your needs.
    2.75 +    * You have a Cocoa App!
    2.76 +        Your SDL app is essentially a Cocoa application. When your app
    2.77 +        starts up and the libraries finish loading, a Cocoa procedure is called,
    2.78 +        which sets up the working directory and calls your main() method.
    2.79 +        You are free to modify your Cocoa app with generally no consequence 
    2.80 +        to SDL. You cannot, however, easily change the SDL window itself.
    2.81 +        Functionality may be added in the future to help this.
    2.82 +    * My development setup:
    2.83 +        I am using version 1.0.1 (v63.0) of Project Builder on MacOS X 10.0.3,
    2.84 +        from the Developer Tools CD for May 2001.
    2.85 +        As of May 31 2001, Apple hasn't released this version of the tools to the public, 
    2.86 +        but I expect that things will still work on older versions.
    2.87 +        
    2.88  Known bugs are listed in the file "BUGS"
     3.1 --- a/configure.in	Thu Jun 07 13:53:51 2001 +0000
     3.2 +++ b/configure.in	Thu Jun 07 14:28:11 2001 +0000
     3.3 @@ -63,6 +63,10 @@
     3.4      *-*-linux*)
     3.5          AC_PROG_CXX
     3.6          ;;
     3.7 +    *-*-darwin*)
     3.8 +        OBJC="???"
     3.9 +        AC_SUBST(OBJC)
    3.10 +        ;;
    3.11  esac
    3.12  AC_PROG_INSTALL
    3.13  AC_FUNC_ALLOCA
    3.14 @@ -1979,6 +1983,7 @@
    3.15  src/video/maccommon/Makefile
    3.16  src/video/macdsp/Makefile
    3.17  src/video/macrom/Makefile
    3.18 +src/video/quartz/Makefile
    3.19  src/video/svga/Makefile
    3.20  src/video/aalib/Makefile
    3.21  src/video/wincommon/Makefile
     4.1 --- a/docs.html	Thu Jun 07 13:53:51 2001 +0000
     4.2 +++ b/docs.html	Thu Jun 07 14:28:11 2001 +0000
     4.3 @@ -16,6 +16,7 @@
     4.4  Major changes since SDL 1.0.0:
     4.5  </H2>
     4.6  <UL>
     4.7 +	<LI> 1.2.1: Added initial support for Quartz video (thanks Darrell!)
     4.8  	<LI> 1.2.1: Added native OpenBSD audio driver (thanks vedge!)
     4.9  	<LI> 1.2.1: Added detection of Open Sound System on Solaris x86
    4.10  	<LI> 1.2.1: Added initial support for Nano-X (thanks Hsieh-Fu!)
     5.1 --- a/include/SDL_main.h	Thu Jun 07 13:53:51 2001 +0000
     5.2 +++ b/include/SDL_main.h	Thu Jun 07 14:28:11 2001 +0000
     5.3 @@ -31,7 +31,7 @@
     5.4  /* Redefine main() on Win32 and MacOS so that it is called by winmain.c */
     5.5  
     5.6  #if defined(WIN32) || (defined(__MWERKS__) && !defined(__BEOS__)) || \
     5.7 -    defined(macintosh)
     5.8 +    defined(macintosh) || defined(__APPLE__)
     5.9  
    5.10  #ifdef __cplusplus
    5.11  #define C_LINKAGE	"C"
     6.1 --- a/include/SDL_video.h	Thu Jun 07 13:53:51 2001 +0000
     6.2 +++ b/include/SDL_video.h	Thu Jun 07 14:28:11 2001 +0000
     6.3 @@ -878,6 +878,10 @@
     6.4   */
     6.5  extern DECLSPEC SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode);
     6.6  
     6.7 +/* Not in public API at the moment - do not use! */
     6.8 +extern DECLSPEC int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
     6.9 +                                    SDL_Surface *dst, SDL_Rect *dstrect);
    6.10 +                    
    6.11  /* Ends C function definitions when using C++ */
    6.12  #ifdef __cplusplus
    6.13  }
     7.1 --- a/src/audio/macrom/SDL_romaudio.c	Thu Jun 07 13:53:51 2001 +0000
     7.2 +++ b/src/audio/macrom/SDL_romaudio.c	Thu Jun 07 14:28:11 2001 +0000
     7.3 @@ -105,9 +105,8 @@
     7.4     UInt32 fill_me, play_me;
     7.5     SndCommand cmd; 
     7.6     SDL_AudioDevice *audio = (SDL_AudioDevice *)chan->userInfo;
     7.7 - 
     7.8 -   fill_me = cmd_passed->param2;  /* buffer that has just finished playing,
     7.9 -so fill it */      
    7.10 +   
    7.11 +   fill_me = cmd_passed->param2;  /* buffer that has just finished playing, so fill it */      
    7.12     play_me = ! fill_me;           /* filled buffer to play _now_ */
    7.13  
    7.14     if ( ! audio->enabled ) {
    7.15 @@ -119,15 +118,21 @@
    7.16     cmd.cmd = bufferCmd;
    7.17     cmd.param1 = 0; 
    7.18     cmd.param2 = (long)&header;
    7.19 -   
    7.20 -    SndDoCommand (chan, &cmd, 0);
    7.21 +
    7.22 +   SndDoCommand (chan, &cmd, 0);
    7.23     
    7.24     memset (buffer[fill_me], 0, audio->spec.size);
    7.25     
    7.26     if ( ! audio->paused ) {
    7.27          if ( audio->convert.needed ) {
    7.28 -            audio->spec.callback(audio->spec.userdata,
    7.29 -                (Uint8 *)audio->convert.buf,audio->convert.len);
    7.30 +            #if MACOSX
    7.31 +                SDL_mutexP(audio->mixer_lock);
    7.32 +            #endif
    7.33 +                audio->spec.callback(audio->spec.userdata,
    7.34 +                    (Uint8 *)audio->convert.buf,audio->convert.len);
    7.35 +            #if MACOSX
    7.36 +                SDL_mutexV(audio->mixer_lock);
    7.37 +            #endif 
    7.38                 SDL_ConvertAudio(&audio->convert);
    7.39  #if 0
    7.40              if ( audio->convert.len_cvt != audio->spec.size ) {
    7.41 @@ -137,11 +142,17 @@
    7.42              memcpy(buffer[fill_me], audio->convert.buf,
    7.43                              audio->convert.len_cvt);
    7.44          } else {
    7.45 +            #if MACOSX
    7.46 +                SDL_mutexP(audio->mixer_lock);
    7.47 +            #endif
    7.48              audio->spec.callback(audio->spec.userdata,
    7.49                  (Uint8 *)buffer[fill_me], audio->spec.size);
    7.50 +            #if MACOSX
    7.51 +                SDL_mutexV(audio->mixer_lock);
    7.52 +            #endif
    7.53          }
    7.54      }
    7.55 -    
    7.56 +
    7.57      if ( running ) {
    7.58           
    7.59        cmd.cmd = callBackCmd;
    7.60 @@ -150,6 +161,7 @@
    7.61     
    7.62        SndDoCommand (chan, &cmd, 0);
    7.63     }
    7.64 +
    7.65  }
    7.66  
    7.67  static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) {
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/main/macosx/SDLMain.h	Thu Jun 07 14:28:11 2001 +0000
     8.3 @@ -0,0 +1,8 @@
     8.4 +#import <Cocoa/Cocoa.h>
     8.5 +
     8.6 +@interface SDLMain : NSObject
     8.7 +{
     8.8 +}
     8.9 +- (IBAction)quit:(id)sender;
    8.10 +- (IBAction)makeFullscreen:(id)sender;
    8.11 +@end
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/main/macosx/SDLMain.m	Thu Jun 07 14:28:11 2001 +0000
     9.3 @@ -0,0 +1,88 @@
     9.4 +/*   SDLMain.m - main entry point for our Cocoa-ized SDL app
     9.5 +       Darrell Walisser - dwaliss1@purdue.edu
     9.6 +
     9.7 +    Feel free to customize this file to suit your needs
     9.8 +*/
     9.9 +
    9.10 +#import "SDL.h"
    9.11 +#import "SDLMain.h"
    9.12 +#import <sys/param.h> /* for MAXPATHLEN */
    9.13 +#import <unistd.h>
    9.14 +
    9.15 +static int    gArgc;
    9.16 +static char  **gArgv;
    9.17 +
    9.18 +/* The main class of the application, the application's delegate */
    9.19 +@implementation SDLMain
    9.20 +
    9.21 +/* Invoked from the Quit menu item */
    9.22 +- (void) quit:(id)sender
    9.23 +{
    9.24 +    	SDL_Event event;
    9.25 +	event.type = SDL_QUIT;
    9.26 +	SDL_PushEvent(&event);
    9.27 +}
    9.28 +
    9.29 +/* Invoked from the "Make fulllscreen" menu item */
    9.30 +- (void) makeFullscreen:(id)sender
    9.31 +{
    9.32 +    
    9.33 +}
    9.34 +
    9.35 +/* Set the working directory to the .app's parent directory */
    9.36 +- (void) setupWorkingDirectory
    9.37 +{
    9.38 +    char parentdir[MAXPATHLEN];
    9.39 +    char *c;
    9.40 +    
    9.41 +    strncpy ( parentdir, gArgv[0], MAXPATHLEN );
    9.42 +    c = (char*) parentdir;
    9.43 +    
    9.44 +    while (*c != '\0')     /* go to end */
    9.45 +        c++;
    9.46 +    
    9.47 +    while (*c != '/')      /* back up to parent */
    9.48 +        c--;
    9.49 +    
    9.50 +    *c = '\0';             /* cut off last part (binary name) */
    9.51 +    
    9.52 +    assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
    9.53 +    assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
    9.54 +}
    9.55 +
    9.56 +/* Called when the internal event loop has just started running */
    9.57 +- (void) applicationDidFinishLaunching: (NSNotification *) note
    9.58 +{
    9.59 +    /* Set the working directory to the .app's parent directory */
    9.60 +    [ self setupWorkingDirectory ];
    9.61 +    
    9.62 +    /* This is passed if we are launched by double-clicking */
    9.63 +    if ( gArgc >= 2 && strncmp (gArgv[1], "-psn", 4) == 0 )
    9.64 +        gArgc = 1;
    9.65 +    
    9.66 +    /* Hand off to main application code */
    9.67 +    SDL_main (gArgc, gArgv);
    9.68 +    exit(0);
    9.69 +}
    9.70 +@end
    9.71 +
    9.72 +#ifdef main
    9.73 +#  undef main
    9.74 +#endif
    9.75 +
    9.76 +/* Main entry point to executible - should *not* be SDL_main! */
    9.77 +int main (int argc, char **argv) {
    9.78 +
    9.79 +    /* Copy the arguments into a global variable */
    9.80 +    int i;
    9.81 +    
    9.82 +    gArgc = argc;
    9.83 +    gArgv = (char**) malloc (sizeof(*gArgv) * gArgc);
    9.84 +    assert (gArgv != NULL);
    9.85 +    for (i = 0; i < gArgc; i++) {
    9.86 +        gArgv[i] = strdup (argv[i]);
    9.87 +    }
    9.88 +    
    9.89 +    NSApplicationMain (argc, argv);
    9.90 +    return 0;
    9.91 +}
    9.92 \ No newline at end of file
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/main/macosx/exports/Makefile	Thu Jun 07 14:28:11 2001 +0000
    10.3 @@ -0,0 +1,35 @@
    10.4 +
    10.5 +EXPORTS = SDL.x
    10.6 +HEADERS = \
    10.7 +	../../../../include/SDL.h \
    10.8 +	../../../../include/SDL_active.h \
    10.9 +	../../../../include/SDL_audio.h \
   10.10 +	../../../../include/SDL_byteorder.h \
   10.11 +	../../../../include/SDL_cdrom.h \
   10.12 +	../../../../include/SDL_copying.h \
   10.13 +	../../../../include/SDL_endian.h \
   10.14 +	../../../../include/SDL_error.h \
   10.15 +	../../../../include/SDL_events.h \
   10.16 +	../../../../include/SDL_getenv.h \
   10.17 +	../../../../include/SDL_joystick.h \
   10.18 +	../../../../include/SDL_keyboard.h \
   10.19 +	../../../../include/SDL_keysym.h \
   10.20 +	../../../../include/SDL_mouse.h \
   10.21 +	../../../../include/SDL_mutex.h \
   10.22 +	../../../../include/SDL_quit.h \
   10.23 +	../../../../include/SDL_rwops.h \
   10.24 +	../../../../include/SDL_syswm.h \
   10.25 +	../../../../include/SDL_thread.h \
   10.26 +	../../../../include/SDL_timer.h \
   10.27 +	../../../../include/SDL_types.h \
   10.28 +	../../../../include/SDL_version.h \
   10.29 +	../../../../include/SDL_video.h
   10.30 +
   10.31 +
   10.32 +all: $(EXPORTS)
   10.33 +
   10.34 +$(EXPORTS): $(HEADERS)
   10.35 +	perl gendef.pl $(HEADERS) >$@ || rm $@
   10.36 +
   10.37 +clean:
   10.38 +	rm -f $(EXPORTS)
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/main/macosx/exports/SDL.x	Thu Jun 07 14:28:11 2001 +0000
    11.3 @@ -0,0 +1,177 @@
    11.4 +	_SDL_Init
    11.5 +	_SDL_InitSubSystem
    11.6 +	_SDL_QuitSubSystem
    11.7 +	_SDL_WasInit
    11.8 +	_SDL_Quit
    11.9 +	_SDL_GetAppState
   11.10 +	_SDL_AudioInit
   11.11 +	_SDL_AudioQuit
   11.12 +	_SDL_AudioDriverName
   11.13 +	_SDL_OpenAudio
   11.14 +	_SDL_GetAudioStatus
   11.15 +	_SDL_PauseAudio
   11.16 +	_SDL_LoadWAV_RW
   11.17 +	_SDL_FreeWAV
   11.18 +	_SDL_BuildAudioCVT
   11.19 +	_SDL_ConvertAudio
   11.20 +	_SDL_MixAudio
   11.21 +	_SDL_LockAudio
   11.22 +	_SDL_UnlockAudio
   11.23 +	_SDL_CloseAudio
   11.24 +	_SDL_CDNumDrives
   11.25 +	_SDL_CDName
   11.26 +	_SDL_CDOpen
   11.27 +	_SDL_CDStatus
   11.28 +	_SDL_CDPlayTracks
   11.29 +	_SDL_CDPlay
   11.30 +	_SDL_CDPause
   11.31 +	_SDL_CDResume
   11.32 +	_SDL_CDStop
   11.33 +	_SDL_CDEject
   11.34 +	_SDL_CDClose
   11.35 +	_SDL_ReadLE16
   11.36 +	_SDL_ReadBE16
   11.37 +	_SDL_ReadLE32
   11.38 +	_SDL_ReadBE32
   11.39 +	_SDL_ReadLE64
   11.40 +	_SDL_ReadBE64
   11.41 +	_SDL_WriteLE16
   11.42 +	_SDL_WriteBE16
   11.43 +	_SDL_WriteLE32
   11.44 +	_SDL_WriteBE32
   11.45 +	_SDL_WriteLE64
   11.46 +	_SDL_WriteBE64
   11.47 +	_SDL_SetError
   11.48 +	_SDL_GetError
   11.49 +	_SDL_ClearError
   11.50 +	_SDL_PumpEvents
   11.51 +	_SDL_PeepEvents
   11.52 +	_SDL_PollEvent
   11.53 +	_SDL_WaitEvent
   11.54 +	_SDL_PushEvent
   11.55 +	_SDL_SetEventFilter
   11.56 +	_SDL_GetEventFilter
   11.57 +	_SDL_EventState
   11.58 +	_SDL_putenv
   11.59 +	_SDL_getenv
   11.60 +	_SDL_NumJoysticks
   11.61 +	_SDL_JoystickName
   11.62 +	_SDL_JoystickOpen
   11.63 +	_SDL_JoystickOpened
   11.64 +	_SDL_JoystickIndex
   11.65 +	_SDL_JoystickNumAxes
   11.66 +	_SDL_JoystickNumBalls
   11.67 +	_SDL_JoystickNumHats
   11.68 +	_SDL_JoystickNumButtons
   11.69 +	_SDL_JoystickUpdate
   11.70 +	_SDL_JoystickEventState
   11.71 +	_SDL_JoystickGetAxis
   11.72 +	_SDL_JoystickGetHat
   11.73 +	_SDL_JoystickGetBall
   11.74 +	_SDL_JoystickGetButton
   11.75 +	_SDL_JoystickClose
   11.76 +	_SDL_EnableUNICODE
   11.77 +	_SDL_EnableKeyRepeat
   11.78 +	_SDL_GetKeyState
   11.79 +	_SDL_GetModState
   11.80 +	_SDL_SetModState
   11.81 +	_SDL_GetKeyName
   11.82 +	_SDL_GetMouseState
   11.83 +	_SDL_GetRelativeMouseState
   11.84 +	_SDL_WarpMouse
   11.85 +	_SDL_CreateCursor
   11.86 +	_SDL_SetCursor
   11.87 +	_SDL_GetCursor
   11.88 +	_SDL_FreeCursor
   11.89 +	_SDL_ShowCursor
   11.90 +	_SDL_CreateMutex
   11.91 +	_SDL_mutexP
   11.92 +	_SDL_mutexV
   11.93 +	_SDL_DestroyMutex
   11.94 +	_SDL_CreateSemaphore
   11.95 +	_SDL_DestroySemaphore
   11.96 +	_SDL_SemWait
   11.97 +	_SDL_SemTryWait
   11.98 +	_SDL_SemWaitTimeout
   11.99 +	_SDL_SemPost
  11.100 +	_SDL_SemValue
  11.101 +	_SDL_CreateCond
  11.102 +	_SDL_DestroyCond
  11.103 +	_SDL_CondSignal
  11.104 +	_SDL_CondBroadcast
  11.105 +	_SDL_CondWait
  11.106 +	_SDL_CondWaitTimeout
  11.107 +	_SDL_RWFromFile
  11.108 +	_SDL_RWFromFP
  11.109 +	_SDL_RWFromMem
  11.110 +	_SDL_AllocRW
  11.111 +	_SDL_FreeRW
  11.112 +	_SDL_GetWMInfo
  11.113 +	_SDL_CreateThread
  11.114 +	_SDL_ThreadID
  11.115 +	_SDL_GetThreadID
  11.116 +	_SDL_WaitThread
  11.117 +	_SDL_KillThread
  11.118 +	_SDL_GetTicks
  11.119 +	_SDL_Delay
  11.120 +	_SDL_SetTimer
  11.121 +	_SDL_AddTimer
  11.122 +	_SDL_RemoveTimer
  11.123 +	_SDL_Linked_Version
  11.124 +	_SDL_VideoInit
  11.125 +	_SDL_VideoQuit
  11.126 +	_SDL_VideoDriverName
  11.127 +	_SDL_GetVideoSurface
  11.128 +	_SDL_GetVideoInfo
  11.129 +	_SDL_VideoModeOK
  11.130 +	_SDL_ListModes
  11.131 +	_SDL_SetVideoMode
  11.132 +	_SDL_UpdateRects
  11.133 +	_SDL_UpdateRect
  11.134 +	_SDL_Flip
  11.135 +	_SDL_SetGamma
  11.136 +	_SDL_SetGammaRamp
  11.137 +	_SDL_GetGammaRamp
  11.138 +	_SDL_SetColors
  11.139 +	_SDL_SetPalette
  11.140 +	_SDL_MapRGB
  11.141 +	_SDL_MapRGBA
  11.142 +	_SDL_GetRGB
  11.143 +	_SDL_GetRGBA
  11.144 +	_SDL_CreateRGBSurface
  11.145 +	_SDL_CreateRGBSurfaceFrom
  11.146 +	_SDL_FreeSurface
  11.147 +	_SDL_LockSurface
  11.148 +	_SDL_UnlockSurface
  11.149 +	_SDL_LoadBMP_RW
  11.150 +	_SDL_SaveBMP_RW
  11.151 +	_SDL_SetColorKey
  11.152 +	_SDL_SetAlpha
  11.153 +	_SDL_SetClipRect
  11.154 +	_SDL_GetClipRect
  11.155 +	_SDL_ConvertSurface
  11.156 +	_SDL_UpperBlit
  11.157 +	_SDL_LowerBlit
  11.158 +	_SDL_FillRect
  11.159 +	_SDL_DisplayFormat
  11.160 +	_SDL_DisplayFormatAlpha
  11.161 +	_SDL_CreateYUVOverlay
  11.162 +	_SDL_LockYUVOverlay
  11.163 +	_SDL_UnlockYUVOverlay
  11.164 +	_SDL_DisplayYUVOverlay
  11.165 +	_SDL_FreeYUVOverlay
  11.166 +	_SDL_GL_LoadLibrary
  11.167 +	_SDL_GL_GetProcAddress
  11.168 +	_SDL_GL_SetAttribute
  11.169 +	_SDL_GL_GetAttribute
  11.170 +	_SDL_GL_SwapBuffers
  11.171 +	_SDL_GL_UpdateRects
  11.172 +	_SDL_GL_Lock
  11.173 +	_SDL_GL_Unlock
  11.174 +	_SDL_WM_SetCaption
  11.175 +	_SDL_WM_GetCaption
  11.176 +	_SDL_WM_SetIcon
  11.177 +	_SDL_WM_IconifyWindow
  11.178 +	_SDL_WM_ToggleFullScreen
  11.179 +	_SDL_WM_GrabInput
  11.180 +	_SDL_SoftStretch
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/main/macosx/exports/gendef.pl	Thu Jun 07 14:28:11 2001 +0000
    12.3 @@ -0,0 +1,20 @@
    12.4 +#!/usr/bin/perl
    12.5 +#
    12.6 +# Program to take a set of header files and generate DLL export definitions
    12.7 +
    12.8 +while ( ($file = shift(@ARGV)) ) {
    12.9 +	if ( ! defined(open(FILE, $file)) ) {
   12.10 +		warn "Couldn't open $file: $!\n";
   12.11 +		next;
   12.12 +	}
   12.13 +	$printed_header = 0;
   12.14 +	$file =~ s,.*/,,;
   12.15 +	while (<FILE>) {
   12.16 +		if ( /DECLSPEC.*\s\**([^\s\(]+)\(/ ) {
   12.17 +			print "\t_$1\n";
   12.18 +		} elsif ( /DECLSPEC.*\s\**([^\s\(]+)$/ ) {
   12.19 +			print "\t_$1\n";
   12.20 +		}
   12.21 +	}
   12.22 +	close(FILE);
   12.23 +}
    13.1 --- a/src/video/SDL_sysvideo.h	Thu Jun 07 13:53:51 2001 +0000
    13.2 +++ b/src/video/SDL_sysvideo.h	Thu Jun 07 14:28:11 2001 +0000
    13.3 @@ -63,7 +63,7 @@
    13.4  #endif
    13.5  struct SDL_VideoDevice {
    13.6  	/* * * */
    13.7 -	/* The name of this audio driver */
    13.8 +	/* The name of this video driver */
    13.9  	const char *name;
   13.10  
   13.11  	/* * * */
   13.12 @@ -377,10 +377,12 @@
   13.13  #ifdef ENABLE_DRAWSPROCKET
   13.14  extern VideoBootStrap DSp_bootstrap;
   13.15  #endif
   13.16 +#ifdef ENABLE_QUARTZ
   13.17 +extern VideoBootStrap QZ_bootstrap;
   13.18 +#endif
   13.19  #ifdef ENABLE_CYBERGRAPHICS
   13.20  extern VideoBootStrap CGX_bootstrap;
   13.21  #endif
   13.22 -
   13.23  /* This is the current video device */
   13.24  extern SDL_VideoDevice *current_video;
   13.25  
    14.1 --- a/src/video/SDL_video.c	Thu Jun 07 13:53:51 2001 +0000
    14.2 +++ b/src/video/SDL_video.c	Thu Jun 07 14:28:11 2001 +0000
    14.3 @@ -84,6 +84,9 @@
    14.4  #ifdef ENABLE_DRAWSPROCKET
    14.5  	&DSp_bootstrap,
    14.6  #endif
    14.7 +#ifdef ENABLE_QUARTZ
    14.8 +	&QZ_bootstrap,
    14.9 +#endif
   14.10  #ifdef ENABLE_CYBERGRAPHICS
   14.11  	&CGX_bootstrap,
   14.12  #endif
    15.1 --- a/src/video/macrom/SDL_romvideo.c	Thu Jun 07 13:53:51 2001 +0000
    15.2 +++ b/src/video/macrom/SDL_romvideo.c	Thu Jun 07 14:28:11 2001 +0000
    15.3 @@ -34,7 +34,7 @@
    15.4     is still at the back on MacOS X, which is where this code is needed.
    15.5   */
    15.6  #if USE_QUICKTIME
    15.7 -#include <Movies.h>
    15.8 +#include <QuickTime/Movies.h>
    15.9  #endif
   15.10  #else
   15.11  #include <LowMem.h>
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/video/quartz/Makefile.am	Thu Jun 07 14:28:11 2001 +0000
    16.3 @@ -0,0 +1,14 @@
    16.4 +
    16.5 +## Makefile.am for SDL using the MacOS X Quartz video driver
    16.6 +
    16.7 +noinst_LTLIBRARIES = libvideo_quartz.la
    16.8 +libvideo_quartz_la_SOURCES = $(QUARTZ_SRCS)
    16.9 +
   16.10 +# The SDL MacOS X Quartz video driver sources
   16.11 +QUARTZ_SRCS = 			\
   16.12 +	SDL_QuartzEvents.m	\
   16.13 +	SDL_QuartzKeys.h	\
   16.14 +	SDL_QuartzVideo.h	\
   16.15 +	SDL_QuartzVideo.m	\
   16.16 +	SDL_QuartzWM.m		\
   16.17 +	SDL_QuartzWindow.m
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Thu Jun 07 14:28:11 2001 +0000
    17.3 @@ -0,0 +1,368 @@
    17.4 +/*
    17.5 +    SDL - Simple DirectMedia Layer
    17.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  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 Library General Public
   17.10 +    License as published by the Free Software Foundation; either
   17.11 +    version 2 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 +    Library General Public License for more details.
   17.17 +
   17.18 +    You should have received a copy of the GNU Library General Public
   17.19 +    License along with this library; if not, write to the Free
   17.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.21 +
   17.22 +    Sam Lantinga
   17.23 +    slouken@devolution.com
   17.24 +*/
   17.25 +
   17.26 +#include "SDL_QuartzKeys.h"
   17.27 +
   17.28 +static void  QZ_InitOSKeymap (_THIS) {
   17.29 +	int i;
   17.30 +
   17.31 +	for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
   17.32 +		keymap[i] = SDLK_UNKNOWN;
   17.33 +
   17.34 +	// This keymap is almost exactly the same as the OS 9 one
   17.35 +        keymap[QZ_ESCAPE] = SDLK_ESCAPE;
   17.36 +	keymap[QZ_F1] = SDLK_F1;
   17.37 +	keymap[QZ_F2] = SDLK_F2;
   17.38 +	keymap[QZ_F3] = SDLK_F3;
   17.39 +	keymap[QZ_F4] = SDLK_F4;
   17.40 +	keymap[QZ_F5] = SDLK_F5;
   17.41 +	keymap[QZ_F6] = SDLK_F6;
   17.42 +	keymap[QZ_F7] = SDLK_F7;
   17.43 +	keymap[QZ_F8] = SDLK_F8;
   17.44 +	keymap[QZ_F9] = SDLK_F9;
   17.45 +	keymap[QZ_F10] = SDLK_F10;
   17.46 +	keymap[QZ_F11] = SDLK_F11;
   17.47 +	keymap[QZ_F12] = SDLK_F12;
   17.48 +	keymap[QZ_PRINT] = SDLK_PRINT;
   17.49 +	keymap[QZ_SCROLLOCK] = SDLK_SCROLLOCK;
   17.50 +	keymap[QZ_PAUSE] = SDLK_PAUSE;
   17.51 +	keymap[QZ_POWER] = SDLK_POWER;
   17.52 +	keymap[QZ_BACKQUOTE] = SDLK_BACKQUOTE;
   17.53 +	keymap[QZ_1] = SDLK_1;
   17.54 +	keymap[QZ_2] = SDLK_2;
   17.55 +	keymap[QZ_3] = SDLK_3;
   17.56 +	keymap[QZ_4] = SDLK_4;
   17.57 +	keymap[QZ_5] = SDLK_5;
   17.58 +	keymap[QZ_6] = SDLK_6;
   17.59 +	keymap[QZ_7] = SDLK_7;
   17.60 +	keymap[QZ_8] = SDLK_8;
   17.61 +	keymap[QZ_9] = SDLK_9;
   17.62 +	keymap[QZ_0] = SDLK_0;
   17.63 +	keymap[QZ_MINUS] = SDLK_MINUS;
   17.64 +	keymap[QZ_EQUALS] = SDLK_EQUALS;
   17.65 +	keymap[QZ_BACKSPACE] = SDLK_BACKSPACE;
   17.66 +	keymap[QZ_INSERT] = SDLK_INSERT;
   17.67 +	keymap[QZ_HOME] = SDLK_HOME;
   17.68 +	keymap[QZ_PAGEUP] = SDLK_PAGEUP;
   17.69 +	keymap[QZ_NUMLOCK] = SDLK_NUMLOCK;
   17.70 +	keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
   17.71 +	keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   17.72 +	keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   17.73 +	keymap[QZ_TAB] = SDLK_TAB;
   17.74 +	keymap[QZ_q] = SDLK_q;
   17.75 +	keymap[QZ_w] = SDLK_w;
   17.76 +	keymap[QZ_e] = SDLK_e;
   17.77 +	keymap[QZ_r] = SDLK_r;
   17.78 +	keymap[QZ_t] = SDLK_t;
   17.79 +	keymap[QZ_y] = SDLK_y;
   17.80 +	keymap[QZ_u] = SDLK_u;
   17.81 +	keymap[QZ_i] = SDLK_i;
   17.82 +	keymap[QZ_o] = SDLK_o;
   17.83 +	keymap[QZ_p] = SDLK_p;
   17.84 +	keymap[QZ_LEFTBRACKET] = SDLK_LEFTBRACKET;
   17.85 +	keymap[QZ_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
   17.86 +	keymap[QZ_BACKSLASH] = SDLK_BACKSLASH;
   17.87 +	keymap[QZ_DELETE] = SDLK_DELETE;
   17.88 +	keymap[QZ_END] = SDLK_END;
   17.89 +	keymap[QZ_PAGEDOWN] = SDLK_PAGEDOWN;
   17.90 +	keymap[QZ_KP7] = SDLK_KP7;
   17.91 +	keymap[QZ_KP8] = SDLK_KP8;
   17.92 +	keymap[QZ_KP9] = SDLK_KP9;
   17.93 +	keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   17.94 +	keymap[QZ_CAPSLOCK] = SDLK_CAPSLOCK;
   17.95 +	keymap[QZ_a] = SDLK_a;
   17.96 +	keymap[QZ_s] = SDLK_s;
   17.97 +	keymap[QZ_d] = SDLK_d;
   17.98 +	keymap[QZ_f] = SDLK_f;
   17.99 +	keymap[QZ_g] = SDLK_g;
  17.100 +	keymap[QZ_h] = SDLK_h;
  17.101 +	keymap[QZ_j] = SDLK_j;
  17.102 +	keymap[QZ_k] = SDLK_k;
  17.103 +	keymap[QZ_l] = SDLK_l;
  17.104 +	keymap[QZ_SEMICOLON] = SDLK_SEMICOLON;
  17.105 +	keymap[QZ_QUOTE] = SDLK_QUOTE;
  17.106 +	keymap[QZ_RETURN] = SDLK_RETURN;
  17.107 +	keymap[QZ_KP4] = SDLK_KP4;
  17.108 +	keymap[QZ_KP5] = SDLK_KP5;
  17.109 +	keymap[QZ_KP6] = SDLK_KP6;
  17.110 +	keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
  17.111 +	keymap[QZ_LSHIFT] = SDLK_LSHIFT;
  17.112 +	keymap[QZ_z] = SDLK_z;
  17.113 +	keymap[QZ_x] = SDLK_x;
  17.114 +	keymap[QZ_c] = SDLK_c;
  17.115 +	keymap[QZ_v] = SDLK_v;
  17.116 +	keymap[QZ_b] = SDLK_b;
  17.117 +	keymap[QZ_n] = SDLK_n;
  17.118 +	keymap[QZ_m] = SDLK_m;
  17.119 +	keymap[QZ_COMMA] = SDLK_COMMA;
  17.120 +	keymap[QZ_PERIOD] = SDLK_PERIOD;
  17.121 +	keymap[QZ_SLASH] = SDLK_SLASH;
  17.122 +	keymap[QZ_UP] = SDLK_UP;
  17.123 +	keymap[QZ_KP1] = SDLK_KP1;
  17.124 +	keymap[QZ_KP2] = SDLK_KP2;
  17.125 +	keymap[QZ_KP3] = SDLK_KP3;
  17.126 +	keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
  17.127 +	keymap[QZ_LCTRL] = SDLK_LCTRL;
  17.128 +	keymap[QZ_LALT] = SDLK_LALT;
  17.129 +	keymap[QZ_LMETA] = SDLK_LMETA;
  17.130 +	keymap[QZ_SPACE] = SDLK_SPACE;
  17.131 +	keymap[QZ_LEFT] = SDLK_LEFT;
  17.132 +	keymap[QZ_DOWN] = SDLK_DOWN;
  17.133 +	keymap[QZ_RIGHT] = SDLK_RIGHT;
  17.134 +	keymap[QZ_KP0] = SDLK_KP0;
  17.135 +	keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
  17.136 +	keymap[QZ_IBOOK_ENTER] = SDLK_KP_ENTER;
  17.137 +	keymap[QZ_IBOOK_RIGHT] = SDLK_RIGHT;
  17.138 +	keymap[QZ_IBOOK_DOWN] = SDLK_DOWN;
  17.139 +	keymap[QZ_IBOOK_UP]   = SDLK_UP;
  17.140 +	keymap[QZ_IBOOK_LEFT] = SDLK_LEFT;
  17.141 +}
  17.142 +
  17.143 +static void QZ_DoKey (int state, NSEvent *event) {
  17.144 +
  17.145 +        NSString *chars;
  17.146 +        int i;
  17.147 +        SDL_keysym key;
  17.148 +        
  17.149 +        /* An event can contain multiple characters */
  17.150 +        /* I'll ignore this fact for now, since there is only one virtual key code per event */
  17.151 +        chars = [ event characters ];
  17.152 +        for (i =0; i < 1 /*[ chars length ] */; i++) {
  17.153 +                    
  17.154 +            key.scancode = [ event keyCode ];
  17.155 +            key.sym      = keymap [ key.scancode ];
  17.156 +            key.unicode  = [ chars characterAtIndex:i];
  17.157 +            key.mod      = KMOD_NONE;
  17.158 +                        
  17.159 +            SDL_PrivateKeyboard (state, &key);
  17.160 +        }
  17.161 +}
  17.162 +
  17.163 +static void QZ_DoModifiers (unsigned int newMods) {
  17.164 +
  17.165 +    const int offset = 18;
  17.166 +    const int mapping[] = { SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, 0, SDLK_LMETA } ;
  17.167 +
  17.168 +    int bit;
  17.169 +    SDL_keysym key;
  17.170 +    key.scancode = 0;
  17.171 +    key.sym      = SDLK_UNKNOWN;
  17.172 +    key.unicode  = 0;
  17.173 +    key.mod      = KMOD_NONE;
  17.174 +    
  17.175 +    /* Iterate through the bits, testing each against the current modifiers */
  17.176 +    for (bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1) {
  17.177 +    
  17.178 +        unsigned int currentMask, newMask;
  17.179 +        
  17.180 +        currentMask = currentMods & bit;
  17.181 +        newMask     = newMods & bit;
  17.182 +        
  17.183 +        if ( currentMask && 
  17.184 +             currentMask != newMask ) {  /* modifier up event */
  17.185 +
  17.186 +            key.sym = mapping[ currentMask >> offset ];
  17.187 +            SDL_PrivateKeyboard (SDL_RELEASED, &key);
  17.188 +        }
  17.189 +        else
  17.190 +        if ( newMask &&
  17.191 +             currentMask != newMask ) {  /* modifier down event */
  17.192 +         
  17.193 +            key.sym = mapping [ newMask >> offset ];
  17.194 +            SDL_PrivateKeyboard (SDL_PRESSED, &key);
  17.195 +        }
  17.196 +    }
  17.197 +    
  17.198 +    currentMods = newMods;
  17.199 +}
  17.200 +
  17.201 +static void QZ_DoActivate (_THIS, NSPoint p) {
  17.202 +    
  17.203 +    inForeground = YES;
  17.204 +
  17.205 +    /* Regrab the mouse */
  17.206 +    if (currentGrabMode == SDL_GRAB_ON) {
  17.207 +        QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
  17.208 +        CGAssociateMouseAndMouseCursorPosition (0);
  17.209 +    }
  17.210 +    
  17.211 +    SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
  17.212 +}
  17.213 +
  17.214 +static void QZ_DoDeactivate (_THIS) {
  17.215 +    
  17.216 +    inForeground = NO;
  17.217 +
  17.218 +    /* Ungrab mouse if it is grabbed */
  17.219 +    if (currentGrabMode == SDL_GRAB_ON) {
  17.220 +        CGAssociateMouseAndMouseCursorPosition (1);
  17.221 +    }
  17.222 +    
  17.223 +    SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
  17.224 +}
  17.225 +
  17.226 +static void QZ_PumpEvents (_THIS) { 
  17.227 +
  17.228 +    NSDate *distantPast = [ NSDate distantPast ];
  17.229 +    
  17.230 +    //NSAutoreleasePool *pool;
  17.231 +    //pool = [ [ NSAutoreleasePool alloc ] init ];
  17.232 +    
  17.233 +    NSEvent *event;
  17.234 +    NSRect winRect;
  17.235 +    NSRect titleBarRect;
  17.236 +            
  17.237 +    winRect = NSMakeRect (0, 0, SDL_VideoSurface->w + 1, SDL_VideoSurface->h + 1);
  17.238 +    titleBarRect = NSMakeRect ( 0, SDL_VideoSurface->h, SDL_VideoSurface->w,
  17.239 +        SDL_VideoSurface->h + 22 );
  17.240 +            
  17.241 +    do {
  17.242 +    
  17.243 +        /* Poll for an event. This will not block */
  17.244 +        event = [ NSApp nextEventMatchingMask:NSAnyEventMask
  17.245 +                    untilDate:distantPast
  17.246 +                    inMode: NSDefaultRunLoopMode dequeue:YES ];
  17.247 +    
  17.248 +        if (event != nil) {
  17.249 +            unsigned int type;
  17.250 +            NSPoint p;
  17.251 +            
  17.252 +            type = [ event type ];
  17.253 +            p = [ event locationInWindow ];
  17.254 +            
  17.255 +            #define DO_MOUSE_DOWN(button, sendToWindow)                                                \
  17.256 +                if ( inForeground ) {                                                                  \
  17.257 +                    if ( NSPointInRect(p,winRect))                                                     \
  17.258 +                        SDL_PrivateMouseButton (SDL_PRESSED, button, p.x, SDL_VideoSurface->h - p.y);  \
  17.259 +                    else if (sendToWindow)                                                             \
  17.260 +                            [ window sendEvent:event ];                                                   \
  17.261 +                }                                                                                      \
  17.262 +                else {                                                                                 \
  17.263 +                    QZ_DoActivate (this, p);                                                           \
  17.264 +                }       
  17.265 +            
  17.266 +            #define DO_MOUSE_UP(button, sendToWindow)                                          \
  17.267 +                if ( ! NSPointInRect (p, titleBarRect) ) \
  17.268 +                    SDL_PrivateMouseButton (SDL_RELEASED, button, p.x, SDL_VideoSurface->h - p.y); \
  17.269 +                if (sendToWindow)                                                              \
  17.270 +                    [ window sendEvent:event ]
  17.271 +                    
  17.272 +            switch ( type) {
  17.273 +            
  17.274 +            case NSLeftMouseDown:  
  17.275 +                if ( NSCommandKeyMask & currentMods ) {
  17.276 +                        DO_MOUSE_DOWN (3, 0);
  17.277 +                } 
  17.278 +                else if ( NSAlternateKeyMask & currentMods ) {
  17.279 +                    DO_MOUSE_DOWN (2, 0);
  17.280 +                } 
  17.281 +                else {
  17.282 +                    DO_MOUSE_DOWN (1, 1);
  17.283 +                }
  17.284 +                break;
  17.285 +            case 25:               DO_MOUSE_DOWN (2, 0); break;
  17.286 +            case NSRightMouseDown: DO_MOUSE_DOWN (3, 0); break;   
  17.287 +            case NSLeftMouseUp:    
  17.288 +            if ( NSCommandKeyMask & currentMods ) {
  17.289 +                        DO_MOUSE_UP (3, 0);
  17.290 +                } 
  17.291 +                else if ( NSAlternateKeyMask & currentMods ) {
  17.292 +                    DO_MOUSE_UP (2, 0);
  17.293 +                } 
  17.294 +                else
  17.295 +                    DO_MOUSE_UP (1, 1);
  17.296 +                break;
  17.297 +            case 26:               DO_MOUSE_UP (2, 0);   break;
  17.298 +            case NSRightMouseUp:   DO_MOUSE_UP (3, 0);   break;
  17.299 +            case NSSystemDefined:
  17.300 +                //if ([event subtype] == 7) {
  17.301 +                //    unsigned int buttons;   // up to 32 mouse button states!
  17.302 +                //    buttons = [ event data2 ];
  17.303 +                //}
  17.304 +                break;
  17.305 +            case NSLeftMouseDragged:
  17.306 +            case NSRightMouseDragged:
  17.307 +            case 27:
  17.308 +                SDL_PrivateMouseMotion (SDL_PRESSED, 0, p.x, SDL_VideoSurface->h - p.y);
  17.309 +                break;
  17.310 +            case NSMouseMoved:
  17.311 +                {
  17.312 +                   static int moves = 0;
  17.313 +                    
  17.314 +                   if ( (moves % 10) == 0 ) {
  17.315 +                        SDL_PrivateMouseMotion (SDL_RELEASED, 0, p.x, SDL_VideoSurface->h - p.y);
  17.316 +                        moves = 0;
  17.317 +                   }
  17.318 +                   else {
  17.319 +                        CGMouseDelta dx, dy;
  17.320 +                        CGGetLastMouseDelta (&dx, &dy);
  17.321 +                        SDL_PrivateMouseMotion (SDL_RELEASED, 1, dx, dy);
  17.322 +                        moves++;
  17.323 +                   }
  17.324 +                }
  17.325 +                break;
  17.326 +            case NSScrollWheel:
  17.327 +                {
  17.328 +                    if (NSPointInRect(p, winRect)) {
  17.329 +                        float dy;
  17.330 +                        dy = [ event deltaY ];
  17.331 +                        if ( dy > 0.0 ) /* Scroll up */
  17.332 +                            SDL_PrivateMouseButton (SDL_PRESSED, 4, p.x, SDL_VideoSurface->h - p.y);
  17.333 +                        else /* Scroll down */
  17.334 +                            SDL_PrivateMouseButton (SDL_PRESSED, 5, p.x, SDL_VideoSurface->h - p.y);
  17.335 +                    }
  17.336 +                }
  17.337 +                break;
  17.338 +            case NSKeyUp:
  17.339 +                QZ_DoKey (SDL_RELEASED, event);
  17.340 +                break;
  17.341 +            case NSKeyDown:
  17.342 +                QZ_DoKey (SDL_PRESSED, event);
  17.343 +                break;
  17.344 +            case NSFlagsChanged:
  17.345 +                QZ_DoModifiers( [ event modifierFlags ] );
  17.346 +                break;
  17.347 +            case NSMouseEntered: break;
  17.348 +            case NSMouseExited: break;
  17.349 +            case NSAppKitDefined:
  17.350 +                switch ( [ event subtype ] ) {
  17.351 +                case NSApplicationActivatedEventType:
  17.352 +                    QZ_DoActivate (this, p);
  17.353 +                    break;
  17.354 +                case NSApplicationDeactivatedEventType:
  17.355 +                    QZ_DoDeactivate (this);
  17.356 +                    break;
  17.357 +                case NSWindowMovedEventType:
  17.358 +                    [ window sendEvent:event ];
  17.359 +                    break;
  17.360 +                }
  17.361 +                break;
  17.362 +            case NSApplicationDefined: break;
  17.363 +            case NSPeriodic: break;
  17.364 +            case NSCursorUpdate: break;
  17.365 +            }
  17.366 +        }
  17.367 +       // [ pool release ];
  17.368 +
  17.369 +      } while (event != nil);
  17.370 +}
  17.371 +
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/video/quartz/SDL_QuartzKeys.h	Thu Jun 07 14:28:11 2001 +0000
    18.3 @@ -0,0 +1,140 @@
    18.4 +/*
    18.5 +    SDL - Simple DirectMedia Layer
    18.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  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 Library General Public
   18.10 +    License as published by the Free Software Foundation; either
   18.11 +    version 2 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 +    Library General Public License for more details.
   18.17 +
   18.18 +    You should have received a copy of the GNU Library General Public
   18.19 +    License along with this library; if not, write to the Free
   18.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.21 +
   18.22 +    Sam Lantinga
   18.23 +    slouken@devolution.com
   18.24 +*/
   18.25 +
   18.26 +/* These are the Macintosh key scancode constants -- from Inside Macintosh */
   18.27 +
   18.28 +#define QZ_ESCAPE		0x35
   18.29 +#define QZ_F1			0x7A
   18.30 +#define QZ_F2			0x78
   18.31 +#define QZ_F3			0x63
   18.32 +#define QZ_F4			0x76
   18.33 +#define QZ_F5			0x60
   18.34 +#define QZ_F6			0x61
   18.35 +#define QZ_F7			0x62
   18.36 +#define QZ_F8			0x64
   18.37 +#define QZ_F9			0x65
   18.38 +#define QZ_F10			0x6D
   18.39 +#define QZ_F11			0x67
   18.40 +#define QZ_F12			0x6F
   18.41 +#define QZ_PRINT		0x69
   18.42 +#define QZ_SCROLLOCK		0x6B
   18.43 +#define QZ_PAUSE		0x71
   18.44 +#define QZ_POWER		0x7F
   18.45 +#define QZ_BACKQUOTE		0x32
   18.46 +#define QZ_1			0x12
   18.47 +#define QZ_2			0x13
   18.48 +#define QZ_3			0x14
   18.49 +#define QZ_4			0x15
   18.50 +#define QZ_5			0x17
   18.51 +#define QZ_6			0x16
   18.52 +#define QZ_7			0x1A
   18.53 +#define QZ_8			0x1C
   18.54 +#define QZ_9			0x19
   18.55 +#define QZ_0			0x1D
   18.56 +#define QZ_MINUS		0x1B
   18.57 +#define QZ_EQUALS		0x18
   18.58 +#define QZ_BACKSPACE		0x33
   18.59 +#define QZ_INSERT		0x72
   18.60 +#define QZ_HOME			0x73
   18.61 +#define QZ_PAGEUP		0x74
   18.62 +#define QZ_NUMLOCK		0x47
   18.63 +#define QZ_KP_EQUALS		0x51
   18.64 +#define QZ_KP_DIVIDE		0x4B
   18.65 +#define QZ_KP_MULTIPLY		0x43
   18.66 +#define QZ_TAB			0x30
   18.67 +#define QZ_q			0x0C
   18.68 +#define QZ_w			0x0D
   18.69 +#define QZ_e			0x0E
   18.70 +#define QZ_r			0x0F
   18.71 +#define QZ_t			0x11
   18.72 +#define QZ_y			0x10
   18.73 +#define QZ_u			0x20
   18.74 +#define QZ_i			0x22
   18.75 +#define QZ_o			0x1F
   18.76 +#define QZ_p			0x23
   18.77 +#define QZ_LEFTBRACKET		0x21
   18.78 +#define QZ_RIGHTBRACKET		0x1E
   18.79 +#define QZ_BACKSLASH		0x2A
   18.80 +#define QZ_DELETE		0x75
   18.81 +#define QZ_END			0x77
   18.82 +#define QZ_PAGEDOWN		0x79
   18.83 +#define QZ_KP7			0x59
   18.84 +#define QZ_KP8			0x5B
   18.85 +#define QZ_KP9			0x5C
   18.86 +#define QZ_KP_MINUS		0x4E
   18.87 +#define QZ_CAPSLOCK		0x39
   18.88 +#define QZ_a			0x00
   18.89 +#define QZ_s			0x01
   18.90 +#define QZ_d			0x02
   18.91 +#define QZ_f			0x03
   18.92 +#define QZ_g			0x05
   18.93 +#define QZ_h			0x04
   18.94 +#define QZ_j			0x26
   18.95 +#define QZ_k			0x28
   18.96 +#define QZ_l			0x25
   18.97 +#define QZ_SEMICOLON		0x29
   18.98 +#define QZ_QUOTE		0x27
   18.99 +#define QZ_RETURN		0x24
  18.100 +#define QZ_KP4			0x56
  18.101 +#define QZ_KP5			0x57
  18.102 +#define QZ_KP6			0x58
  18.103 +#define QZ_KP_PLUS		0x45
  18.104 +#define QZ_LSHIFT		0x38
  18.105 +#define QZ_z			0x06
  18.106 +#define QZ_x			0x07
  18.107 +#define QZ_c			0x08
  18.108 +#define QZ_v			0x09
  18.109 +#define QZ_b			0x0B
  18.110 +#define QZ_n			0x2D
  18.111 +#define QZ_m			0x2E
  18.112 +#define QZ_COMMA		0x2B
  18.113 +#define QZ_PERIOD		0x2F
  18.114 +#define QZ_SLASH		0x2C
  18.115 +#if 0	/* These are the same as the left versions - use left by default */
  18.116 +#define QZ_RSHIFT		0x38
  18.117 +#endif
  18.118 +#define QZ_UP			0x7E
  18.119 +#define QZ_KP1			0x53
  18.120 +#define QZ_KP2			0x54
  18.121 +#define QZ_KP3			0x55
  18.122 +#define QZ_KP_ENTER		0x4C
  18.123 +#define QZ_LCTRL		0x3B
  18.124 +#define QZ_LALT			0x3A
  18.125 +#define QZ_LMETA		0x37
  18.126 +#define QZ_SPACE		0x31
  18.127 +#if 0	/* These are the same as the left versions - use left by default */
  18.128 +#define QZ_RMETA		0x37
  18.129 +#define QZ_RALT			0x3A
  18.130 +#define QZ_RCTRL		0x3B
  18.131 +#endif
  18.132 +#define QZ_LEFT			0x7B
  18.133 +#define QZ_DOWN			0x7D
  18.134 +#define QZ_RIGHT		0x7C
  18.135 +#define QZ_KP0			0x52
  18.136 +#define QZ_KP_PERIOD		0x41
  18.137 +
  18.138 +/* Wierd, these keys are on my iBook under MacOS X */
  18.139 +#define QZ_IBOOK_ENTER		0x34
  18.140 +#define QZ_IBOOK_LEFT		0x3B
  18.141 +#define QZ_IBOOK_RIGHT		0x3C
  18.142 +#define QZ_IBOOK_DOWN		0x3D
  18.143 +#define QZ_IBOOK_UP		0x3E
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Thu Jun 07 14:28:11 2001 +0000
    19.3 @@ -0,0 +1,183 @@
    19.4 +/*
    19.5 +    SDL - Simple DirectMedia Layer
    19.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  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 Library General Public
   19.10 +    License as published by the Free Software Foundation; either
   19.11 +    version 2 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 +    Library General Public License for more details.
   19.17 +
   19.18 +    You should have received a copy of the GNU Library General Public
   19.19 +    License along with this library; if not, write to the Free
   19.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19.21 +
   19.22 +    Sam Lantinga
   19.23 +    slouken@devolution.com
   19.24 +*/
   19.25 +
   19.26 +/*	
   19.27 +    @file   SDL_QuartzVideo.h
   19.28 +    @author Darrell Walisser
   19.29 +    
   19.30 +    @abstract SDL video driver for MacOS X.
   19.31 +    
   19.32 +    @discussion
   19.33 +    
   19.34 +    TODO
   19.35 +        - Hardware Cursor support with NSCursor instead of Carbon
   19.36 +        - Keyboard repeat/mouse speed adjust (if needed)
   19.37 +        - Multiple monitor support (currently only main display)
   19.38 +        - Accelerated blitting support
   19.39 +        - Set the window icon (dock icon when API is available)
   19.40 +        - Avoid erasing window on minimize, or disable minimize
   19.41 +    Problems:
   19.42 +        - OGL not working in full screen with software renderer
   19.43 +        - SetColors sets palette correctly but clears framebuffer
   19.44 +        - Crash in CG after several mode switches
   19.45 +        - Retained windows don't draw their title bar quite right (OS Bug)
   19.46 +        - Should I do depth switching for windowed modes?
   19.47 +        - Launch times are slow, maybe prebinding will help
   19.48 +        - Direct framebuffer access has some artifacts, maybe a driver issue
   19.49 +        - Cursor in 8 bit modes is screwy
   19.50 +        - Modifier + mouse-down maps alternate mouse button, but if modifier is released
   19.51 +           before mouse button, corresponding mouse-up event is not generated.
   19.52 +        - Clicking in content activates app, but doesn't generate the activate event,
   19.53 +          and subsequent switches generate no activate/deactivate events! (OS Bug I hope)
   19.54 +*/
   19.55 +
   19.56 +#include <ApplicationServices/ApplicationServices.h>
   19.57 +#include <OpenGL/OpenGL.h>
   19.58 +#include <Cocoa/Cocoa.h>
   19.59 +#include <Carbon/Carbon.h>
   19.60 +
   19.61 +#include "SDL_video.h"
   19.62 +#include "SDL_error.h"
   19.63 +#include "SDL_syswm.h"
   19.64 +#include "SDL_sysvideo.h"
   19.65 +#include "SDL_pixels_c.h"
   19.66 +#include "SDL_events_c.h"
   19.67 +
   19.68 +/* This is a workaround to directly access NSOpenGLContext's CGL context */
   19.69 +/* We need to do this in order to check for errors */
   19.70 +@interface NSOpenGLContext (CGLContextAccess)
   19.71 +- (CGLContextObj) cglContext;
   19.72 +@end
   19.73 +
   19.74 +@implementation NSOpenGLContext (CGLContextAccess)
   19.75 +- (CGLContextObj) cglContext;
   19.76 +{
   19.77 +    return _contextAuxiliary;
   19.78 +}
   19.79 +@end
   19.80 +
   19.81 +typedef struct SDL_PrivateVideoData {
   19.82 +
   19.83 +    CGDirectDisplayID  display; /* 0 == main display */
   19.84 +    CFDictionaryRef    mode;
   19.85 +    CFDictionaryRef    save_mode;
   19.86 +    CFArrayRef         mode_list;
   19.87 +    CGDirectPaletteRef palette;
   19.88 +    NSOpenGLContext    *gl_context;
   19.89 +    int                width, height, bpp;
   19.90 +    Uint32             flags;
   19.91 +    
   19.92 +    /* Window-only fields */
   19.93 +    NSWindow        *window;
   19.94 +    NSQuickDrawView *view;
   19.95 +    NSString        *title;
   19.96 +    
   19.97 +} SDL_PrivateVideoData ;
   19.98 +
   19.99 +#define _THIS	SDL_VideoDevice *this
  19.100 +#define display_id (this->hidden->display)
  19.101 +#define mode (this->hidden->mode)
  19.102 +#define save_mode (this->hidden->save_mode)
  19.103 +#define mode_list (this->hidden->mode_list)
  19.104 +#define palette (this->hidden->palette)
  19.105 +#define glcontext (this->hidden->glcontext)
  19.106 +#define objc_video (this->hidden->objc_video)
  19.107 +#define gl_context (this->hidden->gl_context)
  19.108 +#define device_width (this->hidden->width)
  19.109 +#define device_height (this->hidden->height)
  19.110 +#define device_bpp (this->hidden->bpp)
  19.111 +#define mode_flags (this->hidden->flags)
  19.112 +#define window (this->hidden->window)
  19.113 +#define windowView (this->hidden->view)
  19.114 +#define windowTitle (this->hidden->title)
  19.115 +
  19.116 +/* Interface for hardware fill not (yet) in the public API */
  19.117 +int CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
  19.118 +                      unsigned int w, unsigned int h, unsigned int color);
  19.119 +int CGSDisplayCanHWFill (CGDirectDisplayID id);
  19.120 +
  19.121 +/* Bootstrap functions */
  19.122 +static int              QZ_Available ();
  19.123 +static SDL_VideoDevice* QZ_CreateDevice (int device_index);
  19.124 +static void             QZ_DeleteDevice (SDL_VideoDevice *device);
  19.125 +
  19.126 +/* Initialization, Query, Setup, and Redrawing functions */
  19.127 +static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
  19.128 +
  19.129 +static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
  19.130 +					 Uint32 flags);
  19.131 +static void         QZ_UnsetVideoMode   (_THIS);
  19.132 +
  19.133 +static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
  19.134 +					 int width, int height, int bpp, 
  19.135 +					 Uint32 flags);
  19.136 +static int          QZ_ToggleFullScreen (_THIS, int on);
  19.137 +static int          QZ_SetColors        (_THIS, int first_color, 
  19.138 +					 int num_colors, SDL_Color *colors);
  19.139 +static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
  19.140 +static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
  19.141 +static void         QZ_VideoQuit        (_THIS);
  19.142 +
  19.143 +/* Hardware surface functions (for fullscreen mode only) */
  19.144 +static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
  19.145 +static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
  19.146 +static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
  19.147 +static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
  19.148 +/* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
  19.149 +
  19.150 +/* Gamma Functions */
  19.151 +static int QZ_SetGamma     (_THIS, float red, float green, float blue);
  19.152 +static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
  19.153 +static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
  19.154 +static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
  19.155 +
  19.156 +/* OpenGL functions */
  19.157 +static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
  19.158 +static void   QZ_TearDownOpenGL (_THIS);
  19.159 +static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
  19.160 +static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
  19.161 +static int    QZ_GL_MakeCurrent    (_THIS);
  19.162 +static void   QZ_GL_SwapBuffers    (_THIS);
  19.163 +static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
  19.164 +
  19.165 +/* Private function to warp the cursor (used internally) */
  19.166 +static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y);
  19.167 +
  19.168 +/* Cursor and Mouse functions */
  19.169 +static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
  19.170 +static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
  19.171 +                                          int w, int h, int hot_x, int hot_y);
  19.172 +static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
  19.173 +static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
  19.174 +static void         QZ_MoveWMCursor     (_THIS, int x, int y);
  19.175 +static void         QZ_CheckMouseMode   (_THIS);
  19.176 +
  19.177 +/* Event functions */
  19.178 +static void         QZ_InitOSKeymap     (_THIS);
  19.179 +static void         QZ_PumpEvents       (_THIS);
  19.180 +
  19.181 +/* Window Manager functions */
  19.182 +static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
  19.183 +static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
  19.184 +static int  QZ_IconifyWindow (_THIS);
  19.185 +static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
  19.186 +/*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Thu Jun 07 14:28:11 2001 +0000
    20.3 @@ -0,0 +1,756 @@
    20.4 +/*
    20.5 +    SDL - Simple DirectMedia Layer
    20.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  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 Library General Public
   20.10 +    License as published by the Free Software Foundation; either
   20.11 +    version 2 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 +    Library General Public License for more details.
   20.17 +
   20.18 +    You should have received a copy of the GNU Library General Public
   20.19 +    License along with this library; if not, write to the Free
   20.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   20.21 +
   20.22 +    Sam Lantinga
   20.23 +    slouken@devolution.com
   20.24 +*/
   20.25 +
   20.26 +#include "SDL_QuartzVideo.h"
   20.27 +
   20.28 +/* Some variables to share among files, put in device structure eventually */
   20.29 +static SDL_GrabMode currentGrabMode = SDL_GRAB_OFF;
   20.30 +static BOOL   inForeground = YES;
   20.31 +static SDLKey keymap[256];
   20.32 +static unsigned int currentMods = 0; /* Current keyboard modifiers, to track modifier state */
   20.33 +
   20.34 +/* Include files into one compile unit...break apart eventually */
   20.35 +#include "SDL_QuartzWM.m"
   20.36 +#include "SDL_QuartzEvents.m"
   20.37 +#include "SDL_QuartzWindow.m"
   20.38 +
   20.39 +char QZ_Error[255]; /* Global error buffer to temporarily store more informative error messages */
   20.40 +
   20.41 +/* Bootstrap binding, enables entry point into the driver */
   20.42 +VideoBootStrap QZ_bootstrap = {
   20.43 +    "Quartz", "MacOS X CoreGraphics", QZ_Available, QZ_CreateDevice
   20.44 +};
   20.45 +
   20.46 +/* Bootstrap functions */
   20.47 +static int QZ_Available () {
   20.48 +    return 1;
   20.49 +}
   20.50 +
   20.51 +static SDL_VideoDevice* QZ_CreateDevice (int device_index) {
   20.52 +
   20.53 +   #pragma unused (device_index)
   20.54 +
   20.55 +    SDL_VideoDevice *device;
   20.56 +    SDL_PrivateVideoData *hidden;
   20.57 +
   20.58 +    device = (SDL_VideoDevice*) malloc (sizeof (*device) );
   20.59 +    hidden = (SDL_PrivateVideoData*) malloc (sizeof (*hidden) );
   20.60 +
   20.61 +    if (device == NULL || hidden == NULL)
   20.62 +        SDL_OutOfMemory ();
   20.63 +
   20.64 +    memset (device, 0, sizeof (*device) );
   20.65 +    memset (hidden, 0, sizeof (*hidden) );
   20.66 +    
   20.67 +    device->hidden = hidden;
   20.68 +
   20.69 +    device->VideoInit        = QZ_VideoInit;
   20.70 +    device->ListModes        = QZ_ListModes;
   20.71 +    device->SetVideoMode     = QZ_SetVideoMode;
   20.72 +    device->ToggleFullScreen = QZ_ToggleFullScreen;
   20.73 +    device->SetColors        = QZ_SetColors;
   20.74 +    /* device->UpdateRects      = QZ_UpdateRects; this is determined by SetVideoMode() */
   20.75 +    device->VideoQuit        = QZ_VideoQuit;
   20.76 +    
   20.77 +    device->LockHWSurface   = QZ_LockHWSurface;
   20.78 +    device->UnlockHWSurface = QZ_UnlockHWSurface;
   20.79 +    device->FreeHWSurface   = QZ_FreeHWSurface;
   20.80 +    /* device->FlipHWSurface   = QZ_FlipHWSurface */;
   20.81 +
   20.82 +    device->SetGamma     = QZ_SetGamma;
   20.83 +    device->GetGamma     = QZ_GetGamma;
   20.84 +    device->SetGammaRamp = QZ_SetGammaRamp;
   20.85 +    device->GetGammaRamp = QZ_GetGammaRamp;
   20.86 +
   20.87 +    device->GL_GetProcAddress = QZ_GL_GetProcAddress;
   20.88 +    device->GL_GetAttribute   = QZ_GL_GetAttribute;
   20.89 +    device->GL_MakeCurrent    = QZ_GL_MakeCurrent;
   20.90 +    device->GL_SwapBuffers    = QZ_GL_SwapBuffers;
   20.91 +    device->GL_LoadLibrary    = QZ_GL_LoadLibrary;
   20.92 +    
   20.93 +    device->FreeWMCursor   = QZ_FreeWMCursor;
   20.94 +    device->CreateWMCursor = QZ_CreateWMCursor;
   20.95 +    device->ShowWMCursor   = QZ_ShowWMCursor;
   20.96 +    device->WarpWMCursor   = QZ_WarpWMCursor;
   20.97 +    device->MoveWMCursor   = QZ_MoveWMCursor;
   20.98 +    device->CheckMouseMode = QZ_CheckMouseMode;
   20.99 +    device->InitOSKeymap   = QZ_InitOSKeymap;
  20.100 +    device->PumpEvents     = QZ_PumpEvents;
  20.101 +
  20.102 +    device->SetCaption    = QZ_SetCaption;
  20.103 +    device->SetIcon       = QZ_SetIcon;
  20.104 +    device->IconifyWindow = QZ_IconifyWindow;
  20.105 +    /*device->GetWMInfo     = QZ_GetWMInfo;*/
  20.106 +    device->GrabInput     = QZ_GrabInput;
  20.107 +    
  20.108 +    device->free = QZ_DeleteDevice;
  20.109 +    
  20.110 +    return device;
  20.111 +}
  20.112 +
  20.113 +static void QZ_DeleteDevice (SDL_VideoDevice *device) {
  20.114 +
  20.115 +    free (device->hidden);
  20.116 +    free (device);
  20.117 +}
  20.118 +
  20.119 +static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
  20.120 +
  20.121 +  /* Initialize the video settings; this data persists between mode switches */
  20.122 +  display_id = kCGDirectMainDisplay; 
  20.123 +  save_mode  = CGDisplayCurrentMode    (display_id);
  20.124 +  mode_list  = CGDisplayAvailableModes (display_id);
  20.125 +  palette    = CGPaletteCreateDefaultColorPalette ();
  20.126 +  
  20.127 +  /* Gather some information that is useful to know about the display */
  20.128 +  CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayBitsPerPixel), 
  20.129 +		    kCFNumberSInt32Type, &device_bpp);
  20.130 +
  20.131 +  CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayWidth),
  20.132 +                    kCFNumberSInt32Type, &device_width);
  20.133 +  
  20.134 +  CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayHeight),
  20.135 +                    kCFNumberSInt32Type, &device_height);
  20.136 +
  20.137 +  video_format->BitsPerPixel = device_bpp;
  20.138 +  windowTitle = @"";
  20.139 +  
  20.140 +  return 0;
  20.141 +}
  20.142 +
  20.143 +static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags) {
  20.144 +    
  20.145 +    CFIndex num_modes = CFArrayGetCount (mode_list);
  20.146 +    CFIndex i;
  20.147 +
  20.148 +    static SDL_Rect **list = NULL;
  20.149 +    int list_size = 0;
  20.150 +
  20.151 +    /* Any windowed mode is acceptable */
  20.152 +    if ( (flags & SDL_FULLSCREEN) == 0 )
  20.153 +        return (SDL_Rect**)-1;
  20.154 +        
  20.155 +    /* Free memory from previous call, if any */
  20.156 +    if ( list != NULL ) {
  20.157 +
  20.158 +      int i = 0;
  20.159 +
  20.160 +      for (i = 0; list[i] != NULL; i++)
  20.161 +	free (list[i]);
  20.162 +
  20.163 +      free (list);
  20.164 +      list = NULL;
  20.165 +    }
  20.166 +
  20.167 +    /* Build list of modes with the requested bpp */
  20.168 +    for (i = num_modes-1; i >= 0; i--) {
  20.169 +   
  20.170 +        CFDictionaryRef onemode = CFArrayGetValueAtIndex (mode_list, i);
  20.171 +	CFNumberRef     number;
  20.172 +	int bpp;
  20.173 +	
  20.174 +	number = CFDictionaryGetValue (onemode, kCGDisplayBitsPerPixel);
  20.175 +	CFNumberGetValue (number, kCFNumberSInt32Type, &bpp);
  20.176 +
  20.177 +	if (bpp == format->BitsPerPixel) {
  20.178 +	  
  20.179 +	  int       intvalue;
  20.180 +	  SDL_Rect *rect;
  20.181 +          int       lastwidth = 0, lastheight = 0, width, height;
  20.182 +
  20.183 +	  number = CFDictionaryGetValue (onemode, kCGDisplayWidth);
  20.184 +	  CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
  20.185 +	  width = (Uint16) intvalue;
  20.186 +	  
  20.187 +	  number = CFDictionaryGetValue (onemode, kCGDisplayHeight);
  20.188 +	  CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
  20.189 +	  height = (Uint16) intvalue;
  20.190 +          
  20.191 +          /* We'll get a lot of modes with the same size, so ignore them */
  20.192 +          if ( width != lastwidth && height != lastheight ) {
  20.193 +
  20.194 +            lastwidth  = width;
  20.195 +            lastheight = height;
  20.196 +	  
  20.197 +            list_size++;
  20.198 +
  20.199 +            if ( list == NULL)
  20.200 +                list = (SDL_Rect**) malloc (sizeof(*list) * list_size+1);
  20.201 +            else
  20.202 +                list = (SDL_Rect**) realloc (list, sizeof(*list) * list_size+1);
  20.203 +            
  20.204 +            rect = (SDL_Rect*) malloc (sizeof(**list));
  20.205 +            
  20.206 +            if (list == NULL || rect == NULL)
  20.207 +                SDL_OutOfMemory ();
  20.208 +    
  20.209 +            rect->w = width;
  20.210 +            rect->h = height;
  20.211 +    
  20.212 +            list[list_size-1] = rect;
  20.213 +            list[list_size]   = NULL;
  20.214 +        }
  20.215 +      }
  20.216 +    }
  20.217 +    
  20.218 +    return list;
  20.219 +}
  20.220 +
  20.221 +static void QZ_UnsetVideoMode (_THIS) {
  20.222 +
  20.223 +    if ( mode_flags & SDL_OPENGL )
  20.224 +        QZ_TearDownOpenGL (this);
  20.225 +
  20.226 +    /* Reset values that may change between switches */
  20.227 +    this->info.blit_fill = 0;
  20.228 +    this->FillHWRect     = NULL;
  20.229 +    this->UpdateRects    = NULL;
  20.230 +    
  20.231 +    /* Restore gamma settings */
  20.232 +    CGDisplayRestoreColorSyncSettings ();
  20.233 +   
  20.234 +    /* Restore original screen resolution */
  20.235 +    if ( mode_flags & SDL_FULLSCREEN ) {
  20.236 +        CGDisplaySwitchToMode (display_id, save_mode);
  20.237 +        CGDisplayRelease (display_id);
  20.238 +    }
  20.239 +    /* Release window mode data structures */
  20.240 +    else { 
  20.241 +        if ( (mode_flags & SDL_OPENGL) == 0 ) {
  20.242 +            UnlockPortBits ( [ windowView qdPort ] );
  20.243 +            [ windowView release  ];
  20.244 +        }
  20.245 +        [ window setContentView:nil ];
  20.246 +        [ window close ];
  20.247 +        [ window release ];
  20.248 +    }
  20.249 +    
  20.250 +    /* Ensure the cursor will be visible and working when we quit */
  20.251 +    CGDisplayShowCursor (display_id);
  20.252 +    CGAssociateMouseAndMouseCursorPosition (1);
  20.253 +}
  20.254 +
  20.255 +static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int width,
  20.256 +                                           int height, int bpp, Uint32 flags) {
  20.257 +    int exact_match;
  20.258 +
  20.259 +    /* See if requested mode exists */
  20.260 +    mode = CGDisplayBestModeForParameters (display_id, bpp, width, 
  20.261 +					   height, &exact_match);
  20.262 +    
  20.263 +    /* Require an exact match to the requested mode */
  20.264 +    if ( ! exact_match ) {
  20.265 +        sprintf (QZ_Error, "Failed to find display resolution: %dx%dx%d", width, height, bpp);
  20.266 +        SDL_SetError (QZ_Error);
  20.267 +        goto ERR_NO_MATCH;
  20.268 +    }
  20.269 +    
  20.270 +    /* Put up the blanking window (a window above all other windows) */
  20.271 +    if ( CGDisplayNoErr != CGDisplayCapture (display_id) ) {
  20.272 +        SDL_SetError ("Failed capturing display");
  20.273 +        goto ERR_NO_CAPTURE;
  20.274 +    }
  20.275 +    
  20.276 +    /* Do the physical switch */
  20.277 +    if ( CGDisplayNoErr != CGDisplaySwitchToMode (display_id, mode) ) {
  20.278 +        SDL_SetError ("Failed switching display resolution");
  20.279 +        goto ERR_NO_SWITCH;
  20.280 +    }
  20.281 +    
  20.282 +    /* None of these methods seem to fix the fullscreen artifacts bug(s) */
  20.283 +#if USE_GDHANDLE
  20.284 +    SetGDevice(GetMainDevice());
  20.285 +    current->pitch = (**(**  GetMainDevice() ).gdPMap).rowBytes & 0x3FFF;
  20.286 +    current->pixels = (**(** GetMainDevice() ).gdPMap).baseAddr;
  20.287 +#elif USE_CREATEPORT
  20.288 +    device_port = CreateNewPortForCGDisplayID((Uint32*)display_id);
  20.289 +    SetPort (device_port);
  20.290 +    LockPortBits ( device_port );
  20.291 +    current->pixels = GetPixBaseAddr ( GetPortPixMap ( device_port ) );
  20.292 +    current->pitch  = GetPixRowBytes ( GetPortPixMap ( device_port ) );
  20.293 +    UnlockPortBits ( device_port );
  20.294 +#else
  20.295 +    current->pixels = (Uint32*) CGDisplayBaseAddress (display_id);
  20.296 +    current->pitch  = CGDisplayBytesPerRow (display_id);
  20.297 +#endif
  20.298 +
  20.299 +    current->w = width;
  20.300 +    current->h = height;
  20.301 +    current->flags |= SDL_FULLSCREEN;  
  20.302 +    current->flags |= SDL_HWSURFACE;
  20.303 +   
  20.304 +    this->UpdateRects = QZ_DirectUpdate;
  20.305 +    
  20.306 +    /* Setup some mode-dependant info */
  20.307 +    if ( CGSDisplayCanHWFill (display_id) ) {
  20.308 +         this->info.blit_fill = 1;
  20.309 +         this->FillHWRect = QZ_FillHWRect;
  20.310 +    }
  20.311 +        
  20.312 +    if ( CGDisplayCanSetPalette (display_id) )
  20.313 +        current->flags |= SDL_HWPALETTE;
  20.314 +    
  20.315 +    /* Setup OpenGL for a fullscreen context */
  20.316 +    if (flags & SDL_OPENGL) {
  20.317 +
  20.318 +        CGLError err;
  20.319 +        CGLContextObj ctx;
  20.320 +        
  20.321 +        if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
  20.322 +            return NULL;
  20.323 +        }
  20.324 +       
  20.325 +        ctx = [ gl_context cglContext ];
  20.326 +        err = CGLSetFullScreen (ctx);
  20.327 +        
  20.328 +        if (err) {
  20.329 +            sprintf (QZ_Error, "Error setting OpenGL fullscreen: %s", CGLErrorString(err));
  20.330 +            SDL_SetError (QZ_Error);
  20.331 +            goto ERR_NO_GL;
  20.332 +        }
  20.333 +         
  20.334 +        [ gl_context makeCurrentContext];
  20.335 +        
  20.336 +        current->flags |= SDL_OPENGL;
  20.337 +    }
  20.338 +
  20.339 +    /* If we don't hide menu bar, it will get events and interrupt the program */
  20.340 +    HideMenuBar ();
  20.341 +    
  20.342 +    /* Save the flags to ensure correct tear-down */
  20.343 +    mode_flags = current->flags;
  20.344 +    
  20.345 +    return current;
  20.346 +
  20.347 + /* Since the blanking window covers *all* windows (even force quit) correct recovery is crutial */
  20.348 + ERR_NO_GL:      CGDisplaySwitchToMode (display_id, save_mode);
  20.349 + ERR_NO_SWITCH:  CGDisplayRelease (display_id);
  20.350 + ERR_NO_CAPTURE:
  20.351 + ERR_NO_MATCH:	return NULL;
  20.352 +}
  20.353 +
  20.354 +static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
  20.355 +                                           int height, int bpp, Uint32 flags) {    
  20.356 +    NSRect rect;    
  20.357 +    rect = NSMakeRect (0, 0, width, height);
  20.358 +    
  20.359 +    /* Manually create a window, avoids having a nib file resource */
  20.360 +    window = [ [ SDL_QuartzWindow alloc ] initWithContentRect:rect 
  20.361 +        styleMask:(NSTitledWindowMask | NSMiniaturizableWindowMask)
  20.362 +        backing: //NSBackingStoreBuffered
  20.363 +            NSBackingStoreRetained
  20.364 +          defer:NO ];
  20.365 +    
  20.366 +    if (window == nil) {
  20.367 +        SDL_SetError ("Could not create the Cocoa window");
  20.368 +        return NULL;
  20.369 +    }
  20.370 +    
  20.371 +    current->w  = width;
  20.372 +    current->h = height;
  20.373 +    
  20.374 +    [ window setTitle:windowTitle ];
  20.375 +    [ window setAcceptsMouseMovedEvents:YES ];
  20.376 +    [ window center ];
  20.377 +        
  20.378 +    /* For OpenGL, we set the content view to a NSOpenGLView */
  20.379 +    if ( flags & SDL_OPENGL ) {
  20.380 +    
  20.381 +        if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
  20.382 +            return NULL;
  20.383 +        }
  20.384 +        
  20.385 +        [ gl_context setView: [ window contentView ] ];
  20.386 +        [ gl_context makeCurrentContext];
  20.387 +        [ window orderFront:nil ];
  20.388 +        current->flags |= SDL_OPENGL;
  20.389 +    }
  20.390 +    /* For 2D, we set the content view to a NSQuickDrawView */
  20.391 +    else {
  20.392 +    
  20.393 +        windowView = [ [ NSQuickDrawView alloc ] init ];
  20.394 +        [ window setContentView:windowView ];
  20.395 +        [ window orderFront:nil ];    
  20.396 +        
  20.397 +        LockPortBits ( [ windowView qdPort ] );
  20.398 +        current->pixels = GetPixBaseAddr ( GetPortPixMap ( [ windowView qdPort ] ) );
  20.399 +        current->pitch  = GetPixRowBytes ( GetPortPixMap ( [ windowView qdPort ] ) );
  20.400 +            
  20.401 +        /* Offset 22 pixels down to fill the full content region */
  20.402 +        current->pixels += 22 * current->pitch;
  20.403 +        
  20.404 +        current->flags |= SDL_SWSURFACE;
  20.405 +        current->flags |= SDL_PREALLOC;
  20.406 +
  20.407 +        this->UpdateRects = QZ_UpdateRects;
  20.408 +    }
  20.409 +    return current;
  20.410 +}
  20.411 +
  20.412 +static SDL_Surface* QZ_SetVideoMode (_THIS, SDL_Surface *current, int width, 
  20.413 +				     int height, int bpp, Uint32 flags) {
  20.414 +
  20.415 +    if (SDL_VideoSurface != NULL)
  20.416 +        QZ_UnsetVideoMode (this);
  20.417 +       
  20.418 +    current->flags = 0;
  20.419 +    
  20.420 +    /* Setup full screen video */
  20.421 +    if ( flags & SDL_FULLSCREEN ) {
  20.422 +        current = QZ_SetVideoFullScreen (this, current, width, height, bpp, flags );
  20.423 +        if (current == NULL)
  20.424 +            return NULL;
  20.425 +    }
  20.426 +    /* Setup windowed video */
  20.427 +    else {
  20.428 +        /* Force bpp to the device's bpp */
  20.429 +        bpp = current->format->BitsPerPixel;
  20.430 +        current = QZ_SetVideoWindowed (this, current, width, height, bpp, flags);
  20.431 +        if (current == NULL)
  20.432 +            return NULL;
  20.433 +    }
  20.434 +    
  20.435 +    /* Setup the new pixel format */
  20.436 +    {
  20.437 +        int amask = 0, 
  20.438 +            rmask = 0, 
  20.439 +            gmask = 0,
  20.440 +            bmask = 0;
  20.441 +            
  20.442 +        switch (bpp) {
  20.443 +            case 16:   /* (1)-5-5-5 RGB */
  20.444 +                amask = 0; 
  20.445 +                rmask = 0x7c00;
  20.446 +                gmask = 0x3e0;
  20.447 +                bmask = 0x1f;
  20.448 +                break;
  20.449 +            case 24:
  20.450 +                SDL_SetError ("24bpp is not available");
  20.451 +                return NULL;
  20.452 +            case 32:   /* (8)-8-8-8 ARGB */
  20.453 +                amask = 0xFF000000;
  20.454 +                rmask = 0x00FF0000;
  20.455 +                gmask = 0x0000FF00;
  20.456 +                bmask = 0x000000FF;
  20.457 +                break;
  20.458 +        }
  20.459 +        
  20.460 +        if ( ! SDL_ReallocFormat (current, bpp,
  20.461 +                                  rmask, gmask, bmask, amask ) ) {
  20.462 +       	   SDL_SetError ("Couldn't reallocate pixel format");
  20.463 +           return NULL;
  20.464 +       	}
  20.465 +    }
  20.466 +    
  20.467 +    /* Warp mouse to origin in order to get passive mouse motion events started correctly */
  20.468 +    QZ_PrivateWarpCursor (this, current->flags & SDL_FULLSCREEN, height, 0, 0);
  20.469 +    
  20.470 +    return current;
  20.471 +}
  20.472 +
  20.473 +static int QZ_ToggleFullScreen (_THIS, int on) { 
  20.474 +    return -1;
  20.475 +}
  20.476 +
  20.477 +static int QZ_SetColors (_THIS, int first_color, int num_colors, 
  20.478 +			 SDL_Color *colors) {
  20.479 +
  20.480 +    CGTableCount  index;
  20.481 +    CGDeviceColor color;
  20.482 +    
  20.483 +    for (index = first_color; index < first_color+num_colors; index++) {
  20.484 +    
  20.485 +        /* Clamp colors between 0.0 and 1.0 */
  20.486 +        color.red   = colors->r / 255.0;
  20.487 +        color.blue  = colors->b / 255.0;
  20.488 +        color.green = colors->g / 255.0;
  20.489 +        
  20.490 +        colors++;
  20.491 +        
  20.492 +        CGPaletteSetColorAtIndex (palette, color, index);
  20.493 +    }
  20.494 +     
  20.495 +    if ( CGDisplayNoErr != CGDisplaySetPalette (display_id, palette) )
  20.496 +        return 0;
  20.497 +        
  20.498 +    return 1;
  20.499 +}
  20.500 +
  20.501 +static void QZ_DirectUpdate (_THIS, int num_rects, SDL_Rect *rects) {
  20.502 +    #pragma unused(this,num_rects,rects)
  20.503 +}
  20.504 +
  20.505 +static void QZ_UpdateRects (_THIS, int numRects, SDL_Rect *rects) { 
  20.506 +    
  20.507 +    if (SDL_VideoSurface->flags & SDL_OPENGLBLIT) {
  20.508 +        QZ_GL_SwapBuffers (this);
  20.509 +    }
  20.510 +    else {
  20.511 +        int i;
  20.512 +        RgnHandle dirty = NewRgn ();
  20.513 +        RgnHandle temp  = NewRgn ();
  20.514 +        
  20.515 +        SetEmptyRgn (dirty);
  20.516 +        
  20.517 +        /* Build the region of dirty rectangles */
  20.518 +        for (i = 0; i < numRects; i++) {
  20.519 +        
  20.520 +            MacSetRectRgn (temp, rects[i].x, rects[i].y, 
  20.521 +                rects[i].x + rects[i].w, rects[i].y + rects[i].h);
  20.522 +            MacUnionRgn (dirty, temp, dirty);
  20.523 +        }
  20.524 +        
  20.525 +        /* Flush the dirty region */
  20.526 +        QDFlushPortBuffer ( [ windowView qdPort ], dirty );
  20.527 +        DisposeRgn (dirty);
  20.528 +        DisposeRgn (temp);
  20.529 +    }
  20.530 +}
  20.531 +
  20.532 +static void QZ_VideoQuit (_THIS) {
  20.533 +
  20.534 +    QZ_UnsetVideoMode (this);
  20.535 +    CGPaletteRelease (palette);
  20.536 +}
  20.537 +
  20.538 +static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) {
  20.539 +
  20.540 +    CGSDisplayHWFill (display_id, rect->x, rect->y, rect->w, rect->h, color);
  20.541 +    return 0;
  20.542 +}
  20.543 +
  20.544 +static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface) { 
  20.545 +
  20.546 +    return 1;
  20.547 +}
  20.548 +
  20.549 +static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface) { 
  20.550 +}
  20.551 +
  20.552 +static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface) {
  20.553 +}
  20.554 +
  20.555 +/*
  20.556 +int QZ_FlipHWSurface (_THIS, SDL_Surface *surface) {
  20.557 +    return 0;
  20.558 +}
  20.559 +*/
  20.560 +
  20.561 +/* Gamma functions */
  20.562 +static int QZ_SetGamma (_THIS, float red, float green, float blue) {
  20.563 +
  20.564 +    const CGGammaValue min = 0.0, max = 1.0;
  20.565 +    
  20.566 +    if ( CGDisplayNoErr != CGSetDisplayTransferByFormula 
  20.567 +        (display_id, min, max, red, min, max, green, min, max, blue) )
  20.568 +        return -1;
  20.569 +    
  20.570 +    return 0;
  20.571 +}
  20.572 +
  20.573 +static int QZ_GetGamma (_THIS, float *red, float *green, float *blue) {
  20.574 +
  20.575 +    CGGammaValue dummy;
  20.576 +    if ( CGDisplayNoErr != CGGetDisplayTransferByFormula
  20.577 +        (display_id, &dummy, &dummy, red, 
  20.578 +	 &dummy, &dummy, green, &dummy, &dummy, blue) )
  20.579 +        
  20.580 +        return -1;
  20.581 +    
  20.582 +    return 0;
  20.583 +}
  20.584 +
  20.585 +static int QZ_SetGammaRamp (_THIS, Uint16 *ramp) {
  20.586 + 
  20.587 +   const CGTableCount tableSize = 255;
  20.588 +   CGGammaValue redTable[tableSize];
  20.589 +   CGGammaValue greenTable[tableSize];
  20.590 +   CGGammaValue blueTable[tableSize];
  20.591 +   
  20.592 +   int i;
  20.593 +   
  20.594 +   /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
  20.595 +   for (i = 0; i < 256; i++)
  20.596 +    redTable[i % 256] = ramp[i] / 65535.0;
  20.597 +   
  20.598 +   for (i=256; i < 512; i++)
  20.599 +    greenTable[i % 256] = ramp[i] / 65535.0;
  20.600 +   
  20.601 +   for (i=512; i < 768; i++)
  20.602 +     blueTable[i % 256] = ramp[i] / 65535.0;
  20.603 +     
  20.604 +    if ( CGDisplayNoErr != CGSetDisplayTransferByTable 
  20.605 +            (display_id, tableSize, redTable, greenTable, blueTable) )        
  20.606 +        return -1;
  20.607 +    
  20.608 +    return 0;
  20.609 +}
  20.610 +
  20.611 +static int QZ_GetGammaRamp (_THIS, Uint16 *ramp) {
  20.612 +    
  20.613 +    const CGTableCount tableSize = 255;
  20.614 +    CGGammaValue redTable[tableSize];
  20.615 +    CGGammaValue greenTable[tableSize];
  20.616 +    CGGammaValue blueTable[tableSize];
  20.617 +    CGTableCount actual;
  20.618 +    int i;
  20.619 +    
  20.620 +    if ( CGDisplayNoErr != CGGetDisplayTransferByTable 
  20.621 +            (display_id, tableSize, redTable, greenTable, blueTable, &actual) ||
  20.622 +          actual != tableSize)
  20.623 +        
  20.624 +        return -1;
  20.625 +    
  20.626 +    /* Pack tables into one array, with values from 0 to 65535 */
  20.627 +    for (i = 0; i < 256; i++)
  20.628 +        ramp[i] = redTable[i % 256] * 65535.0;
  20.629 +   
  20.630 +    for (i=256; i < 512; i++)
  20.631 +        ramp[i] = greenTable[i % 256] * 65535.0;
  20.632 +   
  20.633 +    for (i=512; i < 768; i++)
  20.634 +        ramp[i] = blueTable[i % 256] * 65535.0;
  20.635 +      
  20.636 +    return 0;    
  20.637 +}
  20.638 +
  20.639 +/* OpenGL helper functions */
  20.640 +static int QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags) {
  20.641 +
  20.642 +    NSOpenGLPixelFormatAttribute attr[32];
  20.643 +    NSOpenGLPixelFormat *fmt;
  20.644 +    int i = 0;
  20.645 +    int colorBits = bpp;
  20.646 +
  20.647 +    if ( flags & SDL_FULLSCREEN ) {
  20.648 +    
  20.649 +        attr[i++] = NSOpenGLPFAFullScreen;
  20.650 +    }
  20.651 +    /* In windowed mode, the OpenGL pixel depth must match device pixel depth */
  20.652 +    else if ( colorBits != device_bpp ) { 
  20.653 +
  20.654 +        colorBits = device_bpp;
  20.655 +    }
  20.656 +    
  20.657 +    attr[i++] = NSOpenGLPFAColorSize;
  20.658 +    attr[i++] = colorBits;
  20.659 +    
  20.660 +    attr[i++] = NSOpenGLPFADepthSize;
  20.661 +    attr[i++] = this->gl_config.depth_size;
  20.662 +
  20.663 +    if ( this->gl_config.double_buffer ) {
  20.664 +        attr[i++] = NSOpenGLPFADoubleBuffer;
  20.665 +    }
  20.666 +    
  20.667 +    if ( this->gl_config.stencil_size != 0 ) {
  20.668 +        attr[i++] = NSOpenGLPFAStencilSize;
  20.669 +        attr[i++] = this->gl_config.stencil_size;
  20.670 +    }
  20.671 +    
  20.672 +    attr[i++] = NSOpenGLPFAScreenMask;
  20.673 +    attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
  20.674 +    attr[i] = 0;
  20.675 +    
  20.676 +    fmt = [ [ NSOpenGLPixelFormat alloc ] initWithAttributes:attr ];
  20.677 +    if (fmt == nil) {
  20.678 +        SDL_SetError ("Failed creating OpenGL pixel format");
  20.679 +        return 0;
  20.680 +    }
  20.681 +    
  20.682 +    gl_context = [ [ NSOpenGLContext alloc ] initWithFormat:fmt 
  20.683 +        shareContext:nil];
  20.684 +    
  20.685 +    if (gl_context == nil) {
  20.686 +        SDL_SetError ("Failed creating OpenGL context");
  20.687 +        return 0;
  20.688 +    }	
  20.689 +    
  20.690 +    /* Convince SDL that the GL "driver" is loaded */
  20.691 +    this->gl_config.driver_loaded = 1;
  20.692 +    
  20.693 +    [ fmt release ];
  20.694 +    
  20.695 +    return 1;
  20.696 +}
  20.697 +
  20.698 +static void QZ_TearDownOpenGL (_THIS) {
  20.699 +
  20.700 +    [ NSOpenGLContext clearCurrentContext ];
  20.701 +    [ gl_context clearDrawable ];
  20.702 +    [ gl_context release ];
  20.703 +}
  20.704 +
  20.705 +/* SDL OpenGL functions */
  20.706 +
  20.707 +static int    QZ_GL_LoadLibrary    (_THIS, const char *location) {
  20.708 +    return 1;
  20.709 +}
  20.710 +
  20.711 +static void*  QZ_GL_GetProcAddress (_THIS, const char *proc) {
  20.712 +
  20.713 +    /* We may want to cache the bundleRef at some point */
  20.714 +    CFBundleRef bundle;
  20.715 +    CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, 
  20.716 +        CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
  20.717 +    
  20.718 +    CFStringRef functionName = CFStringCreateWithCString 
  20.719 +        (kCFAllocatorDefault, proc, kCFStringEncodingASCII);
  20.720 +    
  20.721 +    void *function;
  20.722 +    
  20.723 +    bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
  20.724 +    assert (bundle != NULL);
  20.725 +    
  20.726 +    function = CFBundleGetFunctionPointerForName (bundle, functionName);
  20.727 +
  20.728 +    CFRelease ( bundleURL );
  20.729 +    CFRelease ( functionName );
  20.730 +    CFRelease ( bundle );
  20.731 +    
  20.732 +    return function;
  20.733 +}
  20.734 +
  20.735 +static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value) {
  20.736 +
  20.737 +/*
  20.738 +    CGLContextRef ctx = [ gl_context cglContext ];
  20.739 +    CGLContextParameter param;
  20.740 +    
  20.741 +    switch (attrib) {
  20.742 +    case SDL_GL_RED_SIZE: param = CGLContextParameter break;
  20.743 +    
  20.744 +    }
  20.745 +    
  20.746 +    CGLGetParameter (ctx, param, (long*)value);
  20.747 +*/
  20.748 +    *value = -1;
  20.749 +    return -1;
  20.750 +}
  20.751 +
  20.752 +static int    QZ_GL_MakeCurrent    (_THIS) {
  20.753 +    [ gl_context makeCurrentContext ];
  20.754 +    return 0;
  20.755 +}
  20.756 +
  20.757 +static void   QZ_GL_SwapBuffers    (_THIS) {
  20.758 +    [ gl_context flushBuffer ];
  20.759 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Thu Jun 07 14:28:11 2001 +0000
    21.3 @@ -0,0 +1,175 @@
    21.4 +/*
    21.5 +    SDL - Simple DirectMedia Layer
    21.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  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 Library General Public
   21.10 +    License as published by the Free Software Foundation; either
   21.11 +    version 2 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 +    Library General Public License for more details.
   21.17 +
   21.18 +    You should have received a copy of the GNU Library General Public
   21.19 +    License along with this library; if not, write to the Free
   21.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21.21 +
   21.22 +    Sam Lantinga
   21.23 +    slouken@devolution.com
   21.24 +*/
   21.25 +
   21.26 +struct WMcursor {
   21.27 +    Cursor curs;
   21.28 +};
   21.29 +
   21.30 +static void QZ_FreeWMCursor     (_THIS, WMcursor *cursor) { 
   21.31 +
   21.32 +    if ( cursor != NULL )
   21.33 +        free (cursor);
   21.34 +}
   21.35 +
   21.36 +/* Use the Carbon cursor routines for now */
   21.37 +static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
   21.38 +                                          int w, int h, int hot_x, int hot_y) { 
   21.39 +	WMcursor *cursor;
   21.40 +	int row, bytes;
   21.41 +	cursor = (WMcursor *)malloc(sizeof(WMcursor));
   21.42 +	if ( cursor == NULL ) {
   21.43 +		SDL_OutOfMemory();
   21.44 +		return(NULL);
   21.45 +	}
   21.46 +	memset(cursor, 0, sizeof(*cursor));
   21.47 +		
   21.48 +	bytes = (w/8);
   21.49 +	if ( bytes > 2 ) {
   21.50 +		bytes = 2;
   21.51 +	}
   21.52 +	for ( row=0; row<h && (row < 16); ++row ) {
   21.53 +		memcpy(&cursor->curs.data[row], data, bytes);
   21.54 +		data += w/8;
   21.55 +	}
   21.56 +	for ( row=0; row<h && (row < 16); ++row ) {
   21.57 +		memcpy(&cursor->curs.mask[row], mask, bytes);
   21.58 +		mask += w/8;
   21.59 +	}
   21.60 +	cursor->curs.hotSpot.h = hot_x;
   21.61 +	cursor->curs.hotSpot.v = hot_y;
   21.62 +	
   21.63 +        return(cursor);
   21.64 +}
   21.65 +
   21.66 +static int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 
   21.67 +
   21.68 +    static int visible = 1;
   21.69 +    
   21.70 +    if ( cursor == NULL) {
   21.71 +        if ( visible ) {
   21.72 +            HideCursor ();
   21.73 +            visible = 0;
   21.74 +        }
   21.75 +    }
   21.76 +    else {
   21.77 +        SetCursor(&cursor->curs);
   21.78 +        if ( ! visible ) {
   21.79 +            ShowCursor ();
   21.80 +            visible = 1;
   21.81 +        }
   21.82 +    }
   21.83 +
   21.84 +    return 1;
   21.85 +}
   21.86 +
   21.87 +static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y) {
   21.88 +
   21.89 +    CGPoint p;
   21.90 +    
   21.91 +    /* We require absolute screen coordiates for our warp */
   21.92 +    p.x = x;
   21.93 +    p.y = h - y;
   21.94 +        
   21.95 +    if ( fullscreen )
   21.96 +        /* Already absolute coordinates */
   21.97 +        CGDisplayMoveCursorToPoint(display_id, p);
   21.98 +    else {
   21.99 +        /* Convert to absolute screen coordinates */
  21.100 +        NSPoint base, screen;
  21.101 +        base = NSMakePoint (p.x, p.y);
  21.102 +        screen = [ window convertBaseToScreen:base ];
  21.103 +        p.x = screen.x;
  21.104 +        p.y = device_height - screen.y;
  21.105 +        CGDisplayMoveCursorToPoint (display_id, p);
  21.106 +    }
  21.107 +}
  21.108 +
  21.109 +static void QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y) {
  21.110 +    
  21.111 +    /* Only allow warping when in foreground */
  21.112 +    if ( ! inForeground )
  21.113 +        return;
  21.114 +            
  21.115 +    /* Do the actual warp */
  21.116 +    QZ_PrivateWarpCursor (this, SDL_VideoSurface->flags & SDL_FULLSCREEN, 
  21.117 +        SDL_VideoSurface->h, x, y);
  21.118 +    
  21.119 +    /* Generate mouse moved event */
  21.120 +    SDL_PrivateMouseMotion (SDL_RELEASED, 0, x, y);
  21.121 +}
  21.122 +
  21.123 +static void QZ_MoveWMCursor     (_THIS, int x, int y) { }
  21.124 +static void QZ_CheckMouseMode   (_THIS) { }
  21.125 +
  21.126 +static void QZ_SetCaption    (_THIS, const char *title, const char *icon) {
  21.127 +
  21.128 +    NSString *str = [ [ NSString alloc ] initWithCString:title ];
  21.129 +    if (window != nil)
  21.130 +        [ window setTitle:str ];
  21.131 +
  21.132 +    [ windowTitle release ];
  21.133 +    windowTitle = str;
  21.134 +}
  21.135 +
  21.136 +static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask) {
  21.137 +/* Convert icon/mask to NSImage, assign with NSWindow's setMiniwindowImage method */
  21.138 +}
  21.139 +
  21.140 +static int  QZ_IconifyWindow (_THIS) { 
  21.141 +
  21.142 +    /* Bug! minimize erases the framebuffer */
  21.143 +    if ( ! [ window isMiniaturized ] ) {
  21.144 +        [ window miniaturize:nil ];
  21.145 +        return 1;
  21.146 +    }
  21.147 +    else {
  21.148 +        SDL_SetError ("window already iconified");
  21.149 +        return 0;
  21.150 +    }
  21.151 +}
  21.152 +
  21.153 +/*
  21.154 +static int  QZ_GetWMInfo  (_THIS, SDL_SysWMinfo *info) { 
  21.155 +    info->nsWindowPtr = window;
  21.156 +    return 0; 
  21.157 +}*/
  21.158 +
  21.159 +static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) {
  21.160 +
  21.161 +    switch (grab_mode) {
  21.162 +	case SDL_GRAB_QUERY:
  21.163 +            break;
  21.164 +	case SDL_GRAB_OFF:
  21.165 +            CGAssociateMouseAndMouseCursorPosition (1);
  21.166 +            currentGrabMode = SDL_GRAB_OFF;
  21.167 +            break;
  21.168 +	case SDL_GRAB_ON:
  21.169 +            QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
  21.170 +            CGAssociateMouseAndMouseCursorPosition (0);
  21.171 +            currentGrabMode = SDL_GRAB_ON;
  21.172 +            break;
  21.173 +        case SDL_GRAB_FULLSCREEN:
  21.174 +            break;
  21.175 +    }
  21.176 +        
  21.177 +    return currentGrabMode;
  21.178 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/video/quartz/SDL_QuartzWindow.m	Thu Jun 07 14:28:11 2001 +0000
    22.3 @@ -0,0 +1,25 @@
    22.4 +/* Subclass of NSWindow to allow customization if we need it */
    22.5 +
    22.6 +@interface SDL_QuartzWindow : NSWindow
    22.7 +{}
    22.8 +- (void)miniaturize:(id)sender;
    22.9 +- (void)deminiaturize:(id)sender;
   22.10 +@end
   22.11 +
   22.12 +@implementation SDL_QuartzWindow
   22.13 +
   22.14 +/* These methods should be rewritten to fix the miniaturize bug */
   22.15 +- (void)miniaturize:(id)sender
   22.16 +{
   22.17 +    [ super miniaturize:sender ];
   22.18 +}
   22.19 +
   22.20 +- (void)deminiaturize:(id)sender
   22.21 +{
   22.22 +    /* Let the app know they have to redraw everything */
   22.23 +    SDL_PrivateExpose ();
   22.24 +    
   22.25 +    [ super deminiaturize:sender ];
   22.26 +}
   22.27 +
   22.28 +@end
    23.1 --- a/test/testtypes.c	Thu Jun 07 13:53:51 2001 +0000
    23.2 +++ b/test/testtypes.c	Thu Jun 07 14:28:11 2001 +0000
    23.3 @@ -1,6 +1,6 @@
    23.4  
    23.5  #include <stdio.h>
    23.6 -
    23.7 +#include "SDL_main.h"
    23.8  #include "SDL_types.h"
    23.9  
   23.10  int main(int argc, char *argv[])