home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer 2.3 / 1996-04_-_Disc_2.3.bin / ah3 / menu.c < prev    next >
C/C++ Source or Header  |  1995-11-28  |  6KB  |  357 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <graph.h>
  5. //#include "netnow\hmistd.h"
  6. #include "iff.h"
  7. #include "shell.h"
  8. #include "types.h"
  9. #include "frontend.h"
  10. #include "frglobs.h"
  11. #include "frontdef.h"
  12.  
  13. #define PAPER _CYAN
  14. typedef int BOOL;
  15.  
  16.  
  17. /*-----------------03/05/95 10:11-------------------
  18. SIMPLE MENU SYSTEM
  19.  Up to 10 menu entries displayed, with title and instructions.
  20.  Keys 0-9 select menu entry- entry highlighted and number returned to app.
  21. --------------------------------------------------*/
  22.  
  23. /*-----------------01/08/95 15:04-------------------
  24.  I'm about to attempt converting it to use the pcshell. Tch.
  25. --------------------------------------------------*/
  26. /*-----------------01/08/95 16:22-------------------
  27.  nah.
  28. --------------------------------------------------*/
  29.  
  30.  
  31. /****************************************************************************
  32.                                                            GLOBALS
  33.  ***************************************************************************/
  34.  
  35. char menu[10][40];
  36. char title[30];
  37. char instruct[30];
  38. char oldMensel=0;
  39. char swazzBlazz=0; /*Ooh fuck*/
  40. char oMess[40]; /*Current message*/
  41. char blanx[39]="                                       ";
  42. short mensel;
  43. short menu_h,menu_y;
  44. #define     MENU_WIDTH    200
  45. #define    MENU_X        60
  46.  
  47.  
  48.  
  49.  
  50. /***************************************************************************
  51.                                                                FUNCTIONS
  52.  ***************************************************************************/
  53.  
  54.  
  55.  
  56. BOOL doKey (void)
  57. {
  58.     return (keydata->keys_held);
  59. }
  60.  
  61.  
  62.  
  63. /*Checks if 'q' is pressed*/
  64. BOOL quitKey (void)
  65. {
  66.     if(keydeb(K_Q))
  67.         return (1);
  68.     else
  69.         return (0);
  70. }
  71.  
  72.  
  73.  
  74. /*Waits for any key to be pressed*/
  75. void anyKey (void)
  76. {
  77.     while (keydata->keys_held==0)
  78.     {}
  79. }
  80.  
  81.  
  82. /*Waits until 'q' is pressed. */
  83. void waitQuit (void)
  84. {
  85.     while (quitKey()!=TRUE)
  86.     {
  87.         wait_loop(1);
  88.     }
  89. }
  90.  
  91.  
  92.  
  93. /*Clear the screen in current background colour*/
  94. void cls (void)
  95. {
  96. //    _clearscreen (_GCLEARSCREEN);
  97. }
  98.  
  99.  
  100. /*Initialize the menu system (MODE and COLOURS)*/
  101.  
  102. void openGraph (void)
  103. {
  104. }
  105.  
  106.  
  107. /*Resets to default, on application end*/
  108. void closeGraph (void)
  109. {
  110. }
  111.  
  112.  
  113. /*Fills a string with blank characters (use memcpy ???)*/
  114. void clrString (char *the_string,short siz)
  115. {
  116. //short i;
  117. //
  118. //for (i=0;i<siz;i++)
  119. //    {
  120. //    the_string[i]=' ';
  121. //    }
  122.  
  123. }
  124.  
  125.  
  126.  
  127. /*Hellishly boring function*/
  128.  
  129. void stringInput (char *nm,short ypos,short xpos,short siz)
  130. {
  131.  int i;
  132.  char inch=' ';
  133.  int letters=0;
  134.  int maxText=siz;
  135.  char digit[3];
  136.  
  137.  
  138. memset (nm,0,maxText);
  139.  
  140. while (inch!=13)
  141. {
  142.  
  143. if (kbhit())
  144. {
  145.     inch= getch();
  146.  
  147.     /*
  148.     itoa (inch,digit,10);
  149.     _settextposition (ypos+2,xpos);
  150.     _outtext (digit);
  151.     */
  152.  
  153.     if (inch!=13)
  154.     {
  155.         if (inch==8)
  156.         {
  157.             if (letters!=0) letters--;
  158.             nm[letters]=' ';
  159.         }
  160.  
  161.         else
  162.  
  163.         if (letters<maxText)
  164.         {
  165.             nm[letters]=inch;
  166.             letters++;
  167.         }
  168.  
  169.     }
  170.  
  171. }
  172. }
  173.  
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. /*Never makes a menu */
  182.  
  183. void makeMenu (char *mtitle,char *minstruct,char *m0,
  184.                              char *m1,char *m2,char *m3,char *m4,char *m5,
  185.                              char *m6,char *m7,char *m8,char *m9)
  186. {
  187.     int i,j,k;
  188.  
  189.     strcpy (title,mtitle);
  190.     strcpy (instruct,minstruct);
  191.  
  192.     strcpy (menu[0],m0);
  193.     strcpy (menu[1],m1);
  194.     strcpy (menu[2],m2);
  195.     strcpy (menu[3],m3);
  196.     strcpy (menu[4],m4);
  197.     strcpy (menu[5],m5);
  198.     strcpy (menu[6],m6);
  199.     strcpy (menu[7],m7);
  200.     strcpy (menu[8],m8);
  201.     strcpy (menu[9],m9);
  202.  
  203. /*
  204.     for(i=0,j=0;i<10;i++)
  205.     {
  206.         k=stringlen(menu[i]);
  207.         if(k>j)
  208.         j=k;
  209.     }
  210.  
  211.   menu_w=j;
  212.      menu_x=(SCREEN_WIDTH/2)-(menu_w/2);
  213. */
  214.   mensel=0;
  215.   oldMensel=0;
  216. }
  217.  
  218.  
  219.  
  220. /* Display all menu entries */
  221.  
  222. void drawMenu (short entries)
  223. {
  224.     short i,j;
  225.     char msel[20];
  226.     cls();
  227.  
  228.      menu_h=entries*10;
  229.     menu_y=(SCREEN_HEIGHT/2)-(menu_h/2);
  230.    memcpy(scrptr,backim.data,320*200);
  231.     disp_3d_transbox(MENU_X-10,menu_y-10,MENU_WIDTH+20,menu_h+20);
  232.      set_col(255);
  233.     sprint(title,(SCREEN_WIDTH/2)-(stringlen(title))/2,20);
  234.  
  235.     set_col(255);
  236.     sprint(instruct,(SCREEN_WIDTH/2)-(strlen(instruct))/2,30);
  237.  
  238.     /************************/
  239.     for (i=0;i<entries;i++)
  240.     {
  241.         if(mensel==i)
  242.         {
  243.             set_col(255);
  244.         }
  245.         else
  246.         {
  247.             set_col(253);
  248.         }
  249.  
  250.         sprint (menu[i],MENU_X+20,menu_y+(i*10));
  251.  
  252.     }
  253.  
  254.      dispexit();
  255.     disp_cursor();
  256.     /*
  257.     sprint ("MENSEL ",10,30);
  258.     sprintf (msel,"%d",mensel);
  259.     sprint (msel,100,30);
  260.     */
  261.  
  262.     dump_vram();
  263. }
  264.  
  265.  
  266. void reMessPort ()
  267. {
  268.     messPort (oMess);
  269. }
  270.  
  271.  
  272.  
  273. /*display system message in user port*/
  274.  
  275. void messPort (char *strg)
  276. {
  277.     strcpy (oMess,strg);
  278.  
  279.     _settextcolor(_WHITE);
  280.     _setbkcolor (_BLACK);
  281.     _settextposition (24,1);
  282.     _outtext (blanx);
  283.     _settextposition (24,1);
  284.     _outtext(strg);
  285.     _setbkcolor(PAPER);
  286. }
  287.  
  288.  
  289.  
  290. /*Poll keyboard for MENU input, 0-9*/
  291.  
  292. short menuKey ()
  293. {
  294.     char inch;
  295.  
  296.     if (kbhit())
  297.     {
  298.          inch =tolower (getch());
  299.  
  300.         if (inch=='q') return (-2);
  301.          if (inch>='0'&&inch<='9')  return (atoi (&inch));
  302.      }
  303.  
  304.     return (-1);
  305. }
  306.  
  307.  
  308. short menuMouseThingy(short entries)
  309. {int i;
  310.  
  311.  if(ctrlval !=CTRL_SELECT)
  312.     return -1;
  313.  if(mx<MENU_X || mx>MENU_X+MENU_WIDTH)
  314.     return -1;
  315.  if(my<menu_y || my>menu_y+menu_h)
  316.     return -1;
  317.  mensel=(my-menu_y)/10;
  318.  if(mensel==entries)
  319.     --mensel;
  320. }
  321.  
  322.  
  323.  
  324. /*If menu key pressed , highlight and return entry number*/
  325.  
  326. short  menuReq (short entries)
  327. {
  328.  
  329.     drawMenu(entries);
  330.     read_joypad();
  331.     if(menuMouseThingy(entries)!=-1)
  332.         return (mensel);
  333.     switch(ctrlval)
  334.         {
  335.          case CTRL_SELECT:
  336.             ctrlval=0;
  337.              return (mensel);
  338.             case CTRL_UP:
  339.               if(--mensel<0)
  340.               mensel=entries-1;
  341.              drawMenu(entries);
  342.               break;
  343.          case CTRL_CANCEL:
  344.              return (-2);
  345.           case CTRL_DOWN:
  346.               if(++mensel==entries)
  347.                   mensel=0;
  348.              drawMenu(entries);
  349.               break;
  350.          }
  351.     return (-1);
  352.  
  353. }
  354.  
  355.  
  356.  
  357.