home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / CLFEB88.ZIP / MENUDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-10-19  |  3.2 KB  |  97 lines

  1. { menudemo.pas  this program demonstrates a moving-bar menu system
  2.   Copyright (c) 1987 Kevin Shook
  3.   This program is hereby released to the public domain                       }
  4.  
  5. program menudemo;
  6.  
  7.  
  8. type
  9.     move = (up,down,stop);                         { possible movements      }
  10. var
  11.    ch            : char;                           { read from keyboard      }
  12.    direction     : move;                           { direcion of bar         }
  13.    screenmenu    : array[1..5] of string[10];      { menu choices            }
  14.    screenpointer : 0..6;                           { points to item in array }
  15. const
  16.      offset      = 35 ;
  17.      escape      = #27;
  18.  
  19. procedure moveit;                                  { moves menu bar          }
  20. begin
  21.   TextColor(15);
  22.   TextBackground(0);                               { rewrites previous       }
  23.   GotoXY(offset,10+(screenpointer-1)*2);           { menu choice in ordinary }
  24.   write(screenmenu[screenpointer]);                { text                    }
  25.  
  26.   if (direction = up)  then                        { move pointer to new     }
  27.     begin                                          { menu choice             }
  28.       screenpointer := screenpointer-1;
  29.       if (screenpointer < 1) then screenpointer :=5;
  30.     end
  31.   else
  32.     begin
  33.       screenpointer := screenpointer +1;
  34.       if screenpointer > 5 then screenpointer := 1;
  35.     end;
  36.  
  37.     Textcolor(0);
  38.     TextBackground(15);
  39.     GotoXY(offset,10+(screenpointer-1)*2);         { write new menu choice   }
  40.     write(screenmenu[screenpointer]);              { in highlighted text     }
  41.  
  42. end;{of procedure}
  43.  
  44.  
  45.  
  46. begin
  47.  
  48. ScreenMenu[1] := 'Choice #1';                      { menu alternatives       }
  49. ScreenMenu[2] := 'Choice #2';                      { ... call 'em what       }
  50. ScreenMenu[3] := 'Choice #3';                      { you like  ....          }
  51. ScreenMenu[4] := 'Choice #4';
  52. ScreenMenu[5] := 'Choice #5';
  53.  
  54. clrscr;                                            { draws the screen        }
  55. gotoxy(32,1);
  56. write('Menu Demonstration');
  57.  
  58. for ScreenPointer := 1 to 5 do
  59.  begin
  60.   GotoXY(offset,10+(ScreenPointer-1)*2);           { puts the choices        }
  61.   write(ScreenMenu[ScreenPointer]);                { on the screen           }
  62.  end;
  63.  
  64.  
  65.  
  66.  
  67. screenpointer := 2;                                { initializes             }
  68. direction := up;                                   { req'd variables         }
  69. moveit;                                            { draw first bar          }
  70.  
  71. repeat
  72.   if keypressed then
  73.     begin
  74.     read(kbd,ch);
  75.     if ch = #13 then direction := stop;            { RETURN key pressed      }
  76.     if(ch = escape) and (keypressed) then
  77.     begin
  78.       read(kbd,ch);
  79.       if ch = #72 then
  80.         begin
  81.           direction := up;
  82.           moveit;
  83.         end
  84.       else if ch = #80 then
  85.         begin
  86.           direction := down;
  87.           moveit;
  88.       end;
  89.     end
  90.     end;
  91. until (direction = stop);
  92.  
  93. { this program just quits when the RETURN key is pressed.  In a "real"
  94. program, this would be a procedure which returns the value of the position
  95. of the bar (which is stored in the variable ScreenPointer)                   }
  96.  
  97. end.                                               {  of program             }