home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * tx_menu.c - text menu functions.
- *
- * Purpose: This file contains the functions to generate menus and
- * make selections in text mode.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include "blackstr.h"
- #include "kb_head.h"
- #include "sc_head.h"
- #include "tx_head.h"
-
-
- /********
- *
- * tx_menu(menu) - return menu selection number
- *
- **/
-
- int tx_menu(struct MENU *menu)
- {
- int no;
-
- tx_menudsp(menu); /* display it */
- no = tx_menusel(menu); /* return selection */
- tx_menuclr(menu); /* clear it */
- return(no);
- }
-
-
- /********
- *
- * char *tx_menust(menu) - return string pointer selected
- *
- **/
-
- char *tx_menust(struct MENU *menu)
- {
- char *ptr;
-
- tx_menudsp(menu); /* first display it */
- ptr = menu->sel[ tx_menusel(menu)]; /* return pointer */
- tx_menuclr(menu); /* clear the screen */
- return(ptr);
- }
-
-
- /********
- *
- * tx_menuclr(menu) - clear menu on screen
- *
- **/
-
- void tx_menuclr(struct MENU *menu)
- {
- sc_attr(AT_REG);
- sc_clrwin(menu->col,menu->row,menu->col+menu->width,
- 1+menu->row+(menu->noelx+menu->noel-1)/menu->noelx);
- }
-
-
- /********
- *
- * tx_menudsp(menu) - display menu
- *
- **/
-
- void tx_menudsp(struct MENU *menu)
- {
- int i;
-
- sc_cursor(FALSE); /* cursor off */
- sc_attr(AT_REG);
- sc_box(menu->col,menu->row,menu->col+menu->width,
- 1+menu->row+(menu->noelx+menu->noel-1)/menu->noelx);
- sc_setcur(menu->col,menu->row);
- sc_putsfc(menu->title,menu->width);
- for(i=0; i<menu->noel; ++i) {
- tx_menuf(menu,i,AT_REG);
- }
- sc_cursor(TRUE);
- }
-
-
- /********
- *
- * tx_menuf(menu,item,attr) - display a menu item
- *
- **/
-
- void tx_menuf(struct MENU *menu, short int item, short int attr)
- {
- sc_attr(attr);
- sc_setcur(1+menu->col+(item%menu->noelx*(menu->width/menu->noelx)),
- 1+menu->row+(item/menu->noelx));
- sc_clrf(menu->field);
- sc_putsfc(menu->sel[item],menu->field);
- }
-
-
- /********
- *
- * tx_menusel(menu) - get menu selection
- *
- **/
-
- int tx_menusel(struct MENU *menu)
- {
- short c,i,j;
-
- i=j=c=0;
- sc_cursor(FALSE); /* cursor off */
- do {
- tx_menuf(menu,i,AT_REG);
- tx_menuf(menu,j,AT_INV); /* j is new */
- c = kb_getch();
- switch (c){
- case CR:
- case NEWLINE:
- sc_cursor(TRUE);
- return(j); /* return selection */
- case CUR_DN:
- i=j;
- j+= min(menu->noel,menu->noelx);
- break;
- case CUR_UP:
- i=j;
- j-= min(menu->noel,menu->noelx);
- break;
- case CUR_LF:
- i=j--;
- break;
- case CUR_RT:
- i=j++;
- break;
- }
- if(j<0)
- j+= menu->noel;
- else
- if(j>=menu->noel)
- j-= menu->noel;
- } while (1);
- }
-
-