home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / TX_MENU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  2.9 KB  |  150 lines

  1. /*********************
  2.  *
  3.  *  tx_menu.c - text menu functions.
  4.  *
  5.  *  Purpose: This file contains the functions to generate menus and
  6.  *           make selections in text mode.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include "blackstr.h"
  14. #include "kb_head.h"
  15. #include "sc_head.h"
  16. #include "tx_head.h"
  17.  
  18.  
  19. /********
  20.  *
  21.  *   tx_menu(menu) - return menu selection number
  22.  *
  23.  **/
  24.  
  25. int tx_menu(struct MENU *menu)
  26. {
  27.     int no;
  28.  
  29.     tx_menudsp(menu);               /* display it */
  30.     no = tx_menusel(menu);  /* return selection */
  31.     tx_menuclr(menu);               /* clear it */
  32.     return(no);
  33. }
  34.  
  35.  
  36. /********
  37.  *
  38.  *   char *tx_menust(menu) - return string pointer selected
  39.  *
  40.  **/
  41.  
  42. char *tx_menust(struct MENU *menu)
  43. {
  44.     char *ptr;
  45.  
  46.     tx_menudsp(menu);               /* first display it */
  47.     ptr = menu->sel[ tx_menusel(menu)];             /* return pointer */
  48.     tx_menuclr(menu);               /* clear the screen */
  49.     return(ptr);
  50. }
  51.  
  52.  
  53. /********
  54.  *
  55.  *   tx_menuclr(menu) - clear menu on screen
  56.  *
  57.  **/
  58.  
  59. void tx_menuclr(struct MENU *menu)
  60. {
  61.     sc_attr(AT_REG);
  62.     sc_clrwin(menu->col,menu->row,menu->col+menu->width,
  63.             1+menu->row+(menu->noelx+menu->noel-1)/menu->noelx);
  64. }
  65.  
  66.  
  67. /********
  68.  *
  69.  *   tx_menudsp(menu) - display menu
  70.  *
  71.  **/
  72.  
  73. void tx_menudsp(struct MENU *menu)
  74. {
  75.     int i;
  76.  
  77.     sc_cursor(FALSE);       /* cursor off */
  78.     sc_attr(AT_REG);
  79.     sc_box(menu->col,menu->row,menu->col+menu->width,
  80.                1+menu->row+(menu->noelx+menu->noel-1)/menu->noelx);
  81.     sc_setcur(menu->col,menu->row);
  82.     sc_putsfc(menu->title,menu->width);
  83.     for(i=0; i<menu->noel; ++i) {
  84.     tx_menuf(menu,i,AT_REG);
  85.     }
  86.     sc_cursor(TRUE);
  87. }
  88.  
  89.  
  90. /********
  91.  *
  92.  *   tx_menuf(menu,item,attr) - display a menu item
  93.  *
  94.  **/
  95.  
  96. void tx_menuf(struct MENU *menu, short int item, short int attr)
  97. {
  98.     sc_attr(attr);
  99.     sc_setcur(1+menu->col+(item%menu->noelx*(menu->width/menu->noelx)),
  100.                         1+menu->row+(item/menu->noelx));
  101.     sc_clrf(menu->field);
  102.     sc_putsfc(menu->sel[item],menu->field);
  103. }
  104.  
  105.  
  106. /********
  107.  *
  108.  *   tx_menusel(menu) - get menu selection
  109.  *
  110.  **/
  111.  
  112. int tx_menusel(struct MENU *menu)
  113. {
  114.     short c,i,j;
  115.  
  116.     i=j=c=0;
  117.     sc_cursor(FALSE);                       /* cursor off */
  118.     do {
  119.     tx_menuf(menu,i,AT_REG);
  120.     tx_menuf(menu,j,AT_INV);        /* j is new */
  121.     c = kb_getch();
  122.     switch (c){
  123.       case CR:
  124.       case NEWLINE:
  125.           sc_cursor(TRUE);
  126.           return(j);      /* return selection */
  127.       case CUR_DN:
  128.           i=j;
  129.           j+= min(menu->noel,menu->noelx);
  130.           break;
  131.       case CUR_UP:
  132.           i=j;
  133.           j-= min(menu->noel,menu->noelx);
  134.           break;
  135.       case CUR_LF:
  136.           i=j--;
  137.           break;
  138.       case CUR_RT:
  139.           i=j++;
  140.           break;
  141.     }
  142.     if(j<0)
  143.         j+= menu->noel;
  144.     else
  145.         if(j>=menu->noel)
  146.     j-= menu->noel;
  147.     } while (1);
  148. }
  149.     
  150.