ray 0.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/bin/ray +5 -0
- data/bin/ray_irb +4 -0
- data/ext/Makefile +189 -0
- data/ext/SDLMain.h +17 -0
- data/ext/SDLMain.m +381 -0
- data/ext/color.c +147 -0
- data/ext/extconf.rb +92 -0
- data/ext/image.c +192 -0
- data/ext/ray +0 -0
- data/ext/ray.bundle +0 -0
- data/ext/ray.c +125 -0
- data/ext/ray.h +82 -0
- data/ext/ray_ext.bundle +0 -0
- data/ext/ray_ext.so +0 -0
- data/ext/rect.c +204 -0
- data/ext/test.rb +21 -0
- data/lib/ray.rb +1 -0
- data/lib/ray/color.rb +30 -0
- data/lib/ray/ray.rb +11 -0
- data/lib/ray/rect.rb +13 -0
- data/spec/ray/color_spec.rb +44 -0
- data/spec/ray/image_spec.rb +34 -0
- data/spec/ray/ray_spec.rb +15 -0
- data/spec/ray/rect_spec.rb +74 -0
- data/spec_runner.rb +23 -0
- metadata +101 -0
data/.gitignore
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
begin
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
YARD::Rake::YardocTask.new do |t|
|
6
|
+
t.files = ['lib/**/*.rb', 'ext/**/*.c']
|
7
|
+
end
|
8
|
+
rescue LoadError
|
9
|
+
$stderr.puts("YARD is not installed. Please install it " +
|
10
|
+
"with the following command: gem install yard")
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'jeweler'
|
15
|
+
|
16
|
+
Jeweler::Tasks.new do |s|
|
17
|
+
s.name = "ray"
|
18
|
+
|
19
|
+
s.summary = ""
|
20
|
+
s.homepage = "http://github.com/Mon-Ouie/ray"
|
21
|
+
|
22
|
+
s.email = "mon.ouie@gmail.com"
|
23
|
+
s.authors = ["Mon ouïe"]
|
24
|
+
|
25
|
+
s.files |= FileList["lib/**/*.rb"]
|
26
|
+
s.files |= FileList["ext/**/*.{c,h,m}"]
|
27
|
+
s.files |= FileList["bin/ray{,_irb}"]
|
28
|
+
|
29
|
+
s.extensions << "ext/extconf.rb"
|
30
|
+
|
31
|
+
s.executables << "ray" << "ray_irb"
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
$stderr.puts("Jeweler is not installed. Please install it " +
|
35
|
+
"with the following command: gem intall jeweler")
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Run specs"
|
39
|
+
task :spec do
|
40
|
+
load "spec_runner.rb"
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Build C extension"
|
44
|
+
task :ext do
|
45
|
+
cd "ext/"
|
46
|
+
sh "ruby extconf.rb && make clean && make"
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0.pre1
|
data/bin/ray
ADDED
data/bin/ray_irb
ADDED
data/ext/Makefile
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /Users/kilian/.rvm/rubies/ruby-1.9.2-rc2/include/ruby-1.9.1
|
8
|
+
hdrdir = /Users/kilian/.rvm/rubies/ruby-1.9.2-rc2/include/ruby-1.9.1
|
9
|
+
arch_hdrdir = /Users/kilian/.rvm/rubies/ruby-1.9.2-rc2/include/ruby-1.9.1/$(arch)
|
10
|
+
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
11
|
+
prefix = $(DESTDIR)/Users/kilian/.rvm/rubies/ruby-1.9.2-rc2
|
12
|
+
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
13
|
+
exec_prefix = $(prefix)
|
14
|
+
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
15
|
+
sitehdrdir = $(rubyhdrdir)/site_ruby
|
16
|
+
rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
17
|
+
vendordir = $(rubylibprefix)/vendor_ruby
|
18
|
+
sitedir = $(rubylibprefix)/site_ruby
|
19
|
+
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
20
|
+
mandir = $(datarootdir)/man
|
21
|
+
localedir = $(datarootdir)/locale
|
22
|
+
libdir = $(exec_prefix)/lib
|
23
|
+
psdir = $(docdir)
|
24
|
+
pdfdir = $(docdir)
|
25
|
+
dvidir = $(docdir)
|
26
|
+
htmldir = $(docdir)
|
27
|
+
infodir = $(datarootdir)/info
|
28
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
29
|
+
oldincludedir = $(DESTDIR)/usr/include
|
30
|
+
includedir = $(prefix)/include
|
31
|
+
localstatedir = $(prefix)/var
|
32
|
+
sharedstatedir = $(prefix)/com
|
33
|
+
sysconfdir = $(prefix)/etc
|
34
|
+
datadir = $(datarootdir)
|
35
|
+
datarootdir = $(prefix)/share
|
36
|
+
libexecdir = $(exec_prefix)/libexec
|
37
|
+
sbindir = $(exec_prefix)/sbin
|
38
|
+
bindir = $(exec_prefix)/bin
|
39
|
+
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
40
|
+
archdir = $(rubylibdir)/$(arch)
|
41
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
42
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
43
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
44
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
45
|
+
|
46
|
+
CC = gcc
|
47
|
+
CXX = g++
|
48
|
+
LIBRUBY = $(LIBRUBY_SO)
|
49
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
50
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
51
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
52
|
+
OUTFLAG = -o
|
53
|
+
COUTFLAG = -o
|
54
|
+
|
55
|
+
RUBY_EXTCONF_H =
|
56
|
+
cflags = $(optflags) $(debugflags) $(warnflags)
|
57
|
+
optflags = -O3
|
58
|
+
debugflags = -ggdb
|
59
|
+
warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long
|
60
|
+
CFLAGS = -fno-common $(cflags) -fno-common -pipe -pedantic -Wall -std=c99 -Wno-unused-parameter -DRAY_USE_FRAMEWORK -I/opt/local/Library/Frameworks/SDL.framework/Headers -DHAVE_FRAMEWORK_SDL -I/System/Library/Frameworks/Cocoa.framework/Headers -DHAVE_FRAMEWORK_COCOA -I/System/Library/Frameworks/Foundation.framework/Headers -DHAVE_FRAMEWORK_FOUNDATION
|
61
|
+
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
62
|
+
DEFS =
|
63
|
+
CPPFLAGS = -DHAVE_RUBY_RUN_NODE -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
|
64
|
+
CXXFLAGS = $(CFLAGS) $(cxxflags)
|
65
|
+
ldflags = -L. -L/usr/local/lib -F/opt/local/Library/Frameworks -framework SDL -F/System/Library/Frameworks -framework Cocoa -F/System/Library/Frameworks -framework Foundation
|
66
|
+
dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace
|
67
|
+
ARCH_FLAG =
|
68
|
+
DLDFLAGS = $(ldflags) $(dldflags)
|
69
|
+
LDSHARED = $(CC) -dynamic -bundle
|
70
|
+
LDSHAREDXX = $(CXX) -dynamic -bundle
|
71
|
+
AR = ar
|
72
|
+
EXEEXT =
|
73
|
+
|
74
|
+
RUBY_BASE_NAME = ruby
|
75
|
+
RUBY_INSTALL_NAME = ruby
|
76
|
+
RUBY_SO_NAME = ruby.1.9.1
|
77
|
+
arch = x86_64-darwin10.4.0
|
78
|
+
sitearch = $(arch)
|
79
|
+
ruby_version = 1.9.1
|
80
|
+
ruby = /Users/kilian/.rvm/rubies/ruby-1.9.2-rc2/bin/ruby
|
81
|
+
RUBY = $(ruby)
|
82
|
+
RM = rm -f
|
83
|
+
RM_RF = $(RUBY) -run -e rm -- -rf
|
84
|
+
RMDIRS = $(RUBY) -run -e rmdir -- -p
|
85
|
+
MAKEDIRS = /opt/local/bin/gmkdir -p
|
86
|
+
INSTALL = /opt/local/bin/ginstall -c
|
87
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
88
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
89
|
+
COPY = cp
|
90
|
+
|
91
|
+
#### End of system configuration section. ####
|
92
|
+
|
93
|
+
preload =
|
94
|
+
|
95
|
+
libpath = . $(libdir)
|
96
|
+
LIBPATH = -L. -L$(libdir)
|
97
|
+
DEFFILE =
|
98
|
+
|
99
|
+
CLEANFILES = mkmf.log
|
100
|
+
DISTCLEANFILES =
|
101
|
+
DISTCLEANDIRS =
|
102
|
+
|
103
|
+
extout =
|
104
|
+
extout_prefix =
|
105
|
+
target_prefix =
|
106
|
+
LOCAL_LIBS =
|
107
|
+
LIBS = $(LIBRUBYARG_SHARED) -lruby -lpthread -ldl -lobjc
|
108
|
+
SRCS = color.c image.c ray.c rect.c SDLMain.m
|
109
|
+
OBJS = color.o image.o ray.o rect.o SDLMain.o
|
110
|
+
TARGET = ray_ext
|
111
|
+
DLLIB = $(TARGET).bundle
|
112
|
+
EXTSTATIC =
|
113
|
+
STATIC_LIB =
|
114
|
+
|
115
|
+
BINDIR = $(bindir)
|
116
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
117
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
118
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
119
|
+
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
120
|
+
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
121
|
+
|
122
|
+
TARGET_SO = $(DLLIB)
|
123
|
+
CLEANLIBS = $(TARGET).bundle
|
124
|
+
CLEANOBJS = *.o *.bak
|
125
|
+
|
126
|
+
all: ray $(DLLIB)
|
127
|
+
static: $(STATIC_LIB)
|
128
|
+
.PHONY: all install static install-so install-rb
|
129
|
+
.PHONY: clean clean-so clean-rb
|
130
|
+
|
131
|
+
clean-rb-default::
|
132
|
+
clean-rb::
|
133
|
+
clean-so::
|
134
|
+
clean: clean-so clean-rb-default clean-rb
|
135
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
136
|
+
|
137
|
+
distclean-rb-default::
|
138
|
+
distclean-rb::
|
139
|
+
distclean-so::
|
140
|
+
distclean: clean distclean-so distclean-rb-default distclean-rb
|
141
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
142
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
143
|
+
@-$(RMDIRS) $(DISTCLEANDIRS)
|
144
|
+
|
145
|
+
realclean: distclean
|
146
|
+
install: ray install-so install-rb
|
147
|
+
|
148
|
+
install-so: $(RUBYARCHDIR)
|
149
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
150
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
151
|
+
@-$(MAKEDIRS) $(@D)
|
152
|
+
$(INSTALL_PROG) $(DLLIB) $(@D)
|
153
|
+
install-rb: pre-install-rb install-rb-default
|
154
|
+
install-rb-default: pre-install-rb-default
|
155
|
+
pre-install-rb: Makefile
|
156
|
+
pre-install-rb-default: Makefile
|
157
|
+
$(RUBYARCHDIR):
|
158
|
+
$(MAKEDIRS) $@
|
159
|
+
|
160
|
+
site-install: ray site-install-so site-install-rb
|
161
|
+
site-install-so: install-so
|
162
|
+
site-install-rb: install-rb
|
163
|
+
|
164
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
165
|
+
|
166
|
+
.cc.o:
|
167
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
168
|
+
|
169
|
+
.cxx.o:
|
170
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
171
|
+
|
172
|
+
.cpp.o:
|
173
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
174
|
+
|
175
|
+
.C.o:
|
176
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
177
|
+
|
178
|
+
.c.o:
|
179
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
180
|
+
|
181
|
+
$(DLLIB): $(OBJS) Makefile
|
182
|
+
@-$(RM) $(@)
|
183
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
$(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
|
188
|
+
ray: $(OBJS)
|
189
|
+
$(CC) -o ray $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) -lruby
|
data/ext/SDLMain.h
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
|
2
|
+
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
|
3
|
+
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
|
4
|
+
|
5
|
+
Feel free to customize this file to suit your needs
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef _SDLMain_h_
|
9
|
+
#define _SDLMain_h_
|
10
|
+
|
11
|
+
#import <Cocoa/Cocoa.h>
|
12
|
+
|
13
|
+
@interface SDLMain : NSObject {
|
14
|
+
}
|
15
|
+
@end
|
16
|
+
|
17
|
+
#endif /* _SDLMain_h_ */
|
data/ext/SDLMain.m
ADDED
@@ -0,0 +1,381 @@
|
|
1
|
+
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
|
2
|
+
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
|
3
|
+
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
|
4
|
+
|
5
|
+
Feel free to customize this file to suit your needs
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "SDL.h"
|
9
|
+
#include "SDLMain.h"
|
10
|
+
#include <sys/param.h> /* for MAXPATHLEN */
|
11
|
+
#include <unistd.h>
|
12
|
+
|
13
|
+
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
|
14
|
+
but the method still is there and works. To avoid warnings, we declare
|
15
|
+
it ourselves here. */
|
16
|
+
@interface NSApplication(SDL_Missing_Methods)
|
17
|
+
- (void)setAppleMenu:(NSMenu *)menu;
|
18
|
+
@end
|
19
|
+
|
20
|
+
/* Use this flag to determine whether we use SDLMain.nib or not */
|
21
|
+
#define SDL_USE_NIB_FILE 0
|
22
|
+
|
23
|
+
/* Use this flag to determine whether we use CPS (docking) or not */
|
24
|
+
#define SDL_USE_CPS 1
|
25
|
+
#ifdef SDL_USE_CPS
|
26
|
+
/* Portions of CPS.h */
|
27
|
+
typedef struct CPSProcessSerNum
|
28
|
+
{
|
29
|
+
UInt32 lo;
|
30
|
+
UInt32 hi;
|
31
|
+
} CPSProcessSerNum;
|
32
|
+
|
33
|
+
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
|
34
|
+
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
|
35
|
+
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
|
36
|
+
|
37
|
+
#endif /* SDL_USE_CPS */
|
38
|
+
|
39
|
+
static int gArgc;
|
40
|
+
static char **gArgv;
|
41
|
+
static BOOL gFinderLaunch;
|
42
|
+
static BOOL gCalledAppMainline = FALSE;
|
43
|
+
|
44
|
+
static NSString *getApplicationName(void)
|
45
|
+
{
|
46
|
+
const NSDictionary *dict;
|
47
|
+
NSString *appName = 0;
|
48
|
+
|
49
|
+
/* Determine the application name */
|
50
|
+
dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
|
51
|
+
if (dict)
|
52
|
+
appName = [dict objectForKey: @"CFBundleName"];
|
53
|
+
|
54
|
+
if (![appName length])
|
55
|
+
appName = [[NSProcessInfo processInfo] processName];
|
56
|
+
|
57
|
+
return appName;
|
58
|
+
}
|
59
|
+
|
60
|
+
#if SDL_USE_NIB_FILE
|
61
|
+
/* A helper category for NSString */
|
62
|
+
@interface NSString (ReplaceSubString)
|
63
|
+
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
|
64
|
+
@end
|
65
|
+
#endif
|
66
|
+
|
67
|
+
@interface NSApplication (SDLApplication)
|
68
|
+
@end
|
69
|
+
|
70
|
+
@implementation NSApplication (SDLApplication)
|
71
|
+
/* Invoked from the Quit menu item */
|
72
|
+
- (void)terminate:(id)sender
|
73
|
+
{
|
74
|
+
/* Post a SDL_QUIT event */
|
75
|
+
SDL_Event event;
|
76
|
+
event.type = SDL_QUIT;
|
77
|
+
SDL_PushEvent(&event);
|
78
|
+
}
|
79
|
+
@end
|
80
|
+
|
81
|
+
/* The main class of the application, the application's delegate */
|
82
|
+
@implementation SDLMain
|
83
|
+
|
84
|
+
/* Set the working directory to the .app's parent directory */
|
85
|
+
- (void) setupWorkingDirectory:(BOOL)shouldChdir
|
86
|
+
{
|
87
|
+
if (shouldChdir)
|
88
|
+
{
|
89
|
+
char parentdir[MAXPATHLEN];
|
90
|
+
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
91
|
+
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
|
92
|
+
if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
|
93
|
+
chdir(parentdir); /* chdir to the binary app's parent */
|
94
|
+
}
|
95
|
+
CFRelease(url);
|
96
|
+
CFRelease(url2);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
#if SDL_USE_NIB_FILE
|
101
|
+
|
102
|
+
/* Fix menu to contain the real app name instead of "SDL App" */
|
103
|
+
- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
|
104
|
+
{
|
105
|
+
NSRange aRange;
|
106
|
+
NSEnumerator *enumerator;
|
107
|
+
NSMenuItem *menuItem;
|
108
|
+
|
109
|
+
aRange = [[aMenu title] rangeOfString:@"SDL App"];
|
110
|
+
if (aRange.length != 0)
|
111
|
+
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
|
112
|
+
|
113
|
+
enumerator = [[aMenu itemArray] objectEnumerator];
|
114
|
+
while ((menuItem = [enumerator nextObject]))
|
115
|
+
{
|
116
|
+
aRange = [[menuItem title] rangeOfString:@"SDL App"];
|
117
|
+
if (aRange.length != 0)
|
118
|
+
[menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
|
119
|
+
if ([menuItem hasSubmenu])
|
120
|
+
[self fixMenu:[menuItem submenu] withAppName:appName];
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
#else
|
125
|
+
|
126
|
+
static void setApplicationMenu(void)
|
127
|
+
{
|
128
|
+
/* warning: this code is very odd */
|
129
|
+
NSMenu *appleMenu;
|
130
|
+
NSMenuItem *menuItem;
|
131
|
+
NSString *title;
|
132
|
+
NSString *appName;
|
133
|
+
|
134
|
+
appName = getApplicationName();
|
135
|
+
appleMenu = [[NSMenu alloc] initWithTitle:@""];
|
136
|
+
|
137
|
+
/* Add menu items */
|
138
|
+
title = [@"About " stringByAppendingString:appName];
|
139
|
+
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
|
140
|
+
|
141
|
+
[appleMenu addItem:[NSMenuItem separatorItem]];
|
142
|
+
|
143
|
+
title = [@"Hide " stringByAppendingString:appName];
|
144
|
+
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
|
145
|
+
|
146
|
+
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
|
147
|
+
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
|
148
|
+
|
149
|
+
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
150
|
+
|
151
|
+
[appleMenu addItem:[NSMenuItem separatorItem]];
|
152
|
+
|
153
|
+
title = [@"Quit " stringByAppendingString:appName];
|
154
|
+
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
155
|
+
|
156
|
+
|
157
|
+
/* Put menu into the menubar */
|
158
|
+
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
159
|
+
[menuItem setSubmenu:appleMenu];
|
160
|
+
[[NSApp mainMenu] addItem:menuItem];
|
161
|
+
|
162
|
+
/* Tell the application object that this is now the application menu */
|
163
|
+
[NSApp setAppleMenu:appleMenu];
|
164
|
+
|
165
|
+
/* Finally give up our references to the objects */
|
166
|
+
[appleMenu release];
|
167
|
+
[menuItem release];
|
168
|
+
}
|
169
|
+
|
170
|
+
/* Create a window menu */
|
171
|
+
static void setupWindowMenu(void)
|
172
|
+
{
|
173
|
+
NSMenu *windowMenu;
|
174
|
+
NSMenuItem *windowMenuItem;
|
175
|
+
NSMenuItem *menuItem;
|
176
|
+
|
177
|
+
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
178
|
+
|
179
|
+
/* "Minimize" item */
|
180
|
+
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
181
|
+
[windowMenu addItem:menuItem];
|
182
|
+
[menuItem release];
|
183
|
+
|
184
|
+
/* Put menu into the menubar */
|
185
|
+
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
|
186
|
+
[windowMenuItem setSubmenu:windowMenu];
|
187
|
+
[[NSApp mainMenu] addItem:windowMenuItem];
|
188
|
+
|
189
|
+
/* Tell the application object that this is now the window menu */
|
190
|
+
[NSApp setWindowsMenu:windowMenu];
|
191
|
+
|
192
|
+
/* Finally give up our references to the objects */
|
193
|
+
[windowMenu release];
|
194
|
+
[windowMenuItem release];
|
195
|
+
}
|
196
|
+
|
197
|
+
/* Replacement for NSApplicationMain */
|
198
|
+
static void CustomApplicationMain (int argc, char **argv)
|
199
|
+
{
|
200
|
+
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
201
|
+
SDLMain *sdlMain;
|
202
|
+
|
203
|
+
/* Ensure the application object is initialised */
|
204
|
+
[NSApplication sharedApplication];
|
205
|
+
|
206
|
+
#ifdef SDL_USE_CPS
|
207
|
+
{
|
208
|
+
CPSProcessSerNum PSN;
|
209
|
+
/* Tell the dock about us */
|
210
|
+
if (!CPSGetCurrentProcess(&PSN))
|
211
|
+
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
|
212
|
+
if (!CPSSetFrontProcess(&PSN))
|
213
|
+
[NSApplication sharedApplication];
|
214
|
+
}
|
215
|
+
#endif /* SDL_USE_CPS */
|
216
|
+
|
217
|
+
/* Set up the menubar */
|
218
|
+
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
219
|
+
setApplicationMenu();
|
220
|
+
setupWindowMenu();
|
221
|
+
|
222
|
+
/* Create SDLMain and make it the app delegate */
|
223
|
+
sdlMain = [[SDLMain alloc] init];
|
224
|
+
[NSApp setDelegate:sdlMain];
|
225
|
+
|
226
|
+
/* Start the main event loop */
|
227
|
+
[NSApp run];
|
228
|
+
|
229
|
+
[sdlMain release];
|
230
|
+
[pool release];
|
231
|
+
}
|
232
|
+
|
233
|
+
#endif
|
234
|
+
|
235
|
+
|
236
|
+
/*
|
237
|
+
* Catch document open requests...this lets us notice files when the app
|
238
|
+
* was launched by double-clicking a document, or when a document was
|
239
|
+
* dragged/dropped on the app's icon. You need to have a
|
240
|
+
* CFBundleDocumentsType section in your Info.plist to get this message,
|
241
|
+
* apparently.
|
242
|
+
*
|
243
|
+
* Files are added to gArgv, so to the app, they'll look like command line
|
244
|
+
* arguments. Previously, apps launched from the finder had nothing but
|
245
|
+
* an argv[0].
|
246
|
+
*
|
247
|
+
* This message may be received multiple times to open several docs on launch.
|
248
|
+
*
|
249
|
+
* This message is ignored once the app's mainline has been called.
|
250
|
+
*/
|
251
|
+
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
252
|
+
{
|
253
|
+
const char *temparg;
|
254
|
+
size_t arglen;
|
255
|
+
char *arg;
|
256
|
+
char **newargv;
|
257
|
+
|
258
|
+
if (!gFinderLaunch) /* MacOS is passing command line args. */
|
259
|
+
return FALSE;
|
260
|
+
|
261
|
+
if (gCalledAppMainline) /* app has started, ignore this document. */
|
262
|
+
return FALSE;
|
263
|
+
|
264
|
+
temparg = [filename UTF8String];
|
265
|
+
arglen = SDL_strlen(temparg) + 1;
|
266
|
+
arg = (char *) SDL_malloc(arglen);
|
267
|
+
if (arg == NULL)
|
268
|
+
return FALSE;
|
269
|
+
|
270
|
+
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
|
271
|
+
if (newargv == NULL)
|
272
|
+
{
|
273
|
+
SDL_free(arg);
|
274
|
+
return FALSE;
|
275
|
+
}
|
276
|
+
gArgv = newargv;
|
277
|
+
|
278
|
+
SDL_strlcpy(arg, temparg, arglen);
|
279
|
+
gArgv[gArgc++] = arg;
|
280
|
+
gArgv[gArgc] = NULL;
|
281
|
+
return TRUE;
|
282
|
+
}
|
283
|
+
|
284
|
+
|
285
|
+
/* Called when the internal event loop has just started running */
|
286
|
+
- (void) applicationDidFinishLaunching: (NSNotification *) note
|
287
|
+
{
|
288
|
+
int status;
|
289
|
+
|
290
|
+
/* Set the working directory to the .app's parent directory */
|
291
|
+
[self setupWorkingDirectory:gFinderLaunch];
|
292
|
+
|
293
|
+
#if SDL_USE_NIB_FILE
|
294
|
+
/* Set the main menu to contain the real app name instead of "SDL App" */
|
295
|
+
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
|
296
|
+
#endif
|
297
|
+
|
298
|
+
/* Hand off to main application code */
|
299
|
+
gCalledAppMainline = TRUE;
|
300
|
+
status = SDL_main (gArgc, gArgv);
|
301
|
+
|
302
|
+
/* We're done, thank you for playing */
|
303
|
+
exit(status);
|
304
|
+
}
|
305
|
+
@end
|
306
|
+
|
307
|
+
|
308
|
+
@implementation NSString (ReplaceSubString)
|
309
|
+
|
310
|
+
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
|
311
|
+
{
|
312
|
+
unsigned int bufferSize;
|
313
|
+
unsigned int selfLen = (unsigned int)[self length];
|
314
|
+
unsigned int aStringLen = (unsigned int)[aString length];
|
315
|
+
unichar *buffer;
|
316
|
+
NSRange localRange;
|
317
|
+
NSString *result;
|
318
|
+
|
319
|
+
bufferSize = selfLen + aStringLen - (unsigned int)aRange.length;
|
320
|
+
buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
|
321
|
+
|
322
|
+
/* Get first part into buffer */
|
323
|
+
localRange.location = 0;
|
324
|
+
localRange.length = aRange.location;
|
325
|
+
[self getCharacters:buffer range:localRange];
|
326
|
+
|
327
|
+
/* Get middle part into buffer */
|
328
|
+
localRange.location = 0;
|
329
|
+
localRange.length = aStringLen;
|
330
|
+
[aString getCharacters:(buffer+aRange.location) range:localRange];
|
331
|
+
|
332
|
+
/* Get last part into buffer */
|
333
|
+
localRange.location = aRange.location + aRange.length;
|
334
|
+
localRange.length = selfLen - localRange.location;
|
335
|
+
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
|
336
|
+
|
337
|
+
/* Build output string */
|
338
|
+
result = [NSString stringWithCharacters:buffer length:bufferSize];
|
339
|
+
|
340
|
+
NSDeallocateMemoryPages(buffer, bufferSize);
|
341
|
+
|
342
|
+
return result;
|
343
|
+
}
|
344
|
+
|
345
|
+
@end
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
#ifdef main
|
350
|
+
# undef main
|
351
|
+
#endif
|
352
|
+
|
353
|
+
|
354
|
+
/* Main entry point to executable - should *not* be SDL_main! */
|
355
|
+
int main (int argc, char **argv)
|
356
|
+
{
|
357
|
+
/* Copy the arguments into a global variable */
|
358
|
+
/* This is passed if we are launched by double-clicking */
|
359
|
+
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
|
360
|
+
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
|
361
|
+
gArgv[0] = argv[0];
|
362
|
+
gArgv[1] = NULL;
|
363
|
+
gArgc = 1;
|
364
|
+
gFinderLaunch = YES;
|
365
|
+
} else {
|
366
|
+
int i;
|
367
|
+
gArgc = argc;
|
368
|
+
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
|
369
|
+
for (i = 0; i <= argc; i++)
|
370
|
+
gArgv[i] = argv[i];
|
371
|
+
gFinderLaunch = NO;
|
372
|
+
}
|
373
|
+
|
374
|
+
#if SDL_USE_NIB_FILE
|
375
|
+
NSApplicationMain (argc, argv);
|
376
|
+
#else
|
377
|
+
CustomApplicationMain (argc, argv);
|
378
|
+
#endif
|
379
|
+
return 0;
|
380
|
+
}
|
381
|
+
|