home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1987 / 12 / port / menubar.i next >
Text File  |  1987-12-21  |  2KB  |  37 lines

  1. /* MENUBAR.I: Constructs a menu bar per MENUBARSPEC structure      */
  2. /* Externally defined are activepage(), videomode(), wrtstra()     */
  3. /* Notes: Preserve your cursor position before calling this fcn.   */
  4. /*          It does not save or restore caller's cursor.           */
  5. /*        The 'sel' pointer points to a solid string of menu       */
  6. /*          selections in the form "sel1\0sel2\0sel3\0...seln\0"   */
  7. /* --------------------------------------------------------------- */
  8. typedef struct {
  9.   int      background, foreground;      /* colors used in menu bar */
  10.   int      nsels;                          /* number of selections */
  11.   char     *sel;       /* pointer to static selections (see above) */
  12. } MENUBARSPEC;                 /* caller sets up as many as needed */
  13.                      /* does not remember previous cursor position */
  14.  
  15. void menubar (MENUBARSPEC *spec)
  16. {
  17. int   p, i, ncols, start, interval, page;
  18. char  attr;
  19.  
  20.   page = activepage ();                         /* get active page */
  21.   videomode (&ncols);                          /* get screen width */
  22.   gotoxy (0, 0, page);                                  /* go home */
  23.   attr = chattr(spec->foreground, spec->background); /* attributes */
  24.   for (p = 0; p < (ncols-1); p++) {
  25.     wrtcha (' ', attr, page);                    /* blank menu bar */
  26.     gotoxy (wherex (page)+1, 0, page);                  /* advance */
  27.   }
  28.   interval = ncols / spec->nsels;       /* spacing between entries */
  29.   start = i = 0;
  30.   for (p = 0; p < spec->nsels; p++) {          /* write selections */
  31.     gotoxy (start, 0, page);                       /* place cursor */
  32.     wrtstra (&(spec->sel[i]), attr, page);
  33.     i += strlen (&(spec->sel[i])) + 1;         /* find next string */
  34.     start += interval;                  /* next position for entry */
  35.   }
  36. }
  37.