Adding OS X Menu Bar with cocos2d-x 3.3

[todo: convert into a gist, and cleanup post]

I’ll post discussion topics here discussing adding or changing the Menu, but I found out adding MainMenu.xib didn’t work correctly as I have thought during the discussions over on the forum.

Looking into where the menu is created I found out that GLFW3 actually creates its own default menu with only two Menus services(App menu) and Window. The code where it sets this menu up is found in cocoa_window.m over on github.

Once I figured this out I had to investigate how to edit the app or window menu. Looking over the window code, and searching through the various header files from within XCode I was able to add an item to the Window menu.

Update 2015-01-17: I’ve posted up an example project using cocos2d-x 3.3


void STDeviceMac::addMainMenu(GLViewImpl* glview)
{
    NSWindow * appWindow = (NSWindow *)glfwGetCocoaWindow(glview->getWindow());
    if(appWindow)
    {
        // make your obj-c calls here
        NSMenu* menu = [NSApp windowsMenu];
        {
            NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:@"Check for Updates"
                                                              action:@selector(checkForUpdates:)
                                                       keyEquivalent:@""];
            [menuItem setTarget:[SUUpdater sharedUpdater]];
            [menu addItem:menuItem];
        }
        {
            NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:@"Steve's Test"
                                                              action:@selector(test:)
                                                       keyEquivalent:@""];
            [menuItem setTarget:_deviceImpl];
            [menu addItem:menuItem];
        }
    }
}