SDL and menu bar on OS X - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Tools & Technology (/forum-10.html)
+--- Thread: SDL and menu bar on OS X (/thread-263.html)
SDL and menu bar on OS X - A_SN_ - Mar 8, 2010 11:02 AM
I want to make a working menu bar for my SDL program on Mac OS X. I've done Googling on how it's done, but to little avail. I tried the latest SDLMain.m/.h, but don't know how to work with it from there (also Quit doesn't even work on it, shouldn't it work?), and I've tried setting SDL_USE_NIB_FILE to 1 with the latest copy of SDLMain.nib/ in the same place, but the program doesn't even start and XCode reports it exited with status 1.
It's very important that I at least get the Quit option to work, from the menu, not just the shortcut, as even I can't get used to not using it, and then I need to add a whole bunch of menu items and connect it to my already existing C code (works by setting an array of flags). (Disclaimer: I'm not very experienced with Cocoa/ObjC)
Can anyone point me to a definitive solution to how to fix the Quit problem, and perhaps pointers on how to go from there with the rest of the menu? The problem has been around for so long surely someone has it all figured out by now?
SDL and menu bar on OS X - Zorg - Mar 8, 2010 02:34 PM
Last I recall, quit worked for me, just not the shortcut in the SDL templates. There's a solution here how to get the shortcuts to work: http://lists.libsdl.org/pipermail/sdl-libsdl.org/2004-October/046674.html
SDL and menu bar on OS X - A_SN_ - Mar 9, 2010 09:03 AM
zgcoder Wrote:Last I recall, quit worked for me, just not the shortcut in the SDL templates. There's a solution here how to get the shortcuts to work: http://lists.libsdl.org/pipermail/sdl-libsdl.org/2004-October/046674.html
Thanks. I've found that the default SDLMain.m works, except that the SDL_QUIT event is sent but not correctly processed. So at the end of the terminate function I added a exit(EXIT_SUCCESS); (good enough for me).
So it seems a good starting point. The shortcut doesn't work right out the box so I'll look into that now.
SDL and menu bar on OS X - Zorg - Mar 10, 2010 01:12 PM
Here is the file I use (I got rid of SDLMain.h and put the interface inside of SDLMain.m). I don't recall having issues with processing the SDL_QUIT event. Are you processing it correctly in your code (Basically, break out of the game loop and let your program terminate on its own)? The shortcuts, command Q or H or M, seem to work for me too with my SDLMain.m
SDL and menu bar on OS X - A_SN_ - Mar 10, 2010 07:12 PM
zgcoder Wrote:Here is the file I use (I got rid of SDLMain.h and put the interface inside of SDLMain.m). I don't recall having issues with processing the SDL_QUIT event. Are you processing it correctly in your code (Basically, break out of the game loop and let your program terminate on its own)? The shortcuts, command Q or H or M, seem to work for me too with my SDLMain.m
I'm not sure about that, but basically I use a flagging system I made (an array of flags) so now when I click a menu entry it sets the flag and does what it's supposed to do, even for quitting. Also I found a version of SDLMain.m where shortcuts work. So everything's working fine now. What puzzles me is why in SVN the latest SDLMain.m doesn't support the keyboard shortcuts.
SDL and menu bar on OS X - Skorche - Mar 15, 2010 10:18 AM
I just modified the quartz event handling routines to let the menu bar claim the event before passing them on to SDL. Works like a charm. I'd have to look up how I did it though and my main computer is out of service due to a dead battery and a power adapter that was forgotten at work.
SDL and menu bar on OS X - Zorg - Mar 15, 2010 11:52 AM
This is how processing quit is suppose to work. This is partially (modified a bit) taken from the SDL template:
If I wanted to add more menu items, I would add them by using cocoa methods for adding menus (for example, see -setupWindowMenu in SDLMain.m) and set up actions that pass events using SDL's system (for example, see -terminate: in SDLMain.m which handles quitting). So if, say, I wanted to implement a fullscreen menu option, the action would be something like this:
And in the game, I'd check event.type against 27 (this should probably be a constant) to handle fullscreen.
I'm not sure if this is how Skorche does it (no idea what he means by quartz event handling).
SDL and menu bar on OS X - Skorche - Mar 15, 2010 02:12 PM
I had made a trivial modification (added a single line) to the OS X SDL event handling code. The file name was something like QuartzEvent.m or something, though without being able to boot my other computer I can't easily get the specifics.
All I did was to pass the event to the main menu bar object and return early if it did trap the event.
RE: SDL and menu bar on OS X - Skorche - Feb 7, 2012 11:46 AM
Somebody asked about it, so I looked it up.
All I did was add:
To the top of the QZ_DoKey() function in video/quartz/SDL_QuartzEvents.m. It gives the menu a chance to process and swallow the event before it's passed to SDL. Cmd-q will "just work" and other things like Cmd-h or Cmd-m will work and the keypresses that trigger them wont make it to the game to screw things up.
I haven't used SDL in a couple years though. Hopefully it still actually works.
RE: SDL and menu bar on OS X - trailmix - Feb 7, 2012 11:51 AM
Thanks a million!