Intuition Menu Class

This forum is for general developer support questions.

Re: Intuition Menu Class

Postby mritter0 » Sat Sep 12, 2015 7:49 am

In the wiki, the example "Generating a whole menu (sub-)tree from a single tag list" is what I am using for a large menu. This method is suggested. I can not get MA_Hidden and MA_Image to work. Not hidden and no image.
Said tag list is made up for the most part of the usual menuclass tags that are used to specify attributes of the individual objects

Are these tags not honored? If so, why not?
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 212
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Intuition Menu Class

Postby salass00 » Sat Sep 12, 2015 9:16 am

@mritter0

I'm using this method for creating menus in a program I'm working on and MA_Image is working just fine on my 4.1 Final Edition system.

Are you passing a valid BOOPSI image for MA_Image?

The code I'm using is:
Code: Select all
menustrip = NewObject(NULL, "menuclass", MA_Type, T_ROOT, TAG_END);
if (menustrip == NULL)
    THROW();

success = DoNewMenu(menustrip,
    NM_Menu, "Project",    MA_ID, MID_PROJECT,
        NM_Item, "Open...",    MA_Key, "O", MA_ID, MID_OPEN,  MA_Image, get_image("open"),
        NM_Item, "Close",      MA_Key, "K", MA_ID, MID_CLOSE, MA_Image, get_image("close"),
        NM_Item, ML_SEPARATOR,
        NM_Item, "About...",   MA_Key, "?", MA_ID, MID_ABOUT, MA_Image, get_image("info"),
        NM_Item, ML_SEPARATOR,
        NM_Item, "Quit",       MA_Key, "Q", MA_ID, MID_QUIT,  MA_Image, get_image("quit"),
    TAG_END);
if (success == FALSE)
    THROW();


Where get_image() is:
Code: Select all
Object *XXXX::get_image(CONST_STRPTR name) {
   TEXT normal_path[256];
   TEXT selected_path[256];
   TEXT disabled_path[256];

   Strlcpy(normal_path, "tbimages:", sizeof(normal_path));
   AddPart(normal_path, name, sizeof(normal_path));
   Strlcpy(selected_path, normal_path, sizeof(selected_path));
   Strlcat(selected_path, "_s", sizeof(selected_path));
   Strlcpy(disabled_path, normal_path, sizeof(disabled_path));
   Strlcat(disabled_path, "_g", sizeof(disabled_path));

   return NewObject(BitMapClass, NULL,
      BITMAP_Screen,             screen,
      BITMAP_Masking,            TRUE,
      BITMAP_SourceFile,         normal_path,
      BITMAP_SelectSourceFile,   selected_path,
      BITMAP_DisabledSourceFile, disabled_path,
      TAG_END);
}
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 506
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland

Re: Intuition Menu Class

Postby broadblues » Sat Sep 12, 2015 1:44 pm

@xenix

I also noticed that IIntuition->SetMenuStrip() produces a warning for a menu class argument:
warning: passing argument 3 of 'IIntuition->SetMenuStrip' from incompatible pointer type

Maybe a seperate function (like SetMenuStripObj) with correct argument types would have been more in keeping with C language type identification.


The menuclass object has a menustrip in it, in the same way as a boopsi gadget has a gadget, so there is no need for a seperate function, you just need to cast the pointer, just as you would if you followed the convention of makeing all your gadgets Object * ather than struct Gadgets *s.

A seperate function to avoid a cast is a bit silly, especially given Salass00's point about other functions in the API.

You could always write a macro :-)
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 538
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Intuition Menu Class

Postby xenic » Sat Sep 12, 2015 5:32 pm

@broadblues
The menuclass object has a menustrip in it, in the same way as a boopsi gadget has a gadget, so there is no need for a seperate function, you just need to cast the pointer, just as you would if you followed the convention of makeing all your gadgets Object * ather than struct Gadgets *s.

A seperate function to avoid a cast is a bit silly, especially given Salass00's point about other functions in the API.

It's just my personal opinion but it seems silly to have to fill my programs full of type casting to avoid "type" warnings so I can focus on the meaningfull compiler warnings.

@all
I would like to point out that I would never have figured out how to use the new menu class without reading the AmigaOS documentation WIKI. I think the SDK should include a text or PDF version of the current developer WIKI with a warning that the online version may be more up-to-date. Some of us would be lost if the WIKI pages ever go down.

I actually read the SDK autodocs but the Intuition autodoc was not updated to cover changes regarding menu class. The autodoc entries for SetMenuStrip() ClearMenuStrip() and ResetMenuStrip() need to be updated to indicate how they should be used with menu class. My program would have had the appropriate type casting to begin with if the autodocs were up-to-date.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1146
Joined: Sun Jun 19, 2011 1:06 am

Re: Intuition Menu Class

Postby mritter0 » Sat Sep 12, 2015 6:38 pm

@salass00

Stupid error on my part for the images. I was locking the screen after creating the menus.

I still can not get MA_Hidden to work at creation. No big deal, I only have 2 items and they are temporary. I use SetAtts() to hide them after menu creation, before SetMenuStrip().
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 212
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Intuition Menu Class

Postby gazelle » Sun Sep 13, 2015 5:35 pm

xenic wrote:I would like to point out that I would never have figured out how to use the new menu class without reading the AmigaOS documentation WIKI. I think the SDK should include a text or PDF version of the current developer WIKI with a warning that the online version may be more up-to-date. Some of us would be lost if the WIKI pages ever go down.

SDK:Examples/GUI/MenuClass/MenuClass.c
SDK:Examples/GUI/MenuClass/MenuClassLocalize.c
User avatar
gazelle
 
Posts: 102
Joined: Sun Mar 04, 2012 1:49 pm
Location: Frohnleiten, Austria

Previous

Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 3 guests