mirror of
https://github.com/yawut/SDL.git
synced 2026-08-11 19:45:43 -05:00
Unpacked project archives to get individual file history in subversion
This commit is contained in:
Binary file not shown.
28
Xcode/TemplatesForXcode/SDL Application/Info.plist
Normal file
28
Xcode/TemplatesForXcode/SDL Application/Info.plist
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.yourcompany.«PROJECTNAMEASXML»</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>SDLMain</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
FilesToRename = {
|
||||
"SDLApp_Prefix.pch" = "<22>PROJECTNAME<4D>_Prefix.pch";
|
||||
};
|
||||
FilesToMacroExpand = (
|
||||
"<22>PROJECTNAME<4D>_Prefix.pch",
|
||||
"Info.plist",
|
||||
"English.lproj/InfoPlist.strings",
|
||||
"main.c",
|
||||
);
|
||||
Description = "This project builds an SDL-based application.";
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 42;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
002F39FA09D0881F00EBEB88 /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 002F39F909D0881F00EBEB88 /* SDL.framework */; };
|
||||
002F3A0009D0884600EBEB88 /* SDL.framework in Copy Frameworks into .app bundle */ = {isa = PBXBuildFile; fileRef = 002F39F909D0881F00EBEB88 /* SDL.framework */; };
|
||||
002F3A2E09D0888800EBEB88 /* SDLMain.m in Sources */ = {isa = PBXBuildFile; fileRef = 002F3A2C09D0888800EBEB88 /* SDLMain.m */; };
|
||||
002F3A3F09D088BA00EBEB88 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F3A3E09D088BA00EBEB88 /* main.c */; };
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXBuildStyle section */
|
||||
4A9504CCFFE6A4B311CA0CBA /* Debug */ = {
|
||||
isa = PBXBuildStyle;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
4A9504CDFFE6A4B311CA0CBA /* Release */ = {
|
||||
isa = PBXBuildStyle;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End PBXBuildStyle section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
002F39FD09D0883400EBEB88 /* Copy Frameworks into .app bundle */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
002F3A0009D0884600EBEB88 /* SDL.framework in Copy Frameworks into .app bundle */,
|
||||
);
|
||||
name = "Copy Frameworks into .app bundle";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
002F39F909D0881F00EBEB88 /* SDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL.framework; path = /Library/Frameworks/SDL.framework; sourceTree = "<absolute>"; };
|
||||
002F3A2B09D0888800EBEB88 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SDLMain.h; sourceTree = SOURCE_ROOT; };
|
||||
002F3A2C09D0888800EBEB88 /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SDLMain.m; sourceTree = SOURCE_ROOT; };
|
||||
002F3A3E09D088BA00EBEB88 /* main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = SOURCE_ROOT; };
|
||||
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||
32CA4F630368D1EE00C91783 /* «PROJECTNAME»_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; path = "«PROJECTNAME»_Prefix.pch"; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
|
||||
8D1107320486CEB800E47090 /* «PROJECTNAME».app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "«PROJECTNAME».app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
8D11072E0486CEB800E47090 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
002F39FA09D0881F00EBEB88 /* SDL.framework in Frameworks */,
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
080E96DDFE201D6D7F000001 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F3A2B09D0888800EBEB88 /* SDLMain.h */,
|
||||
002F3A2C09D0888800EBEB88 /* SDLMain.m */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F39F909D0881F00EBEB88 /* SDL.framework */,
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
|
||||
);
|
||||
name = "Linked Frameworks";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
|
||||
);
|
||||
name = "Other Frameworks";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
19C28FACFE9D520D11CA2CBB /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8D1107320486CEB800E47090 /* «PROJECTNAME».app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97314FDCFA39411CA2CEA /* «PROJECTNAMEASXML» */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
080E96DDFE201D6D7F000001 /* Classes */,
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */,
|
||||
29B97317FDCFA39411CA2CEA /* Resources */,
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */,
|
||||
19C28FACFE9D520D11CA2CBB /* Products */,
|
||||
);
|
||||
name = "«PROJECTNAMEASXML»";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32CA4F630368D1EE00C91783 /* «PROJECTNAME»_Prefix.pch */,
|
||||
002F3A3E09D088BA00EBEB88 /* main.c */,
|
||||
);
|
||||
name = "Other Sources";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97317FDCFA39411CA2CEA /* Resources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8D1107310486CEB800E47090 /* Info.plist */,
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
|
||||
);
|
||||
name = Resources;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
8D1107260486CEB800E47090 /* «PROJECTNAME» */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "«PROJECTNAME»" */;
|
||||
buildPhases = (
|
||||
8D1107290486CEB800E47090 /* Resources */,
|
||||
8D11072C0486CEB800E47090 /* Sources */,
|
||||
8D11072E0486CEB800E47090 /* Frameworks */,
|
||||
002F39FD09D0883400EBEB88 /* Copy Frameworks into .app bundle */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
buildSettings = {
|
||||
};
|
||||
dependencies = (
|
||||
);
|
||||
name = "«PROJECTNAME»";
|
||||
productInstallPath = "$(HOME)/Applications";
|
||||
productName = "«PROJECTNAME»";
|
||||
productReference = 8D1107320486CEB800E47090 /* «PROJECTNAME».app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
29B97313FDCFA39411CA2CEA /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLApp" */;
|
||||
buildSettings = {
|
||||
};
|
||||
buildStyles = (
|
||||
4A9504CCFFE6A4B311CA0CBA /* Debug */,
|
||||
4A9504CDFFE6A4B311CA0CBA /* Release */,
|
||||
);
|
||||
hasScannedForEncodings = 1;
|
||||
mainGroup = 29B97314FDCFA39411CA2CEA /* «PROJECTNAMEASXML» */;
|
||||
projectDirPath = "";
|
||||
targets = (
|
||||
8D1107260486CEB800E47090 /* «PROJECTNAME» */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
8D1107290486CEB800E47090 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
8D11072C0486CEB800E47090 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
002F3A2E09D0888800EBEB88 /* SDLMain.m in Sources */,
|
||||
002F3A3F09D088BA00EBEB88 /* main.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
089C165DFE840E0CC02AAC07 /* English */,
|
||||
);
|
||||
name = InfoPlist.strings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
C01FCF4B08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = YES;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(HOME)/Applications";
|
||||
PRODUCT_NAME = "«PROJECTNAME»";
|
||||
WRAPPER_EXTENSION = app;
|
||||
ZERO_LINK = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
C01FCF4C08A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = (
|
||||
ppc,
|
||||
i386,
|
||||
);
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(HOME)/Applications";
|
||||
PRODUCT_NAME = "«PROJECTNAME»";
|
||||
WRAPPER_EXTENSION = app;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
C01FCF4F08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks",
|
||||
/Library/Frameworks,
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks/SDL.framework/Headers",
|
||||
/Library/Frameworks/SDL.framework/Headers,
|
||||
"$(HEADER_SEARCH_PATHS)",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
C01FCF5008A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks",
|
||||
/Library/Frameworks,
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks/SDL.framework/Headers",
|
||||
/Library/Frameworks/SDL.framework/Headers,
|
||||
"$(HEADER_SEARCH_PATHS)",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "«PROJECTNAME»" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
C01FCF4B08A954540054247B /* Debug */,
|
||||
C01FCF4C08A954540054247B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLApp" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
C01FCF4F08A954540054247B /* Debug */,
|
||||
C01FCF5008A954540054247B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// Prefix header for all source files of the '<27>PROJECTNAME<4D>' target in the '<27>PROJECTNAME<4D>' project
|
||||
//
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
11
Xcode/TemplatesForXcode/SDL Application/SDLMain.h
Normal file
11
Xcode/TemplatesForXcode/SDL Application/SDLMain.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/* 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
|
||||
383
Xcode/TemplatesForXcode/SDL Application/SDLMain.m
Normal file
383
Xcode/TemplatesForXcode/SDL Application/SDLMain.m
Normal file
@@ -0,0 +1,383 @@
|
||||
/* 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;
|
||||
}
|
||||
65
Xcode/TemplatesForXcode/SDL Application/main.c
Normal file
65
Xcode/TemplatesForXcode/SDL Application/main.c
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
/* Simple program: Create a blank window, wait for keypress, quit.
|
||||
|
||||
Please see the SDL documentation for details on using the SDL API:
|
||||
/Developer/Documentation/SDL/docs.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Uint32 initflags = SDL_INIT_VIDEO; /* See documentation for details */
|
||||
SDL_Surface *screen;
|
||||
Uint8 video_bpp = 0;
|
||||
Uint32 videoflags = SDL_SWSURFACE;
|
||||
int done;
|
||||
SDL_Event event;
|
||||
|
||||
/* Initialize the SDL library */
|
||||
if ( SDL_Init(initflags) < 0 ) {
|
||||
fprintf(stderr, "Couldn't initialize SDL: %s\n",
|
||||
SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
screen=SDL_SetVideoMode(640,480, video_bpp, videoflags);
|
||||
if (screen == NULL) {
|
||||
fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
|
||||
video_bpp, SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
done = 0;
|
||||
while ( !done ) {
|
||||
|
||||
/* Check for events */
|
||||
while ( SDL_PollEvent(&event) ) {
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
/* Any keypress quits the app... */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up the SDL library */
|
||||
SDL_Quit();
|
||||
return(0);
|
||||
}
|
||||
Binary file not shown.
19
Xcode/TemplatesForXcode/SDL Cocoa Application/English.lproj/SDLMain.nib/classes.nib
generated
Normal file
19
Xcode/TemplatesForXcode/SDL Cocoa Application/English.lproj/SDLMain.nib/classes.nib
generated
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
IBClasses = (
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
ACTIONS = {
|
||||
help = id;
|
||||
newGame = id;
|
||||
openGame = id;
|
||||
prefsMenu = id;
|
||||
saveGame = id;
|
||||
saveGameAs = id;
|
||||
};
|
||||
CLASS = SDLMain;
|
||||
LANGUAGE = ObjC;
|
||||
SUPERCLASS = NSObject;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
||||
21
Xcode/TemplatesForXcode/SDL Cocoa Application/English.lproj/SDLMain.nib/info.nib
generated
Normal file
21
Xcode/TemplatesForXcode/SDL Cocoa Application/English.lproj/SDLMain.nib/info.nib
generated
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>62 117 356 240 0 0 1152 848 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>29</key>
|
||||
<string>62 362 195 44 0 0 1152 848 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>291.0</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>29</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>6L60</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
Xcode/TemplatesForXcode/SDL Cocoa Application/English.lproj/SDLMain.nib/objects.nib
generated
Normal file
BIN
Xcode/TemplatesForXcode/SDL Cocoa Application/English.lproj/SDLMain.nib/objects.nib
generated
Normal file
Binary file not shown.
28
Xcode/TemplatesForXcode/SDL Cocoa Application/Info.plist
Normal file
28
Xcode/TemplatesForXcode/SDL Cocoa Application/Info.plist
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.yourcompany.«PROJECTNAMEASXML»</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>SDLMain</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// Prefix header for all source files of the '<27>PROJECTNAME<4D>' target in the '<27>PROJECTNAME<4D>' project
|
||||
//
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
FilesToRename = {
|
||||
"SDLApp_Prefix.pch" = "<22>PROJECTNAME<4D>_Prefix.pch";
|
||||
};
|
||||
FilesToMacroExpand = (
|
||||
"<22>PROJECTNAME<4D>_Prefix.pch",
|
||||
"Info.plist",
|
||||
"English.lproj/InfoPlist.strings",
|
||||
"main.c",
|
||||
);
|
||||
Description = "This project builds an SDL-based application with Cocoa menus.";
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 42;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
002F39FA09D0881F00EBEB88 /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 002F39F909D0881F00EBEB88 /* SDL.framework */; };
|
||||
002F3A0009D0884600EBEB88 /* SDL.framework in Copy Frameworks into .app bundle */ = {isa = PBXBuildFile; fileRef = 002F39F909D0881F00EBEB88 /* SDL.framework */; };
|
||||
002F3A2E09D0888800EBEB88 /* SDLMain.m in Sources */ = {isa = PBXBuildFile; fileRef = 002F3A2C09D0888800EBEB88 /* SDLMain.m */; };
|
||||
002F3A3F09D088BA00EBEB88 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F3A3E09D088BA00EBEB88 /* main.c */; };
|
||||
002F3AF109D08F1000EBEB88 /* SDLMain.nib in Resources */ = {isa = PBXBuildFile; fileRef = 002F3AEF09D08F1000EBEB88 /* SDLMain.nib */; };
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXBuildStyle section */
|
||||
4A9504CCFFE6A4B311CA0CBA /* Debug */ = {
|
||||
isa = PBXBuildStyle;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
4A9504CDFFE6A4B311CA0CBA /* Release */ = {
|
||||
isa = PBXBuildStyle;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End PBXBuildStyle section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
002F39FD09D0883400EBEB88 /* Copy Frameworks into .app bundle */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
002F3A0009D0884600EBEB88 /* SDL.framework in Copy Frameworks into .app bundle */,
|
||||
);
|
||||
name = "Copy Frameworks into .app bundle";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
002F39F909D0881F00EBEB88 /* SDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL.framework; path = /Library/Frameworks/SDL.framework; sourceTree = "<absolute>"; };
|
||||
002F3A2B09D0888800EBEB88 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SDLMain.h; sourceTree = SOURCE_ROOT; };
|
||||
002F3A2C09D0888800EBEB88 /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SDLMain.m; sourceTree = SOURCE_ROOT; };
|
||||
002F3A3E09D088BA00EBEB88 /* main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = SOURCE_ROOT; };
|
||||
002F3AF009D08F1000EBEB88 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/SDLMain.nib; sourceTree = "<group>"; };
|
||||
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||
32CA4F630368D1EE00C91783 /* «PROJECTNAME»_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; path = "«PROJECTNAME»_Prefix.pch"; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
|
||||
8D1107320486CEB800E47090 /* «PROJECTNAME».app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "«PROJECTNAME».app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
8D11072E0486CEB800E47090 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
002F39FA09D0881F00EBEB88 /* SDL.framework in Frameworks */,
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
080E96DDFE201D6D7F000001 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F3A2B09D0888800EBEB88 /* SDLMain.h */,
|
||||
002F3A2C09D0888800EBEB88 /* SDLMain.m */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F39F909D0881F00EBEB88 /* SDL.framework */,
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
|
||||
);
|
||||
name = "Linked Frameworks";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
|
||||
);
|
||||
name = "Other Frameworks";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
19C28FACFE9D520D11CA2CBB /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8D1107320486CEB800E47090 /* «PROJECTNAME».app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97314FDCFA39411CA2CEA /* «PROJECTNAMEASXML» */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
080E96DDFE201D6D7F000001 /* Classes */,
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */,
|
||||
29B97317FDCFA39411CA2CEA /* Resources */,
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */,
|
||||
19C28FACFE9D520D11CA2CBB /* Products */,
|
||||
);
|
||||
name = "«PROJECTNAMEASXML»";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32CA4F630368D1EE00C91783 /* «PROJECTNAME»_Prefix.pch */,
|
||||
002F3A3E09D088BA00EBEB88 /* main.c */,
|
||||
);
|
||||
name = "Other Sources";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97317FDCFA39411CA2CEA /* Resources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8D1107310486CEB800E47090 /* Info.plist */,
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
|
||||
002F3AEF09D08F1000EBEB88 /* SDLMain.nib */,
|
||||
);
|
||||
name = Resources;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
8D1107260486CEB800E47090 /* «PROJECTNAME» */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "«PROJECTNAME»" */;
|
||||
buildPhases = (
|
||||
8D1107290486CEB800E47090 /* Resources */,
|
||||
8D11072C0486CEB800E47090 /* Sources */,
|
||||
8D11072E0486CEB800E47090 /* Frameworks */,
|
||||
002F39FD09D0883400EBEB88 /* Copy Frameworks into .app bundle */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
buildSettings = {
|
||||
};
|
||||
dependencies = (
|
||||
);
|
||||
name = "«PROJECTNAME»";
|
||||
productInstallPath = "$(HOME)/Applications";
|
||||
productName = "«PROJECTNAME»";
|
||||
productReference = 8D1107320486CEB800E47090 /* «PROJECTNAME».app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
29B97313FDCFA39411CA2CEA /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLCocoaApp" */;
|
||||
buildSettings = {
|
||||
};
|
||||
buildStyles = (
|
||||
4A9504CCFFE6A4B311CA0CBA /* Debug */,
|
||||
4A9504CDFFE6A4B311CA0CBA /* Release */,
|
||||
);
|
||||
hasScannedForEncodings = 1;
|
||||
mainGroup = 29B97314FDCFA39411CA2CEA /* «PROJECTNAMEASXML» */;
|
||||
projectDirPath = "";
|
||||
targets = (
|
||||
8D1107260486CEB800E47090 /* «PROJECTNAME» */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
8D1107290486CEB800E47090 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
|
||||
002F3AF109D08F1000EBEB88 /* SDLMain.nib in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
8D11072C0486CEB800E47090 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
002F3A2E09D0888800EBEB88 /* SDLMain.m in Sources */,
|
||||
002F3A3F09D088BA00EBEB88 /* main.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
002F3AEF09D08F1000EBEB88 /* SDLMain.nib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
002F3AF009D08F1000EBEB88 /* English */,
|
||||
);
|
||||
name = SDLMain.nib;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
089C165DFE840E0CC02AAC07 /* English */,
|
||||
);
|
||||
name = InfoPlist.strings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
C01FCF4B08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = YES;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(HOME)/Applications";
|
||||
PRODUCT_NAME = "«PROJECTNAME»";
|
||||
WRAPPER_EXTENSION = app;
|
||||
ZERO_LINK = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
C01FCF4C08A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = (
|
||||
ppc,
|
||||
i386,
|
||||
);
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(HOME)/Applications";
|
||||
PRODUCT_NAME = "«PROJECTNAME»";
|
||||
WRAPPER_EXTENSION = app;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
C01FCF4F08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks",
|
||||
/Library/Frameworks,
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks/SDL.framework/Headers",
|
||||
/Library/Frameworks/SDL.framework/Headers,
|
||||
"$(HEADER_SEARCH_PATHS)",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
C01FCF5008A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks",
|
||||
/Library/Frameworks,
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks/SDL.framework/Headers",
|
||||
/Library/Frameworks/SDL.framework/Headers,
|
||||
"$(HEADER_SEARCH_PATHS)",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "«PROJECTNAME»" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
C01FCF4B08A954540054247B /* Debug */,
|
||||
C01FCF4C08A954540054247B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLCocoaApp" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
C01FCF4F08A954540054247B /* Debug */,
|
||||
C01FCF5008A954540054247B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
|
||||
}
|
||||
17
Xcode/TemplatesForXcode/SDL Cocoa Application/SDLMain.h
Normal file
17
Xcode/TemplatesForXcode/SDL Cocoa Application/SDLMain.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/* 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
|
||||
- (IBAction)prefsMenu:(id)sender;
|
||||
- (IBAction)newGame:(id)sender;
|
||||
- (IBAction)openGame:(id)sender;
|
||||
- (IBAction)saveGame:(id)sender;
|
||||
- (IBAction)saveGameAs:(id)sender;
|
||||
- (IBAction)help:(id)sender;
|
||||
@end
|
||||
436
Xcode/TemplatesForXcode/SDL Cocoa Application/SDLMain.m
Normal file
436
Xcode/TemplatesForXcode/SDL Cocoa Application/SDLMain.m
Normal file
@@ -0,0 +1,436 @@
|
||||
/* 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 1
|
||||
|
||||
/* 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
|
||||
|
||||
- (IBAction)prefsMenu:(id)sender
|
||||
{
|
||||
printf ("prefs menu\n");
|
||||
}
|
||||
|
||||
- (IBAction)newGame:(id)sender
|
||||
{
|
||||
printf ("new game\n");
|
||||
|
||||
NSRunAlertPanel (@"Get ready to blow up some... stuff!",
|
||||
@"Click OK to begin total carnage. Click Cancel to prevent total carnage.", @"OK", @"Cancel", nil);
|
||||
}
|
||||
|
||||
- (IBAction)openGame:(id)sender
|
||||
{
|
||||
NSString *path = nil;
|
||||
NSOpenPanel *openPanel = [ NSOpenPanel openPanel ];
|
||||
|
||||
if ( [ openPanel runModalForDirectory:nil
|
||||
file:@"SavedGame" types:nil ] ) {
|
||||
|
||||
path = [ [ openPanel filenames ] objectAtIndex:0 ];
|
||||
}
|
||||
|
||||
printf ("open game: %s\n", [ path cString ]);
|
||||
}
|
||||
|
||||
- (IBAction)saveGame:(id)sender
|
||||
{
|
||||
NSString *path = nil;
|
||||
NSSavePanel *savePanel = [ NSSavePanel savePanel ];
|
||||
|
||||
if ( [ savePanel runModalForDirectory:nil
|
||||
file:@"SaveGameFile" ] ) {
|
||||
|
||||
path = [ savePanel filename ];
|
||||
}
|
||||
|
||||
printf ("save game: %s\n", [ path cString ]);
|
||||
}
|
||||
|
||||
- (IBAction)saveGameAs:(id)sender
|
||||
{
|
||||
printf ("save game as\n");
|
||||
}
|
||||
|
||||
- (IBAction)help:(id)sender
|
||||
{
|
||||
NSRunAlertPanel (@"Oh help, where have ye gone?",
|
||||
@"Sorry, there is no help available.\n\nThis message brought to you by We Don't Document, Inc.\n\n", @"Rats", @"Good, I never read it anyway", nil);
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
65
Xcode/TemplatesForXcode/SDL Cocoa Application/main.c
Normal file
65
Xcode/TemplatesForXcode/SDL Cocoa Application/main.c
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
/* Simple program: Create a blank window, wait for keypress, quit.
|
||||
|
||||
Please see the SDL documentation for details on using the SDL API:
|
||||
/Developer/Documentation/SDL/docs.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Uint32 initflags = SDL_INIT_VIDEO; /* See documentation for details */
|
||||
SDL_Surface *screen;
|
||||
Uint8 video_bpp = 0;
|
||||
Uint32 videoflags = SDL_SWSURFACE;
|
||||
int done;
|
||||
SDL_Event event;
|
||||
|
||||
/* Initialize the SDL library */
|
||||
if ( SDL_Init(initflags) < 0 ) {
|
||||
fprintf(stderr, "Couldn't initialize SDL: %s\n",
|
||||
SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
screen=SDL_SetVideoMode(640,480, video_bpp, videoflags);
|
||||
if (screen == NULL) {
|
||||
fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
|
||||
video_bpp, SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
done = 0;
|
||||
while ( !done ) {
|
||||
|
||||
/* Check for events */
|
||||
while ( SDL_PollEvent(&event) ) {
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
/* Any keypress quits the app... */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up the SDL library */
|
||||
SDL_Quit();
|
||||
return(0);
|
||||
}
|
||||
Binary file not shown.
21
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/English.lproj/SDLMain.nib/classes.nib
generated
Normal file
21
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/English.lproj/SDLMain.nib/classes.nib
generated
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
IBClasses = (
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
ACTIONS = {changeNumberOfSprites = id; selectUpdateMode = id; };
|
||||
CLASS = MyController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {"_framesPerSecond" = id; "_numSprites" = id; "_view" = id; "_window" = id; };
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{CLASS = MyCustomView; LANGUAGE = ObjC; SUPERCLASS = NSQuickDrawView; },
|
||||
{CLASS = MyCustomWindow; LANGUAGE = ObjC; SUPERCLASS = NSWindow; },
|
||||
{
|
||||
CLASS = SDLMain;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {"_controller" = id; };
|
||||
SUPERCLASS = NSObject;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
||||
28
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/English.lproj/SDLMain.nib/info.nib
generated
Normal file
28
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/English.lproj/SDLMain.nib/info.nib
generated
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>89 138 361 280 0 0 1152 848 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>29</key>
|
||||
<string>62 362 233 44 0 0 1152 848 </string>
|
||||
<key>368</key>
|
||||
<string>782 578 355 456 0 0 1920 1178 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>443.0</string>
|
||||
<key>IBLockedObjects</key>
|
||||
<array>
|
||||
<integer>328</integer>
|
||||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>368</integer>
|
||||
<integer>326</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8H14</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/English.lproj/SDLMain.nib/objects.nib
generated
Normal file
BIN
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/English.lproj/SDLMain.nib/objects.nib
generated
Normal file
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.yourcompany.«PROJECTNAMEASXML»</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>SDLMain</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// MyController.h
|
||||
// SDL Custom Cocoa App
|
||||
//
|
||||
// Created by Darrell Walisser on Fri Jul 18 2003.
|
||||
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SDL.h"
|
||||
|
||||
extern id gController; // instance of this class from nib
|
||||
|
||||
// Declare SDL_QuartzWindowDelegate (defined in SDL.framework)
|
||||
@interface SDL_QuartzWindowDelegate : NSObject
|
||||
@end
|
||||
|
||||
@interface MyController : NSObject
|
||||
{
|
||||
// Interface Builder Outlets
|
||||
IBOutlet id _framesPerSecond;
|
||||
IBOutlet id _numSprites;
|
||||
IBOutlet id _window;
|
||||
IBOutlet id _view;
|
||||
|
||||
// Private instance variables
|
||||
int _nSprites;
|
||||
int _max_speed;
|
||||
int _doFlip;
|
||||
Uint8* _mem;
|
||||
|
||||
SDL_Surface* _screen;
|
||||
SDL_Surface* _sprite;
|
||||
SDL_Rect* _sprite_rects;
|
||||
SDL_Rect* _positions;
|
||||
SDL_Rect* _velocities;
|
||||
int _sprites_visible;
|
||||
Uint16 _sprite_w, _sprite_h;
|
||||
|
||||
int _mouse_x, _mouse_y;
|
||||
}
|
||||
// Interface Builder Actions
|
||||
- (IBAction)changeNumberOfSprites:(id)sender;
|
||||
- (IBAction)selectUpdateMode:(id)sender;
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,506 @@
|
||||
//
|
||||
// MyController.m
|
||||
// SDL Custom Cocoa App
|
||||
//
|
||||
// Created by Darrell Walisser on Fri Jul 18 2003.
|
||||
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MyController.h"
|
||||
#import "SDL.h"
|
||||
|
||||
id gController;
|
||||
|
||||
@implementation MyController
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [ super init ];
|
||||
if (self) {
|
||||
|
||||
_nSprites = 10;
|
||||
_max_speed = 4;
|
||||
_doFlip = 0;
|
||||
_mem = NULL;
|
||||
_screen = NULL;
|
||||
_sprite_rects = NULL;
|
||||
_positions = NULL;
|
||||
_velocities = NULL;
|
||||
_sprites_visible = 1;
|
||||
_sprite_w = 0;
|
||||
_sprite_h = 0;
|
||||
_mouse_x = 0;
|
||||
_mouse_y = 0;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupCocoaWindow
|
||||
{
|
||||
// If you want the close button to send SDL_Quit,
|
||||
// you can attach the SDL_QuartzWindowDelegate to the window
|
||||
[ _window setDelegate:
|
||||
[ [ [ SDL_QuartzWindowDelegate alloc ] init ] autorelease ] ];
|
||||
|
||||
// Make the window visible and the frontmost window
|
||||
[ _window makeKeyAndOrderFront:nil ];
|
||||
|
||||
// Make the window accept passive motion events (when the button is released)
|
||||
[ _window setAcceptsMouseMovedEvents:YES ];
|
||||
}
|
||||
|
||||
- (void)setCocoaEnvironmentVariables
|
||||
{
|
||||
// Export cocoa objects to environment
|
||||
// SDL will use these when you call SDL_SetVideoMode
|
||||
|
||||
// The window must be visible when you call SDL_SetVideoMode,
|
||||
// and the view must lie completely within the window.
|
||||
//
|
||||
// The width and height passed to SDL_SetVideoMode should match
|
||||
// the width/height of the view (the window can be any size)
|
||||
//
|
||||
// For resizing to work, you must set the appropriate
|
||||
// attributes on the window and view. Then the SDL_RESIZABLE
|
||||
// flag will be set automatically
|
||||
//
|
||||
// SDL will retain a reference to the window, and
|
||||
// will release it when unsetting the video mode
|
||||
//
|
||||
// The view is not retained (the window object manages this).
|
||||
//
|
||||
char buffer[256];
|
||||
printf ("NSWindow=%p\n", _window);
|
||||
sprintf (buffer, "%d", (int)_window);
|
||||
setenv ("SDL_NSWindowPointer", buffer, 1);
|
||||
|
||||
printf ("NSQuickDrawView=%p\n", _view);
|
||||
sprintf (buffer, "%d", (int)_view);
|
||||
setenv ("SDL_NSQuickDrawViewPointer", buffer, 1);
|
||||
|
||||
// Also tell SDL to pass keyboard events to Cocoa
|
||||
// In this case, Cocoa will get the event before SDL_PollEvent returns it
|
||||
// Note that mouse events (button, motion) will always be passed, regardless of this setting
|
||||
setenv ("SDL_ENABLEAPPEVENTS", "1", 1);
|
||||
}
|
||||
|
||||
- (void)printFlags:(Uint32)flags withName:(const char*)name
|
||||
{
|
||||
printf ("%s", name);
|
||||
|
||||
if (flags & SDL_SWSURFACE)
|
||||
printf (" - SDL_SWSURFACE");
|
||||
if (flags & SDL_HWSURFACE)
|
||||
printf (" - SDL_HWSURFACE");
|
||||
if (flags & SDL_ASYNCBLIT)
|
||||
printf (" - SDL_ASYNCBLIT");
|
||||
if (flags & SDL_ANYFORMAT)
|
||||
printf (" - SDL_ANYFORMAT");
|
||||
if (flags & SDL_HWPALETTE)
|
||||
printf (" - SDL_HWPALETTE");
|
||||
if (flags & SDL_DOUBLEBUF)
|
||||
printf (" - SDL_DOUBLEBUF");
|
||||
if (flags & SDL_FULLSCREEN)
|
||||
printf (" - SDL_FULLSCREEN");
|
||||
if (flags & SDL_OPENGL)
|
||||
printf (" - SDL_OPENGL");
|
||||
if (flags & SDL_OPENGLBLIT)
|
||||
printf (" - SDL_OPENGLBLIT");
|
||||
if (flags & SDL_RESIZABLE)
|
||||
printf (" - SDL_RESIZABLE");
|
||||
if (flags & SDL_NOFRAME)
|
||||
printf (" - SDL_NOFRAME");
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
// This is a way of telling whether or not to use hardware surfaces
|
||||
// Note: this does nothing on Mac OS X at the moment - there is no
|
||||
// hardware-accelerated blitting support.
|
||||
- (Uint32)fastestFlags:(Uint32)flags :(int)width :(int)height :(int)bpp
|
||||
{
|
||||
const SDL_VideoInfo *info;
|
||||
|
||||
// Hardware acceleration is only used in fullscreen mode
|
||||
flags |= SDL_FULLSCREEN;
|
||||
|
||||
// Check for various video capabilities
|
||||
info = SDL_GetVideoInfo();
|
||||
if ( info->blit_hw_CC && info->blit_fill ) {
|
||||
// We use accelerated colorkeying and color filling
|
||||
flags |= SDL_HWSURFACE;
|
||||
}
|
||||
// If we have enough video memory, and will use accelerated
|
||||
// blits directly to it, then use page flipping.
|
||||
if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
|
||||
|
||||
// Direct hardware blitting without double-buffering
|
||||
// causes really bad flickering.
|
||||
if ( info->video_mem*1024 > (height*width*bpp/8) ) {
|
||||
flags |= SDL_DOUBLEBUF;
|
||||
} else {
|
||||
flags &= ~SDL_HWSURFACE;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the flags
|
||||
return flags;
|
||||
}
|
||||
|
||||
- (int)loadSpriteFromFile:(const char*)file
|
||||
{
|
||||
SDL_Surface *temp;
|
||||
|
||||
// Load the sprite image
|
||||
_sprite = SDL_LoadBMP (file);
|
||||
if ( _sprite == NULL ) {
|
||||
fprintf (stderr, "Couldn't load %s: %s", file, SDL_GetError ());
|
||||
return (-1);
|
||||
}
|
||||
|
||||
// Set transparent pixel as the pixel at (0,0)
|
||||
if ( _sprite->format->palette ) {
|
||||
SDL_SetColorKey (_sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL),
|
||||
*(Uint8 *)_sprite->pixels);
|
||||
}
|
||||
|
||||
/* Convert sprite to video format */
|
||||
temp = SDL_DisplayFormat (_sprite);
|
||||
SDL_FreeSurface (_sprite);
|
||||
if ( temp == NULL ) {
|
||||
fprintf(stderr, "Couldn't convert background: %s\n",
|
||||
SDL_GetError ());
|
||||
return (-1);
|
||||
}
|
||||
_sprite = temp;
|
||||
|
||||
// We're ready to roll. :)
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (void)allocSprites
|
||||
{
|
||||
/* Allocate memory for the sprite info */
|
||||
_mem = (Uint8 *)malloc (4*sizeof(SDL_Rect)*_nSprites);
|
||||
if ( _mem == NULL ) {
|
||||
fprintf (stderr, "Out of memory!\n");
|
||||
exit (2);
|
||||
}
|
||||
|
||||
_sprite_rects = (SDL_Rect *)_mem;
|
||||
_positions = _sprite_rects;
|
||||
_sprite_rects += _nSprites;
|
||||
_velocities = _sprite_rects;
|
||||
_sprite_rects += _nSprites;
|
||||
_sprite_w = _sprite->w;
|
||||
_sprite_h = _sprite->h;
|
||||
}
|
||||
|
||||
- (void)freeSprites
|
||||
{
|
||||
free (_mem);
|
||||
_mem = NULL;
|
||||
}
|
||||
|
||||
- (void)initSprites
|
||||
{
|
||||
// Give each sprite a random starting position and velocity
|
||||
int i;
|
||||
|
||||
srand(time(NULL));
|
||||
for ( i=0; i < _nSprites; ++i ) {
|
||||
_positions[i].x = rand()%(_screen->w - _sprite->w);
|
||||
_positions[i].y = rand()%(_screen->h - _sprite->h);
|
||||
_positions[i].w = _sprite->w;
|
||||
_positions[i].h = _sprite->h;
|
||||
_velocities[i].x = 0;
|
||||
_velocities[i].y = 0;
|
||||
while ( ! _velocities[i].x && ! _velocities[i].y ) {
|
||||
_velocities[i].x = (rand()%(_max_speed*2+1)) - _max_speed;
|
||||
_velocities[i].y = (rand()%(_max_speed*2+1)) - _max_speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)moveSprites:(int)backgroundColor;
|
||||
{
|
||||
int i, nupdates;
|
||||
SDL_Rect area, *position, *velocity;
|
||||
|
||||
nupdates = 0;
|
||||
// Erase all the sprites if necessary
|
||||
if ( _sprites_visible ) {
|
||||
SDL_FillRect (_screen, NULL, backgroundColor);
|
||||
}
|
||||
|
||||
// Move the sprite, bounce at the wall, and draw
|
||||
for ( i=0; i < _nSprites; ++i ) {
|
||||
position = &_positions[i];
|
||||
velocity = &_velocities[i];
|
||||
position->x += velocity->x;
|
||||
if ( (position->x < 0) || (position->x >= (_screen->w - _sprite_w)) ) {
|
||||
velocity->x = -velocity->x;
|
||||
position->x += velocity->x;
|
||||
}
|
||||
position->y += velocity->y;
|
||||
if ( (position->y < 0) || (position->y >= (_screen->h - _sprite_w)) ) {
|
||||
velocity->y = -velocity->y;
|
||||
position->y += velocity->y;
|
||||
}
|
||||
|
||||
// Blit the sprite onto the screen
|
||||
area = *position;
|
||||
SDL_BlitSurface (_sprite, NULL, _screen, &area);
|
||||
_sprite_rects[nupdates++] = area;
|
||||
}
|
||||
|
||||
// Update the screen!
|
||||
if ( _doFlip ) {
|
||||
SDL_Flip (_screen);
|
||||
} else {
|
||||
SDL_UpdateRects (_screen, nupdates, _sprite_rects);
|
||||
}
|
||||
|
||||
_sprites_visible = 1;
|
||||
}
|
||||
|
||||
- (int)run:(int)argc argv:(char*[])argv
|
||||
{
|
||||
int width, height;
|
||||
Uint8 video_bpp;
|
||||
Uint32 videoflags;
|
||||
Uint32 background;
|
||||
int done;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
|
||||
// Initialize SDL
|
||||
if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) {
|
||||
fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
|
||||
exit (1);
|
||||
}
|
||||
atexit(SDL_Quit);
|
||||
|
||||
videoflags = SDL_SWSURFACE|SDL_ANYFORMAT;
|
||||
width = 640;
|
||||
height = 480;
|
||||
video_bpp = 8;
|
||||
while ( argc > 1 ) {
|
||||
--argc;
|
||||
if ( strcmp(argv[argc-1], "-width") == 0 ) {
|
||||
width = atoi (argv[argc]);
|
||||
--argc;
|
||||
} else
|
||||
if ( strcmp(argv[argc-1], "-height") == 0 ) {
|
||||
height = atoi (argv[argc]);
|
||||
--argc;
|
||||
} else
|
||||
if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
|
||||
video_bpp = atoi (argv[argc]);
|
||||
videoflags &= ~SDL_ANYFORMAT;
|
||||
--argc;
|
||||
} else
|
||||
if ( strcmp (argv[argc], "-fast") == 0 ) {
|
||||
videoflags = [ self fastestFlags:videoflags :width :height :video_bpp ];
|
||||
} else
|
||||
if ( strcmp (argv[argc], "-hw") == 0 ) {
|
||||
videoflags ^= SDL_HWSURFACE;
|
||||
} else
|
||||
if ( strcmp (argv[argc], "-flip") == 0 ) {
|
||||
videoflags ^= SDL_DOUBLEBUF;
|
||||
} else
|
||||
if ( strcmp (argv[argc], "-fullscreen") == 0 ) {
|
||||
videoflags ^= SDL_FULLSCREEN;
|
||||
} else
|
||||
if ( isdigit(argv[argc][0]) ) {
|
||||
_nSprites = atoi (argv[argc]);
|
||||
} else {
|
||||
fprintf (stderr,
|
||||
"Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numSprites]\n",
|
||||
argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
// The width/height passed to SDL_SetVideoMode should match the size of the NSView
|
||||
width = [ _view frame ].size.width;
|
||||
height = [ _view frame ].size.height;
|
||||
videoflags &= ~SDL_FULLSCREEN; // this only for windowed mode
|
||||
if ( [ _window styleMask ] & NSResizableWindowMask ) // enable resizable window
|
||||
videoflags |= SDL_RESIZABLE;
|
||||
[ self setupCocoaWindow ];
|
||||
[ self setCocoaEnvironmentVariables ];
|
||||
_mouse_x = width/2;
|
||||
_mouse_y = width/2;
|
||||
|
||||
// Set video mode
|
||||
_screen = SDL_SetVideoMode (width, height, video_bpp, videoflags);
|
||||
if ( ! _screen ) {
|
||||
fprintf (stderr, "Couldn't set %dx%d video mode: %s\n",
|
||||
width, height, SDL_GetError());
|
||||
exit (2);
|
||||
}
|
||||
|
||||
// Print out surface info
|
||||
[ self printFlags:videoflags withName:"Requested flags: " ];
|
||||
[ self printFlags:_screen->flags withName:"Got flags: " ];
|
||||
|
||||
// Load the sprite
|
||||
// The sprite is located in the Resources section of the .app bundle.
|
||||
// SDL does not seem aware of bundle paths, so we must construct the path manually.
|
||||
NSString* resource_path = [[NSBundle mainBundle] resourcePath];
|
||||
NSString* icon_path = [resource_path stringByAppendingString:@"/icon.bmp"];
|
||||
if ( [ self loadSpriteFromFile:[icon_path UTF8String] ] < 0 ) {
|
||||
exit (1);
|
||||
}
|
||||
|
||||
[ self allocSprites ];
|
||||
[ self initSprites ];
|
||||
|
||||
background = SDL_MapRGB (_screen->format, 0x00, 0x00, 0x00);
|
||||
|
||||
// Print out information about our surfaces
|
||||
printf("Screen is at %d bits per pixel\n", _screen->format->BitsPerPixel);
|
||||
if ( (_screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
|
||||
printf ("Screen is in video memory\n");
|
||||
} else {
|
||||
printf ("Screen is in system memory\n");
|
||||
}
|
||||
if ( (_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
|
||||
printf ("Screen has double-buffering enabled\n");
|
||||
}
|
||||
if ( (_sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
|
||||
printf ("Sprite is in video memory\n");
|
||||
} else {
|
||||
printf ("Sprite is in system memory\n");
|
||||
}
|
||||
|
||||
// Run a sample blit to trigger blit acceleration
|
||||
{
|
||||
SDL_Rect dst;
|
||||
dst.x = 0;
|
||||
dst.y = 0;
|
||||
dst.w = _sprite->w;
|
||||
dst.h = _sprite->h;
|
||||
SDL_BlitSurface (_sprite, NULL, _screen, &dst);
|
||||
SDL_FillRect (_screen, &dst, background);
|
||||
}
|
||||
if ( (_sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
|
||||
printf("Sprite blit uses hardware acceleration\n");
|
||||
}
|
||||
if ( (_sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
|
||||
printf("Sprite blit uses RLE acceleration\n");
|
||||
}
|
||||
|
||||
// Loop, blitting sprites and waiting for a keystroke
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
_sprites_visible = 0;
|
||||
while ( !done ) {
|
||||
// Check for events
|
||||
++frames;
|
||||
while ( SDL_PollEvent(&event) ) {
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_VIDEORESIZE:
|
||||
|
||||
// Recreate the video mode. Use the same bpp and flags
|
||||
// that the original window was created with
|
||||
_screen = SDL_SetVideoMode (event.resize.w, event.resize.h,
|
||||
video_bpp, videoflags);
|
||||
|
||||
// Clear screen and reinit sprite positions
|
||||
SDL_FillRect (_screen, NULL, 0);
|
||||
[ self initSprites ];
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
|
||||
_velocities[_nSprites-1].x = 0;
|
||||
_velocities[_nSprites-1].y = 0;
|
||||
_positions[_nSprites-1].x = event.motion.x - _sprite->w/2;
|
||||
_positions[_nSprites-1].y = event.motion.y - _sprite->h/2;
|
||||
//printf ("motion: %d %d\n", event.motion.x, event.motion.y);
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
|
||||
_velocities[_nSprites-1].x = 0;
|
||||
_velocities[_nSprites-1].y = 0;
|
||||
_positions[_nSprites-1].x = event.button.x;
|
||||
_positions[_nSprites-1].y = event.button.y;
|
||||
//printf ("button: %d %d\n", event.button.x, event.button.y);
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
|
||||
// Escape also quits the app
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE)
|
||||
done = 1;
|
||||
|
||||
// Control-W warps the cursor
|
||||
if (event.key.keysym.sym == SDLK_w &&
|
||||
( SDL_GetModState () & KMOD_LCTRL ) )
|
||||
SDL_WarpMouse (_screen->w/2, _screen->h/2);
|
||||
|
||||
// Control-G toggles input grabbing
|
||||
if (event.key.keysym.sym == SDLK_g &&
|
||||
( SDL_GetModState () & KMOD_LCTRL ) )
|
||||
if ( SDL_WM_GrabInput (SDL_GRAB_QUERY) == SDL_GRAB_OFF )
|
||||
SDL_WM_GrabInput (SDL_GRAB_ON);
|
||||
else
|
||||
SDL_WM_GrabInput (SDL_GRAB_OFF);
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw sprites
|
||||
[ self moveSprites:background ];
|
||||
|
||||
// Update fps counter every 100 frames
|
||||
if ((frames % 100) == 0) {
|
||||
now = SDL_GetTicks ();
|
||||
[ _framesPerSecond setFloatValue:((float)frames*1000)/(now-then) ];
|
||||
frames = 0;
|
||||
then = now;
|
||||
}
|
||||
}
|
||||
[ self freeSprites ];
|
||||
SDL_FreeSurface (_sprite);
|
||||
|
||||
SDL_Quit ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (IBAction)changeNumberOfSprites:(id)sender
|
||||
{
|
||||
[ _numSprites setIntValue:[ sender intValue ] ];
|
||||
[ self freeSprites ];
|
||||
_nSprites = [ sender intValue ];
|
||||
[ self allocSprites ];
|
||||
[ self initSprites ];
|
||||
SDL_FillRect (_screen, NULL, 0);
|
||||
SDL_Flip (_screen);
|
||||
}
|
||||
|
||||
- (IBAction)selectUpdateMode:(id)sender
|
||||
{
|
||||
_doFlip = ![ sender selectedRow ]; // row is 0 or 1
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Hand off to instance of MyController
|
||||
// This instance is created when SDLMain.nib is loaded,
|
||||
// and the global variable is set in [SDLMain applicationDidFinishLaunching:]
|
||||
return [ gController run:argc argv:argv ];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// MyCustomView.h
|
||||
// SDL Custom View App
|
||||
//
|
||||
// Created by Darrell Walisser on Fri Jul 18 2003.
|
||||
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
|
||||
@interface MyCustomView : NSQuickDrawView
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// MyCustomView.m
|
||||
// SDL Custom View App
|
||||
//
|
||||
// Created by Darrell Walisser on Fri Jul 18 2003.
|
||||
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MyCustomView.h"
|
||||
|
||||
|
||||
@implementation MyCustomView
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame
|
||||
{
|
||||
self = [ super initWithFrame:frame ];
|
||||
if (self) {
|
||||
// Initialization code here.
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)drawRect:(NSRect)rect
|
||||
{
|
||||
// Drawing code here.
|
||||
}
|
||||
|
||||
- (BOOL)mouseDownCanMoveWindow
|
||||
{
|
||||
// If you use textured windows, this disables
|
||||
// moving the window by dragging in the view
|
||||
return NO;
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// MyCustomWindow.h
|
||||
// SDL Custom View App
|
||||
//
|
||||
// Created by Darrell Walisser on Fri Jul 18 2003.
|
||||
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
// Be a subclass of SDL_QuartzWindow so SDL will
|
||||
// handle the redraw problems when minimizing the window
|
||||
// This class is defined in SDL.framework
|
||||
@interface SDL_QuartzWindow : NSWindow
|
||||
@end
|
||||
|
||||
// Also assign SDL_QuartzWindowDelegate to the window
|
||||
// to perform other tasks. You can subclass this delegate
|
||||
// if you want to add your own delegation methods
|
||||
// This class is defined in SDL.framework
|
||||
@interface SDL_QuartzWindowDelegate : NSObject
|
||||
@end
|
||||
|
||||
// Declare our custom class
|
||||
@interface MyCustomWindow : SDL_QuartzWindow
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// MyCustomWindow.m
|
||||
// SDL Custom View App
|
||||
//
|
||||
// Created by Darrell Walisser on Fri Jul 18 2003.
|
||||
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MyCustomWindow.h"
|
||||
|
||||
|
||||
@implementation MyCustomWindow
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// Prefix header for all source files of the '<27>PROJECTNAME<4D>' target in the '<27>PROJECTNAME<4D>' project
|
||||
//
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
FilesToRename = {
|
||||
"SDLApp_Prefix.pch" = "<22>PROJECTNAME<4D>_Prefix.pch";
|
||||
};
|
||||
FilesToMacroExpand = (
|
||||
"<22>PROJECTNAME<4D>_Prefix.pch",
|
||||
"Info.plist",
|
||||
"English.lproj/InfoPlist.strings",
|
||||
"MyController.h",
|
||||
"MyController.m",
|
||||
"MyCustomView.h",
|
||||
"MyCustomView.m",
|
||||
"MyCustomWindow.h",
|
||||
"MyCustomWindow.m",
|
||||
);
|
||||
Description = "This project builds an SDL-based application that draws into a custom Cocoa window and view and interfaces with native Cocoa widgets.";
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 42;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
002F39FA09D0881F00EBEB88 /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 002F39F909D0881F00EBEB88 /* SDL.framework */; };
|
||||
002F3A0009D0884600EBEB88 /* SDL.framework in Copy Frameworks into .app bundle */ = {isa = PBXBuildFile; fileRef = 002F39F909D0881F00EBEB88 /* SDL.framework */; };
|
||||
002F3A2E09D0888800EBEB88 /* SDLMain.m in Sources */ = {isa = PBXBuildFile; fileRef = 002F3A2C09D0888800EBEB88 /* SDLMain.m */; };
|
||||
0035F33609D097C8005563B5 /* MyController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0035F33009D097C8005563B5 /* MyController.m */; };
|
||||
0035F33809D097C8005563B5 /* MyCustomView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0035F33209D097C8005563B5 /* MyCustomView.m */; };
|
||||
0035F33A09D097C8005563B5 /* MyCustomWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 0035F33409D097C8005563B5 /* MyCustomWindow.m */; };
|
||||
0035F34609D09825005563B5 /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 0035F34509D09825005563B5 /* icon.bmp */; };
|
||||
0035F3AD09D09A3D005563B5 /* SDLMain.nib in Resources */ = {isa = PBXBuildFile; fileRef = 0035F3AB09D09A3D005563B5 /* SDLMain.nib */; };
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXBuildStyle section */
|
||||
4A9504CCFFE6A4B311CA0CBA /* Debug */ = {
|
||||
isa = PBXBuildStyle;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
4A9504CDFFE6A4B311CA0CBA /* Release */ = {
|
||||
isa = PBXBuildStyle;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End PBXBuildStyle section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
002F39FD09D0883400EBEB88 /* Copy Frameworks into .app bundle */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
002F3A0009D0884600EBEB88 /* SDL.framework in Copy Frameworks into .app bundle */,
|
||||
);
|
||||
name = "Copy Frameworks into .app bundle";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
002F39F909D0881F00EBEB88 /* SDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL.framework; path = /Library/Frameworks/SDL.framework; sourceTree = "<absolute>"; };
|
||||
002F3A2B09D0888800EBEB88 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SDLMain.h; sourceTree = SOURCE_ROOT; };
|
||||
002F3A2C09D0888800EBEB88 /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SDLMain.m; sourceTree = SOURCE_ROOT; };
|
||||
0035F32F09D097C8005563B5 /* MyController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MyController.h; sourceTree = SOURCE_ROOT; };
|
||||
0035F33009D097C8005563B5 /* MyController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MyController.m; sourceTree = SOURCE_ROOT; };
|
||||
0035F33109D097C8005563B5 /* MyCustomView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MyCustomView.h; sourceTree = SOURCE_ROOT; };
|
||||
0035F33209D097C8005563B5 /* MyCustomView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MyCustomView.m; sourceTree = SOURCE_ROOT; };
|
||||
0035F33309D097C8005563B5 /* MyCustomWindow.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MyCustomWindow.h; sourceTree = SOURCE_ROOT; };
|
||||
0035F33409D097C8005563B5 /* MyCustomWindow.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MyCustomWindow.m; sourceTree = SOURCE_ROOT; };
|
||||
0035F34509D09825005563B5 /* icon.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = icon.bmp; sourceTree = SOURCE_ROOT; };
|
||||
0035F3AC09D09A3D005563B5 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/SDLMain.nib; sourceTree = "<group>"; };
|
||||
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||
32CA4F630368D1EE00C91783 /* «PROJECTNAME»_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; path = "«PROJECTNAME»_Prefix.pch"; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
|
||||
8D1107320486CEB800E47090 /* «PROJECTNAME».app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "«PROJECTNAME».app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
8D11072E0486CEB800E47090 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
002F39FA09D0881F00EBEB88 /* SDL.framework in Frameworks */,
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
080E96DDFE201D6D7F000001 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0035F32F09D097C8005563B5 /* MyController.h */,
|
||||
0035F33009D097C8005563B5 /* MyController.m */,
|
||||
0035F33109D097C8005563B5 /* MyCustomView.h */,
|
||||
0035F33209D097C8005563B5 /* MyCustomView.m */,
|
||||
0035F33309D097C8005563B5 /* MyCustomWindow.h */,
|
||||
0035F33409D097C8005563B5 /* MyCustomWindow.m */,
|
||||
002F3A2B09D0888800EBEB88 /* SDLMain.h */,
|
||||
002F3A2C09D0888800EBEB88 /* SDLMain.m */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F39F909D0881F00EBEB88 /* SDL.framework */,
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
|
||||
);
|
||||
name = "Linked Frameworks";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
|
||||
);
|
||||
name = "Other Frameworks";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
19C28FACFE9D520D11CA2CBB /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8D1107320486CEB800E47090 /* «PROJECTNAME».app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97314FDCFA39411CA2CEA /* «PROJECTNAMEASXML» */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
080E96DDFE201D6D7F000001 /* Classes */,
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */,
|
||||
29B97317FDCFA39411CA2CEA /* Resources */,
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */,
|
||||
19C28FACFE9D520D11CA2CBB /* Products */,
|
||||
);
|
||||
name = "«PROJECTNAMEASXML»";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32CA4F630368D1EE00C91783 /* «PROJECTNAME»_Prefix.pch */,
|
||||
);
|
||||
name = "Other Sources";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97317FDCFA39411CA2CEA /* Resources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0035F34509D09825005563B5 /* icon.bmp */,
|
||||
8D1107310486CEB800E47090 /* Info.plist */,
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
|
||||
0035F3AB09D09A3D005563B5 /* SDLMain.nib */,
|
||||
);
|
||||
name = Resources;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
8D1107260486CEB800E47090 /* «PROJECTNAME» */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "«PROJECTNAME»" */;
|
||||
buildPhases = (
|
||||
8D1107290486CEB800E47090 /* Resources */,
|
||||
8D11072C0486CEB800E47090 /* Sources */,
|
||||
8D11072E0486CEB800E47090 /* Frameworks */,
|
||||
002F39FD09D0883400EBEB88 /* Copy Frameworks into .app bundle */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
buildSettings = {
|
||||
};
|
||||
dependencies = (
|
||||
);
|
||||
name = "«PROJECTNAME»";
|
||||
productInstallPath = "$(HOME)/Applications";
|
||||
productName = "«PROJECTNAME»";
|
||||
productReference = 8D1107320486CEB800E47090 /* «PROJECTNAME».app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
29B97313FDCFA39411CA2CEA /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLCustomCocoaApp" */;
|
||||
buildSettings = {
|
||||
};
|
||||
buildStyles = (
|
||||
4A9504CCFFE6A4B311CA0CBA /* Debug */,
|
||||
4A9504CDFFE6A4B311CA0CBA /* Release */,
|
||||
);
|
||||
hasScannedForEncodings = 1;
|
||||
mainGroup = 29B97314FDCFA39411CA2CEA /* «PROJECTNAMEASXML» */;
|
||||
projectDirPath = "";
|
||||
targets = (
|
||||
8D1107260486CEB800E47090 /* «PROJECTNAME» */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
8D1107290486CEB800E47090 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
|
||||
0035F34609D09825005563B5 /* icon.bmp in Resources */,
|
||||
0035F3AD09D09A3D005563B5 /* SDLMain.nib in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
8D11072C0486CEB800E47090 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
002F3A2E09D0888800EBEB88 /* SDLMain.m in Sources */,
|
||||
0035F33609D097C8005563B5 /* MyController.m in Sources */,
|
||||
0035F33809D097C8005563B5 /* MyCustomView.m in Sources */,
|
||||
0035F33A09D097C8005563B5 /* MyCustomWindow.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
0035F3AB09D09A3D005563B5 /* SDLMain.nib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
0035F3AC09D09A3D005563B5 /* English */,
|
||||
);
|
||||
name = SDLMain.nib;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
089C165DFE840E0CC02AAC07 /* English */,
|
||||
);
|
||||
name = InfoPlist.strings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
C01FCF4B08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = YES;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(HOME)/Applications";
|
||||
PRODUCT_NAME = "«PROJECTNAME»";
|
||||
WRAPPER_EXTENSION = app;
|
||||
ZERO_LINK = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
C01FCF4C08A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = (
|
||||
ppc,
|
||||
i386,
|
||||
);
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(HOME)/Applications";
|
||||
PRODUCT_NAME = "«PROJECTNAME»";
|
||||
WRAPPER_EXTENSION = app;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
C01FCF4F08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks",
|
||||
/Library/Frameworks,
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks/SDL.framework/Headers",
|
||||
/Library/Frameworks/SDL.framework/Headers,
|
||||
"$(HEADER_SEARCH_PATHS)",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
C01FCF5008A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks",
|
||||
/Library/Frameworks,
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks/SDL.framework/Headers",
|
||||
/Library/Frameworks/SDL.framework/Headers,
|
||||
"$(HEADER_SEARCH_PATHS)",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "«PROJECTNAME»" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
C01FCF4B08A954540054247B /* Debug */,
|
||||
C01FCF4C08A954540054247B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLCustomCocoaApp" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
C01FCF4F08A954540054247B /* Debug */,
|
||||
C01FCF5008A954540054247B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/* 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
|
||||
{
|
||||
IBOutlet id _controller;
|
||||
}
|
||||
@end
|
||||
386
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/SDLMain.m
Normal file
386
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/SDLMain.m
Normal file
@@ -0,0 +1,386 @@
|
||||
/* 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 "MyController.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 1
|
||||
|
||||
/* 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;
|
||||
|
||||
gController = _controller;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
BIN
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/icon.bmp
Normal file
BIN
Xcode/TemplatesForXcode/SDL Custom Cocoa Application/icon.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 578 B |
Binary file not shown.
28
Xcode/TemplatesForXcode/SDL OpenGL Application/Info.plist
Normal file
28
Xcode/TemplatesForXcode/SDL OpenGL Application/Info.plist
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.yourcompany.«PROJECTNAMEASXML»</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>SDLMain</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// Prefix header for all source files of the '<27>PROJECTNAME<4D>' target in the '<27>PROJECTNAME<4D>' project
|
||||
//
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
11
Xcode/TemplatesForXcode/SDL OpenGL Application/SDLMain.h
Normal file
11
Xcode/TemplatesForXcode/SDL OpenGL Application/SDLMain.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/* 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
|
||||
383
Xcode/TemplatesForXcode/SDL OpenGL Application/SDLMain.m
Normal file
383
Xcode/TemplatesForXcode/SDL OpenGL Application/SDLMain.m
Normal file
@@ -0,0 +1,383 @@
|
||||
/* 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;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
FilesToRename = {
|
||||
"SDLApp_Prefix.pch" = "<22>PROJECTNAME<4D>_Prefix.pch";
|
||||
};
|
||||
FilesToMacroExpand = (
|
||||
"<22>PROJECTNAME<4D>_Prefix.pch",
|
||||
"Info.plist",
|
||||
"English.lproj/InfoPlist.strings",
|
||||
"main.c",
|
||||
);
|
||||
Description = "This project builds an SDL-based application that uses OpenGL.";
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 42;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
002F39FA09D0881F00EBEB88 /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 002F39F909D0881F00EBEB88 /* SDL.framework */; };
|
||||
002F3A0009D0884600EBEB88 /* SDL.framework in Copy Frameworks into .app bundle */ = {isa = PBXBuildFile; fileRef = 002F39F909D0881F00EBEB88 /* SDL.framework */; };
|
||||
002F3A2E09D0888800EBEB88 /* SDLMain.m in Sources */ = {isa = PBXBuildFile; fileRef = 002F3A2C09D0888800EBEB88 /* SDLMain.m */; };
|
||||
002F3A3F09D088BA00EBEB88 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F3A3E09D088BA00EBEB88 /* main.c */; };
|
||||
002F3BFA09D0938900EBEB88 /* atlantis.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F3BF409D0938900EBEB88 /* atlantis.c */; };
|
||||
002F3BFC09D0938900EBEB88 /* dolphin.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F3BF609D0938900EBEB88 /* dolphin.c */; };
|
||||
002F3BFD09D0938900EBEB88 /* shark.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F3BF709D0938900EBEB88 /* shark.c */; };
|
||||
002F3BFE09D0938900EBEB88 /* swim.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F3BF809D0938900EBEB88 /* swim.c */; };
|
||||
002F3BFF09D0938900EBEB88 /* whale.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F3BF909D0938900EBEB88 /* whale.c */; };
|
||||
002F3C0109D093BD00EBEB88 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 002F3C0009D093BD00EBEB88 /* OpenGL.framework */; };
|
||||
002F3C6109D0951E00EBEB88 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 002F3C6009D0951E00EBEB88 /* GLUT.framework */; };
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXBuildStyle section */
|
||||
4A9504CCFFE6A4B311CA0CBA /* Debug */ = {
|
||||
isa = PBXBuildStyle;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
4A9504CDFFE6A4B311CA0CBA /* Release */ = {
|
||||
isa = PBXBuildStyle;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End PBXBuildStyle section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
002F39FD09D0883400EBEB88 /* Copy Frameworks into .app bundle */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
002F3A0009D0884600EBEB88 /* SDL.framework in Copy Frameworks into .app bundle */,
|
||||
);
|
||||
name = "Copy Frameworks into .app bundle";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
002F39F909D0881F00EBEB88 /* SDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL.framework; path = /Library/Frameworks/SDL.framework; sourceTree = "<absolute>"; };
|
||||
002F3A2B09D0888800EBEB88 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SDLMain.h; sourceTree = SOURCE_ROOT; };
|
||||
002F3A2C09D0888800EBEB88 /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SDLMain.m; sourceTree = SOURCE_ROOT; };
|
||||
002F3A3E09D088BA00EBEB88 /* main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = SOURCE_ROOT; };
|
||||
002F3BF409D0938900EBEB88 /* atlantis.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = atlantis.c; path = atlantis/atlantis.c; sourceTree = SOURCE_ROOT; };
|
||||
002F3BF509D0938900EBEB88 /* atlantis.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = atlantis.h; path = atlantis/atlantis.h; sourceTree = SOURCE_ROOT; };
|
||||
002F3BF609D0938900EBEB88 /* dolphin.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = dolphin.c; path = atlantis/dolphin.c; sourceTree = SOURCE_ROOT; };
|
||||
002F3BF709D0938900EBEB88 /* shark.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = shark.c; path = atlantis/shark.c; sourceTree = SOURCE_ROOT; };
|
||||
002F3BF809D0938900EBEB88 /* swim.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = swim.c; path = atlantis/swim.c; sourceTree = SOURCE_ROOT; };
|
||||
002F3BF909D0938900EBEB88 /* whale.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = whale.c; path = atlantis/whale.c; sourceTree = SOURCE_ROOT; };
|
||||
002F3C0009D093BD00EBEB88 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; };
|
||||
002F3C6009D0951E00EBEB88 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = ../../../../../../../../../../System/Library/Frameworks/GLUT.framework; sourceTree = SOURCE_ROOT; };
|
||||
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||
32CA4F630368D1EE00C91783 /* «PROJECTNAME»_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; path = "«PROJECTNAME»_Prefix.pch"; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
|
||||
8D1107320486CEB800E47090 /* «PROJECTNAME».app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "«PROJECTNAME».app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
8D11072E0486CEB800E47090 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
002F39FA09D0881F00EBEB88 /* SDL.framework in Frameworks */,
|
||||
002F3C6109D0951E00EBEB88 /* GLUT.framework in Frameworks */,
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
|
||||
002F3C0109D093BD00EBEB88 /* OpenGL.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
002F3BF309D0937800EBEB88 /* atlantis */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F3BF409D0938900EBEB88 /* atlantis.c */,
|
||||
002F3BF509D0938900EBEB88 /* atlantis.h */,
|
||||
002F3BF609D0938900EBEB88 /* dolphin.c */,
|
||||
002F3BF709D0938900EBEB88 /* shark.c */,
|
||||
002F3BF809D0938900EBEB88 /* swim.c */,
|
||||
002F3BF909D0938900EBEB88 /* whale.c */,
|
||||
);
|
||||
name = atlantis;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
080E96DDFE201D6D7F000001 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F3A2B09D0888800EBEB88 /* SDLMain.h */,
|
||||
002F3A2C09D0888800EBEB88 /* SDLMain.m */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F39F909D0881F00EBEB88 /* SDL.framework */,
|
||||
002F3C6009D0951E00EBEB88 /* GLUT.framework */,
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
|
||||
002F3C0009D093BD00EBEB88 /* OpenGL.framework */,
|
||||
);
|
||||
name = "Linked Frameworks";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
|
||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
|
||||
);
|
||||
name = "Other Frameworks";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
19C28FACFE9D520D11CA2CBB /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8D1107320486CEB800E47090 /* «PROJECTNAME».app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97314FDCFA39411CA2CEA /* «PROJECTNAMEASXML» */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
080E96DDFE201D6D7F000001 /* Classes */,
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */,
|
||||
29B97317FDCFA39411CA2CEA /* Resources */,
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */,
|
||||
19C28FACFE9D520D11CA2CBB /* Products */,
|
||||
);
|
||||
name = "«PROJECTNAMEASXML»";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
002F3BF309D0937800EBEB88 /* atlantis */,
|
||||
32CA4F630368D1EE00C91783 /* «PROJECTNAME»_Prefix.pch */,
|
||||
002F3A3E09D088BA00EBEB88 /* main.c */,
|
||||
);
|
||||
name = "Other Sources";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97317FDCFA39411CA2CEA /* Resources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8D1107310486CEB800E47090 /* Info.plist */,
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
|
||||
);
|
||||
name = Resources;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
8D1107260486CEB800E47090 /* «PROJECTNAME» */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "«PROJECTNAME»" */;
|
||||
buildPhases = (
|
||||
8D1107290486CEB800E47090 /* Resources */,
|
||||
8D11072C0486CEB800E47090 /* Sources */,
|
||||
8D11072E0486CEB800E47090 /* Frameworks */,
|
||||
002F39FD09D0883400EBEB88 /* Copy Frameworks into .app bundle */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
buildSettings = {
|
||||
};
|
||||
dependencies = (
|
||||
);
|
||||
name = "«PROJECTNAME»";
|
||||
productInstallPath = "$(HOME)/Applications";
|
||||
productName = "«PROJECTNAME»";
|
||||
productReference = 8D1107320486CEB800E47090 /* «PROJECTNAME».app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
29B97313FDCFA39411CA2CEA /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLOpenGLApp" */;
|
||||
buildSettings = {
|
||||
};
|
||||
buildStyles = (
|
||||
4A9504CCFFE6A4B311CA0CBA /* Debug */,
|
||||
4A9504CDFFE6A4B311CA0CBA /* Release */,
|
||||
);
|
||||
hasScannedForEncodings = 1;
|
||||
mainGroup = 29B97314FDCFA39411CA2CEA /* «PROJECTNAMEASXML» */;
|
||||
projectDirPath = "";
|
||||
targets = (
|
||||
8D1107260486CEB800E47090 /* «PROJECTNAME» */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
8D1107290486CEB800E47090 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
8D11072C0486CEB800E47090 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
002F3A2E09D0888800EBEB88 /* SDLMain.m in Sources */,
|
||||
002F3A3F09D088BA00EBEB88 /* main.c in Sources */,
|
||||
002F3BFA09D0938900EBEB88 /* atlantis.c in Sources */,
|
||||
002F3BFC09D0938900EBEB88 /* dolphin.c in Sources */,
|
||||
002F3BFD09D0938900EBEB88 /* shark.c in Sources */,
|
||||
002F3BFE09D0938900EBEB88 /* swim.c in Sources */,
|
||||
002F3BFF09D0938900EBEB88 /* whale.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
089C165DFE840E0CC02AAC07 /* English */,
|
||||
);
|
||||
name = InfoPlist.strings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
C01FCF4B08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = YES;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(HOME)/Applications";
|
||||
PRODUCT_NAME = "«PROJECTNAME»";
|
||||
WRAPPER_EXTENSION = app;
|
||||
ZERO_LINK = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
C01FCF4C08A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = (
|
||||
ppc,
|
||||
i386,
|
||||
);
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
INFOPLIST_FILE = Info.plist;
|
||||
INSTALL_PATH = "$(HOME)/Applications";
|
||||
PRODUCT_NAME = "«PROJECTNAME»";
|
||||
WRAPPER_EXTENSION = app;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
C01FCF4F08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks",
|
||||
/Library/Frameworks,
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks/SDL.framework/Headers",
|
||||
/Library/Frameworks/SDL.framework/Headers,
|
||||
"$(HEADER_SEARCH_PATHS)",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
C01FCF5008A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks",
|
||||
/Library/Frameworks,
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(HOME)/Library/Frameworks/SDL.framework/Headers",
|
||||
/Library/Frameworks/SDL.framework/Headers,
|
||||
"$(HEADER_SEARCH_PATHS)",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "«PROJECTNAME»" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
C01FCF4B08A954540054247B /* Debug */,
|
||||
C01FCF4C08A954540054247B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLOpenGLApp" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
C01FCF4F08A954540054247B /* Debug */,
|
||||
C01FCF5008A954540054247B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
|
||||
}
|
||||
@@ -0,0 +1,459 @@
|
||||
|
||||
/* Copyright (c) Mark J. Kilgard, 1994. */
|
||||
|
||||
/**
|
||||
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
|
||||
* ALL RIGHTS RESERVED
|
||||
* Permission to use, copy, modify, and distribute this software for
|
||||
* any purpose and without fee is hereby granted, provided that the above
|
||||
* copyright notice appear in all copies and that both the copyright notice
|
||||
* and this permission notice appear in supporting documentation, and that
|
||||
* the name of Silicon Graphics, Inc. not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission.
|
||||
*
|
||||
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
||||
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
||||
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
||||
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
||||
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
||||
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
||||
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
||||
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* US Government Users Restricted Rights
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
||||
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
||||
* clause at DFARS 252.227-7013 and/or in similar or successor
|
||||
* clauses in the FAR or the DOD or NASA FAR Supplement.
|
||||
* Unpublished-- rights reserved under the copyright laws of the
|
||||
* United States. Contractor/manufacturer is Silicon Graphics,
|
||||
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
||||
*
|
||||
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
#include <GLUT/glut.h>
|
||||
#include "atlantis.h"
|
||||
|
||||
fishRec sharks[NUM_SHARKS];
|
||||
fishRec momWhale;
|
||||
fishRec babyWhale;
|
||||
fishRec dolph;
|
||||
|
||||
GLboolean Timing = GL_TRUE;
|
||||
|
||||
int w_win = 640;
|
||||
int h_win = 480;
|
||||
GLint count = 0;
|
||||
GLenum StrMode = GL_VENDOR;
|
||||
|
||||
GLboolean moving;
|
||||
|
||||
static double mtime(void)
|
||||
{
|
||||
struct timeval tk_time;
|
||||
struct timezone tz;
|
||||
|
||||
gettimeofday(&tk_time, &tz);
|
||||
|
||||
return 4294.967296 * tk_time.tv_sec + 0.000001 * tk_time.tv_usec;
|
||||
}
|
||||
|
||||
static double filter(double in, double *save)
|
||||
{
|
||||
static double k1 = 0.9;
|
||||
static double k2 = 0.05;
|
||||
|
||||
save[3] = in;
|
||||
save[1] = save[0]*k1 + k2*(save[3] + save[2]);
|
||||
|
||||
save[0]=save[1];
|
||||
save[2]=save[3];
|
||||
|
||||
return(save[1]);
|
||||
}
|
||||
|
||||
void DrawStr(const char *str)
|
||||
{
|
||||
GLint i = 0;
|
||||
|
||||
if(!str) return;
|
||||
|
||||
while(str[i])
|
||||
{
|
||||
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InitFishs(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_SHARKS; i++) {
|
||||
sharks[i].x = 70000.0 + rand() % 6000;
|
||||
sharks[i].y = rand() % 6000;
|
||||
sharks[i].z = rand() % 6000;
|
||||
sharks[i].psi = rand() % 360 - 180.0;
|
||||
sharks[i].v = 1.0;
|
||||
}
|
||||
|
||||
dolph.x = 30000.0;
|
||||
dolph.y = 0.0;
|
||||
dolph.z = 6000.0;
|
||||
dolph.psi = 90.0;
|
||||
dolph.theta = 0.0;
|
||||
dolph.v = 3.0;
|
||||
|
||||
momWhale.x = 70000.0;
|
||||
momWhale.y = 0.0;
|
||||
momWhale.z = 0.0;
|
||||
momWhale.psi = 90.0;
|
||||
momWhale.theta = 0.0;
|
||||
momWhale.v = 3.0;
|
||||
|
||||
babyWhale.x = 60000.0;
|
||||
babyWhale.y = -2000.0;
|
||||
babyWhale.z = -2000.0;
|
||||
babyWhale.psi = 90.0;
|
||||
babyWhale.theta = 0.0;
|
||||
babyWhale.v = 3.0;
|
||||
}
|
||||
|
||||
void
|
||||
Atlantis_Init(void)
|
||||
{
|
||||
static float ambient[] = {0.2, 0.2, 0.2, 1.0};
|
||||
static float diffuse[] = {1.0, 1.0, 1.0, 1.0};
|
||||
static float position[] = {0.0, 1.0, 0.0, 0.0};
|
||||
static float mat_shininess[] = {90.0};
|
||||
static float mat_specular[] = {0.8, 0.8, 0.8, 1.0};
|
||||
static float mat_diffuse[] = {0.46, 0.66, 0.795, 1.0};
|
||||
static float mat_ambient[] = {0.3, 0.4, 0.5, 1.0};
|
||||
static float lmodel_ambient[] = {0.4, 0.4, 0.4, 1.0};
|
||||
static float lmodel_localviewer[] = {0.0};
|
||||
//GLfloat map1[4] = {0.0, 0.0, 0.0, 0.0};
|
||||
//GLfloat map2[4] = {0.0, 0.0, 0.0, 0.0};
|
||||
static float fog_color[] = {0.0, 0.5, 0.9, 1.0};
|
||||
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
glDepthFunc(GL_LESS);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, position);
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
||||
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
|
||||
|
||||
InitFishs();
|
||||
|
||||
glEnable(GL_FOG);
|
||||
glFogi(GL_FOG_MODE, GL_EXP);
|
||||
glFogf(GL_FOG_DENSITY, 0.0000025);
|
||||
glFogfv(GL_FOG_COLOR, fog_color);
|
||||
|
||||
glClearColor(0.0, 0.5, 0.9, 1.0);
|
||||
}
|
||||
|
||||
void
|
||||
Atlantis_Reshape(int width, int height)
|
||||
{
|
||||
w_win = width;
|
||||
h_win = height;
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60.0, (GLfloat) width / (GLfloat) height, 20000.0, 300000.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
void
|
||||
Atlantis_Animate(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_SHARKS; i++) {
|
||||
SharkPilot(&sharks[i]);
|
||||
SharkMiss(i);
|
||||
}
|
||||
WhalePilot(&dolph);
|
||||
dolph.phi++;
|
||||
//glutPostRedisplay();
|
||||
WhalePilot(&momWhale);
|
||||
momWhale.phi++;
|
||||
WhalePilot(&babyWhale);
|
||||
babyWhale.phi++;
|
||||
}
|
||||
|
||||
void
|
||||
Atlantis_Key(unsigned char key, int x, int y)
|
||||
{
|
||||
switch (key) {
|
||||
case 't':
|
||||
Timing = !Timing;
|
||||
break;
|
||||
case ' ':
|
||||
switch(StrMode)
|
||||
{
|
||||
case GL_EXTENSIONS:
|
||||
StrMode = GL_VENDOR;
|
||||
break;
|
||||
case GL_VENDOR:
|
||||
StrMode = GL_RENDERER;
|
||||
break;
|
||||
case GL_RENDERER:
|
||||
StrMode = GL_VERSION;
|
||||
break;
|
||||
case GL_VERSION:
|
||||
StrMode = GL_EXTENSIONS;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 27: /* Esc will quit */
|
||||
exit(1);
|
||||
break;
|
||||
case 's': /* "s" start animation */
|
||||
moving = GL_TRUE;
|
||||
//glutIdleFunc(Animate);
|
||||
break;
|
||||
case 'a': /* "a" stop animation */
|
||||
moving = GL_FALSE;
|
||||
//glutIdleFunc(NULL);
|
||||
break;
|
||||
case '.': /* "." will advance frame */
|
||||
if (!moving) {
|
||||
Atlantis_Animate();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
void Display(void)
|
||||
{
|
||||
static float P123[3] = {-448.94, -203.14, 9499.60};
|
||||
static float P124[3] = {-442.64, -185.20, 9528.07};
|
||||
static float P125[3] = {-441.07, -148.05, 9528.07};
|
||||
static float P126[3] = {-443.43, -128.84, 9499.60};
|
||||
static float P127[3] = {-456.87, -146.78, 9466.67};
|
||||
static float P128[3] = {-453.68, -183.93, 9466.67};
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
FishTransform(&dolph);
|
||||
DrawDolphin(&dolph);
|
||||
glPopMatrix();
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
Atlantis_Display(void)
|
||||
{
|
||||
int i;
|
||||
static double th[4] = {0.0, 0.0, 0.0, 0.0};
|
||||
static double t1 = 0.0, t2 = 0.0, t;
|
||||
char num_str[128];
|
||||
|
||||
t1 = t2;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
for (i = 0; i < NUM_SHARKS; i++) {
|
||||
glPushMatrix();
|
||||
FishTransform(&sharks[i]);
|
||||
DrawShark(&sharks[i]);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
FishTransform(&dolph);
|
||||
DrawDolphin(&dolph);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
FishTransform(&momWhale);
|
||||
DrawWhale(&momWhale);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
FishTransform(&babyWhale);
|
||||
glScalef(0.45, 0.45, 0.3);
|
||||
DrawWhale(&babyWhale);
|
||||
glPopMatrix();
|
||||
|
||||
if(Timing)
|
||||
{
|
||||
t2 = mtime();
|
||||
t = t2 - t1;
|
||||
if(t > 0.0001) t = 1.0 / t;
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glColor3f(1.0, 0.0, 0.0);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, w_win, 0, h_win, -10.0, 10.0);
|
||||
|
||||
glRasterPos2f(5.0, 5.0);
|
||||
|
||||
switch(StrMode)
|
||||
{
|
||||
case GL_VENDOR:
|
||||
sprintf(num_str, "%0.2f Hz, %dx%d, VENDOR: ", filter(t, th), w_win, h_win);
|
||||
DrawStr(num_str);
|
||||
DrawStr(glGetString(GL_VENDOR));
|
||||
break;
|
||||
case GL_RENDERER:
|
||||
sprintf(num_str, "%0.2f Hz, %dx%d, RENDERER: ", filter(t, th), w_win, h_win);
|
||||
DrawStr(num_str);
|
||||
DrawStr(glGetString(GL_RENDERER));
|
||||
break;
|
||||
case GL_VERSION:
|
||||
sprintf(num_str, "%0.2f Hz, %dx%d, VERSION: ", filter(t, th), w_win, h_win);
|
||||
DrawStr(num_str);
|
||||
DrawStr(glGetString(GL_VERSION));
|
||||
break;
|
||||
case GL_EXTENSIONS:
|
||||
sprintf(num_str, "%0.2f Hz, %dx%d, EXTENSIONS: ", filter(t, th), w_win, h_win);
|
||||
DrawStr(num_str);
|
||||
DrawStr(glGetString(GL_EXTENSIONS));
|
||||
break;
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
Visible(int state)
|
||||
{
|
||||
if (state == GLUT_VISIBLE) {
|
||||
if (moving)
|
||||
glutIdleFunc(Animate);
|
||||
} else {
|
||||
if (moving)
|
||||
glutIdleFunc(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
timingSelect(int value)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case 1:
|
||||
StrMode = GL_VENDOR;
|
||||
break;
|
||||
case 2:
|
||||
StrMode = GL_RENDERER;
|
||||
break;
|
||||
case 3:
|
||||
StrMode = GL_VERSION;
|
||||
break;
|
||||
case 4:
|
||||
StrMode = GL_EXTENSIONS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
menuSelect(int value)
|
||||
{
|
||||
switch (value) {
|
||||
case 1:
|
||||
moving = GL_TRUE;
|
||||
glutIdleFunc(Animate);
|
||||
break;
|
||||
case 2:
|
||||
moving = GL_FALSE;
|
||||
glutIdleFunc(NULL);
|
||||
break;
|
||||
case 4:
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
GLboolean fullscreen = GL_FALSE;
|
||||
GLint time_menu;
|
||||
|
||||
srand(0);
|
||||
|
||||
glutInit(&argc, argv);
|
||||
if (argc > 1 && !strcmp(argv[1], "-w"))
|
||||
fullscreen = GL_FALSE;
|
||||
|
||||
//glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitDisplayString("rgba double depth=24");
|
||||
if (fullscreen) {
|
||||
glutGameModeString("1024x768:32");
|
||||
glutEnterGameMode();
|
||||
} else {
|
||||
glutInitWindowSize(320, 240);
|
||||
glutCreateWindow("Atlantis Timing");
|
||||
}
|
||||
Init();
|
||||
glutDisplayFunc(Display);
|
||||
glutReshapeFunc(Reshape);
|
||||
glutKeyboardFunc(Key);
|
||||
moving = GL_TRUE;
|
||||
glutIdleFunc(Animate);
|
||||
glutVisibilityFunc(Visible);
|
||||
|
||||
time_menu = glutCreateMenu(timingSelect);
|
||||
glutAddMenuEntry("GL_VENDOR", 1);
|
||||
glutAddMenuEntry("GL_RENDERER", 2);
|
||||
glutAddMenuEntry("GL_VERSION", 3);
|
||||
glutAddMenuEntry("GL_EXTENSIONS", 4);
|
||||
|
||||
glutCreateMenu(menuSelect);
|
||||
glutAddMenuEntry("Start motion", 1);
|
||||
glutAddMenuEntry("Stop motion", 2);
|
||||
glutAddSubMenu("Timing Mode", time_menu);
|
||||
glutAddMenuEntry("Quit", 4);
|
||||
|
||||
//glutAttachMenu(GLUT_RIGHT_BUTTON);
|
||||
glutAttachMenu(GLUT_RIGHT_BUTTON);
|
||||
glutMainLoop();
|
||||
return 0; // ANSI C requires main to return int.
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
|
||||
* ALL RIGHTS RESERVED
|
||||
* Permission to use, copy, modify, and distribute this software for
|
||||
* any purpose and without fee is hereby granted, provided that the above
|
||||
* copyright notice appear in all copies and that both the copyright notice
|
||||
* and this permission notice appear in supporting documentation, and that
|
||||
* the name of Silicon Graphics, Inc. not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission.
|
||||
*
|
||||
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
||||
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
||||
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
||||
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
||||
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
||||
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
||||
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
||||
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* US Government Users Restricted Rights
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
||||
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
||||
* clause at DFARS 252.227-7013 and/or in similar or successor
|
||||
* clauses in the FAR or the DOD or NASA FAR Supplement.
|
||||
* Unpublished-- rights reserved under the copyright laws of the
|
||||
* United States. Contractor/manufacturer is Silicon Graphics,
|
||||
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
||||
*
|
||||
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
|
||||
*/
|
||||
#define RAD 57.295
|
||||
#define RRAD 0.01745
|
||||
|
||||
#define NUM_SHARKS 4
|
||||
#define SHARKSIZE 6000
|
||||
#define SHARKSPEED 100.0
|
||||
|
||||
#define WHALESPEED 250.0
|
||||
|
||||
typedef struct _fishRec {
|
||||
float x, y, z, phi, theta, psi, v;
|
||||
float xt, yt, zt;
|
||||
float htail, vtail;
|
||||
float dtheta;
|
||||
int spurt, attack;
|
||||
} fishRec;
|
||||
|
||||
extern fishRec sharks[NUM_SHARKS];
|
||||
extern fishRec momWhale;
|
||||
extern fishRec babyWhale;
|
||||
extern fishRec dolph;
|
||||
|
||||
extern void FishTransform(fishRec *);
|
||||
extern void WhalePilot(fishRec *);
|
||||
extern void SharkPilot(fishRec *);
|
||||
extern void SharkMiss(int);
|
||||
extern void DrawWhale(fishRec *);
|
||||
extern void DrawShark(fishRec *);
|
||||
extern void DrawDolphin(fishRec *);
|
||||
1934
Xcode/TemplatesForXcode/SDL OpenGL Application/atlantis/dolphin.c
Normal file
1934
Xcode/TemplatesForXcode/SDL OpenGL Application/atlantis/dolphin.c
Normal file
File diff suppressed because it is too large
Load Diff
1308
Xcode/TemplatesForXcode/SDL OpenGL Application/atlantis/shark.c
Normal file
1308
Xcode/TemplatesForXcode/SDL OpenGL Application/atlantis/shark.c
Normal file
File diff suppressed because it is too large
Load Diff
188
Xcode/TemplatesForXcode/SDL OpenGL Application/atlantis/swim.c
Normal file
188
Xcode/TemplatesForXcode/SDL OpenGL Application/atlantis/swim.c
Normal file
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
|
||||
* ALL RIGHTS RESERVED
|
||||
* Permission to use, copy, modify, and distribute this software for
|
||||
* any purpose and without fee is hereby granted, provided that the above
|
||||
* copyright notice appear in all copies and that both the copyright notice
|
||||
* and this permission notice appear in supporting documentation, and that
|
||||
* the name of Silicon Graphics, Inc. not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission.
|
||||
*
|
||||
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
||||
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
||||
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
||||
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
||||
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
||||
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
||||
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
||||
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* US Government Users Restricted Rights
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
||||
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
||||
* clause at DFARS 252.227-7013 and/or in similar or successor
|
||||
* clauses in the FAR or the DOD or NASA FAR Supplement.
|
||||
* Unpublished-- rights reserved under the copyright laws of the
|
||||
* United States. Contractor/manufacturer is Silicon Graphics,
|
||||
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
||||
*
|
||||
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
|
||||
*/
|
||||
#include <math.h>
|
||||
#include <stdlib.h> /* For rand(). */
|
||||
#include <GLUT/glut.h>
|
||||
#include "atlantis.h"
|
||||
|
||||
void
|
||||
FishTransform(fishRec * fish)
|
||||
{
|
||||
|
||||
glTranslatef(fish->y, fish->z, -fish->x);
|
||||
glRotatef(-fish->psi, 0.0, 1.0, 0.0);
|
||||
glRotatef(fish->theta, 1.0, 0.0, 0.0);
|
||||
glRotatef(-fish->phi, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
void
|
||||
WhalePilot(fishRec * fish)
|
||||
{
|
||||
|
||||
fish->phi = -20.0;
|
||||
fish->theta = 0.0;
|
||||
fish->psi -= 0.5;
|
||||
|
||||
fish->x += WHALESPEED * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD);
|
||||
fish->y += WHALESPEED * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD);
|
||||
fish->z += WHALESPEED * fish->v * sin(fish->theta / RAD);
|
||||
}
|
||||
|
||||
void
|
||||
SharkPilot(fishRec * fish)
|
||||
{
|
||||
static int sign = 1;
|
||||
float X, Y, Z, tpsi, ttheta, thetal;
|
||||
|
||||
fish->xt = 60000.0;
|
||||
fish->yt = 0.0;
|
||||
fish->zt = 0.0;
|
||||
|
||||
X = fish->xt - fish->x;
|
||||
Y = fish->yt - fish->y;
|
||||
Z = fish->zt - fish->z;
|
||||
|
||||
thetal = fish->theta;
|
||||
|
||||
ttheta = RAD * atan(Z / (sqrt(X * X + Y * Y)));
|
||||
|
||||
if (ttheta > fish->theta + 0.25) {
|
||||
fish->theta += 0.5;
|
||||
} else if (ttheta < fish->theta - 0.25) {
|
||||
fish->theta -= 0.5;
|
||||
}
|
||||
if (fish->theta > 90.0) {
|
||||
fish->theta = 90.0;
|
||||
}
|
||||
if (fish->theta < -90.0) {
|
||||
fish->theta = -90.0;
|
||||
}
|
||||
fish->dtheta = fish->theta - thetal;
|
||||
|
||||
tpsi = RAD * atan2(Y, X);
|
||||
|
||||
fish->attack = 0;
|
||||
|
||||
if (fabs(tpsi - fish->psi) < 10.0) {
|
||||
fish->attack = 1;
|
||||
} else if (fabs(tpsi - fish->psi) < 45.0) {
|
||||
if (fish->psi > tpsi) {
|
||||
fish->psi -= 0.5;
|
||||
if (fish->psi < -180.0) {
|
||||
fish->psi += 360.0;
|
||||
}
|
||||
} else if (fish->psi < tpsi) {
|
||||
fish->psi += 0.5;
|
||||
if (fish->psi > 180.0) {
|
||||
fish->psi -= 360.0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (rand() % 100 > 98) {
|
||||
sign = 1 - sign;
|
||||
}
|
||||
fish->psi += sign;
|
||||
if (fish->psi > 180.0) {
|
||||
fish->psi -= 360.0;
|
||||
}
|
||||
if (fish->psi < -180.0) {
|
||||
fish->psi += 360.0;
|
||||
}
|
||||
}
|
||||
|
||||
if (fish->attack) {
|
||||
if (fish->v < 1.1) {
|
||||
fish->spurt = 1;
|
||||
}
|
||||
if (fish->spurt) {
|
||||
fish->v += 0.2;
|
||||
}
|
||||
if (fish->v > 5.0) {
|
||||
fish->spurt = 0;
|
||||
}
|
||||
if ((fish->v > 1.0) && (!fish->spurt)) {
|
||||
fish->v -= 0.2;
|
||||
}
|
||||
} else {
|
||||
if (!(rand() % 400) && (!fish->spurt)) {
|
||||
fish->spurt = 1;
|
||||
}
|
||||
if (fish->spurt) {
|
||||
fish->v += 0.05;
|
||||
}
|
||||
if (fish->v > 3.0) {
|
||||
fish->spurt = 0;
|
||||
}
|
||||
if ((fish->v > 1.0) && (!fish->spurt)) {
|
||||
fish->v -= 0.05;
|
||||
}
|
||||
}
|
||||
|
||||
fish->x += SHARKSPEED * fish->v * cos(fish->psi / RAD) * cos(fish->theta / RAD);
|
||||
fish->y += SHARKSPEED * fish->v * sin(fish->psi / RAD) * cos(fish->theta / RAD);
|
||||
fish->z += SHARKSPEED * fish->v * sin(fish->theta / RAD);
|
||||
}
|
||||
|
||||
void
|
||||
SharkMiss(int i)
|
||||
{
|
||||
int j;
|
||||
float avoid, thetal;
|
||||
float X, Y, Z, R;
|
||||
|
||||
for (j = 0; j < NUM_SHARKS; j++) {
|
||||
if (j != i) {
|
||||
X = sharks[j].x - sharks[i].x;
|
||||
Y = sharks[j].y - sharks[i].y;
|
||||
Z = sharks[j].z - sharks[i].z;
|
||||
|
||||
R = sqrt(X * X + Y * Y + Z * Z);
|
||||
|
||||
avoid = 1.0;
|
||||
thetal = sharks[i].theta;
|
||||
|
||||
if (R < SHARKSIZE) {
|
||||
if (Z > 0.0) {
|
||||
sharks[i].theta -= avoid;
|
||||
} else {
|
||||
sharks[i].theta += avoid;
|
||||
}
|
||||
}
|
||||
sharks[i].dtheta += (sharks[i].theta - thetal);
|
||||
}
|
||||
}
|
||||
}
|
||||
1798
Xcode/TemplatesForXcode/SDL OpenGL Application/atlantis/whale.c
Normal file
1798
Xcode/TemplatesForXcode/SDL OpenGL Application/atlantis/whale.c
Normal file
File diff suppressed because it is too large
Load Diff
179
Xcode/TemplatesForXcode/SDL OpenGL Application/main.c
Normal file
179
Xcode/TemplatesForXcode/SDL OpenGL Application/main.c
Normal file
@@ -0,0 +1,179 @@
|
||||
|
||||
/* Simple program: Create a blank window, wait for keypress, quit.
|
||||
|
||||
Please see the SDL documentation for details on using the SDL API:
|
||||
/Developer/Documentation/SDL/docs.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
extern void Atlantis_Init ();
|
||||
extern void Atlantis_Reshape (int w, int h);
|
||||
extern void Atlantis_Animate ();
|
||||
extern void Atlantis_Display ();
|
||||
|
||||
static SDL_Surface *gScreen;
|
||||
|
||||
static void initAttributes ()
|
||||
{
|
||||
// Setup attributes we want for the OpenGL context
|
||||
|
||||
int value;
|
||||
|
||||
// Don't set color bit sizes (SDL_GL_RED_SIZE, etc)
|
||||
// Mac OS X will always use 8-8-8-8 ARGB for 32-bit screens and
|
||||
// 5-5-5 RGB for 16-bit screens
|
||||
|
||||
// Request a 16-bit depth buffer (without this, there is no depth buffer)
|
||||
value = 16;
|
||||
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, value);
|
||||
|
||||
|
||||
// Request double-buffered OpenGL
|
||||
// The fact that windows are double-buffered on Mac OS X has no effect
|
||||
// on OpenGL double buffering.
|
||||
value = 1;
|
||||
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, value);
|
||||
}
|
||||
|
||||
static void printAttributes ()
|
||||
{
|
||||
// Print out attributes of the context we created
|
||||
int nAttr;
|
||||
int i;
|
||||
|
||||
int attr[] = { SDL_GL_RED_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_GREEN_SIZE,
|
||||
SDL_GL_ALPHA_SIZE, SDL_GL_BUFFER_SIZE, SDL_GL_DEPTH_SIZE };
|
||||
|
||||
char *desc[] = { "Red size: %d bits\n", "Blue size: %d bits\n", "Green size: %d bits\n",
|
||||
"Alpha size: %d bits\n", "Color buffer size: %d bits\n",
|
||||
"Depth bufer size: %d bits\n" };
|
||||
|
||||
nAttr = sizeof(attr) / sizeof(int);
|
||||
|
||||
for (i = 0; i < nAttr; i++) {
|
||||
|
||||
int value;
|
||||
SDL_GL_GetAttribute (attr[i], &value);
|
||||
printf (desc[i], value);
|
||||
}
|
||||
}
|
||||
|
||||
static void createSurface (int fullscreen)
|
||||
{
|
||||
Uint32 flags = 0;
|
||||
|
||||
flags = SDL_OPENGL;
|
||||
if (fullscreen)
|
||||
flags |= SDL_FULLSCREEN;
|
||||
|
||||
// Create window
|
||||
gScreen = SDL_SetVideoMode (640, 480, 0, flags);
|
||||
if (gScreen == NULL) {
|
||||
|
||||
fprintf (stderr, "Couldn't set 640x480 OpenGL video mode: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
static void initGL ()
|
||||
{
|
||||
Atlantis_Init ();
|
||||
Atlantis_Reshape (gScreen->w, gScreen->h);
|
||||
}
|
||||
|
||||
static void drawGL ()
|
||||
{
|
||||
Atlantis_Animate ();
|
||||
Atlantis_Display ();
|
||||
}
|
||||
|
||||
static void mainLoop ()
|
||||
{
|
||||
SDL_Event event;
|
||||
int done = 0;
|
||||
int fps = 24;
|
||||
int delay = 1000/fps;
|
||||
int thenTicks = -1;
|
||||
int nowTicks;
|
||||
|
||||
while ( !done ) {
|
||||
|
||||
/* Check for events */
|
||||
while ( SDL_PollEvent (&event) ) {
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
/* Any keypress quits the app... */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw at 24 hz
|
||||
// This approach is not normally recommended - it is better to
|
||||
// use time-based animation and run as fast as possible
|
||||
drawGL ();
|
||||
SDL_GL_SwapBuffers ();
|
||||
|
||||
// Time how long each draw-swap-delay cycle takes
|
||||
// and adjust delay to get closer to target framerate
|
||||
if (thenTicks > 0) {
|
||||
nowTicks = SDL_GetTicks ();
|
||||
delay += (1000/fps - (nowTicks-thenTicks));
|
||||
thenTicks = nowTicks;
|
||||
if (delay < 0)
|
||||
delay = 1000/fps;
|
||||
}
|
||||
else {
|
||||
thenTicks = SDL_GetTicks ();
|
||||
}
|
||||
|
||||
SDL_Delay (delay);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Init SDL video subsystem
|
||||
if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) {
|
||||
|
||||
fprintf(stderr, "Couldn't initialize SDL: %s\n",
|
||||
SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Set GL context attributes
|
||||
initAttributes ();
|
||||
|
||||
// Create GL context
|
||||
createSurface (0);
|
||||
|
||||
// Get GL context attributes
|
||||
printAttributes ();
|
||||
|
||||
// Init GL state
|
||||
initGL ();
|
||||
|
||||
// Draw, get events...
|
||||
mainLoop ();
|
||||
|
||||
// Cleanup
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user