mirror of
https://github.com/joel16/SDL2.git
synced 2024-12-02 16:26:28 +00:00
The Mac OS X Cocoa video driver is under construction...
Note that SDLmain is no longer necessary on Mac OS X. :) --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401976
This commit is contained in:
parent
d4e887aa04
commit
6822a805b4
46
configure.in
46
configure.in
@ -1046,36 +1046,11 @@ CheckBWINDOW()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
dnl Set up the Carbon/QuickDraw video driver for Mac OS X (but not Darwin)
|
dnl Set up the Cocoa video driver for Mac OS X (but not Darwin)
|
||||||
CheckCARBON()
|
|
||||||
{
|
|
||||||
AC_ARG_ENABLE(video-carbon,
|
|
||||||
AC_HELP_STRING([--enable-video-carbon], [use Carbon/QuickDraw video driver [[default=no]]]),
|
|
||||||
, enable_video_carbon=no)
|
|
||||||
if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
|
|
||||||
AC_MSG_CHECKING(for Carbon framework)
|
|
||||||
have_carbon=no
|
|
||||||
AC_TRY_COMPILE([
|
|
||||||
#include <Carbon/Carbon.h>
|
|
||||||
],[
|
|
||||||
],[
|
|
||||||
have_carbon=yes
|
|
||||||
])
|
|
||||||
AC_MSG_RESULT($have_carbon)
|
|
||||||
if test x$have_carbon = xyes; then
|
|
||||||
AC_DEFINE(SDL_VIDEO_DRIVER_TOOLBOX)
|
|
||||||
SOURCES="$SOURCES $srcdir/src/video/maccommon/*.c"
|
|
||||||
SOURCES="$SOURCES $srcdir/src/video/macrom/*.c"
|
|
||||||
have_video=yes
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
dnl Set up the Cocoa/Quartz video driver for Mac OS X (but not Darwin)
|
|
||||||
CheckCOCOA()
|
CheckCOCOA()
|
||||||
{
|
{
|
||||||
AC_ARG_ENABLE(video-cocoa,
|
AC_ARG_ENABLE(video-cocoa,
|
||||||
AC_HELP_STRING([--enable-video-cocoa], [use Cocoa/Quartz video driver [[default=yes]]]),
|
AC_HELP_STRING([--enable-video-cocoa], [use Cocoa video driver [[default=yes]]]),
|
||||||
, enable_video_cocoa=yes)
|
, enable_video_cocoa=yes)
|
||||||
if test x$enable_video = xyes -a x$enable_video_cocoa = xyes; then
|
if test x$enable_video = xyes -a x$enable_video_cocoa = xyes; then
|
||||||
save_CFLAGS="$CFLAGS"
|
save_CFLAGS="$CFLAGS"
|
||||||
@ -1092,8 +1067,8 @@ AC_HELP_STRING([--enable-video-cocoa], [use Cocoa/Quartz video driver [[default=
|
|||||||
AC_MSG_RESULT($have_cocoa)
|
AC_MSG_RESULT($have_cocoa)
|
||||||
CFLAGS="$save_CFLAGS"
|
CFLAGS="$save_CFLAGS"
|
||||||
if test x$have_cocoa = xyes; then
|
if test x$have_cocoa = xyes; then
|
||||||
AC_DEFINE(SDL_VIDEO_DRIVER_QUARTZ)
|
AC_DEFINE(SDL_VIDEO_DRIVER_COCOA)
|
||||||
SOURCES="$SOURCES $srcdir/src/video/quartz/*.m"
|
SOURCES="$SOURCES $srcdir/src/video/cocoa/*.m"
|
||||||
have_video=yes
|
have_video=yes
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -1526,9 +1501,6 @@ CheckMacGL()
|
|||||||
if test x$enable_video_cocoa = xyes; then
|
if test x$enable_video_cocoa = xyes; then
|
||||||
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGL"
|
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,OpenGL"
|
||||||
fi
|
fi
|
||||||
if test x$enable_video_carbon = xyes; then
|
|
||||||
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AGL"
|
|
||||||
fi
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -2453,7 +2425,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
CheckCOCOA
|
CheckCOCOA
|
||||||
CheckCARBON
|
|
||||||
CheckX11
|
CheckX11
|
||||||
CheckMacGL
|
CheckMacGL
|
||||||
CheckOpenGLX11
|
CheckOpenGLX11
|
||||||
@ -2492,11 +2463,9 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
|
|||||||
have_timers=yes
|
have_timers=yes
|
||||||
fi
|
fi
|
||||||
# The Mac OS X platform requires special setup.
|
# The Mac OS X platform requires special setup.
|
||||||
SDLMAIN_SOURCES="$srcdir/src/main/macosx/*.m"
|
|
||||||
EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings"
|
EXTRA_CFLAGS="$EXTRA_CFLAGS -fpascal-strings"
|
||||||
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Cocoa"
|
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Cocoa"
|
||||||
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Carbon"
|
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Carbon"
|
||||||
SDL_LIBS="-lSDLmain $SDL_LIBS"
|
|
||||||
# If either the audio or CD driver is used, add the AudioUnit framework
|
# If either the audio or CD driver is used, add the AudioUnit framework
|
||||||
if test x$enable_audio = xyes -o x$enable_cdrom = xyes; then
|
if test x$enable_audio = xyes -o x$enable_cdrom = xyes; then
|
||||||
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit"
|
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit"
|
||||||
@ -2623,7 +2592,6 @@ OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.lo,g'`
|
|||||||
OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.S,$(objects)/\1.lo,g'`
|
OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.S,$(objects)/\1.lo,g'`
|
||||||
|
|
||||||
SDLMAIN_OBJECTS=`echo $SDLMAIN_SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.cc,$(objects)/\1.o,g'`
|
SDLMAIN_OBJECTS=`echo $SDLMAIN_SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.cc,$(objects)/\1.o,g'`
|
||||||
SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.m,$(objects)/\1.o,g'`
|
|
||||||
SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.o,g'`
|
SDLMAIN_OBJECTS=`echo $SDLMAIN_OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.o,g'`
|
||||||
|
|
||||||
# Set runtime shared library paths as needed
|
# Set runtime shared library paths as needed
|
||||||
@ -2642,12 +2610,8 @@ fi
|
|||||||
case "$ARCH" in
|
case "$ARCH" in
|
||||||
macosx)
|
macosx)
|
||||||
SDL_LIBS="$SDL_LIBS -Wl,-framework,Cocoa"
|
SDL_LIBS="$SDL_LIBS -Wl,-framework,Cocoa"
|
||||||
# Is this still needed?
|
|
||||||
#if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
|
|
||||||
# SDL_LIBS="$SDL_LIBS -Wl,-framework,Carbon"
|
|
||||||
#fi
|
|
||||||
# Evil hack to allow static linking on Mac OS X
|
# Evil hack to allow static linking on Mac OS X
|
||||||
SDL_STATIC_LIBS="\${exec_prefix}/lib/libSDLmain.a \${exec_prefix}/lib/libSDL.a $EXTRA_LDFLAGS"
|
SDL_STATIC_LIBS="\${exec_prefix}/lib/libSDL.a $EXTRA_LDFLAGS"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
SDL_STATIC_LIBS="$SDL_LIBS"
|
SDL_STATIC_LIBS="$SDL_LIBS"
|
||||||
|
@ -251,6 +251,7 @@
|
|||||||
/* Enable various video drivers */
|
/* Enable various video drivers */
|
||||||
#undef SDL_VIDEO_DRIVER_AALIB
|
#undef SDL_VIDEO_DRIVER_AALIB
|
||||||
#undef SDL_VIDEO_DRIVER_BWINDOW
|
#undef SDL_VIDEO_DRIVER_BWINDOW
|
||||||
|
#undef SDL_VIDEO_DRIVER_COCOA
|
||||||
#undef SDL_VIDEO_DRIVER_CYBERGRAPHICS
|
#undef SDL_VIDEO_DRIVER_CYBERGRAPHICS
|
||||||
#undef SDL_VIDEO_DRIVER_DC
|
#undef SDL_VIDEO_DRIVER_DC
|
||||||
#undef SDL_VIDEO_DRIVER_DGA
|
#undef SDL_VIDEO_DRIVER_DGA
|
||||||
@ -270,7 +271,6 @@
|
|||||||
#undef SDL_VIDEO_DRIVER_PICOGUI
|
#undef SDL_VIDEO_DRIVER_PICOGUI
|
||||||
#undef SDL_VIDEO_DRIVER_PS2GS
|
#undef SDL_VIDEO_DRIVER_PS2GS
|
||||||
#undef SDL_VIDEO_DRIVER_QTOPIA
|
#undef SDL_VIDEO_DRIVER_QTOPIA
|
||||||
#undef SDL_VIDEO_DRIVER_QUARTZ
|
|
||||||
#undef SDL_VIDEO_DRIVER_RISCOS
|
#undef SDL_VIDEO_DRIVER_RISCOS
|
||||||
#undef SDL_VIDEO_DRIVER_SVGALIB
|
#undef SDL_VIDEO_DRIVER_SVGALIB
|
||||||
#undef SDL_VIDEO_DRIVER_TOOLBOX
|
#undef SDL_VIDEO_DRIVER_TOOLBOX
|
||||||
|
@ -113,12 +113,8 @@
|
|||||||
#define SDL_TIMER_UNIX 1
|
#define SDL_TIMER_UNIX 1
|
||||||
|
|
||||||
/* Enable various video drivers */
|
/* Enable various video drivers */
|
||||||
|
#define SDL_VIDEO_DRIVER_COCOA 1
|
||||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||||
#if TARGET_API_MAC_CARBON
|
|
||||||
#define SDL_VIDEO_DRIVER_TOOLBOX 1
|
|
||||||
#else
|
|
||||||
#define SDL_VIDEO_DRIVER_QUARTZ 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Enable OpenGL support */
|
/* Enable OpenGL support */
|
||||||
#define SDL_VIDEO_OPENGL 1
|
#define SDL_VIDEO_OPENGL 1
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
#include "SDL_stdinc.h"
|
#include "SDL_stdinc.h"
|
||||||
|
|
||||||
/* Redefine main() on Win32 and MacOS so that it is called by winmain.c */
|
/* Redefine main() on some platforms so that it is called by SDL */
|
||||||
|
|
||||||
#if defined(__WIN32__) || \
|
#if defined(__WIN32__) || \
|
||||||
(defined(__MWERKS__) && !defined(__BEOS__)) || \
|
(defined(__MWERKS__) && !defined(__BEOS__)) || \
|
||||||
defined(__MACOS__) || defined(__MACOSX__) || \
|
defined(__MACOS__) || \
|
||||||
defined(__SYMBIAN32__) || defined(QWS)
|
defined(__SYMBIAN32__) || defined(QWS)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
|
||||||
<plist version="0.9">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
|
||||||
<string>English</string>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>@EXECUTABLE_NAME@</string>
|
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
|
||||||
<string>6.0</string>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>@PACKAGE@</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>APPL</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>@VERSION@</string>
|
|
||||||
<key>CFBundleSignature</key>
|
|
||||||
<string>????</string>
|
|
||||||
<key>NSMainNibFile</key>
|
|
||||||
<string>SDLMain.nib</string>
|
|
||||||
<key>NSPrincipalClass</key>
|
|
||||||
<string>NSApplication</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
@ -1,11 +0,0 @@
|
|||||||
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
|
|
||||||
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
|
|
||||||
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
|
|
||||||
|
|
||||||
Feel free to customize this file to suit your needs
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
|
|
||||||
@ interface SDLMain:NSObject @ end
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -1,384 +0,0 @@
|
|||||||
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
|
|
||||||
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
|
|
||||||
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
|
|
||||||
|
|
||||||
Feel free to customize this file to suit your needs
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import "SDL.h"
|
|
||||||
#import "SDLMain.h"
|
|
||||||
#import <sys/param.h> /* for MAXPATHLEN */
|
|
||||||
#import <unistd.h>
|
|
||||||
|
|
||||||
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
|
|
||||||
but the method still is there and works. To avoid warnings, we declare
|
|
||||||
it ourselves here. */
|
|
||||||
@interface NSApplication(SDL_Missing_Methods)
|
|
||||||
- (void)setAppleMenu:(NSMenu *)menu;
|
|
||||||
@end
|
|
||||||
|
|
||||||
/* Use this flag to determine whether we use SDLMain.nib or not */
|
|
||||||
#define SDL_USE_NIB_FILE 0
|
|
||||||
|
|
||||||
/* Use this flag to determine whether we use CPS (docking) or not */
|
|
||||||
#define SDL_USE_CPS 1
|
|
||||||
#ifdef SDL_USE_CPS
|
|
||||||
/* Portions of CPS.h */
|
|
||||||
typedef struct CPSProcessSerNum
|
|
||||||
{
|
|
||||||
UInt32 lo;
|
|
||||||
UInt32 hi;
|
|
||||||
} CPSProcessSerNum;
|
|
||||||
|
|
||||||
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
|
|
||||||
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
|
|
||||||
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
|
|
||||||
|
|
||||||
#endif /* SDL_USE_CPS */
|
|
||||||
|
|
||||||
static int gArgc;
|
|
||||||
static char **gArgv;
|
|
||||||
static BOOL gFinderLaunch;
|
|
||||||
static BOOL gCalledAppMainline = FALSE;
|
|
||||||
|
|
||||||
static NSString *getApplicationName(void)
|
|
||||||
{
|
|
||||||
NSDictionary *dict;
|
|
||||||
NSString *appName = 0;
|
|
||||||
|
|
||||||
/* Determine the application name */
|
|
||||||
dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
|
|
||||||
if (dict)
|
|
||||||
appName = [dict objectForKey: @"CFBundleName"];
|
|
||||||
|
|
||||||
if (![appName length])
|
|
||||||
appName = [[NSProcessInfo processInfo] processName];
|
|
||||||
|
|
||||||
return appName;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SDL_USE_NIB_FILE
|
|
||||||
/* A helper category for NSString */
|
|
||||||
@interface NSString (ReplaceSubString)
|
|
||||||
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
|
|
||||||
@end
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@interface SDLApplication : NSApplication
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation SDLApplication
|
|
||||||
/* Invoked from the Quit menu item */
|
|
||||||
- (void)terminate:(id)sender
|
|
||||||
{
|
|
||||||
/* Post a SDL_QUIT event */
|
|
||||||
SDL_Event event;
|
|
||||||
event.type = SDL_QUIT;
|
|
||||||
SDL_PushEvent(&event);
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
/* The main class of the application, the application's delegate */
|
|
||||||
@implementation SDLMain
|
|
||||||
|
|
||||||
/* Set the working directory to the .app's parent directory */
|
|
||||||
- (void) setupWorkingDirectory:(BOOL)shouldChdir
|
|
||||||
{
|
|
||||||
if (shouldChdir)
|
|
||||||
{
|
|
||||||
char parentdir[MAXPATHLEN];
|
|
||||||
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
|
||||||
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
|
|
||||||
if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
|
|
||||||
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
|
|
||||||
}
|
|
||||||
CFRelease(url);
|
|
||||||
CFRelease(url2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SDL_USE_NIB_FILE
|
|
||||||
|
|
||||||
/* Fix menu to contain the real app name instead of "SDL App" */
|
|
||||||
- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
|
|
||||||
{
|
|
||||||
NSRange aRange;
|
|
||||||
NSEnumerator *enumerator;
|
|
||||||
NSMenuItem *menuItem;
|
|
||||||
|
|
||||||
aRange = [[aMenu title] rangeOfString:@"SDL App"];
|
|
||||||
if (aRange.length != 0)
|
|
||||||
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
|
|
||||||
|
|
||||||
enumerator = [[aMenu itemArray] objectEnumerator];
|
|
||||||
while ((menuItem = [enumerator nextObject]))
|
|
||||||
{
|
|
||||||
aRange = [[menuItem title] rangeOfString:@"SDL App"];
|
|
||||||
if (aRange.length != 0)
|
|
||||||
[menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
|
|
||||||
if ([menuItem hasSubmenu])
|
|
||||||
[self fixMenu:[menuItem submenu] withAppName:appName];
|
|
||||||
}
|
|
||||||
[ aMenu sizeToFit ];
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static void setApplicationMenu(void)
|
|
||||||
{
|
|
||||||
/* warning: this code is very odd */
|
|
||||||
NSMenu *appleMenu;
|
|
||||||
NSMenuItem *menuItem;
|
|
||||||
NSString *title;
|
|
||||||
NSString *appName;
|
|
||||||
|
|
||||||
appName = getApplicationName();
|
|
||||||
appleMenu = [[NSMenu alloc] initWithTitle:@""];
|
|
||||||
|
|
||||||
/* Add menu items */
|
|
||||||
title = [@"About " stringByAppendingString:appName];
|
|
||||||
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
|
|
||||||
|
|
||||||
[appleMenu addItem:[NSMenuItem separatorItem]];
|
|
||||||
|
|
||||||
title = [@"Hide " stringByAppendingString:appName];
|
|
||||||
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
|
|
||||||
|
|
||||||
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
|
|
||||||
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
|
|
||||||
|
|
||||||
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
|
||||||
|
|
||||||
[appleMenu addItem:[NSMenuItem separatorItem]];
|
|
||||||
|
|
||||||
title = [@"Quit " stringByAppendingString:appName];
|
|
||||||
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
|
||||||
|
|
||||||
|
|
||||||
/* Put menu into the menubar */
|
|
||||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
|
||||||
[menuItem setSubmenu:appleMenu];
|
|
||||||
[[NSApp mainMenu] addItem:menuItem];
|
|
||||||
|
|
||||||
/* Tell the application object that this is now the application menu */
|
|
||||||
[NSApp setAppleMenu:appleMenu];
|
|
||||||
|
|
||||||
/* Finally give up our references to the objects */
|
|
||||||
[appleMenu release];
|
|
||||||
[menuItem release];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a window menu */
|
|
||||||
static void setupWindowMenu(void)
|
|
||||||
{
|
|
||||||
NSMenu *windowMenu;
|
|
||||||
NSMenuItem *windowMenuItem;
|
|
||||||
NSMenuItem *menuItem;
|
|
||||||
|
|
||||||
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
|
||||||
|
|
||||||
/* "Minimize" item */
|
|
||||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
|
||||||
[windowMenu addItem:menuItem];
|
|
||||||
[menuItem release];
|
|
||||||
|
|
||||||
/* Put menu into the menubar */
|
|
||||||
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
|
|
||||||
[windowMenuItem setSubmenu:windowMenu];
|
|
||||||
[[NSApp mainMenu] addItem:windowMenuItem];
|
|
||||||
|
|
||||||
/* Tell the application object that this is now the window menu */
|
|
||||||
[NSApp setWindowsMenu:windowMenu];
|
|
||||||
|
|
||||||
/* Finally give up our references to the objects */
|
|
||||||
[windowMenu release];
|
|
||||||
[windowMenuItem release];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Replacement for NSApplicationMain */
|
|
||||||
static void CustomApplicationMain (int argc, char **argv)
|
|
||||||
{
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
SDLMain *sdlMain;
|
|
||||||
|
|
||||||
/* Ensure the application object is initialised */
|
|
||||||
[SDLApplication sharedApplication];
|
|
||||||
|
|
||||||
#ifdef SDL_USE_CPS
|
|
||||||
{
|
|
||||||
CPSProcessSerNum PSN;
|
|
||||||
/* Tell the dock about us */
|
|
||||||
if (!CPSGetCurrentProcess(&PSN))
|
|
||||||
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
|
|
||||||
if (!CPSSetFrontProcess(&PSN))
|
|
||||||
[SDLApplication sharedApplication];
|
|
||||||
}
|
|
||||||
#endif /* SDL_USE_CPS */
|
|
||||||
|
|
||||||
/* Set up the menubar */
|
|
||||||
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
|
||||||
setApplicationMenu();
|
|
||||||
setupWindowMenu();
|
|
||||||
|
|
||||||
/* Create SDLMain and make it the app delegate */
|
|
||||||
sdlMain = [[SDLMain alloc] init];
|
|
||||||
[NSApp setDelegate:sdlMain];
|
|
||||||
|
|
||||||
/* Start the main event loop */
|
|
||||||
[NSApp run];
|
|
||||||
|
|
||||||
[sdlMain release];
|
|
||||||
[pool release];
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Catch document open requests...this lets us notice files when the app
|
|
||||||
* was launched by double-clicking a document, or when a document was
|
|
||||||
* dragged/dropped on the app's icon. You need to have a
|
|
||||||
* CFBundleDocumentsType section in your Info.plist to get this message,
|
|
||||||
* apparently.
|
|
||||||
*
|
|
||||||
* Files are added to gArgv, so to the app, they'll look like command line
|
|
||||||
* arguments. Previously, apps launched from the finder had nothing but
|
|
||||||
* an argv[0].
|
|
||||||
*
|
|
||||||
* This message may be received multiple times to open several docs on launch.
|
|
||||||
*
|
|
||||||
* This message is ignored once the app's mainline has been called.
|
|
||||||
*/
|
|
||||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
|
||||||
{
|
|
||||||
const char *temparg;
|
|
||||||
size_t arglen;
|
|
||||||
char *arg;
|
|
||||||
char **newargv;
|
|
||||||
|
|
||||||
if (!gFinderLaunch) /* MacOS is passing command line args. */
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (gCalledAppMainline) /* app has started, ignore this document. */
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
temparg = [filename UTF8String];
|
|
||||||
arglen = SDL_strlen(temparg) + 1;
|
|
||||||
arg = (char *) SDL_malloc(arglen);
|
|
||||||
if (arg == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
|
|
||||||
if (newargv == NULL)
|
|
||||||
{
|
|
||||||
SDL_free(arg);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
gArgv = newargv;
|
|
||||||
|
|
||||||
SDL_strlcpy(arg, temparg, arglen);
|
|
||||||
gArgv[gArgc++] = arg;
|
|
||||||
gArgv[gArgc] = NULL;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Called when the internal event loop has just started running */
|
|
||||||
- (void) applicationDidFinishLaunching: (NSNotification *) note
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Set the working directory to the .app's parent directory */
|
|
||||||
[self setupWorkingDirectory:gFinderLaunch];
|
|
||||||
|
|
||||||
#if SDL_USE_NIB_FILE
|
|
||||||
/* Set the main menu to contain the real app name instead of "SDL App" */
|
|
||||||
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Hand off to main application code */
|
|
||||||
gCalledAppMainline = TRUE;
|
|
||||||
status = SDL_main (gArgc, gArgv);
|
|
||||||
|
|
||||||
/* We're done, thank you for playing */
|
|
||||||
exit(status);
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
||||||
@implementation NSString (ReplaceSubString)
|
|
||||||
|
|
||||||
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
|
|
||||||
{
|
|
||||||
unsigned int bufferSize;
|
|
||||||
unsigned int selfLen = [self length];
|
|
||||||
unsigned int aStringLen = [aString length];
|
|
||||||
unichar *buffer;
|
|
||||||
NSRange localRange;
|
|
||||||
NSString *result;
|
|
||||||
|
|
||||||
bufferSize = selfLen + aStringLen - aRange.length;
|
|
||||||
buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
|
|
||||||
|
|
||||||
/* Get first part into buffer */
|
|
||||||
localRange.location = 0;
|
|
||||||
localRange.length = aRange.location;
|
|
||||||
[self getCharacters:buffer range:localRange];
|
|
||||||
|
|
||||||
/* Get middle part into buffer */
|
|
||||||
localRange.location = 0;
|
|
||||||
localRange.length = aStringLen;
|
|
||||||
[aString getCharacters:(buffer+aRange.location) range:localRange];
|
|
||||||
|
|
||||||
/* Get last part into buffer */
|
|
||||||
localRange.location = aRange.location + aRange.length;
|
|
||||||
localRange.length = selfLen - localRange.location;
|
|
||||||
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
|
|
||||||
|
|
||||||
/* Build output string */
|
|
||||||
result = [NSString stringWithCharacters:buffer length:bufferSize];
|
|
||||||
|
|
||||||
NSDeallocateMemoryPages(buffer, bufferSize);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef main
|
|
||||||
# undef main
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Main entry point to executable - should *not* be SDL_main! */
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
/* Copy the arguments into a global variable */
|
|
||||||
/* This is passed if we are launched by double-clicking */
|
|
||||||
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
|
|
||||||
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
|
|
||||||
gArgv[0] = argv[0];
|
|
||||||
gArgv[1] = NULL;
|
|
||||||
gArgc = 1;
|
|
||||||
gFinderLaunch = YES;
|
|
||||||
} else {
|
|
||||||
int i;
|
|
||||||
gArgc = argc;
|
|
||||||
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
|
|
||||||
for (i = 0; i <= argc; i++)
|
|
||||||
gArgv[i] = argv[i];
|
|
||||||
gFinderLaunch = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SDL_USE_NIB_FILE
|
|
||||||
[SDLApplication poseAsClass:[NSApplication class]];
|
|
||||||
NSApplicationMain (argc, argv);
|
|
||||||
#else
|
|
||||||
CustomApplicationMain (argc, argv);
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
12
src/main/macosx/SDLMain.nib/classes.nib
generated
12
src/main/macosx/SDLMain.nib/classes.nib
generated
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
IBClasses = (
|
|
||||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
|
||||||
{
|
|
||||||
ACTIONS = {makeFullscreen = id; quit = id; };
|
|
||||||
CLASS = SDLMain;
|
|
||||||
LANGUAGE = ObjC;
|
|
||||||
SUPERCLASS = NSObject;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
IBVersion = 1;
|
|
||||||
}
|
|
12
src/main/macosx/SDLMain.nib/info.nib
generated
12
src/main/macosx/SDLMain.nib/info.nib
generated
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
|
||||||
<plist version="0.9">
|
|
||||||
<dict>
|
|
||||||
<key>IBDocumentLocation</key>
|
|
||||||
<string>49 97 356 240 0 0 987 746 </string>
|
|
||||||
<key>IBMainMenuLocation</key>
|
|
||||||
<string>20 515 195 44 0 46 800 532 </string>
|
|
||||||
<key>IBUserGuides</key>
|
|
||||||
<dict/>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
BIN
src/main/macosx/SDLMain.nib/objects.nib
generated
BIN
src/main/macosx/SDLMain.nib/objects.nib
generated
Binary file not shown.
1
src/main/macosx/info.nib
generated
1
src/main/macosx/info.nib
generated
@ -1 +0,0 @@
|
|||||||
// This is just a stub file to force automake to create the install directory
|
|
@ -296,8 +296,8 @@ typedef struct VideoBootStrap
|
|||||||
SDL_VideoDevice *(*create) (int devindex);
|
SDL_VideoDevice *(*create) (int devindex);
|
||||||
} VideoBootStrap;
|
} VideoBootStrap;
|
||||||
|
|
||||||
#if SDL_VIDEO_DRIVER_QUARTZ
|
#if SDL_VIDEO_DRIVER_COCOA
|
||||||
extern VideoBootStrap QZ_bootstrap;
|
extern VideoBootStrap COCOA_bootstrap;
|
||||||
#endif
|
#endif
|
||||||
#if SDL_VIDEO_DRIVER_X11
|
#if SDL_VIDEO_DRIVER_X11
|
||||||
extern VideoBootStrap X11_bootstrap;
|
extern VideoBootStrap X11_bootstrap;
|
||||||
|
@ -43,8 +43,8 @@
|
|||||||
|
|
||||||
/* Available video drivers */
|
/* Available video drivers */
|
||||||
static VideoBootStrap *bootstrap[] = {
|
static VideoBootStrap *bootstrap[] = {
|
||||||
#if SDL_VIDEO_DRIVER_QUARTZ
|
#if SDL_VIDEO_DRIVER_COCOA
|
||||||
&QZ_bootstrap,
|
&COCOA_bootstrap,
|
||||||
#endif
|
#endif
|
||||||
#if SDL_VIDEO_DRIVER_X11
|
#if SDL_VIDEO_DRIVER_X11
|
||||||
&X11_bootstrap,
|
&X11_bootstrap,
|
||||||
|
32
src/video/cocoa/SDL_cocoaevents.h
Normal file
32
src/video/cocoa/SDL_cocoaevents.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#ifndef _SDL_cocoaevents_h
|
||||||
|
#define _SDL_cocoaevents_h
|
||||||
|
|
||||||
|
extern void Cocoa_RegisterApp(void);
|
||||||
|
extern void Cocoa_PumpEvents(_THIS);
|
||||||
|
|
||||||
|
#endif /* _SDL_cocoaevents_h */
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
170
src/video/cocoa/SDL_cocoaevents.m
Normal file
170
src/video/cocoa/SDL_cocoaevents.m
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include "SDL_cocoavideo.h"
|
||||||
|
|
||||||
|
/* setAppleMenu disappeared from the headers in 10.4 */
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||||
|
@interface NSApplication(NSAppleMenu)
|
||||||
|
- (void)setAppleMenu:(NSMenu *)menu;
|
||||||
|
@end
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@interface SDLApplication : NSApplication
|
||||||
|
{
|
||||||
|
}
|
||||||
|
- (void)finishLaunching;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation SDLApplication
|
||||||
|
|
||||||
|
- (void)finishLaunching
|
||||||
|
{
|
||||||
|
[super finishLaunching];
|
||||||
|
_running = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
static NSString *
|
||||||
|
GetApplicationName(void)
|
||||||
|
{
|
||||||
|
NSDictionary *dict;
|
||||||
|
NSString *appName = 0;
|
||||||
|
|
||||||
|
/* Determine the application name */
|
||||||
|
dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
|
||||||
|
if (dict)
|
||||||
|
appName = [dict objectForKey: @"CFBundleName"];
|
||||||
|
|
||||||
|
if (![appName length])
|
||||||
|
appName = [[NSProcessInfo processInfo] processName];
|
||||||
|
|
||||||
|
return appName;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
CreateApplicationMenus(void)
|
||||||
|
{
|
||||||
|
NSString *appName;
|
||||||
|
NSString *title;
|
||||||
|
NSMenu *appleMenu;
|
||||||
|
NSMenu *windowMenu;
|
||||||
|
NSMenuItem *menuItem;
|
||||||
|
|
||||||
|
/* Create the main menu bar */
|
||||||
|
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
||||||
|
|
||||||
|
/* Create the application menu */
|
||||||
|
appName = GetApplicationName();
|
||||||
|
appleMenu = [[NSMenu alloc] initWithTitle:@""];
|
||||||
|
|
||||||
|
/* Add menu items */
|
||||||
|
title = [@"About " stringByAppendingString:appName];
|
||||||
|
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
|
||||||
|
|
||||||
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
title = [@"Hide " stringByAppendingString:appName];
|
||||||
|
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
|
||||||
|
|
||||||
|
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
|
||||||
|
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
|
||||||
|
|
||||||
|
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
||||||
|
|
||||||
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
title = [@"Quit " stringByAppendingString:appName];
|
||||||
|
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
||||||
|
|
||||||
|
/* Put menu into the menubar */
|
||||||
|
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
||||||
|
[menuItem setSubmenu:appleMenu];
|
||||||
|
[[NSApp mainMenu] addItem:menuItem];
|
||||||
|
[menuItem release];
|
||||||
|
|
||||||
|
/* Tell the application object that this is now the application menu */
|
||||||
|
[NSApp setAppleMenu:appleMenu];
|
||||||
|
[appleMenu release];
|
||||||
|
|
||||||
|
|
||||||
|
/* Create the window menu */
|
||||||
|
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
||||||
|
|
||||||
|
/* "Minimize" item */
|
||||||
|
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
||||||
|
[windowMenu addItem:menuItem];
|
||||||
|
[menuItem release];
|
||||||
|
|
||||||
|
/* Put menu into the menubar */
|
||||||
|
menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
|
||||||
|
[menuItem setSubmenu:windowMenu];
|
||||||
|
[[NSApp mainMenu] addItem:menuItem];
|
||||||
|
[menuItem release];
|
||||||
|
|
||||||
|
/* Tell the application object that this is now the window menu */
|
||||||
|
[NSApp setWindowsMenu:windowMenu];
|
||||||
|
[windowMenu release];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_RegisterApp(void)
|
||||||
|
{
|
||||||
|
ProcessSerialNumber psn;
|
||||||
|
NSAutoreleasePool *pool;
|
||||||
|
|
||||||
|
if (!GetCurrentProcess(&psn)) {
|
||||||
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||||
|
SetFrontProcess(&psn);
|
||||||
|
}
|
||||||
|
|
||||||
|
pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
if (NSApp == nil) {
|
||||||
|
[SDLApplication sharedApplication];
|
||||||
|
|
||||||
|
if ([NSApp mainMenu] == nil) {
|
||||||
|
CreateApplicationMenus();
|
||||||
|
}
|
||||||
|
[NSApp finishLaunching];
|
||||||
|
}
|
||||||
|
[pool release];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_PumpEvents(_THIS)
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *pool;
|
||||||
|
|
||||||
|
pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
for ( ; [NSApp isRunning]; ) {
|
||||||
|
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
|
||||||
|
if ( event == nil ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
[NSApp sendEvent:event];
|
||||||
|
}
|
||||||
|
[pool release];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
32
src/video/cocoa/SDL_cocoakeyboard.h
Normal file
32
src/video/cocoa/SDL_cocoakeyboard.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#ifndef _SDL_cocoakeyboard_h
|
||||||
|
#define _SDL_cocoakeyboard_h
|
||||||
|
|
||||||
|
extern void Cocoa_InitKeyboard(_THIS);
|
||||||
|
extern void Cocoa_QuitKeyboard(_THIS);
|
||||||
|
|
||||||
|
#endif /* _SDL_cocoakeyboard_h */
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
46
src/video/cocoa/SDL_cocoakeyboard.m
Normal file
46
src/video/cocoa/SDL_cocoakeyboard.m
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include "SDL_cocoavideo.h"
|
||||||
|
|
||||||
|
#include "../../events/SDL_keyboard_c.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_InitKeyboard(_THIS)
|
||||||
|
{
|
||||||
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
|
SDL_Keyboard keyboard;
|
||||||
|
|
||||||
|
SDL_zero(keyboard);
|
||||||
|
data->keyboard = SDL_AddKeyboard(&keyboard, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_QuitKeyboard(_THIS)
|
||||||
|
{
|
||||||
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
|
|
||||||
|
SDL_DelKeyboard(data->keyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
34
src/video/cocoa/SDL_cocoamodes.h
Normal file
34
src/video/cocoa/SDL_cocoamodes.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#ifndef _SDL_cocoamodes_h
|
||||||
|
#define _SDL_cocoamodes_h
|
||||||
|
|
||||||
|
extern void Cocoa_InitModes(_THIS);
|
||||||
|
extern void Cocoa_GetDisplayModes(_THIS);
|
||||||
|
extern int Cocoa_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
|
||||||
|
extern void Cocoa_QuitModes(_THIS);
|
||||||
|
|
||||||
|
#endif /* _SDL_cocoamodes_h */
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
56
src/video/cocoa/SDL_cocoamodes.m
Normal file
56
src/video/cocoa/SDL_cocoamodes.m
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include "SDL_cocoavideo.h"
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_InitModes(_THIS)
|
||||||
|
{
|
||||||
|
SDL_VideoDisplay display;
|
||||||
|
SDL_DisplayMode mode;
|
||||||
|
|
||||||
|
SDL_zero(display);
|
||||||
|
SDL_zero(mode);
|
||||||
|
display.desktop_mode = mode;
|
||||||
|
display.current_mode = mode;
|
||||||
|
SDL_AddVideoDisplay(&display);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_GetDisplayModes(_THIS)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
Cocoa_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_QuitModes(_THIS)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
32
src/video/cocoa/SDL_cocoamouse.h
Normal file
32
src/video/cocoa/SDL_cocoamouse.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#ifndef _SDL_cocoamouse_h
|
||||||
|
#define _SDL_cocoamouse_h
|
||||||
|
|
||||||
|
extern void Cocoa_InitMouse(_THIS);
|
||||||
|
extern void Cocoa_QuitMouse(_THIS);
|
||||||
|
|
||||||
|
#endif /* _SDL_cocoamouse_h */
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
46
src/video/cocoa/SDL_cocoamouse.m
Normal file
46
src/video/cocoa/SDL_cocoamouse.m
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include "SDL_cocoavideo.h"
|
||||||
|
|
||||||
|
#include "../../events/SDL_mouse_c.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_InitMouse(_THIS)
|
||||||
|
{
|
||||||
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
|
SDL_Mouse mouse;
|
||||||
|
|
||||||
|
SDL_zero(mouse);
|
||||||
|
data->mouse = SDL_AddMouse(&mouse, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_QuitMouse(_THIS)
|
||||||
|
{
|
||||||
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
|
|
||||||
|
SDL_DelMouse(data->mouse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
50
src/video/cocoa/SDL_cocoavideo.h
Normal file
50
src/video/cocoa/SDL_cocoavideo.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#ifndef _SDL_cocoavideo_h
|
||||||
|
#define _SDL_cocoavideo_h
|
||||||
|
|
||||||
|
#include <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#include "../SDL_sysvideo.h"
|
||||||
|
|
||||||
|
#include "SDL_cocoaevents.h"
|
||||||
|
#include "SDL_cocoakeyboard.h"
|
||||||
|
#include "SDL_cocoamodes.h"
|
||||||
|
#include "SDL_cocoamouse.h"
|
||||||
|
/*
|
||||||
|
#include "SDL_cocoaopengl.h"
|
||||||
|
#include "SDL_cocoawindow.h"
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private display data */
|
||||||
|
|
||||||
|
typedef struct SDL_VideoData
|
||||||
|
{
|
||||||
|
int mouse;
|
||||||
|
int keyboard;
|
||||||
|
} SDL_VideoData;
|
||||||
|
|
||||||
|
#endif /* _SDL_cocoavideo_h */
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
132
src/video/cocoa/SDL_cocoavideo.m
Normal file
132
src/video/cocoa/SDL_cocoavideo.m
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
SDL - Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2006 Sam Lantinga
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Sam Lantinga
|
||||||
|
slouken@libsdl.org
|
||||||
|
*/
|
||||||
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include "SDL_cocoavideo.h"
|
||||||
|
|
||||||
|
/* Initialization/Query functions */
|
||||||
|
static int Cocoa_VideoInit(_THIS);
|
||||||
|
static void Cocoa_VideoQuit(_THIS);
|
||||||
|
|
||||||
|
/* Cocoa driver bootstrap functions */
|
||||||
|
|
||||||
|
static int
|
||||||
|
Cocoa_Available(void)
|
||||||
|
{
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Cocoa_DeleteDevice(SDL_VideoDevice * device)
|
||||||
|
{
|
||||||
|
SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
|
||||||
|
|
||||||
|
SDL_free(device->driverdata);
|
||||||
|
SDL_free(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SDL_VideoDevice *
|
||||||
|
Cocoa_CreateDevice(int devindex)
|
||||||
|
{
|
||||||
|
SDL_VideoDevice *device;
|
||||||
|
SDL_VideoData *data;
|
||||||
|
|
||||||
|
Cocoa_RegisterApp();
|
||||||
|
|
||||||
|
/* Initialize all variables that we clean on shutdown */
|
||||||
|
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||||
|
if (device) {
|
||||||
|
data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
|
||||||
|
}
|
||||||
|
if (!device || !data) {
|
||||||
|
SDL_OutOfMemory();
|
||||||
|
if (device) {
|
||||||
|
SDL_free(device);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
device->driverdata = data;
|
||||||
|
|
||||||
|
/* Set the function pointers */
|
||||||
|
device->VideoInit = Cocoa_VideoInit;
|
||||||
|
device->VideoQuit = Cocoa_VideoQuit;
|
||||||
|
device->GetDisplayModes = Cocoa_GetDisplayModes;
|
||||||
|
device->SetDisplayMode = Cocoa_SetDisplayMode;
|
||||||
|
device->PumpEvents = Cocoa_PumpEvents;
|
||||||
|
|
||||||
|
/*
|
||||||
|
device->CreateWindow = Cocoa_CreateWindow;
|
||||||
|
device->CreateWindowFrom = Cocoa_CreateWindowFrom;
|
||||||
|
device->SetWindowTitle = Cocoa_SetWindowTitle;
|
||||||
|
device->SetWindowPosition = Cocoa_SetWindowPosition;
|
||||||
|
device->SetWindowSize = Cocoa_SetWindowSize;
|
||||||
|
device->ShowWindow = Cocoa_ShowWindow;
|
||||||
|
device->HideWindow = Cocoa_HideWindow;
|
||||||
|
device->RaiseWindow = Cocoa_RaiseWindow;
|
||||||
|
device->MaximizeWindow = Cocoa_MaximizeWindow;
|
||||||
|
device->MinimizeWindow = Cocoa_MinimizeWindow;
|
||||||
|
device->RestoreWindow = Cocoa_RestoreWindow;
|
||||||
|
device->SetWindowGrab = Cocoa_SetWindowGrab;
|
||||||
|
device->DestroyWindow = Cocoa_DestroyWindow;
|
||||||
|
device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
|
||||||
|
#ifdef SDL_VIDEO_OPENGL
|
||||||
|
device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
|
||||||
|
device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
|
||||||
|
device->GL_GetWindowAttribute = Cocoa_GL_GetWindowAttribute;
|
||||||
|
device->GL_CreateContext = Cocoa_GL_CreateContext;
|
||||||
|
device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
|
||||||
|
device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
|
||||||
|
device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
|
||||||
|
device->GL_SwapWindow = Cocoa_GL_SwapWindow;
|
||||||
|
device->GL_DeleteContext = Cocoa_GL_DeleteContext;
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
device->free = Cocoa_DeleteDevice;
|
||||||
|
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoBootStrap COCOA_bootstrap = {
|
||||||
|
"cocoa", "SDL Cocoa video driver",
|
||||||
|
Cocoa_Available, Cocoa_CreateDevice
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Cocoa_VideoInit(_THIS)
|
||||||
|
{
|
||||||
|
Cocoa_InitModes(_this);
|
||||||
|
Cocoa_InitKeyboard(_this);
|
||||||
|
Cocoa_InitMouse(_this);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_VideoQuit(_THIS)
|
||||||
|
{
|
||||||
|
Cocoa_QuitModes(_this);
|
||||||
|
Cocoa_QuitKeyboard(_this);
|
||||||
|
Cocoa_QuitMouse(_this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim: set ts=4 sw=4 expandtab: */
|
@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2003 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
#include "SDL_config.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
Obscuring code: maximum number of windows above ours (inclusive)
|
|
||||||
|
|
||||||
Note: this doesn't work too well in practice and should be
|
|
||||||
phased out when we add OpenGL 2D acceleration. It was never
|
|
||||||
enabled in the first place, so this shouldn't be a problem ;-)
|
|
||||||
*/
|
|
||||||
#define kMaxWindows 256
|
|
||||||
|
|
||||||
/* Some of the Core Graphics Server API for obscuring code */
|
|
||||||
#define kCGSWindowLevelTop 2147483632
|
|
||||||
#define kCGSWindowLevelDockIconDrag 500
|
|
||||||
#define kCGSWindowLevelDockMenu 101
|
|
||||||
#define kCGSWindowLevelMenuIgnore 21
|
|
||||||
#define kCGSWindowLevelMenu 20
|
|
||||||
#define kCGSWindowLevelDockLabel 12
|
|
||||||
#define kCGSWindowLevelDockIcon 11
|
|
||||||
#define kCGSWindowLevelDock 10
|
|
||||||
#define kCGSWindowLevelUtility 3
|
|
||||||
#define kCGSWindowLevelNormal 0
|
|
||||||
|
|
||||||
/*
|
|
||||||
For completeness; We never use these window levels, they are always below us
|
|
||||||
#define kCGSWindowLevelMBarShadow -20
|
|
||||||
#define kCGSWindowLevelDesktopPicture -2147483647
|
|
||||||
#define kCGSWindowLevelDesktop -2147483648
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef CGError CGSError;
|
|
||||||
typedef long CGSWindowCount;
|
|
||||||
typedef void *CGSConnectionID;
|
|
||||||
typedef int CGSWindowID;
|
|
||||||
typedef CGSWindowID *CGSWindowIDList;
|
|
||||||
typedef CGWindowLevel CGSWindowLevel;
|
|
||||||
typedef NSRect CGSRect;
|
|
||||||
|
|
||||||
extern CGSConnectionID _CGSDefaultConnection();
|
|
||||||
|
|
||||||
extern CGSError CGSGetOnScreenWindowList(CGSConnectionID cid,
|
|
||||||
CGSConnectionID owner,
|
|
||||||
CGSWindowCount listCapacity,
|
|
||||||
CGSWindowIDList list,
|
|
||||||
CGSWindowCount * listCount);
|
|
||||||
|
|
||||||
extern CGSError CGSGetScreenRectForWindow(CGSConnectionID cid,
|
|
||||||
CGSWindowID wid, CGSRect * rect);
|
|
||||||
|
|
||||||
extern CGWindowLevel CGSGetWindowLevel(CGSConnectionID cid,
|
|
||||||
CGSWindowID wid,
|
|
||||||
CGSWindowLevel * level);
|
|
||||||
|
|
||||||
extern CGSError CGSDisplayHWFill(CGDirectDisplayID id, unsigned int x,
|
|
||||||
unsigned int y, unsigned int w,
|
|
||||||
unsigned int h, unsigned int color);
|
|
||||||
|
|
||||||
extern CGSError CGSDisplayCanHWFill(CGDirectDisplayID id);
|
|
||||||
|
|
||||||
extern CGSError CGSGetMouseEnabledFlags(CGSConnectionID cid, CGSWindowID wid,
|
|
||||||
int *flags);
|
|
||||||
|
|
||||||
int CGSDisplayHWSync(CGDirectDisplayID id);
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
File diff suppressed because it is too large
Load Diff
@ -1,329 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2003 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
#include "SDL_config.h"
|
|
||||||
|
|
||||||
#include "SDL_QuartzVideo.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GL_ARB_Multisample is supposed to be available in 10.1, according to Apple:
|
|
||||||
*
|
|
||||||
* http://developer.apple.com/opengl/extensions.html#GL_ARB_multisample
|
|
||||||
*
|
|
||||||
* ...but it isn't in the system headers, according to Sam:
|
|
||||||
*
|
|
||||||
* http://www.libsdl.org/pipermail/sdl/2003-December/058335.html
|
|
||||||
*
|
|
||||||
* These are normally enums and not #defines in the system headers.
|
|
||||||
*
|
|
||||||
* --ryan.
|
|
||||||
*/
|
|
||||||
#if (MAC_OS_X_VERSION_MAX_ALLOWED < 1020)
|
|
||||||
#define NSOpenGLPFASampleBuffers ((NSOpenGLPixelFormatAttribute) 55)
|
|
||||||
#define NSOpenGLPFASamples ((NSOpenGLPixelFormatAttribute) 56)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
@ implementation NSOpenGLContext (CGLContextAccess)
|
|
||||||
- (CGLContextObj) cglContext;
|
|
||||||
{
|
|
||||||
return _contextAuxiliary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
/* OpenGL helper functions (used internally) */
|
|
||||||
int
|
|
||||||
QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags)
|
|
||||||
{
|
|
||||||
|
|
||||||
NSOpenGLPixelFormatAttribute attr[32];
|
|
||||||
NSOpenGLPixelFormat *fmt;
|
|
||||||
int i = 0;
|
|
||||||
int colorBits = bpp;
|
|
||||||
|
|
||||||
/* if a GL library hasn't been loaded at this point, load the default. */
|
|
||||||
if (!this->gl_config.driver_loaded) {
|
|
||||||
if (QZ_GL_LoadLibrary (this, NULL) == -1)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & SDL_FULLSCREEN) {
|
|
||||||
|
|
||||||
attr[i++] = NSOpenGLPFAFullScreen;
|
|
||||||
}
|
|
||||||
/* In windowed mode, the OpenGL pixel depth must match device pixel depth */
|
|
||||||
else if (colorBits != device_bpp) {
|
|
||||||
|
|
||||||
colorBits = device_bpp;
|
|
||||||
}
|
|
||||||
|
|
||||||
attr[i++] = NSOpenGLPFAColorSize;
|
|
||||||
attr[i++] = colorBits;
|
|
||||||
|
|
||||||
attr[i++] = NSOpenGLPFADepthSize;
|
|
||||||
attr[i++] = this->gl_config.depth_size;
|
|
||||||
|
|
||||||
if (this->gl_config.double_buffer) {
|
|
||||||
attr[i++] = NSOpenGLPFADoubleBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->gl_config.stereo) {
|
|
||||||
attr[i++] = NSOpenGLPFAStereo;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->gl_config.stencil_size != 0) {
|
|
||||||
attr[i++] = NSOpenGLPFAStencilSize;
|
|
||||||
attr[i++] = this->gl_config.stencil_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((this->gl_config.accum_red_size +
|
|
||||||
this->gl_config.accum_green_size +
|
|
||||||
this->gl_config.accum_blue_size +
|
|
||||||
this->gl_config.accum_alpha_size) > 0) {
|
|
||||||
attr[i++] = NSOpenGLPFAAccumSize;
|
|
||||||
attr[i++] =
|
|
||||||
this->gl_config.accum_red_size +
|
|
||||||
this->gl_config.accum_green_size +
|
|
||||||
this->gl_config.accum_blue_size +
|
|
||||||
this->gl_config.accum_alpha_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->gl_config.multisamplebuffers != 0) {
|
|
||||||
attr[i++] = NSOpenGLPFASampleBuffers;
|
|
||||||
attr[i++] = this->gl_config.multisamplebuffers;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->gl_config.multisamplesamples != 0) {
|
|
||||||
attr[i++] = NSOpenGLPFASamples;
|
|
||||||
attr[i++] = this->gl_config.multisamplesamples;
|
|
||||||
attr[i++] = NSOpenGLPFANoRecovery;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->gl_config.accelerated > 0) {
|
|
||||||
attr[i++] = NSOpenGLPFAAccelerated;
|
|
||||||
}
|
|
||||||
|
|
||||||
attr[i++] = NSOpenGLPFAScreenMask;
|
|
||||||
attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
|
|
||||||
attr[i] = 0;
|
|
||||||
|
|
||||||
fmt =[[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
|
||||||
if (fmt == nil) {
|
|
||||||
SDL_SetError ("Failed creating OpenGL pixel format");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_context =[[NSOpenGLContext alloc] initWithFormat: fmt shareContext:nil];
|
|
||||||
|
|
||||||
[fmt release];
|
|
||||||
|
|
||||||
if (gl_context == nil) {
|
|
||||||
SDL_SetError ("Failed creating OpenGL context");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Synchronize QZ_GL_SwapBuffers() to vertical retrace.
|
|
||||||
* (Apple's documentation is not completely clear about what this setting
|
|
||||||
* exactly does, IMHO - for a detailed explanation see
|
|
||||||
* http://lists.apple.com/archives/mac-opengl/2006/Jan/msg00080.html )
|
|
||||||
*/
|
|
||||||
if (this->gl_config.swap_control >= 0) {
|
|
||||||
long value;
|
|
||||||
value = this->gl_config.swap_control;
|
|
||||||
[gl_context setValues: &value forParameter:NSOpenGLCPSwapInterval];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
|
|
||||||
* "You are blowing a couple of the internal OpenGL function caches. This
|
|
||||||
* appears to be happening in the VAO case. You can tell OpenGL to up
|
|
||||||
* the cache size by issuing the following calls right after you create
|
|
||||||
* the OpenGL context. The default cache size is 16." --ryan.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GLI_ARRAY_FUNC_CACHE_MAX
|
|
||||||
#define GLI_ARRAY_FUNC_CACHE_MAX 284
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef GLI_SUBMIT_FUNC_CACHE_MAX
|
|
||||||
#define GLI_SUBMIT_FUNC_CACHE_MAX 280
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{
|
|
||||||
long cache_max = 64;
|
|
||||||
CGLContextObj ctx =[gl_context cglContext];
|
|
||||||
CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
|
|
||||||
CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* End Wisdom from Apple Engineer section. --ryan. */
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_TearDownOpenGL (_THIS)
|
|
||||||
{
|
|
||||||
|
|
||||||
[NSOpenGLContext clearCurrentContext];
|
|
||||||
[gl_context clearDrawable];
|
|
||||||
[gl_context release];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* SDL OpenGL functions */
|
|
||||||
static const char *DEFAULT_OPENGL_LIB_NAME =
|
|
||||||
"/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib";
|
|
||||||
|
|
||||||
int
|
|
||||||
QZ_GL_LoadLibrary (_THIS, const char *location)
|
|
||||||
{
|
|
||||||
if (gl_context != NULL) {
|
|
||||||
SDL_SetError ("OpenGL context already created");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opengl_library != NULL)
|
|
||||||
SDL_UnloadObject (opengl_library);
|
|
||||||
|
|
||||||
if (location == NULL)
|
|
||||||
location = DEFAULT_OPENGL_LIB_NAME;
|
|
||||||
|
|
||||||
opengl_library = SDL_LoadObject (location);
|
|
||||||
if (opengl_library != NULL) {
|
|
||||||
this->gl_config.driver_loaded = 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->gl_config.driver_loaded = 0;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
QZ_GL_GetProcAddress (_THIS, const char *proc)
|
|
||||||
{
|
|
||||||
return SDL_LoadFunction (opengl_library, proc);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
QZ_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value)
|
|
||||||
{
|
|
||||||
|
|
||||||
GLenum attr = 0;
|
|
||||||
|
|
||||||
QZ_GL_MakeCurrent (this);
|
|
||||||
|
|
||||||
switch (attrib) {
|
|
||||||
case SDL_GL_RED_SIZE:
|
|
||||||
attr = GL_RED_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_BLUE_SIZE:
|
|
||||||
attr = GL_BLUE_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_GREEN_SIZE:
|
|
||||||
attr = GL_GREEN_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_ALPHA_SIZE:
|
|
||||||
attr = GL_ALPHA_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_DOUBLEBUFFER:
|
|
||||||
attr = GL_DOUBLEBUFFER;
|
|
||||||
break;
|
|
||||||
case SDL_GL_DEPTH_SIZE:
|
|
||||||
attr = GL_DEPTH_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_STENCIL_SIZE:
|
|
||||||
attr = GL_STENCIL_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_ACCUM_RED_SIZE:
|
|
||||||
attr = GL_ACCUM_RED_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_ACCUM_GREEN_SIZE:
|
|
||||||
attr = GL_ACCUM_GREEN_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_ACCUM_BLUE_SIZE:
|
|
||||||
attr = GL_ACCUM_BLUE_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_ACCUM_ALPHA_SIZE:
|
|
||||||
attr = GL_ACCUM_ALPHA_BITS;
|
|
||||||
break;
|
|
||||||
case SDL_GL_STEREO:
|
|
||||||
attr = GL_STEREO;
|
|
||||||
break;
|
|
||||||
case SDL_GL_MULTISAMPLEBUFFERS:
|
|
||||||
attr = GL_SAMPLE_BUFFERS_ARB;
|
|
||||||
break;
|
|
||||||
case SDL_GL_MULTISAMPLESAMPLES:
|
|
||||||
attr = GL_SAMPLES_ARB;
|
|
||||||
break;
|
|
||||||
case SDL_GL_BUFFER_SIZE:
|
|
||||||
{
|
|
||||||
GLint bits = 0;
|
|
||||||
GLint component;
|
|
||||||
|
|
||||||
/* there doesn't seem to be a single flag in OpenGL for this! */
|
|
||||||
glGetIntegerv (GL_RED_BITS, &component);
|
|
||||||
bits += component;
|
|
||||||
glGetIntegerv (GL_GREEN_BITS, &component);
|
|
||||||
bits += component;
|
|
||||||
glGetIntegerv (GL_BLUE_BITS, &component);
|
|
||||||
bits += component;
|
|
||||||
glGetIntegerv (GL_ALPHA_BITS, &component);
|
|
||||||
bits += component;
|
|
||||||
|
|
||||||
*value = bits;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case SDL_GL_ACCELERATED_VISUAL:
|
|
||||||
{
|
|
||||||
long val;
|
|
||||||
/* FIXME: How do we get this information here?
|
|
||||||
[fmt getValues: &val forAttribute: NSOpenGLPFAAccelerated attr forVirtualScreen: 0];
|
|
||||||
*/
|
|
||||||
val = (this->gl_config.accelerated != 0);;
|
|
||||||
*value = val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case SDL_GL_SWAP_CONTROL:
|
|
||||||
{
|
|
||||||
long val;
|
|
||||||
[gl_context getValues: &val forParameter:NSOpenGLCPSwapInterval];
|
|
||||||
*value = val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glGetIntegerv (attr, (GLint *) value);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
QZ_GL_MakeCurrent (_THIS)
|
|
||||||
{
|
|
||||||
[gl_context makeCurrentContext];
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_GL_SwapBuffers (_THIS)
|
|
||||||
{
|
|
||||||
[gl_context flushBuffer];
|
|
||||||
}
|
|
@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2003 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
#include "SDL_config.h"
|
|
||||||
|
|
||||||
/* These are the Macintosh key scancode constants -- from Inside Macintosh */
|
|
||||||
|
|
||||||
#define QZ_ESCAPE 0x35
|
|
||||||
#define QZ_F1 0x7A
|
|
||||||
#define QZ_F2 0x78
|
|
||||||
#define QZ_F3 0x63
|
|
||||||
#define QZ_F4 0x76
|
|
||||||
#define QZ_F5 0x60
|
|
||||||
#define QZ_F6 0x61
|
|
||||||
#define QZ_F7 0x62
|
|
||||||
#define QZ_F8 0x64
|
|
||||||
#define QZ_F9 0x65
|
|
||||||
#define QZ_F10 0x6D
|
|
||||||
#define QZ_F11 0x67
|
|
||||||
#define QZ_F12 0x6F
|
|
||||||
#define QZ_PRINT 0x69
|
|
||||||
#define QZ_SCROLLOCK 0x6B
|
|
||||||
#define QZ_PAUSE 0x71
|
|
||||||
#define QZ_POWER 0x7F
|
|
||||||
#define QZ_BACKQUOTE 0x32
|
|
||||||
#define QZ_1 0x12
|
|
||||||
#define QZ_2 0x13
|
|
||||||
#define QZ_3 0x14
|
|
||||||
#define QZ_4 0x15
|
|
||||||
#define QZ_5 0x17
|
|
||||||
#define QZ_6 0x16
|
|
||||||
#define QZ_7 0x1A
|
|
||||||
#define QZ_8 0x1C
|
|
||||||
#define QZ_9 0x19
|
|
||||||
#define QZ_0 0x1D
|
|
||||||
#define QZ_MINUS 0x1B
|
|
||||||
#define QZ_EQUALS 0x18
|
|
||||||
#define QZ_BACKSPACE 0x33
|
|
||||||
#define QZ_INSERT 0x72
|
|
||||||
#define QZ_HOME 0x73
|
|
||||||
#define QZ_PAGEUP 0x74
|
|
||||||
#define QZ_NUMLOCK 0x47
|
|
||||||
#define QZ_KP_EQUALS 0x51
|
|
||||||
#define QZ_KP_DIVIDE 0x4B
|
|
||||||
#define QZ_KP_MULTIPLY 0x43
|
|
||||||
#define QZ_TAB 0x30
|
|
||||||
#define QZ_q 0x0C
|
|
||||||
#define QZ_w 0x0D
|
|
||||||
#define QZ_e 0x0E
|
|
||||||
#define QZ_r 0x0F
|
|
||||||
#define QZ_t 0x11
|
|
||||||
#define QZ_y 0x10
|
|
||||||
#define QZ_u 0x20
|
|
||||||
#define QZ_i 0x22
|
|
||||||
#define QZ_o 0x1F
|
|
||||||
#define QZ_p 0x23
|
|
||||||
#define QZ_LEFTBRACKET 0x21
|
|
||||||
#define QZ_RIGHTBRACKET 0x1E
|
|
||||||
#define QZ_BACKSLASH 0x2A
|
|
||||||
#define QZ_DELETE 0x75
|
|
||||||
#define QZ_END 0x77
|
|
||||||
#define QZ_PAGEDOWN 0x79
|
|
||||||
#define QZ_KP7 0x59
|
|
||||||
#define QZ_KP8 0x5B
|
|
||||||
#define QZ_KP9 0x5C
|
|
||||||
#define QZ_KP_MINUS 0x4E
|
|
||||||
#define QZ_CAPSLOCK 0x39
|
|
||||||
#define QZ_a 0x00
|
|
||||||
#define QZ_s 0x01
|
|
||||||
#define QZ_d 0x02
|
|
||||||
#define QZ_f 0x03
|
|
||||||
#define QZ_g 0x05
|
|
||||||
#define QZ_h 0x04
|
|
||||||
#define QZ_j 0x26
|
|
||||||
#define QZ_k 0x28
|
|
||||||
#define QZ_l 0x25
|
|
||||||
#define QZ_SEMICOLON 0x29
|
|
||||||
#define QZ_QUOTE 0x27
|
|
||||||
#define QZ_RETURN 0x24
|
|
||||||
#define QZ_KP4 0x56
|
|
||||||
#define QZ_KP5 0x57
|
|
||||||
#define QZ_KP6 0x58
|
|
||||||
#define QZ_KP_PLUS 0x45
|
|
||||||
#define QZ_LSHIFT 0x38
|
|
||||||
#define QZ_z 0x06
|
|
||||||
#define QZ_x 0x07
|
|
||||||
#define QZ_c 0x08
|
|
||||||
#define QZ_v 0x09
|
|
||||||
#define QZ_b 0x0B
|
|
||||||
#define QZ_n 0x2D
|
|
||||||
#define QZ_m 0x2E
|
|
||||||
#define QZ_COMMA 0x2B
|
|
||||||
#define QZ_PERIOD 0x2F
|
|
||||||
#define QZ_SLASH 0x2C
|
|
||||||
#if 1 /* Panther now defines right side keys */
|
|
||||||
#define QZ_RSHIFT 0x3C
|
|
||||||
#endif
|
|
||||||
#define QZ_UP 0x7E
|
|
||||||
#define QZ_KP1 0x53
|
|
||||||
#define QZ_KP2 0x54
|
|
||||||
#define QZ_KP3 0x55
|
|
||||||
#define QZ_KP_ENTER 0x4C
|
|
||||||
#define QZ_LCTRL 0x3B
|
|
||||||
#define QZ_LALT 0x3A
|
|
||||||
#define QZ_LMETA 0x37
|
|
||||||
#define QZ_SPACE 0x31
|
|
||||||
#if 1 /* Panther now defines right side keys */
|
|
||||||
#define QZ_RMETA 0x36
|
|
||||||
#define QZ_RALT 0x3D
|
|
||||||
#define QZ_RCTRL 0x3E
|
|
||||||
#endif
|
|
||||||
#define QZ_LEFT 0x7B
|
|
||||||
#define QZ_DOWN 0x7D
|
|
||||||
#define QZ_RIGHT 0x7C
|
|
||||||
#define QZ_KP0 0x52
|
|
||||||
#define QZ_KP_PERIOD 0x41
|
|
||||||
|
|
||||||
/* Wierd, these keys are on my iBook under Mac OS X */
|
|
||||||
#define QZ_IBOOK_ENTER 0x34
|
|
||||||
#define QZ_IBOOK_LEFT 0x3B
|
|
||||||
#define QZ_IBOOK_RIGHT 0x3C
|
|
||||||
#define QZ_IBOOK_DOWN 0x3D
|
|
||||||
#define QZ_IBOOK_UP 0x3E
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -1,298 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2003 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
#include "SDL_config.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
@file SDL_QuartzVideo.h
|
|
||||||
@author Darrell Walisser, Max Horn, et al.
|
|
||||||
|
|
||||||
@abstract SDL video driver for Mac OS X.
|
|
||||||
|
|
||||||
@discussion
|
|
||||||
|
|
||||||
TODO
|
|
||||||
- Hardware Cursor support with NSCursor instead of Carbon
|
|
||||||
- Keyboard repeat/mouse speed adjust (if needed)
|
|
||||||
- Multiple monitor support (currently only main display)
|
|
||||||
- Accelerated blitting support
|
|
||||||
- Fix white OpenGL window on minimize (fixed) (update: broken again on 10.2)
|
|
||||||
- Find out what events should be sent/ignored if window is minimized
|
|
||||||
- Find a way to deal with external resolution/depth switch while app is running
|
|
||||||
- Check accuracy of QZ_SetGamma()
|
|
||||||
Problems:
|
|
||||||
- OGL not working in full screen with software renderer
|
|
||||||
- SetColors sets palette correctly but clears framebuffer
|
|
||||||
- Crash in CG after several mode switches (I think this has been fixed)
|
|
||||||
- Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
|
|
||||||
- Cursor in 8 bit modes is screwy (might just be Radeon PCI bug) (update: not just Radeon)
|
|
||||||
- Warping cursor delays mouse events for a fraction of a second,
|
|
||||||
there is a hack around this that helps a bit
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Needs to be first, so QuickTime.h doesn't include glext.h (10.4) */
|
|
||||||
#include "SDL_opengl.h"
|
|
||||||
|
|
||||||
#include <Cocoa/Cocoa.h>
|
|
||||||
#include <Carbon/Carbon.h>
|
|
||||||
#include <QuickTime/QuickTime.h>
|
|
||||||
#include <OpenGL/CGLTypes.h> /* For CGLContextObj */
|
|
||||||
#include <IOKit/IOKitLib.h> /* For powersave handling */
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include "SDL_thread.h"
|
|
||||||
#include "SDL_video.h"
|
|
||||||
#include "SDL_error.h"
|
|
||||||
#include "SDL_timer.h"
|
|
||||||
#include "SDL_loadso.h"
|
|
||||||
#include "SDL_syswm.h"
|
|
||||||
#include "../SDL_sysvideo.h"
|
|
||||||
#include "../SDL_pixels_c.h"
|
|
||||||
#include "../../events/SDL_events_c.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
This is a workaround to directly access NSOpenGLContext's CGL context
|
|
||||||
We need this to check for errors NSOpenGLContext doesn't support
|
|
||||||
*/
|
|
||||||
@ interface NSOpenGLContext(CGLContextAccess) - (CGLContextObj) cglContext;
|
|
||||||
@end
|
|
||||||
/* Main driver structure to store required state information */
|
|
||||||
typedef struct SDL_PrivateVideoData
|
|
||||||
{
|
|
||||||
|
|
||||||
CGDirectDisplayID
|
|
||||||
display; /* 0 == main display (only support single display) */
|
|
||||||
CFDictionaryRef
|
|
||||||
mode; /* current mode of the display */
|
|
||||||
CFDictionaryRef
|
|
||||||
save_mode; /* original mode of the display */
|
|
||||||
CFArrayRef
|
|
||||||
mode_list; /* list of available fullscreen modes */
|
|
||||||
CGDirectPaletteRef
|
|
||||||
palette; /* palette of an 8-bit display */
|
|
||||||
NSOpenGLContext *
|
|
||||||
gl_context; /* OpenGL rendering context */
|
|
||||||
Uint32
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
bpp; /* frequently used data about the display */
|
|
||||||
Uint32
|
|
||||||
flags; /* flags for current mode, for teardown purposes */
|
|
||||||
Uint32
|
|
||||||
video_set; /* boolean; indicates if video was set correctly */
|
|
||||||
Uint32
|
|
||||||
warp_flag; /* boolean; notify to event loop that a warp just occured */
|
|
||||||
Uint32
|
|
||||||
warp_ticks; /* timestamp when the warp occured */
|
|
||||||
NSWindow *
|
|
||||||
window; /* Cocoa window to implement the SDL window */
|
|
||||||
NSQuickDrawView *
|
|
||||||
view; /* the window's view; draw 2D and OpenGL into this view */
|
|
||||||
SDL_Surface *
|
|
||||||
resize_icon; /* icon for the resize badge, we have to draw it by hand */
|
|
||||||
SDL_GrabMode
|
|
||||||
current_grab_mode; /* default value is SDL_GRAB_OFF */
|
|
||||||
SDL_Rect **
|
|
||||||
client_mode_list; /* resolution list to pass back to client */
|
|
||||||
SDLKey
|
|
||||||
keymap[256]; /* Mac OS X to SDL key mapping */
|
|
||||||
Uint32
|
|
||||||
current_mods; /* current keyboard modifiers, to track modifier state */
|
|
||||||
Uint32
|
|
||||||
last_virtual_button; /* last virtual mouse button pressed */
|
|
||||||
io_connect_t
|
|
||||||
power_connection; /* used with IOKit to detect wake from sleep */
|
|
||||||
Uint8
|
|
||||||
expect_mouse_up; /* used to determine when to send mouse up events */
|
|
||||||
Uint8
|
|
||||||
grab_state; /* used to manage grab behavior */
|
|
||||||
NSPoint
|
|
||||||
cursor_loc; /* saved cursor coords, for activate/deactivate when grabbed */
|
|
||||||
BOOL
|
|
||||||
cursor_should_be_visible; /* tells if cursor is supposed to be visible (SDL_ShowCursor) */
|
|
||||||
BOOL
|
|
||||||
cursor_visible; /* tells if cursor is *actually* visible or not */
|
|
||||||
Uint8 *
|
|
||||||
sw_buffers[2]; /* pointers to the two software buffers for double-buffer emulation */
|
|
||||||
SDL_Thread *
|
|
||||||
thread; /* thread for async updates to the screen */
|
|
||||||
SDL_sem *
|
|
||||||
sem1, *
|
|
||||||
sem2; /* synchronization for async screen updates */
|
|
||||||
Uint8 *
|
|
||||||
current_buffer; /* the buffer being copied to the screen */
|
|
||||||
BOOL
|
|
||||||
quit_thread; /* used to quit the async blitting thread */
|
|
||||||
SInt32
|
|
||||||
system_version; /* used to dis-/enable workarounds depending on the system version */
|
|
||||||
|
|
||||||
ImageDescriptionHandle
|
|
||||||
yuv_idh;
|
|
||||||
MatrixRecordPtr
|
|
||||||
yuv_matrix;
|
|
||||||
DecompressorComponent
|
|
||||||
yuv_codec;
|
|
||||||
ImageSequence
|
|
||||||
yuv_seq;
|
|
||||||
PlanarPixmapInfoYUV420 *
|
|
||||||
yuv_pixmap;
|
|
||||||
Sint16
|
|
||||||
yuv_width,
|
|
||||||
yuv_height;
|
|
||||||
CGrafPtr
|
|
||||||
yuv_port;
|
|
||||||
|
|
||||||
void *
|
|
||||||
opengl_library; /* dynamically loaded OpenGL library. */
|
|
||||||
} SDL_PrivateVideoData;
|
|
||||||
|
|
||||||
#define _THIS SDL_VideoDevice *this
|
|
||||||
#define display_id (this->hidden->display)
|
|
||||||
#define mode (this->hidden->mode)
|
|
||||||
#define save_mode (this->hidden->save_mode)
|
|
||||||
#define mode_list (this->hidden->mode_list)
|
|
||||||
#define palette (this->hidden->palette)
|
|
||||||
#define gl_context (this->hidden->gl_context)
|
|
||||||
#define device_width (this->hidden->width)
|
|
||||||
#define device_height (this->hidden->height)
|
|
||||||
#define device_bpp (this->hidden->bpp)
|
|
||||||
#define mode_flags (this->hidden->flags)
|
|
||||||
#define qz_window (this->hidden->window)
|
|
||||||
#define window_view (this->hidden->view)
|
|
||||||
#define video_set (this->hidden->video_set)
|
|
||||||
#define warp_ticks (this->hidden->warp_ticks)
|
|
||||||
#define warp_flag (this->hidden->warp_flag)
|
|
||||||
#define resize_icon (this->hidden->resize_icon)
|
|
||||||
#define current_grab_mode (this->hidden->current_grab_mode)
|
|
||||||
#define client_mode_list (this->hidden->client_mode_list)
|
|
||||||
#define keymap (this->hidden->keymap)
|
|
||||||
#define current_mods (this->hidden->current_mods)
|
|
||||||
#define last_virtual_button (this->hidden->last_virtual_button)
|
|
||||||
#define power_connection (this->hidden->power_connection)
|
|
||||||
#define expect_mouse_up (this->hidden->expect_mouse_up)
|
|
||||||
#define grab_state (this->hidden->grab_state)
|
|
||||||
#define cursor_loc (this->hidden->cursor_loc)
|
|
||||||
#define cursor_should_be_visible (this->hidden->cursor_should_be_visible)
|
|
||||||
#define cursor_visible (this->hidden->cursor_visible)
|
|
||||||
#define sw_buffers (this->hidden->sw_buffers)
|
|
||||||
#define thread (this->hidden->thread)
|
|
||||||
#define sem1 (this->hidden->sem1)
|
|
||||||
#define sem2 (this->hidden->sem2)
|
|
||||||
#define current_buffer (this->hidden->current_buffer)
|
|
||||||
#define quit_thread (this->hidden->quit_thread)
|
|
||||||
#define system_version (this->hidden->system_version)
|
|
||||||
#define opengl_library (this->hidden->opengl_library)
|
|
||||||
|
|
||||||
/* grab states - the input is in one of these states */
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
QZ_UNGRABBED = 0,
|
|
||||||
QZ_VISIBLE_GRAB,
|
|
||||||
QZ_INVISIBLE_GRAB
|
|
||||||
};
|
|
||||||
|
|
||||||
/* grab actions - these can change the grabbed state */
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
QZ_ENABLE_GRAB = 0,
|
|
||||||
QZ_DISABLE_GRAB,
|
|
||||||
QZ_HIDECURSOR,
|
|
||||||
QZ_SHOWCURSOR
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Gamma Functions */
|
|
||||||
int
|
|
||||||
QZ_SetGamma(_THIS, float red, float green, float blue);
|
|
||||||
int
|
|
||||||
QZ_GetGamma(_THIS, float *red, float *green, float *blue);
|
|
||||||
int
|
|
||||||
QZ_SetGammaRamp(_THIS, Uint16 * ramp);
|
|
||||||
int
|
|
||||||
QZ_GetGammaRamp(_THIS, Uint16 * ramp);
|
|
||||||
|
|
||||||
/* OpenGL functions */
|
|
||||||
int
|
|
||||||
QZ_SetupOpenGL(_THIS, int bpp, Uint32 flags);
|
|
||||||
void
|
|
||||||
QZ_TearDownOpenGL(_THIS);
|
|
||||||
void *
|
|
||||||
QZ_GL_GetProcAddress(_THIS, const char *proc);
|
|
||||||
int
|
|
||||||
QZ_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
|
|
||||||
int
|
|
||||||
QZ_GL_MakeCurrent(_THIS);
|
|
||||||
void
|
|
||||||
QZ_GL_SwapBuffers(_THIS);
|
|
||||||
int
|
|
||||||
QZ_GL_LoadLibrary(_THIS, const char *location);
|
|
||||||
|
|
||||||
/* Cursor and Mouse functions */
|
|
||||||
void
|
|
||||||
QZ_FreeWMCursor(_THIS, WMcursor * cursor);
|
|
||||||
WMcursor *
|
|
||||||
QZ_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
|
|
||||||
int w, int h, int hot_x, int hot_y);
|
|
||||||
int
|
|
||||||
QZ_ShowWMCursor(_THIS, WMcursor * cursor);
|
|
||||||
void
|
|
||||||
QZ_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
|
|
||||||
void
|
|
||||||
QZ_MoveWMCursor(_THIS, int x, int y);
|
|
||||||
void
|
|
||||||
QZ_CheckMouseMode(_THIS);
|
|
||||||
void
|
|
||||||
QZ_UpdateMouse(_THIS);
|
|
||||||
|
|
||||||
/* Event functions */
|
|
||||||
void
|
|
||||||
QZ_InitOSKeymap(_THIS);
|
|
||||||
void
|
|
||||||
QZ_PumpEvents(_THIS);
|
|
||||||
|
|
||||||
/* Window Manager functions */
|
|
||||||
void
|
|
||||||
QZ_SetCaption(_THIS, const char *title, const char *icon);
|
|
||||||
void
|
|
||||||
QZ_SetIcon(_THIS, SDL_Surface * icon, Uint8 * mask);
|
|
||||||
int
|
|
||||||
QZ_IconifyWindow(_THIS);
|
|
||||||
SDL_GrabMode
|
|
||||||
QZ_GrabInput(_THIS, SDL_GrabMode grab_mode);
|
|
||||||
/*int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info);*/
|
|
||||||
|
|
||||||
/* YUV functions */
|
|
||||||
SDL_Overlay *QZ_CreateYUVOverlay(_THIS, int width, int height,
|
|
||||||
Uint32 format, SDL_Surface * display);
|
|
||||||
|
|
||||||
|
|
||||||
/* Private functions (used internally) */
|
|
||||||
void QZ_PrivateWarpCursor(_THIS, int x, int y);
|
|
||||||
void QZ_ChangeGrabState(_THIS, int action);
|
|
||||||
void QZ_RegisterForSleepNotifications(_THIS);
|
|
||||||
void QZ_ShowMouse(_THIS);
|
|
||||||
void QZ_HideMouse(_THIS);
|
|
||||||
void QZ_PrivateGlobalToLocal(_THIS, NSPoint * p);
|
|
||||||
void QZ_PrivateCocoaToSDL(_THIS, NSPoint * p);
|
|
||||||
BOOL
|
|
||||||
QZ_IsMouseInWindow(_THIS);
|
|
||||||
void QZ_DoActivate(_THIS);
|
|
||||||
void QZ_DoDeactivate(_THIS);
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
File diff suppressed because it is too large
Load Diff
@ -1,492 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2003 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
#include "SDL_config.h"
|
|
||||||
|
|
||||||
#include "SDL_QuartzVideo.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct WMcursor
|
|
||||||
{
|
|
||||||
NSCursor *nscursor;
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_FreeWMCursor(_THIS, WMcursor * cursor)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (cursor != NULL) {
|
|
||||||
[cursor->nscursor release];
|
|
||||||
free(cursor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WMcursor *
|
|
||||||
QZ_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
|
|
||||||
int w, int h, int hot_x, int hot_y)
|
|
||||||
{
|
|
||||||
WMcursor *cursor;
|
|
||||||
NSBitmapImageRep *imgrep;
|
|
||||||
NSImage *img;
|
|
||||||
unsigned char *planes[5];
|
|
||||||
int i;
|
|
||||||
NSAutoreleasePool *pool;
|
|
||||||
|
|
||||||
pool =[[NSAutoreleasePool alloc] init];
|
|
||||||
|
|
||||||
/* Allocate the cursor memory */
|
|
||||||
cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
|
|
||||||
if (cursor == NULL)
|
|
||||||
goto outOfMemory;
|
|
||||||
|
|
||||||
/* create the image representation and get the pointers to its storage */
|
|
||||||
imgrep =[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: w pixelsHigh: h bitsPerSample: 1 samplesPerPixel: 2 hasAlpha: YES isPlanar: YES colorSpaceName: NSDeviceBlackColorSpace bytesPerRow: (w + 7) / 8 bitsPerPixel:0] autorelease];
|
|
||||||
if (imgrep == nil)
|
|
||||||
goto outOfMemory;
|
|
||||||
[imgrep getBitmapDataPlanes:planes];
|
|
||||||
|
|
||||||
/* copy data and mask, extending the mask to all black pixels because the inversion effect doesn't work with Cocoa's alpha-blended cursors */
|
|
||||||
for (i = 0; i < (w + 7) / 8 * h; i++) {
|
|
||||||
planes[0][i] = data[i];
|
|
||||||
planes[1][i] = mask[i] | data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* create image and cursor */
|
|
||||||
img =[[[NSImage alloc] initWithSize:NSMakeSize(w, h)] autorelease];
|
|
||||||
if (img == nil)
|
|
||||||
goto outOfMemory;
|
|
||||||
[img addRepresentation:imgrep];
|
|
||||||
if (system_version < 0x1030) { /* on 10.2, cursors must be 16*16 */
|
|
||||||
if (w > 16 || h > 16) { /* too big: scale it down */
|
|
||||||
[img setScalesWhenResized:YES];
|
|
||||||
hot_x = hot_x * 16 / w;
|
|
||||||
hot_y = hot_y * 16 / h;
|
|
||||||
} else { /* too small (or just right): extend it (from the bottom left corner, so hot_y must be adjusted) */
|
|
||||||
hot_y += 16 - h;
|
|
||||||
}
|
|
||||||
[img setSize:NSMakeSize(16, 16)];
|
|
||||||
}
|
|
||||||
cursor->nscursor =[[NSCursor alloc] initWithImage: img hotSpot:NSMakePoint(hot_x,
|
|
||||||
hot_y)];
|
|
||||||
if (cursor->nscursor == nil)
|
|
||||||
goto outOfMemory;
|
|
||||||
|
|
||||||
[pool release];
|
|
||||||
return (cursor);
|
|
||||||
|
|
||||||
outOfMemory:
|
|
||||||
[pool release];
|
|
||||||
if (cursor != NULL)
|
|
||||||
SDL_free(cursor);
|
|
||||||
SDL_OutOfMemory();
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_ShowMouse(_THIS)
|
|
||||||
{
|
|
||||||
if (!cursor_visible) {
|
|
||||||
[NSCursor unhide];
|
|
||||||
cursor_visible = YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_HideMouse(_THIS)
|
|
||||||
{
|
|
||||||
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) {
|
|
||||||
[NSCursor hide];
|
|
||||||
cursor_visible = NO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL
|
|
||||||
QZ_IsMouseInWindow(_THIS)
|
|
||||||
{
|
|
||||||
if (qz_window == nil)
|
|
||||||
return YES; /*fullscreen */
|
|
||||||
else {
|
|
||||||
NSPoint p =[qz_window mouseLocationOutsideOfEventStream];
|
|
||||||
p.y -= 1.0f; /* Apparently y goes from 1 to h, not from 0 to h-1 (i.e. the "location of the mouse" seems to be defined as "the location of the top left corner of the mouse pointer's hot pixel" */
|
|
||||||
return NSPointInRect(p,[window_view frame]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
QZ_ShowWMCursor(_THIS, WMcursor * cursor)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (cursor == NULL) {
|
|
||||||
if (cursor_should_be_visible) {
|
|
||||||
QZ_HideMouse(this);
|
|
||||||
cursor_should_be_visible = NO;
|
|
||||||
QZ_ChangeGrabState(this, QZ_HIDECURSOR);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
[cursor->nscursor set];
|
|
||||||
if (!cursor_should_be_visible) {
|
|
||||||
QZ_ShowMouse(this);
|
|
||||||
cursor_should_be_visible = YES;
|
|
||||||
QZ_ChangeGrabState(this, QZ_SHOWCURSOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Coordinate conversion functions, for convenience
|
|
||||||
Cocoa sets the origin at the lower left corner of the window/screen
|
|
||||||
SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
|
|
||||||
The routines were written so they could be called before SetVideoMode() has finished;
|
|
||||||
this might have limited usefulness at the moment, but the extra cost is trivial.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Convert Cocoa screen coordinate to Cocoa window coordinate */
|
|
||||||
void
|
|
||||||
QZ_PrivateGlobalToLocal(_THIS, NSPoint * p)
|
|
||||||
{
|
|
||||||
|
|
||||||
*p =[qz_window convertScreenToBase:*p];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Convert Cocoa window coordinate to Cocoa screen coordinate */
|
|
||||||
void
|
|
||||||
QZ_PrivateLocalToGlobal(_THIS, NSPoint * p)
|
|
||||||
{
|
|
||||||
|
|
||||||
*p =[qz_window convertBaseToScreen:*p];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert SDL coordinate to Cocoa coordinate */
|
|
||||||
void
|
|
||||||
QZ_PrivateSDLToCocoa(_THIS, NSPoint * p)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
|
|
||||||
|
|
||||||
p->y = CGDisplayPixelsHigh(display_id) - p->y;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
*p =[window_view convertPoint: *p toView:nil];
|
|
||||||
|
|
||||||
/* We need a workaround in OpenGL mode */
|
|
||||||
if (SDL_VideoSurface->flags & SDL_OPENGL) {
|
|
||||||
p->y =[window_view frame].size.height - p->y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert Cocoa coordinate to SDL coordinate */
|
|
||||||
void
|
|
||||||
QZ_PrivateCocoaToSDL(_THIS, NSPoint * p)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
|
|
||||||
|
|
||||||
p->y = CGDisplayPixelsHigh(display_id) - p->y;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
*p =[window_view convertPoint: *p fromView:nil];
|
|
||||||
|
|
||||||
/* We need a workaround in OpenGL mode */
|
|
||||||
if (SDL_VideoSurface != NULL
|
|
||||||
&& (SDL_VideoSurface->flags & SDL_OPENGL)) {
|
|
||||||
p->y =[window_view frame].size.height - p->y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert SDL coordinate to window server (CoreGraphics) coordinate */
|
|
||||||
CGPoint
|
|
||||||
QZ_PrivateSDLToCG(_THIS, NSPoint * p)
|
|
||||||
{
|
|
||||||
|
|
||||||
CGPoint cgp;
|
|
||||||
|
|
||||||
if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
|
|
||||||
|
|
||||||
int height;
|
|
||||||
|
|
||||||
QZ_PrivateSDLToCocoa(this, p);
|
|
||||||
QZ_PrivateLocalToGlobal(this, p);
|
|
||||||
|
|
||||||
height = CGDisplayPixelsHigh(display_id);
|
|
||||||
p->y = height - p->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
cgp.x = p->x;
|
|
||||||
cgp.y = p->y;
|
|
||||||
|
|
||||||
return cgp;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0 /* Dead code */
|
|
||||||
/* Convert window server (CoreGraphics) coordinate to SDL coordinate */
|
|
||||||
void
|
|
||||||
QZ_PrivateCGToSDL(_THIS, NSPoint * p)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
|
|
||||||
|
|
||||||
int height;
|
|
||||||
|
|
||||||
/* Convert CG Global to Cocoa Global */
|
|
||||||
height = CGDisplayPixelsHigh(display_id);
|
|
||||||
p->y = height - p->y;
|
|
||||||
|
|
||||||
QZ_PrivateGlobalToLocal(this, p);
|
|
||||||
QZ_PrivateCocoaToSDL(this, p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* Dead code */
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_PrivateWarpCursor(_THIS, int x, int y)
|
|
||||||
{
|
|
||||||
|
|
||||||
NSPoint p;
|
|
||||||
CGPoint cgp;
|
|
||||||
|
|
||||||
p = NSMakePoint(x, y);
|
|
||||||
cgp = QZ_PrivateSDLToCG(this, &p);
|
|
||||||
|
|
||||||
/* this is the magic call that fixes cursor "freezing" after warp */
|
|
||||||
CGSetLocalEventsSuppressionInterval(0.0);
|
|
||||||
CGWarpMouseCursorPosition(cgp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Only allow warping when in foreground */
|
|
||||||
if (![NSApp isActive])
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Do the actual warp */
|
|
||||||
if (grab_state != QZ_INVISIBLE_GRAB)
|
|
||||||
QZ_PrivateWarpCursor(this, x, y);
|
|
||||||
|
|
||||||
/* Generate the mouse moved event */
|
|
||||||
SDL_PrivateMouseMotion(0, 0, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_MoveWMCursor(_THIS, int x, int y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void
|
|
||||||
QZ_CheckMouseMode(_THIS)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_SetCaption(_THIS, const char *title, const char *icon)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (qz_window != nil) {
|
|
||||||
NSString *string;
|
|
||||||
if (title != NULL) {
|
|
||||||
string =[[NSString alloc] initWithUTF8String:title];
|
|
||||||
[qz_window setTitle:string];
|
|
||||||
[string release];
|
|
||||||
}
|
|
||||||
if (icon != NULL) {
|
|
||||||
string =[[NSString alloc] initWithUTF8String:icon];
|
|
||||||
[qz_window setMiniwindowTitle:string];
|
|
||||||
[string release];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_SetIcon(_THIS, SDL_Surface * icon, Uint8 * mask)
|
|
||||||
{
|
|
||||||
NSBitmapImageRep *imgrep;
|
|
||||||
NSImage *img;
|
|
||||||
SDL_Surface *mergedSurface;
|
|
||||||
NSAutoreleasePool *pool;
|
|
||||||
Uint8 *pixels;
|
|
||||||
SDL_bool iconSrcAlpha;
|
|
||||||
Uint8 iconAlphaValue;
|
|
||||||
int i, j, maskPitch, index;
|
|
||||||
|
|
||||||
pool =[[NSAutoreleasePool alloc] init];
|
|
||||||
|
|
||||||
imgrep =[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4 * icon->w bitsPerPixel:32] autorelease];
|
|
||||||
if (imgrep == nil)
|
|
||||||
goto freePool;
|
|
||||||
pixels =[imgrep bitmapData];
|
|
||||||
SDL_memset(pixels, 0, 4 * icon->w * icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
|
|
||||||
|
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
||||||
#define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
|
|
||||||
#else
|
|
||||||
#define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
|
|
||||||
#endif
|
|
||||||
mergedSurface =
|
|
||||||
SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4 * icon->w,
|
|
||||||
BYTEORDER_DEPENDENT_RGBA_MASKS);
|
|
||||||
if (mergedSurface == NULL)
|
|
||||||
goto freePool;
|
|
||||||
|
|
||||||
/* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
|
|
||||||
iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
|
|
||||||
iconAlphaValue = icon->format->alpha;
|
|
||||||
SDL_SetAlpha(icon, 0, 255);
|
|
||||||
SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
|
|
||||||
if (iconSrcAlpha)
|
|
||||||
SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
|
|
||||||
|
|
||||||
SDL_FreeSurface(mergedSurface);
|
|
||||||
|
|
||||||
/* apply mask, source alpha, and premultiply color values by alpha */
|
|
||||||
maskPitch = (icon->w + 7) / 8;
|
|
||||||
for (i = 0; i < icon->h; i++) {
|
|
||||||
for (j = 0; j < icon->w; j++) {
|
|
||||||
index = i * 4 * icon->w + j * 4;
|
|
||||||
if (!(mask[i * maskPitch + j / 8] & (128 >> j % 8))) {
|
|
||||||
pixels[index + 3] = 0;
|
|
||||||
} else {
|
|
||||||
if (iconSrcAlpha) {
|
|
||||||
if (icon->format->Amask == 0)
|
|
||||||
pixels[index + 3] = icon->format->alpha;
|
|
||||||
} else {
|
|
||||||
pixels[index + 3] = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pixels[index + 3] < 255) {
|
|
||||||
pixels[index + 0] =
|
|
||||||
(Uint16) pixels[index + 0] * pixels[index + 3] / 255;
|
|
||||||
pixels[index + 1] =
|
|
||||||
(Uint16) pixels[index + 1] * pixels[index + 3] / 255;
|
|
||||||
pixels[index + 2] =
|
|
||||||
(Uint16) pixels[index + 2] * pixels[index + 3] / 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
img =[[[NSImage alloc] initWithSize:NSMakeSize(icon->w,
|
|
||||||
icon->h)] autorelease];
|
|
||||||
if (img == nil)
|
|
||||||
goto freePool;
|
|
||||||
[img addRepresentation:imgrep];
|
|
||||||
[NSApp setApplicationIconImage:img];
|
|
||||||
|
|
||||||
freePool:
|
|
||||||
[pool release];
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
QZ_IconifyWindow(_THIS)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (![qz_window isMiniaturized]) {
|
|
||||||
[qz_window miniaturize:nil];
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
SDL_SetError("window already iconified");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) {
|
|
||||||
info->nsWindowPtr = qz_window;
|
|
||||||
return 0;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void
|
|
||||||
QZ_ChangeGrabState(_THIS, int action)
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
Figure out what the next state should be based on the action.
|
|
||||||
Ignore actions that can't change the current state.
|
|
||||||
*/
|
|
||||||
if (grab_state == QZ_UNGRABBED) {
|
|
||||||
if (action == QZ_ENABLE_GRAB) {
|
|
||||||
if (cursor_should_be_visible)
|
|
||||||
grab_state = QZ_VISIBLE_GRAB;
|
|
||||||
else
|
|
||||||
grab_state = QZ_INVISIBLE_GRAB;
|
|
||||||
}
|
|
||||||
} else if (grab_state == QZ_VISIBLE_GRAB) {
|
|
||||||
if (action == QZ_DISABLE_GRAB)
|
|
||||||
grab_state = QZ_UNGRABBED;
|
|
||||||
else if (action == QZ_HIDECURSOR)
|
|
||||||
grab_state = QZ_INVISIBLE_GRAB;
|
|
||||||
} else {
|
|
||||||
assert(grab_state == QZ_INVISIBLE_GRAB);
|
|
||||||
|
|
||||||
if (action == QZ_DISABLE_GRAB)
|
|
||||||
grab_state = QZ_UNGRABBED;
|
|
||||||
else if (action == QZ_SHOWCURSOR)
|
|
||||||
grab_state = QZ_VISIBLE_GRAB;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now apply the new state */
|
|
||||||
if (grab_state == QZ_UNGRABBED) {
|
|
||||||
|
|
||||||
CGAssociateMouseAndMouseCursorPosition(1);
|
|
||||||
} else if (grab_state == QZ_VISIBLE_GRAB) {
|
|
||||||
|
|
||||||
CGAssociateMouseAndMouseCursorPosition(1);
|
|
||||||
} else {
|
|
||||||
assert(grab_state == QZ_INVISIBLE_GRAB);
|
|
||||||
|
|
||||||
QZ_PrivateWarpCursor(this, SDL_VideoSurface->w / 2,
|
|
||||||
SDL_VideoSurface->h / 2);
|
|
||||||
CGAssociateMouseAndMouseCursorPosition(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_GrabMode
|
|
||||||
QZ_GrabInput(_THIS, SDL_GrabMode grab_mode)
|
|
||||||
{
|
|
||||||
|
|
||||||
int doGrab = grab_mode & SDL_GRAB_ON;
|
|
||||||
/*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN; */
|
|
||||||
|
|
||||||
if (this->screen == NULL) {
|
|
||||||
SDL_SetError("QZ_GrabInput: screen is NULL");
|
|
||||||
return SDL_GRAB_OFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!video_set) {
|
|
||||||
/*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */
|
|
||||||
current_grab_mode = grab_mode;
|
|
||||||
return grab_mode; /* Will be set later on mode switch */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grab_mode != SDL_GRAB_QUERY) {
|
|
||||||
if (doGrab)
|
|
||||||
QZ_ChangeGrabState(this, QZ_ENABLE_GRAB);
|
|
||||||
else
|
|
||||||
QZ_ChangeGrabState(this, QZ_DISABLE_GRAB);
|
|
||||||
|
|
||||||
current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
return current_grab_mode;
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2003 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
#include "SDL_config.h"
|
|
||||||
|
|
||||||
/* Subclass of NSWindow to fix genie effect and support resize events */
|
|
||||||
@ interface SDL_QuartzWindow: NSWindow - (void) miniaturize:(id) sender;
|
|
||||||
-(void) display;
|
|
||||||
-(void) setFrame:(NSRect)
|
|
||||||
frameRect display:(BOOL) flag;
|
|
||||||
-(void) appDidHide:(NSNotification *) note;
|
|
||||||
-(void) appWillUnhide:(NSNotification *) note;
|
|
||||||
-(void) appDidUnhide:(NSNotification *) note;
|
|
||||||
-(id) initWithContentRect:(NSRect)
|
|
||||||
contentRect styleMask:(unsigned int)
|
|
||||||
styleMask backing:(NSBackingStoreType)
|
|
||||||
backingType defer:(BOOL) flag;
|
|
||||||
@end
|
|
||||||
/* Delegate for our NSWindow to send SDLQuit() on close */
|
|
||||||
@ interface SDL_QuartzWindowDelegate: NSObject - (BOOL) windowShouldClose:(id)
|
|
||||||
sender;
|
|
||||||
@end
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -1,214 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2003 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
#include "SDL_config.h"
|
|
||||||
|
|
||||||
#include "SDL_QuartzVideo.h"
|
|
||||||
#include "SDL_QuartzWindow.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
This function makes the *SDL region* of the window 100% opaque.
|
|
||||||
The genie effect uses the alpha component. Otherwise,
|
|
||||||
it doesn't seem to matter what value it has.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
QZ_SetPortAlphaOpaque ()
|
|
||||||
{
|
|
||||||
|
|
||||||
SDL_Surface *surface = current_video->screen;
|
|
||||||
int bpp;
|
|
||||||
|
|
||||||
bpp = surface->format->BitsPerPixel;
|
|
||||||
|
|
||||||
if (bpp == 32) {
|
|
||||||
|
|
||||||
Uint32 *pixels = (Uint32 *) surface->pixels;
|
|
||||||
Uint32 rowPixels = surface->pitch / 4;
|
|
||||||
Uint32 i, j;
|
|
||||||
|
|
||||||
for (i = 0; i < surface->h; i++)
|
|
||||||
for (j = 0; j < surface->w; j++) {
|
|
||||||
|
|
||||||
pixels[(i * rowPixels) + j] |= 0xFF000000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@implementation SDL_QuartzWindow
|
|
||||||
/* we override these methods to fix the miniaturize animation/dock icon bug */
|
|
||||||
- (void) miniaturize:(id) sender {
|
|
||||||
if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
Future: Grab framebuffer and put into NSImage
|
|
||||||
[ qz_window setMiniwindowImage:image ];
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/* make the alpha channel opaque so anim won't have holes in it */
|
|
||||||
QZ_SetPortAlphaOpaque ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* window is hidden now */
|
|
||||||
SDL_PrivateAppActive (0, SDL_APPACTIVE);
|
|
||||||
|
|
||||||
[super miniaturize:sender];
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) display {
|
|
||||||
/*
|
|
||||||
This method fires just before the window deminaturizes from the Dock.
|
|
||||||
|
|
||||||
We'll save the current visible surface, let the window manager redraw any
|
|
||||||
UI elements, and restore the SDL surface. This way, no expose event
|
|
||||||
is required, and the deminiaturize works perfectly.
|
|
||||||
*/
|
|
||||||
SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
|
|
||||||
|
|
||||||
/* make sure pixels are fully opaque */
|
|
||||||
if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL))
|
|
||||||
QZ_SetPortAlphaOpaque ();
|
|
||||||
|
|
||||||
/* save current visible SDL surface */
|
|
||||||
[self cacheImageInRect:[window_view frame]];
|
|
||||||
|
|
||||||
/* let the window manager redraw controls, border, etc */
|
|
||||||
[super display];
|
|
||||||
|
|
||||||
/* restore visible SDL surface */
|
|
||||||
[self restoreCachedImage];
|
|
||||||
|
|
||||||
/* window is visible again */
|
|
||||||
SDL_PrivateAppActive (1, SDL_APPACTIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) setFrame:(NSRect)
|
|
||||||
frameRect display:(BOOL) flag
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
If the video surface is NULL, this originated from QZ_SetVideoMode,
|
|
||||||
so don't send the resize event.
|
|
||||||
*/
|
|
||||||
SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
|
|
||||||
|
|
||||||
if (this && SDL_VideoSurface == NULL) {
|
|
||||||
|
|
||||||
[super setFrame: frameRect display:flag];
|
|
||||||
} else if (this && qz_window) {
|
|
||||||
|
|
||||||
NSRect newViewFrame;
|
|
||||||
|
|
||||||
[super setFrame: frameRect display:flag];
|
|
||||||
|
|
||||||
newViewFrame =[window_view frame];
|
|
||||||
|
|
||||||
SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height);
|
|
||||||
|
|
||||||
/* If not OpenGL, we have to update the pixels and pitch */
|
|
||||||
if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL)) {
|
|
||||||
|
|
||||||
CGrafPtr thePort =[window_view qdPort];
|
|
||||||
LockPortBits (thePort);
|
|
||||||
|
|
||||||
SDL_VideoSurface->pixels =
|
|
||||||
GetPixBaseAddr (GetPortPixMap (thePort));
|
|
||||||
SDL_VideoSurface->pitch =
|
|
||||||
GetPixRowBytes (GetPortPixMap (thePort));
|
|
||||||
|
|
||||||
/*
|
|
||||||
SDL_VideoSurface->pixels now points to the window's pixels
|
|
||||||
We want it to point to the *view's* pixels
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
int vOffset =[qz_window frame].size.height -
|
|
||||||
newViewFrame.size.height - newViewFrame.origin.y;
|
|
||||||
|
|
||||||
int hOffset = newViewFrame.origin.x;
|
|
||||||
|
|
||||||
SDL_VideoSurface->pixels =
|
|
||||||
(Uint8 *) SDL_VideoSurface->pixels +
|
|
||||||
(vOffset * SDL_VideoSurface->pitch) +
|
|
||||||
hOffset * (device_bpp / 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
UnlockPortBits (thePort);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) appDidHide:(NSNotification *) note {
|
|
||||||
SDL_PrivateAppActive (0, SDL_APPACTIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) appWillUnhide:(NSNotification *) note {
|
|
||||||
SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
|
|
||||||
|
|
||||||
if (this) {
|
|
||||||
|
|
||||||
/* make sure pixels are fully opaque */
|
|
||||||
if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL))
|
|
||||||
QZ_SetPortAlphaOpaque ();
|
|
||||||
|
|
||||||
/* save current visible SDL surface */
|
|
||||||
[self cacheImageInRect:[window_view frame]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) appDidUnhide:(NSNotification *) note {
|
|
||||||
/* restore cached image, since it may not be current, post expose event too */
|
|
||||||
[self restoreCachedImage];
|
|
||||||
|
|
||||||
/*SDL_PrivateExpose (); */
|
|
||||||
|
|
||||||
SDL_PrivateAppActive (1, SDL_APPACTIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
-(id) initWithContentRect:(NSRect)
|
|
||||||
contentRect styleMask:(unsigned int)
|
|
||||||
styleMask backing:(NSBackingStoreType)
|
|
||||||
backingType defer:(BOOL) flag
|
|
||||||
{
|
|
||||||
/* Make our window subclass receive these application notifications */
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appDidHide: )name: NSApplicationDidHideNotification object:NSApp];
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appDidUnhide: )name: NSApplicationDidUnhideNotification object:NSApp];
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appWillUnhide: )name: NSApplicationWillUnhideNotification object:NSApp];
|
|
||||||
|
|
||||||
return[super initWithContentRect: contentRect styleMask: styleMask backing: backingType defer:flag];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end @ implementation SDL_QuartzWindowDelegate - (BOOL) windowShouldClose:(id) sender
|
|
||||||
{
|
|
||||||
SDL_PrivateQuit ();
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) windowDidBecomeKey:(NSNotification *) aNotification {
|
|
||||||
QZ_DoActivate (current_video);
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) windowDidResignKey:(NSNotification *) aNotification {
|
|
||||||
QZ_DoDeactivate (current_video);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,330 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2003 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
#include "SDL_config.h"
|
|
||||||
|
|
||||||
#include "SDL_QuartzVideo.h"
|
|
||||||
#include "SDL_QuartzWindow.h"
|
|
||||||
#include "../SDL_yuvfuncs.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define yuv_idh (this->hidden->yuv_idh)
|
|
||||||
#define yuv_matrix (this->hidden->yuv_matrix)
|
|
||||||
#define yuv_codec (this->hidden->yuv_codec)
|
|
||||||
#define yuv_seq (this->hidden->yuv_seq)
|
|
||||||
#define yuv_pixmap (this->hidden->yuv_pixmap)
|
|
||||||
#define yuv_data (this->hidden->yuv_data)
|
|
||||||
#define yuv_width (this->hidden->yuv_width)
|
|
||||||
#define yuv_height (this->hidden->yuv_height)
|
|
||||||
#define yuv_port (this->hidden->yuv_port)
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
QZ_LockYUV (_THIS, SDL_Overlay * overlay)
|
|
||||||
{
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
QZ_UnlockYUV (_THIS, SDL_Overlay * overlay)
|
|
||||||
{
|
|
||||||
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
QZ_DisplayYUV (_THIS, SDL_Overlay * overlay, SDL_Rect * src, SDL_Rect * dst)
|
|
||||||
{
|
|
||||||
|
|
||||||
OSErr err;
|
|
||||||
CodecFlags flags;
|
|
||||||
|
|
||||||
if (dst->x != 0 || dst->y != 0) {
|
|
||||||
|
|
||||||
SDL_SetError ("Need a dst at (0,0)");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dst->w != yuv_width || dst->h != yuv_height) {
|
|
||||||
|
|
||||||
Fixed scale_x, scale_y;
|
|
||||||
|
|
||||||
scale_x = FixDiv (Long2Fix (dst->w), Long2Fix (overlay->w));
|
|
||||||
scale_y = FixDiv (Long2Fix (dst->h), Long2Fix (overlay->h));
|
|
||||||
|
|
||||||
SetIdentityMatrix (yuv_matrix);
|
|
||||||
ScaleMatrix (yuv_matrix, scale_x, scale_y, Long2Fix (0),
|
|
||||||
Long2Fix (0));
|
|
||||||
|
|
||||||
SetDSequenceMatrix (yuv_seq, yuv_matrix);
|
|
||||||
|
|
||||||
yuv_width = dst->w;
|
|
||||||
yuv_height = dst->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((err = DecompressSequenceFrameS (yuv_seq,
|
|
||||||
(void *) yuv_pixmap,
|
|
||||||
sizeof (PlanarPixmapInfoYUV420),
|
|
||||||
codecFlagUseImageBuffer, &flags,
|
|
||||||
nil) != noErr)) {
|
|
||||||
SDL_SetError ("DecompressSequenceFrameS failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
return err != noErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
QZ_FreeHWYUV (_THIS, SDL_Overlay * overlay)
|
|
||||||
{
|
|
||||||
|
|
||||||
CDSequenceEnd (yuv_seq);
|
|
||||||
ExitMovies ();
|
|
||||||
|
|
||||||
SDL_free (overlay->hwfuncs);
|
|
||||||
SDL_free (overlay->pitches);
|
|
||||||
SDL_free (overlay->pixels);
|
|
||||||
|
|
||||||
if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
|
|
||||||
[qz_window close];
|
|
||||||
qz_window = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free (yuv_matrix);
|
|
||||||
DisposeHandle ((Handle) yuv_idh);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check for 16 byte alignment, bail otherwise */
|
|
||||||
#define CHECK_ALIGN(x) do { if ((Uint32)x & 15) { SDL_SetError("Alignment error"); return NULL; } } while(0)
|
|
||||||
|
|
||||||
/* align a byte offset, return how much to add to make it a multiple of 16 */
|
|
||||||
#define ALIGN(x) ((16 - (x & 15)) & 15)
|
|
||||||
|
|
||||||
SDL_Overlay *
|
|
||||||
QZ_CreateYUVOverlay (_THIS, int width, int height,
|
|
||||||
Uint32 format, SDL_Surface * display)
|
|
||||||
{
|
|
||||||
|
|
||||||
Uint32 codec;
|
|
||||||
OSStatus err;
|
|
||||||
CGrafPtr port;
|
|
||||||
SDL_Overlay *overlay;
|
|
||||||
|
|
||||||
if (format == SDL_YV12_OVERLAY || format == SDL_IYUV_OVERLAY) {
|
|
||||||
|
|
||||||
codec = kYUV420CodecType;
|
|
||||||
} else {
|
|
||||||
SDL_SetError ("Hardware: unsupported video format");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
yuv_idh =
|
|
||||||
(ImageDescriptionHandle) NewHandleClear (sizeof (ImageDescription));
|
|
||||||
if (yuv_idh == NULL) {
|
|
||||||
SDL_OutOfMemory ();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
yuv_matrix = (MatrixRecordPtr) SDL_malloc (sizeof (MatrixRecord));
|
|
||||||
if (yuv_matrix == NULL) {
|
|
||||||
SDL_OutOfMemory ();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EnterMovies () != noErr) {
|
|
||||||
SDL_SetError ("Could not init QuickTime for YUV playback");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = FindCodec (codec, bestSpeedCodec, nil, &yuv_codec);
|
|
||||||
if (err != noErr) {
|
|
||||||
SDL_SetError ("Could not find QuickTime codec for format");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
Acceleration requires a window to be present.
|
|
||||||
A CGrafPtr that points to the screen isn't good enough
|
|
||||||
*/
|
|
||||||
NSRect content =
|
|
||||||
NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
|
|
||||||
|
|
||||||
qz_window =[[SDL_QuartzWindow alloc] initWithContentRect: content styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer:NO];
|
|
||||||
|
|
||||||
if (qz_window == nil) {
|
|
||||||
SDL_SetError ("Could not create the Cocoa window");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
[qz_window setContentView:[[NSQuickDrawView alloc] init]];
|
|
||||||
[qz_window setReleasedWhenClosed:YES];
|
|
||||||
[qz_window center];
|
|
||||||
[qz_window setAcceptsMouseMovedEvents:YES];
|
|
||||||
[qz_window setLevel:CGShieldingWindowLevel ()];
|
|
||||||
[qz_window makeKeyAndOrderFront:nil];
|
|
||||||
|
|
||||||
port =[[qz_window contentView] qdPort];
|
|
||||||
SetPort (port);
|
|
||||||
|
|
||||||
/*
|
|
||||||
BUG: would like to remove white flash when window kicks in
|
|
||||||
{
|
|
||||||
Rect r;
|
|
||||||
SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
|
|
||||||
PaintRect (&r);
|
|
||||||
QDFlushPortBuffer (port, nil);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
port =[window_view qdPort];
|
|
||||||
SetPort (port);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetIdentityMatrix (yuv_matrix);
|
|
||||||
|
|
||||||
HLock ((Handle) yuv_idh);
|
|
||||||
|
|
||||||
(**yuv_idh).idSize = sizeof (ImageDescription);
|
|
||||||
(**yuv_idh).cType = codec;
|
|
||||||
(**yuv_idh).version = 1;
|
|
||||||
(**yuv_idh).revisionLevel = 0;
|
|
||||||
(**yuv_idh).width = width;
|
|
||||||
(**yuv_idh).height = height;
|
|
||||||
(**yuv_idh).hRes = Long2Fix (72);
|
|
||||||
(**yuv_idh).vRes = Long2Fix (72);
|
|
||||||
(**yuv_idh).spatialQuality = codecLosslessQuality;
|
|
||||||
(**yuv_idh).frameCount = 1;
|
|
||||||
(**yuv_idh).clutID = -1;
|
|
||||||
(**yuv_idh).dataSize = 0;
|
|
||||||
(**yuv_idh).depth = 24;
|
|
||||||
|
|
||||||
HUnlock ((Handle) yuv_idh);
|
|
||||||
|
|
||||||
err = DecompressSequenceBeginS (&yuv_seq,
|
|
||||||
yuv_idh,
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
port,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
yuv_matrix,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
codecFlagUseImageBuffer,
|
|
||||||
codecLosslessQuality, yuv_codec);
|
|
||||||
|
|
||||||
if (err != noErr) {
|
|
||||||
SDL_SetError ("Error trying to start YUV codec.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
overlay = (SDL_Overlay *) SDL_malloc (sizeof (*overlay));
|
|
||||||
if (overlay == NULL) {
|
|
||||||
SDL_OutOfMemory ();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
overlay->format = format;
|
|
||||||
overlay->w = width;
|
|
||||||
overlay->h = height;
|
|
||||||
overlay->planes = 3;
|
|
||||||
overlay->hw_overlay = 1;
|
|
||||||
{
|
|
||||||
int offset;
|
|
||||||
Uint8 **pixels;
|
|
||||||
Uint16 *pitches;
|
|
||||||
int plane2, plane3;
|
|
||||||
|
|
||||||
if (format == SDL_IYUV_OVERLAY) {
|
|
||||||
|
|
||||||
plane2 = 1; /* Native codec format */
|
|
||||||
plane3 = 2;
|
|
||||||
} else if (format == SDL_YV12_OVERLAY) {
|
|
||||||
|
|
||||||
/* switch the U and V planes */
|
|
||||||
plane2 = 2; /* U plane maps to plane 3 */
|
|
||||||
plane3 = 1; /* V plane maps to plane 2 */
|
|
||||||
} else {
|
|
||||||
SDL_SetError ("Unsupported YUV format");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pixels = (Uint8 **) SDL_malloc (sizeof (*pixels) * 3);
|
|
||||||
pitches = (Uint16 *) SDL_malloc (sizeof (*pitches) * 3);
|
|
||||||
if (pixels == NULL || pitches == NULL) {
|
|
||||||
SDL_OutOfMemory ();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
yuv_pixmap = (PlanarPixmapInfoYUV420 *)
|
|
||||||
SDL_malloc (sizeof (PlanarPixmapInfoYUV420) +
|
|
||||||
(width * height * 2));
|
|
||||||
if (yuv_pixmap == NULL) {
|
|
||||||
SDL_OutOfMemory ();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* CHECK_ALIGN(yuv_pixmap); */
|
|
||||||
offset = sizeof (PlanarPixmapInfoYUV420);
|
|
||||||
/* offset += ALIGN(offset); */
|
|
||||||
/* CHECK_ALIGN(offset); */
|
|
||||||
|
|
||||||
pixels[0] = (Uint8 *) yuv_pixmap + offset;
|
|
||||||
/* CHECK_ALIGN(pixels[0]); */
|
|
||||||
|
|
||||||
pitches[0] = width;
|
|
||||||
yuv_pixmap->componentInfoY.offset = offset;
|
|
||||||
yuv_pixmap->componentInfoY.rowBytes = width;
|
|
||||||
|
|
||||||
offset += width * height;
|
|
||||||
pixels[plane2] = (Uint8 *) yuv_pixmap + offset;
|
|
||||||
pitches[plane2] = width / 2;
|
|
||||||
yuv_pixmap->componentInfoCb.offset = offset;
|
|
||||||
yuv_pixmap->componentInfoCb.rowBytes = width / 2;
|
|
||||||
|
|
||||||
offset += (width * height / 4);
|
|
||||||
pixels[plane3] = (Uint8 *) yuv_pixmap + offset;
|
|
||||||
pitches[plane3] = width / 2;
|
|
||||||
yuv_pixmap->componentInfoCr.offset = offset;
|
|
||||||
yuv_pixmap->componentInfoCr.rowBytes = width / 2;
|
|
||||||
|
|
||||||
overlay->pixels = pixels;
|
|
||||||
overlay->pitches = pitches;
|
|
||||||
}
|
|
||||||
|
|
||||||
overlay->hwfuncs = SDL_malloc (sizeof (*overlay->hwfuncs));
|
|
||||||
if (overlay->hwfuncs == NULL) {
|
|
||||||
SDL_OutOfMemory ();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
overlay->hwfuncs->Lock = QZ_LockYUV;
|
|
||||||
overlay->hwfuncs->Unlock = QZ_UnlockYUV;
|
|
||||||
overlay->hwfuncs->Display = QZ_DisplayYUV;
|
|
||||||
overlay->hwfuncs->FreeHW = QZ_FreeHWYUV;
|
|
||||||
|
|
||||||
yuv_width = overlay->w;
|
|
||||||
yuv_height = overlay->h;
|
|
||||||
|
|
||||||
return overlay;
|
|
||||||
}
|
|
@ -3,6 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user