home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_04 / 1n04055a < prev    next >
Text File  |  1990-06-25  |  3KB  |  125 lines

  1. #include    <stdio.h>
  2. #include    <ctype.h>
  3. #include    <string.h>
  4. #include    <graphics.h>
  5.  
  6. extern    struct    menu    *m;
  7. extern    int        m_total;
  8. extern    int        current;
  9. extern    FILE    *menu_amp;
  10.  
  11. #define    MAX_MENU_CHOICES    400
  12. #define    MAX_MENU_LENGTH        16
  13. #define    INVALID                -1
  14. #define    LEFT                0
  15. #define    TOP                    1
  16. #define    RIGHT                2
  17. #define    BOTTOM                3
  18. #define    KEY                    4
  19. #define    TEXT_LINE            12  /* text height + leading in pixels */
  20. #define    TEXT_HEIGHT            8    /* text height in pixels */
  21. #define    TEXT_WIDTH            8    /* text width in pixels */
  22. #define    FALSE                0
  23. #define    TRUE                1
  24.  
  25. /*
  26. ************************************************************************
  27. *    out_menu - display menu currents to user
  28. *
  29. *    Parameters:
  30. *        edge (out) - menu current screen coordinates and index values
  31. *
  32. *    Global:
  33. *        m_total - total menu currents in menu array
  34. *        m[]->level - menu current level in hiearachy
  35. *        m[]->name - text string for menu
  36. *        menu_area[4] - edges of menu display area
  37. *        current - current menu current
  38. *
  39. *    Copyright:
  40. *        Original code by William H. Roetzheim
  41. *        Copyright 1989 by William H. Roetzheim
  42. *        All rights reserved.
  43. **********************************************************************
  44. */
  45.  
  46. void out_menu(int edge[MAX_MENU_CHOICES][6])
  47. {
  48.     int        i,j;
  49.     int        found;
  50.     int        x;            /* x position on line */
  51.     int        y;            /* y position on line */
  52.     char    string[MAX_MENU_LENGTH];
  53.     char    location[161];
  54.     int        level;
  55.     int        item = 0;
  56.     struct    environment    *e;
  57.  
  58.     for (i = 0; i < MAX_MENU_CHOICES; i++)
  59.     {
  60.         edge[i][0] = INVALID;    /* invalid (i.e. empty ) */
  61.         edge[i][1] = INVALID;
  62.         edge[i][2] = INVALID;
  63.         edge[i][3] = INVALID;
  64.         edge[i][4] = INVALID;
  65.         edge[i][5] = INVALID;
  66.     }
  67.  
  68.     level = m[current].level;
  69.     /* move up to first element in this list */
  70.     while ((current > 0) && (m[current -1].level >= level )) current--;
  71.  
  72.     /* clear old menu currents */
  73.     fill_box(menu_area[LEFT], menu_area[TOP], menu_area[RIGHT], menu_area[BOTTOM]);
  74.  
  75.     /* now display each menu current individually */
  76.     x = 8;    /* pointer onto x coordinate of menu fill_box */
  77.     y = 2;
  78.     while ((current < m_total) && (m[current].level >= level))
  79.     {
  80.         if (m[current].level == level)
  81.         {
  82.             fseek(menu_amp, current * MAX_MENU_LENGTH, SEEK_SET);
  83.             fread(string,MAX_MENU_LENGTH,1,menu_amp);
  84.  
  85.             if (x + textwidth(string) > menu_area[RIGHT])
  86.             {
  87.                 y += TEXT_LINE;
  88.                 x = 8;
  89.             }
  90.             if ((y > TEXT_LINE + 2) || (item >= MAX_MENU_CHOICES))
  91.             {
  92.                 error (11,"out_menu");
  93.                 break;
  94.             }
  95.             /* find location of key letter */
  96.             for (i = 0; i < strlen(string) -1; i++)
  97.             {
  98.                 found = TRUE;
  99.                 for (j = 0; j < item; j++)
  100.                 {
  101.                     if (edge[j][KEY] == toupper(string[i])) found = FALSE;
  102.                 }
  103.                 if (found == TRUE) break;
  104.             }
  105.             edge[item][KEY] = toupper(string[i]);
  106.             line(x + (i * TEXT_WIDTH), y + TEXT_HEIGHT, x + ((i + 1) * TEXT_WIDTH),
  107.                 y + TEXT_HEIGHT);
  108.  
  109.             edge[item][LEFT] = x;    /* left edge */
  110.             outtextxy(x,y,string);
  111.             x += textwidth(string);
  112.  
  113.             edge[item][TOP] = 0;    /* top */
  114.             edge[item][RIGHT] = x;    /* right edge */
  115.             edge[item][BOTTOM] = y + TEXT_HEIGHT;    /* bottom edge */
  116.  
  117.  
  118.             edge[item][5] = current;
  119.  
  120.             x += 16;    /* space between words */
  121.             item++;
  122.         }
  123.         current++;
  124.     }
  125. }