Menu Functions

Before we get to the functions lets see how we actually setup and use menus.

Menus come in 2 flavours - Normal Menus which are attached to windows, and Quick Menus which are unattached floating menus called up by the Right Mouse Button.

Normal Menus

Before you can make any normal menus you first need to have a Window ready. So lets make one...

mywin.WINDOW=GUI_WINDOW(0,0,100,100,"A Window")

Now we are ready to attach some menus to it.

The process of setting up menus (and QMenus) is pretty simple. First we make our menus and sub menus, then we make the menu items that go in these menus. So lets get on with it and make a couple of menus....

First we'll make 2 main menus

file_mnu=GUI_MENU(mywin,"File")

edit_mnu=GUI_MENU(mywin,"Edit")

Now lets add a sub menu to our Edit Menu

option_mnu=GUI_SUBMENU(mywin)

Thats it......now we add the items to the menus.

Please Note : the order in which we add our items is the order in which they appear in the menus, just thought I'd mention it ;)

Our file menu items first.....

new_itm=GUI_MENUITEM(file_mnu,"New",1)

load_itm=GUI_MENUITEM(file_mnu,"Load",1)

What about adding a nice divider line? Why not :)

GUI_MENULINE(file_mnu)

Final file menu item...

quit_itm=GUI_MENUITEM(file_mnu,"Quit",1)

Right, that menu is finished, so lets do the edit menu now...

Lets start off with a pointer to that options sub menu.

GUI_SUBMENUITEM(edit_mnu,option_mnu,"Options",1)

That will add a menu item that will open a sub menu when the mouse is over it (well, it should do anyway :P )

If you wanted to add any more items to the edit menu you would do it now, but I couldn't be arsed. So we'll add some items to that options sub menu instead.

option1_itm=GUI_MENUBUTTUN(option_mnu,"1st Option",1,1,1)

option2_itm=GUI_MENUBUTTUN(option_mnu,"2nd Option",0,1,1)

option3_itm=GUI_MENUBUTTUN(option_mnu,"3rd Option",0,1,1)

We have just added 3 clickable menu buttons to our options sub_menu.

Thats it, the menus are done. Wasn't that easy-peasy? But how do you interact with menus within your program? Well, whenever you call the GUI() function XLnt checks for menu (and QMenu) access. If a Menu item has been clicked then the EVENT$ string is set to "MENU" and the ID of the item selected is placed in the variable GUI_MENUHIT. Example:

GUI()

If EVENT$="MENU" and GUI_MENUHIT=load_itm

  ;Insert load code here

Endif

Simple!

QMenus

If you understand menus then you'll have no trouble with QMenus (Quick Menus). Basically its the same code with only 2 differences...

Firstly, because QMenus work independantly of windows we do not need to specify a window when we first setup the menus.

Secondly, QMenus consist of only one Main Menu with sub menus branching from it.

For Example:

main_qmnu=GUI_MENU(NULL,"Main Menu")

file_qmnu=GUI_SUBMENU(NULL)

edit_qmnu=GUI_SUBMENU(NULL)

GUI_SUBMENUITEM(main_qmnu,file_qmnu,"File",1)

GUI_SUBMENUITEM(main_qmnu,edit_qmnu,"Edit",1)

Now we just add items in the normal way :

new_itm=GUI_MENUITEM(file_qmnu,"New",1)

load_itm=GUI_MENUITEM(file_qmnu,"Load",1)

QMenus act in exactly the same way as regards GUI(). However, if a QMenu item has been selected then EVENT$ will contain"QMenu" and the item hit will be held in GUI_QMENUHIT.

QMenu Variables

Because QMenus are not attached to windows we have to have some way of controlling them. This is done through 2 variables : GUI_QUICKMENU and GUI_QMENU_ON.

GUI_QUICKMENU contains the ID of the current QMenu : eg, main_qmnu in our example above.

GUI_QMenu_ON is used to toggle all QMenus On and Off - you may not want menus appearing when you press the right mouse button. So if GUI_QMENU_ON is set to False then no QMenus will appear when the RMB is pressed.

Did you get all that? Who said No ? Well tough! :P

Function list time...

Function Name What it does
GUI_MENU() Add a menu
GUI_SUBMENU() Add a sub-menu
GUI_MENUITEM() Add a menu item to a menu
GUI_MENUBUTTUN() Add a clickabe button to a menu
GUI_MENULINE() Insert a line into a menu
GUI_MENUSPACE() Insert a space into a menu
GUI_SUBMENUITEM() Insert a pointer to a sub-menu into a menu
GUI_MENUSTATE() Returns if a menu button is On or Off
GUI_SETSTATE() Turns a menu button On or Off
GUI_TOGGLEITEM() Activates/Deactivates a menu item