What good is any program without a menu? Not much. Without menus you are relegated to memorizing keystroke commands to perform different functions. Because menus are so intuitive to use, that was the next gadget I focused on for my Action! Windowing Library. Maybe this library needs a name now? I’ll think about that.
In this post I detail the function created to present the vertical menu, describe how it works, then finish with a demonstration program, with bonus video of the demonstration in action (pun intended 🙂 ).
Function
This gadget is named GMenuV. The menu is navigated using the UP, DOWN, ENTER, and ESC keys. UP moves the selection indicator up, DOWN moves the selection indicator down. The selection indicator will roll from top to bottom and vise-versa. ENTER selects the currently highlighted item. ESC will exit the menu.
The parameters required are:
- bN = BYTE, window handle to display the menu in
- x = BYTE, x (column) position in the window to display the menu
- y = BYTE, y (row) position in the window to display the menu
- w = BYTE, width of each menu item (must be one size fits all)
- pS = CHAR POINTER, string containing each menu item without delimiters
The function returns a BYTE value which will be the number of the selected menu item or 0 if ESC is used to exit.
Further documentation of the function is inline:
; -------------------------------------- ; Proc..: GMenuV(BYTE bN,x,y,w CHAR POINTER pS) ; Desc..: Displays vertical menu ; Params: bN = number of window handle ; x = column for cursor ; y = row for cursor ; w = width of menu items ; pS = menu items string ; -------------------------------------- BYTE FUNC GMenuV(BYTE bN,x,y,w CHAR POINTER pS) ; Variables used BYTE bL,bR,h,bC,i,bK ; String to hold 1 menu item of max size (38) CHAR ARRAY cL(39) ; Set item number default in return value bR=1 ; Compute # items based on length of the menu string ; and specified width of each item. bC=pS(0)/w ; Repeat until done DO ; Display each item using a loop for bL=0 to bC DO ; Compute menu item position in menu string h=(bL*w)+1 ; Copy menu item into temp string from menu string ; starting at the computed position, up to the ; position plus the menu item length SCopyS(cL,pS,h,h+w) ; If current item is the selected item, ; inverse the selection if bL+1=bR then ; Inverse the string for i=1 to cL(0) DO cL(i)==!128 OD fi ; Print item at column,row count within window WPrint(bN,x,y+bL,cL) OD ; Get key bK=WaitKC() ; Process key ; -- DOWN -- if bK=KDOWN then ; Increment item number bR==+1 ; If item number is greater than max, set to 1 if bR>bC then bR=1 fi ; -- UP -- elseif bK=KUP then ; Decrement item number bR==-1 ; If item number is less than 1, set to max if bR<1 then bR=bC fi ; -- ENTER -- elseif bK=KENTER then ; Exit loop EXIT ; -- ESC -- elseif bK=KESC then ; Set item number (return value) to 0, exit loop bR=0 EXIT fi OD ; Return item number selected RETURN(bR)
Example Program
This sample program utilizes many pieces of my Action! Windowing Library. It is well documented so I will not break it down. Feel free to ask questions if needed.
; Program: WINMENUV.ACT ; Date...: 2016.07 ; Desc...: Test Window Program ; License: Creative Commons ; Attribution-NonCommercial- ; NoDerivatives ; 4.0 International ; Include library INCLUDE "D3:DEFINES.ACT" INCLUDE "D3:DEFWIN.ACT" INCLUDE "D3:LIBSTR.ACT" INCLUDE "D3:LIBWIN.ACT" INCLUDE "D3:LIBMISC.ACT" INCLUDE "D3:LIBGADG.ACT" ; Start MODULE PROC Main() ; Window handles and other byte vars BYTE bW1,bW2,bW3,bCh,bLp,bS ; Menu strings CHAR ARRAY cM(31),cM2(57) ; Init Window System WInit() ; Open window 1 (title) bW1=WOpen(2,2,36,3,WINVON) WPrint(bW1,WPCENT,1,"Unfinished Bitness") ; Open window 2 (main menu) bW2=WOpen(15,7,9,5,WINVOFF) WTitle(bW2,"Menu") ; Define main menu ; Each item is stacked back to back using the ; full width of the desired display size. ; This example is 7 characters. SCopy(cM," Open> Close Exit ") ; Do this until exit DO ; Display main menu ; In window bW2 at position 1,1 (of window) ; with menu items 7 chars wide, ; in the char string cM. ; Save returned selection to bCh. bCh=GMenuV(bW2,1,1,7,cM) ; Process choice ; -- OPEN -- if bCh=1 then ; Open window 3 (sub menu) bW3=WOpen(22,8,16,6,WINVOFF) ; Define sub menu ; Submenu uses 14 character strings. SCopy(cM2," FILENAME.001 FILENAME.002 FILENAME.003 FILENAME.004 ") ; Display sub menu ; In window bW3 at position 1,1 (of window) ; with menu items 14 chars wide, ; in the char string cM2. ; Save returned selection to bCh (not used here). bCh=GMenuV(bW3,1,1,14,cM2) ; Close sub menu window WClose(bW3) ; -- EXIT -- elseif bCh=3 then ; Exit loop exit fi OD ; Close open windows WClose(bW2) WClose(bW1) RETURN
Results
Screen shot of the primary menu being displayed:
Now the submenu being displayed:
Now a video demonstration: