home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.lzh / Lib / CommandScreen.cc < prev    next >
Text File  |  1994-04-23  |  3KB  |  104 lines

  1. /* -*- Mode: C -*- */
  2. /* CommandScreen.cc - CommandScreen class - command menu loop
  3.  * Created by Robert Heller on Wed Dec 11 19:40:03 1991
  4.  *
  5.  * ------------------------------------------------------------------
  6.  * Home Libarian by Deepwoods Software
  7.  * Common Class library implementation code
  8.  * ------------------------------------------------------------------
  9.  * Modification History:
  10.  * ------------------------------------------------------------------
  11.  * Contents:
  12.  * ------------------------------------------------------------------
  13.  * 
  14.  * 
  15.  * Copyright (c) 1991,1992 by Robert heller (D/B/A Deepwoods Software)
  16.  *        All Rights Reserved
  17.  * 
  18.  */
  19.  
  20. #ifdef MESSYDOS
  21. #include <cmdscren.h>
  22. #else
  23. #include <CommandScreen.h>
  24. #endif
  25.  
  26. void CommandScreen::HiliteCommand(int command,Boolean hilite)
  27. {
  28.     int lineo = CommandSpecs[command-1].LineNumber;
  29.     Terminal::term->PenPos(lineo,1);
  30.     if (hilite) Terminal::term->RevsPen();
  31.     else Terminal::term->PlainPen();
  32.     Terminal::term->PutStrAt(lineo,1,CommandSpecs[command-1].Text);
  33.     if (!hilite) Terminal::term->RevsPen();
  34.     else Terminal::term->PlainPen();
  35.     Terminal::term->PenPos(lineo,1);
  36. }
  37.  
  38. CommandScreen::CommandScreen(const char* title,int numcommands,
  39.                  CommandDescr *commands)
  40. {
  41.     strcpy(Title,title);
  42.     if (numcommands > MaxNumCommands) {
  43.         Terminal::term->Error(termErr,"Too many commands on a command screen!");
  44.         numcommands = MaxNumCommands;
  45.     }
  46.     for (int i = 0; i < numcommands; i++) {
  47.         CommandSpecs[i] = commands[i];
  48.         CommandSpecs[i].LineNumber = i + 3;
  49.     }
  50.     NumCommands = numcommands;
  51.     currentCommand = 1;
  52. }
  53.                  
  54. void CommandScreen::RePaint()
  55. {
  56.     int c = (Terminal::term->colms - strlen(Title)) >> 1;
  57.     Terminal::term->Clear();
  58.     Terminal::term->RevsPen();
  59.     Terminal::term->PutStrAt(1,c,Title);
  60.     Terminal::term->PlainPen();
  61.     for (int i = 0;i < NumCommands;i++) {
  62.         if ((i+1) == currentCommand) Terminal::term->RevsPen();
  63.         Terminal::term->PutStrAt(CommandSpecs[i].LineNumber,1,CommandSpecs[i].Text);
  64.         if ((i+1) == currentCommand) Terminal::term->PlainPen();
  65.     }
  66.     Terminal::term->PenPos(CommandSpecs[currentCommand-1].LineNumber,1);
  67. }
  68.  
  69. int CommandScreen::RunScreen()
  70. {
  71.     RePaint();
  72.     for (;;) {
  73.         int commd = 0;
  74.         int n = 0;
  75.         switch (Terminal::term->GetKey()) {
  76.             case upCmd :
  77.                 commd = (currentCommand == 1 ? 0 : currentCommand-1);
  78.                 break;
  79.             case downCmd :
  80.                 commd = (currentCommand == NumCommands ? 0 : currentCommand+1);
  81.                 break;
  82.             case '\r':
  83. #ifdef OSK
  84.             case '\l':
  85. #else
  86.             case '\n':
  87. #endif
  88.                 n = currentCommand-1;
  89.                 n = (*CommandSpecs[n].Function)();
  90.                 if (n == 0) return(1);
  91.                 else if (n < 0) RePaint();
  92.                 continue;
  93.             case escCmd : return(0);
  94.         }
  95.         if (commd == 0) Terminal::term->Bell();
  96.         else {
  97.             HiliteCommand(currentCommand,false);
  98.             HiliteCommand(currentCommand = commd,true);
  99.         }
  100.     }
  101. }
  102.  
  103.  
  104.