On 21 Jun 2011, at 4:22 , Matthew Leverton wrote:
> How does the following seem with respect to OS X?
> * al_get_supported_menu_types()
> 1: application
> 2: window (display)
> 4: popup
> * al_show_menu(ALLEGRO_MENU *menu, ALLEGRO_DISPLAY *display);
> If window menus are NOT supported then the first call would always set
> the application menu. Subsequent calls to setting display menus would
> Perhaps passing NULL as the display could set the application menu
> explicitly, but unless GTK supports both application (e.g., Unity) and
> window menus, then I think making the distinction would only hinder
> compatibility across platforms as Windows-only and OS X-only people
> may not consider the other side.
I think it could work, but I find it a bit confusing. That may be because the two ways of doing menus (per-window or per-application) are really very different and trying to catch both in one API ends up being messy one way or the other. I have to admit that in any thoughts I've ever had of doing this, I'd only thought of single-window applications.
Perhaps that's the most common use-case though, so maybe it's fine to optimise for that?
> * al_popup_menu(ALLEGRO_MENU *menu, ALLEGRO_DISPLAY *display, int x,
> int y, int flags);
> Shows a context menu at the given location.
I think that's fine. I never really looked into context menus very much, but I think the API would fit from what I remember.
> * al_hide_menu(ALLEGRO_MENU *menu);
> Hides any menu of any type. If problematic, it wouldn't necessarily
> need to be supported. (Although the OS specific implementation could
> be to delete the menu item in question, and then re-add it if it is
> later shown.)
Might be a good idea to have it return true/false to indicate success or failure. Even if we intend to eventuall fix that, it helps getting the early implementation done.
Unless it's very easy to do on all platforms, of course.
> I did a quick search on stackoverflow, and saw code like:
> NSMenu* rootMenu = [NSApp mainMenu];
> [rootMenu removeItemAtIndex:2];
> Is that the type of menu Allegro is currently using? It seemed like it
> could be updated programmatically from the various questions I looked
Yes, it is.
I hadn't thought to try removeItemAtIndex, but with hindsight it makes sense. We can then probably also insert at random places, which is very useful.