[SDL] OS X: Extra menu items, eg quit
Darrell Walisser
walisser at mac.com
Thu Jul 17 13:42:03 PDT 2003
On Thursday, July 17, 2003, at 03:01 PM, sdl-request at libsdl.org wrote:
> Message: 4
> Date: Thu, 17 Jul 2003 00:43:46 +0100
> From: Joseph Humfrey <joseph at mansefield.net>
> To: SDL Mailing List <sdl at libsdl.org>
> Subject: [SDL] OS X: Extra menu items, eg quit
> Reply-To: sdl at libsdl.org
>
> Given the template project file for an SDL application in Project
> Builder, how can I modify it so that it adds menu options into the
> application menu? I would like these since my game is going to be
> strictly a windowed desktop affair. Basically, at the minimum, I would
> like to have Quit available in the application menu, but other options
> such as New Game would also be useful, even though I have my own
> in-game interface.
>
> After browsing through SDLMain.m, it appears that some Obj-C could be
> used to simply add the menu items there, but I don't know Cocoa or
> Obj-C, so I don't really know how to do so! Also, how easy would it be
> to get the New Game menu item to send a message to my C code? Any
> example code would be very much appreciated!
>
If you've played with Cocoa at all, you've probably seen those .nib
resource files and edited them in Interface Builder. If not, I suggest
you do this first and figure out how the actions and outlets work.
In earlier versions of SDL on Mac OS X, we actually required a .nib
file - for mapping the file->quit menu item to the SDL_Quit event. This
was revised some time ago so that the menu was built by hand, so no
.nib file is is required (btw - the empty file menu is a bug).
So, how to re-enable this old behavior? If you look at SDLMain.m,
you'll see a macro #define SDL_USE_NIB_FILE 0, change that to #define
SDL_USE_NIB_FILE 1. Then copy SDLMain.nib from
SDL.framework/Contents/Resources into your project. Finally, go to your
target settings (command-option-e), and in the Cocoa section make the
main nib file SDLMain.nib and the main class SDLMain.
Now, you should be able to open up SDLMain.nib (that you copied to your
project), and add new menu items. Of course, you'll have to add
connections and new actions to SDLMain - but if you've gone through the
Cocoa tutorials this should be a snap (see
http://developer.apple.com/documentation/Cocoa/index.html to get
started).
I should really create some more project templates for this stuff. I
can already think of several:
- SDL Cocoa/nib Application
- SDL OpenGL Application
- SDL Custom NSView Application
More information about the SDL
mailing list