Hello everyone.
can someone post a simple menu example?
I tried with these examples here: http://www.pcguru.plus.com/tutorial/menus2.html
i get four warnings for the following:
initialization makes integer from pointer without a cast
struct MenuItem item1 =
{ NULL, 0, 0, 48, 12, ITEMTEXT|ITEMENABLED|HIGHCOMP, 0, &text4, &text4, NULL, NULL, 0 };
struct MenuItem item2 =
{ &item1, 0, 12, 48, 12, ITEMTEXT|ITEMENABLED|HIGHCOMP, 0, &text3, &text3, NULL, NULL, 0 };
struct MenuItem item3 =
{ &item2, 0, 24, 48, 12, ITEMTEXT|ITEMENABLED|HIGHCOMP, 0, &text2, &text2, NULL, NULL, 0 };
struct MenuItem item4 =
{ &item3, 0, 36, 48, 12, ITEMTEXT|ITEMENABLED|HIGHCOMP, 0, &text1, &text1, NULL, NULL, 0 };
The Command field of struct MenuItem is a BYTE. It should be initialized with 0, not with NULL.
Actually this way of creating menus is from Kickstart 1.3 times. It needs manual layout and is not font-sensitive (unless you do font-sensitive layouting).
Since Kickstart 2.0 (and AFAIK still in OS 4.1) one should use GadTools to create menus. Here is an example: http://thomas-rapp.homepage.t-online.de/examples/gtmenu.c
That example is funny as it uses OpenWindowTags(). Well funny to me. It also uses the complicated Wait() method. I always used WaitPort() in those circumstances. It also uses GadTools messaging functions. :-? If you ask me thay example is buggy! :-)
@thomas
thank you for the example and the explaination. Going to try the code.
@Hypex
can you post, please, and example of the alternative methods instead of openwindowtags and wait?
Sure. I can modify the example code. Note there is no problem using OpenWindowTags() as it is easier to use. It was just unusual for a program doing old style menus. But using GadTools functions for Intuition events looks like a no-no to me if GadTools gadgets aren't even used. Looks like the programmer was trying to make some things easier. I also added some missing pointer checks :-)
Thank you for this new example.
So what should i use? OpenWindowTags or the window class?
@AmigaBlitter
Depends what you want to do. If you want to have font sensitive GUI elements then definitely window.class. If you want your window to have an iconify gadget then window.class helps with that too.
You should definitely use gadtools.library for menus though as in thomas' example code or even better use the WINDOW_NewMenu tag of window.class which makes things even easier since you won't have to mess around with gadtools.library even as window.class will do most of this work for you (you just need to init the NewMenu array and pass it to window.class using the WINDOW_NewMenu tag).
@thomas
Yes, this is true. Even object-oriented GUI toolkits like ReAction wrap around the GadTools menu creation and layouting system.
The new WINDOW_NewMenu tag in Window Class is trying to make things more straightforward but, in my view, somewhat misses the target. The tag takes a pointer to a NewMenu array that defines the menu's structure and initial state. So far so good, but my gripe is that each WM_OPEN (re)sets the menu to this initial state. In reality it means that the programmer must save the state of all menu items before iconification: the current state will be lost because uniconification entails a WM_OPEN = a menu reset. WINDOW_NewMenu cares to make things easier but then gives you more work to do. What you gain on the swings you lose on the roundabouts :-) In other words, bad implementation.
So I still prefer using GadTools for menus in my Window Class-based windows.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@AmigaBlitter
You should read this introductory article to give you an overview of how GUI programming is done in AmigaOS.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@trixie
Not really that much trouble, but of course it would be easier if window.class would just update the state of the NewMenu structures before freeing the menus in WM_CLOSE. As a measure against programs that might declare the NewMenu array as const this feature could be enabled using a tag like WINDOW_UpdateNewMenuOnClose.
@salass00
It does bother me because I regularly use checkmarked or disabled items in menus, and the class is always resetting them to defaults at iconification time. Preserving them means extra work. The toolkit should help me, not give me more work on top of what I'm already busy enough doing.
WM_ICONIFY you mean. The method should definitely care to preserve the menu state because iconification is not program termination but, rather, hibernation. There's absolutely no logic in resetting any state to its initial value when the program merely goes to sleep. Just like in life: if you fall asleep naked you'll likely wake up naked as well :-)
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
No, I mean both WM_CLOSE and WM_ICONIFY.
@salass00
Whatever, as long as it works properly :-)
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@AmigaBlitter
Well you've jumped from old style to new style. I think to use the window class you would need to learn about it where as OpenWindowTags() will let you directly open a window. You've started off with old style menus but do you want to stay that way on purpose or just implement a menu bar?
Either way it depends on what you want to create and if you need to keep it simple or need to go more low level.
@Trixie
I readed your nice article. It's really well written.
@hypex
Yes, i was a little confused using old, new, OO classes, macro and so on..
@Trixie @hypex
Could i have, please, a complete example that do the following:
* Open a screen (Pubscreen or custom screen)
* Open two windows on the opened screen
* attach different menu on the windows
* manage events for the two windows.
Thank you in advance.
@AmigaBlitter
I don't have a ready example but if you study the User Interface Libraries section of the AmigaOS Documentation Wiki, you'll find some. For screen programming under AmigaOS4 I recommend having a look at an article I wrote for OS4coding.net.
Alternatively, if you want to learn to program GUIs in a object-oriented way, you will want to start with the BOOPSI section and then have a look at this source code, which shows (among other things) how to open a ReAction window using the Window Class.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@Trixie
I read many tutorial, but i haven't find a tutorial that explain how to open two (or more) windows under a customscreen with different menu for each window and different event listener.
thank you, however
Here is an example: http://thomas-rapp.homepage.t-online.de/examples/scrwin.c
Note that there are different ways to achieve the goal. Depending on the exact purpose, other methods might be better. You didn't describe detailed enough what you actually want.
@AmigaBlitter
Sorry I can't be of more help, I haven't done any traditional Intuition programming since late 1990s (when OS3.5 introduced ReAction). I've been following the object-oriented path ever since.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@thomas
really thank you for the example.
:)
@thomas
Thanks. That saves me mocking up another example.
Unfortunately WaitPort() can't be used as complexities increase but that the way of the beast. :-)
@thomas
The example works fine.
What about if i need to attach some images on the different windows? Eventually even some graphical buttons.
Thank you very much.
And if i want to attach a background image for every window? Moreover, i would like to know if is possible to use graphical buttons or use images as buttons.
Thank you
I saw other examples here to load an image, but it's not done using the New OO methods. I would like to use the new methods suggested, to avoid the trixie anger :P
Now you are exactly in the situation I had in mind when I wrote "Depending on the exact purpose, other methods might be better. You didn't describe detailed enough what you actually want".
You didn't tell us earlier what you want to do in the end and therefore we led you into a dead-end street. You got a simple example how to quickly open a window. But these basic windows do not allow to add "OO" objects.
If you had told us in the beginning that you want to add GUI objects to the windows, the example would have looked completely different. Now a complete new example needs to be developed.
Sorry if i've been not clear.
I want to learn reaction programming with the latest OO methods, with the methods described by trixie (what to do and not to do).
Your code works very well and it0s clear. Now i would like to know how to load an inmage in a window (background) and to load other images in this window (as graphical buttons), using your scrwin.
Thank you
Kind regards
P.S.
I've sent you some PM.
Here is a ReAction example with screen, window, backfill graphics, graphical buttons and menu: http://thomas-rapp.homepage.t-online.de/examples/toolbar.c
Your home work is to add the second window :-)
Thank you.as i said in a previous post, i'm a little confused with the current programming methods on os4, so forgive me for any mistake i do evem with names and terms. i would like. to learn the last shout on os4 programming so any help is welcome.
i read trixie tutorial and recomandations and studying your code
:)
Well, my example compiles on OS4 but was made with OS3 in mind. If you want to use "the last shout" on OS4, you should check new functions and attributes for optimisation.
For example the make_menu function is unnecessary if you use WINDOW_NewMenu instead of WINDOW_MenuStrip. You need to GetAttr() WINDOW_MenuStrip later in the WMHI_MENUPICK case.
Similarly you might want to use CreateBackFillHook with BFHA_BitMap instead of using a custom backfill routine.
Nah, too hard for me. I'm in the "study" phase at the moment. I understood the more easy scrwin, but toolbar it's more complicated for me. Btw, no images are loaded for the toolbar (a requester appear instead).
Thank you. I continue to study and try.
The toolbar needs AISS. http://www.masonicons.info/6.html
How can it be that you want "the last shout" in programming but don't use "the last shout" regarding updates?
Pages