home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / UTILITYS / FONTM2A.ARC / MENU.INC < prev    next >
Text File  |  1989-09-27  |  3KB  |  91 lines

  1. {This module needs to come after the SCRH.INC, WINDOWS.INC modules, seeing
  2. as it uses certain routines from these modules. MENU.INC needs to have defined a global
  3. constant max_menu_items which is the maximum size of the menus.
  4.  
  5. Summary of routines in this include file:
  6.  
  7. Menu(x,y,string)            The string is evaluated as a menu list with
  8.                             individual items delimited by |. This list is
  9.                             printed with right-justification and a border
  10.                             at x,y. What's behind it is saved. Returns the
  11.                             selected option's number or 0 if ESC is pressed.
  12. }
  13.  
  14.  
  15. function menu (mx,my: integer; menu_str: str80): integer;
  16. var
  17.   menu_items: array[1..max_menu_items] of string[20];
  18.   menu_size,menu_width,i,j: integer;
  19.   within_menu: boolean;
  20.   ch:char;
  21.  
  22. function rjust(work:str80):str80;
  23. begin
  24.   while length(work)<menu_width do insert(' ',work,1);
  25.   rjust:=work;
  26. end;
  27.  
  28. begin
  29.   within_menu:=true;
  30.   for i:=1 to max_menu_items do menu_items[i]:='';
  31.   menu_size:=1; {current menu size}
  32.   for i:=1 to length(menu_str) do
  33.   begin
  34.     if menu_str[i]='|' then menu_size:=menu_size+1
  35.     else
  36.       menu_items[menu_size]:=menu_items[menu_size]+menu_str[i];
  37.   end; {parse out menu options}
  38.   menu_width:=0;
  39.   for i:=1 to menu_size do
  40.   begin
  41.     if length(menu_items[i])>menu_width then menu_width:=length(menu_items[i]);
  42.   end; {now we have the maximum width of the menu}
  43.   pushwind(mx,my,menu_width+2,menu_size);
  44.   use('P'); setcolor(3);
  45.   for i:=1 to menu_size do
  46.   begin
  47.     putat(mx,my+i-1); {print up options}
  48.     print(' '+rjust(menu_items[i])+' ');
  49.   end;
  50.   j:=1; {option on menu}
  51.   repeat
  52.   begin
  53.     putat(mx+1,my+j-1);
  54.     setcolor(11); use('p'); print (rjust(menu_items[j])); setcolor(3); use('P');
  55.     zapcursor; {cursor off}
  56.     read(kbd,ch); {get a key from keyboard}
  57.     case ch of
  58.     '1'..'9' : begin
  59.            if ord(ch)-$30<=menu_size then
  60.            begin
  61.              putat(mx+1,my+j-1);
  62.              print(rjust(menu_items[j]));
  63.              j:=ord(ch)-$30;
  64.            end;
  65.          end;
  66.     ^X : begin
  67.            if j<menu_size then
  68.            begin
  69.              putat(mx+1,my+j-1);
  70.              print(rjust(menu_items[j]));
  71.              j:=j+1;
  72.            end;
  73.          end;
  74.     ^E : begin
  75.            if j>1 then
  76.            begin
  77.              putat(mx+1,my+j-1);
  78.              print(rjust(menu_items[j]));
  79.              j:=j-1;
  80.            end;
  81.          end;
  82.     end; {case}
  83.   end {repeat}
  84.   until (ch=^M) or (ch=^[);
  85.   write (^[,'(');
  86.   if ch=^M then menu:=j else menu:=0; {return option code}
  87.   within_menu:=false;
  88.   use('p');
  89.   popwind;
  90. end; {menu procedure}
  91.