English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 10 April 2023, 22:29   #1
desiv
Registered User
 
desiv's Avatar
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,770
How to handle CHECKIT|MENUTOGGLE menu items?

I have a question on the best way to handle CHECKIT menu items.

I have a program that has 4 CHECKIT|MENUTOGGLE|CHECKED menu items.

When I wrote the program (32 years ago), I didn't know the Amiga would multi select, so my code looked for what you selected via MENUPICK and reacted.
So, if you RMB, go to Options, then go to Sounds and let go or left click (once), it will change the state (whether checked or not) of the Sounds item and I set or unset a variable showing that.

What I didn't think about was that you could left click multiple times; i.e. go to options, and then while still holding the RMB, left click the item to toggle it more than once and/or left click other items in that menu while still holding the RMB... Which means my variables I set can get out of sync with the checkmark shown...

So, I am thinking I might have to change my code to react to left click activity also.. (Have to see how?)

But what would be nicer would be if my program could read the checked status (is the checkmark there) of the menu item. That way, I wouldn't need to check my variable, but at the end of any/all menu activity, I could check the status (checked or not) of all the menutoggle items and set my variables accordingly.
Or, just wait until I need to check.
i.e. Just before my play sound function, check the status of that checkmark on the menu. If it is checked, play the sound, if not, don't.
But I'm not sure if I can check the status of the menu items (is it all event driven?)...

Is there a best practice on how to do that in Amiga C?
Quick check of my Amiga C books aren't showing that...

Pointers to good references on this would also be appreciated.
The Amiga C Manual doesn't seem to be helping me here either. ;-)

Thanx,
desiv is offline  
Old 10 April 2023, 23:16   #2
desiv
Registered User
 
desiv's Avatar
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,770
Hmmm...

The more I look at this, I am thinking the issue might be in the convoluted method I used to try to set my variables...

So, if what I am seeing shouldn't happen, then that probably makes sense...
desiv is offline  
Old 11 April 2023, 00:50   #3
desiv
Registered User
 
desiv's Avatar
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,770
No, it's not my messy variable code. I mean, that is messy. ;-)
But I added some puts() statements to print that it detected my menu choice.

When I Left Click select multiple items, it ignores the 2nd item selected , but does add (or remove) the checkmark (I didn't try more than two).
Doesn't matter which order/which option.
I am doing this:
Wait( 1 <<my_window->UserPort->mp_SigBit );
while(my_message = (struct IntuitMessage *) GetMsg(my_window->UserPort))

And then checking MENUPICK
case MENUPICK:
if( code != MENUNULL)
/* A menu Item was chosen, which one? */

And then I am running a switch on MENUNUM (code)) to see which selection was registered on which menu item.

If I Left click multiples, only the first registers a hit in the code (a puts() message telling me it sensed it), but both of them get (or have removed) their checkmarks...

Everything works great, as long as I don't multiple select with the LMB.

Thoughts?
desiv is offline  
Old 11 April 2023, 06:58   #4
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,066
When you receive a MENUPICK message, call intui ItemAddress(msg->im_Code), check if the returned item_ptr is not NULL just in case, and then you can traverse the item_ptr->mi_NextSelect list until you've reached MENUNULL to go through all the selected items.
a/b is offline  
Old 11 April 2023, 17:02   #5
desiv
Registered User
 
desiv's Avatar
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,770
Thanx!

Quote:
Originally Posted by a/b View Post
When you receive a MENUPICK message, call intui ItemAddress(msg->im_Code), check if the returned item_ptr is not NULL just in case, and then you can traverse the item_ptr->mi_NextSelect list until you've reached MENUNULL to go through all the selected items.
Now I just have to see if I can figure out how to traverse an item. ;-)

I am also considering just making a requester to handle the options too, if I can't figure it out or it's significantly more messy.
If I am understanding it, it does sound like it would simplify some things...

I am NOT a good C programmer and all my C exp was 20-30 years ago. ;-)
Just getting back into it...

Thanx again!
desiv is offline  
Old 11 April 2023, 17:59   #6
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,066
Well, my code is in asm, but basically it's something like:
Code:
UWORD code = msg->Code;
while (code != MENUNULL) {
  struct MenuItem* item = ItemAddress(menu_strip,code);
  // process item

  code = item->NextSelect;
}
a/b is offline  
Old 11 April 2023, 18:03   #7
desiv
Registered User
 
desiv's Avatar
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,770
Quote:
Originally Posted by a/b View Post
Well, my code is in asm,
Thanx!

Yeah, I've been googling and checking books and every reference I've found has been around asm programming... ;-)
desiv is offline  
Old 12 April 2023, 05:37   #8
desiv
Registered User
 
desiv's Avatar
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,770
Quote:
Originally Posted by a/b View Post
but basically it's something
That did it! Thanx...
Basically this:
Code:
while (code != MENUNULL)
  {
    /* Check the code whenever there is an action - i.e. not MENUNULL */
    struct MenuItem* item = ItemAddress(&my_menu, code);
    if (ITEMNUM (code) == 0)
	Sound ^= 1UL << 0;
    if (ITEMNUM (code) == 1)
	Sound ^= 1UL << 1;
    if (ITEMNUM (code) == 2)
	Cycle ^= 1UL << 0;
    if (ITEMNUM (code) == 3)
	{
           if (DeckLoop == 1)
             DeckLoop = 3;
           else
             DeckLoop = 1;
        }
    code = item->NextSelect;
  }
I still have some other stuff to cleanup, but it appears to be working!
My compiler gives me a warning about int-ptr conversion on struct line, but I think that makes sense?....
Anyway, thanx again!
desiv is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Would the Amiga be able to handle Angry Birds? Steve Retrogaming General Discussion 129 26 May 2023 17:40
Menus in 1.3, CHECKIT "Checkmark" not clearing.. desiv Coders. C/C++ 2 09 April 2023 04:02
How does Paula handle pending interrupts? bloodline Coders. Asm / Hardware 6 21 January 2018 15:45
How do you get the Handle of an existing Shape? earok Coders. Blitz Basic 1 22 April 2017 11:00
How do you guys handle CommodoreUSA threads please? Pyromania project.EAB 9 17 February 2011 02:25

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:08.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.12674 seconds with 13 queries