home *** CD-ROM | disk | FTP | other *** search
/ Doom Fever / Doom_Fever-1995_Maple_Media.iso / wad / source.zip / MENUS.C < prev    next >
C/C++ Source or Header  |  1994-05-20  |  20KB  |  776 lines

  1. /*
  2.    Menu utilities by Raphaël Quinet <quinet@montefiore.ulg.ac.be>
  3.    Drop-down menus by Dewi Morgan <d.morgan@bradford.ac.uk>
  4.  
  5.    You are allowed to use any parts of this code in another program, as
  6.    long as you give credits to the authors in the documentation and in
  7.    the program itself.  Read the file README.1ST for more information.
  8.  
  9.    This program comes with absolutely no warranty.
  10.  
  11.    MENUS.C - Simple menus for DEU (or other programs).
  12. */
  13.  
  14. /* the includes */
  15. #include "deu.h"
  16.  
  17.  
  18. /*
  19.    draws a line of text in a menu
  20. */
  21.  
  22. void DisplayMenuText( int x0, int y0, int line, char *text, int highlightnum, Bool shownumbers)
  23. {
  24.    char h[ 2];
  25.  
  26.    if (UseMouse)
  27.       HideMousePointer();
  28.    if (shownumbers)
  29.    {
  30.       DrawScreenText( x0 + 26, y0 + 8 + line * 10, "- %s", text);
  31.       SetColor( WHITE);
  32.       if (line < 9)
  33.      DrawScreenText( x0 + 10, y0 + 8 + line * 10, "%d", line + 1, text);
  34.       else
  35.      DrawScreenText( x0 + 10, y0 + 8 + line * 10, "%c", line + 56, text);
  36.    }
  37.    else
  38.    {
  39.       if (highlightnum > 0)
  40.       {
  41.      DrawScreenText( x0 + 10, y0 + 8 + line * 10, text);
  42.      SetColor( WHITE);
  43.      h[ 0] = text[ highlightnum - 1];
  44.      h[ 1] = '\0';
  45.      DrawScreenText( x0 + 2 + highlightnum * 8, y0 + 8 + line * 10, h);
  46.       }
  47.       else
  48.       {
  49.      SetColor( DARKGRAY);
  50.      DrawScreenText( x0 + 10, y0 + 8 + line * 10, text);
  51.       }
  52.    }
  53.    if (UseMouse)
  54.       ShowMousePointer();
  55. }
  56.  
  57.  
  58.  
  59. /*
  60.    display and execute a menu
  61. */
  62.  
  63. int DisplayMenuArray( int x0, int y0, char *menutitle, int numitems, int *okkeys, char *menustr[ 30], int highlight[ 30])
  64. {
  65.    int     maxlen, line, oldline;
  66.    Bool    ok;
  67.    int     key, buttons, oldbuttons;
  68.  
  69.    /* compute maxlen */
  70.    if (menutitle)
  71.       maxlen = strlen( menutitle) - 2;
  72.    else
  73.       maxlen = 1;
  74.    for (line = 0; line < numitems; line++)
  75.       if (strlen( menustr[ line]) > maxlen)
  76.      maxlen = strlen( menustr[ line]);
  77.  
  78.    /* display the menu */
  79.    if (UseMouse)
  80.       HideMousePointer();
  81.    if (x0 < 0)
  82.       x0 = (ScrMaxX - maxlen * 8 - (okkeys ? 19 : 53)) / 2;
  83.    if (y0 < 0)
  84.       y0 = (ScrMaxY - numitems * 10 - (menutitle ? 28 : 12)) / 2;
  85.    if (x0 > ScrMaxX - maxlen * 8 - (okkeys ? 19 : 53))
  86.       x0 = ScrMaxX - maxlen * 8 - (okkeys ? 19 : 53);
  87.    DrawScreenBox3D( x0, y0, x0 + maxlen * 8 + (okkeys ? 19 : 53), y0 + numitems * 10 + (menutitle ? 28 : 12));
  88.    SetColor( YELLOW);
  89.    if (menutitle)
  90.       DrawScreenText( x0 + 10, y0 + 8, menutitle);
  91.    if (UseMouse)
  92.       ShowMousePointer();
  93.    for (line = 0; line < numitems; line++)
  94.    {
  95.       SetColor( BLACK);
  96.       DisplayMenuText( x0, y0 + (menutitle ? 16 : 0), line, menustr[ line], highlight[ line], !okkeys);
  97.    }
  98.    oldline = -1;
  99.    line = 0;
  100.    oldbuttons = 0x0000;
  101.    ok = FALSE;
  102.  
  103.    while (! ok)
  104.    {
  105.       if (UseMouse)
  106.       {
  107.      GetMouseCoords( &PointerX, &PointerY, &buttons);
  108.      /* right button = cancel */
  109.      if ((buttons & 0x0002) == 0x0002)
  110.      {
  111.         line = -1;
  112.         ok = TRUE;
  113.      }
  114.      /* left button = select */
  115.      else if (buttons == 0x0001 && PointerX >= x0 && PointerX <= x0 + maxlen * 8 + 53)
  116.         line = (PointerY - y0 - (menutitle ? 24 : 8)) / 10;
  117.      /* release left button = accept selection */
  118.      else if (buttons == 0x0000 && oldbuttons == 0x0001)
  119.         ok = TRUE;
  120.      oldbuttons = buttons;
  121.       }
  122.       if (bioskey( 1))
  123.       {
  124.      key = bioskey( 0);
  125.  
  126.      /* enter key = accept selection */
  127.      if ((key & 0x00FF) == 0x000D)
  128.         ok = TRUE;
  129.      /* escape key = cancel */
  130.      else if ((key & 0x00FF) == 0x001B)
  131.      {
  132.         line = -1;
  133.         ok = TRUE;
  134.      }
  135.      /* up arrow = select previous line */
  136.      else if ((key & 0xFF00) == 0x4800)
  137.      {
  138.         if (line > 0)
  139.            line--;
  140.         else
  141.            line = numitems - 1;
  142.      }
  143.      /* down arrow = select next line */
  144.      else if ((key & 0xFF00) == 0x5000)
  145.      {
  146.         if (line < numitems - 1)
  147.            line++;
  148.         else
  149.            line = 0;
  150.      }
  151.      /* home = select first line */
  152.      else if ((key & 0xFF00) == 0x4700)
  153.         line = 0;
  154.      /* end = select last line */
  155.      else if ((key & 0xFF00) == 0x4F00)
  156.         line = numitems - 1;
  157.      /* pgup = select line - 5 */
  158.      else if ((key & 0xFF00) == 0x4900)
  159.      {
  160.         if (line >= 5)
  161.            line -= 5;
  162.         else
  163.            line = 0;
  164.      }
  165.      /* pgdn = select line + 5 */
  166.      else if ((key & 0xFF00) == 0x5100)
  167.      {
  168.         if (line < numitems - 5)
  169.            line += 5;
  170.         else
  171.            line = numitems - 1;
  172.      }
  173.      /* number or alphabetic key = enter selection */
  174.      else if ((key & 0x00FF) >= '1' && (key & 0x00FF) <= '9' && ((key & 0x00FF) - '1') < numitems)
  175.      {
  176.         line = (key & 0x00FF) - '1';
  177.         ok = TRUE;
  178.      }
  179.      else if ((key & 0x00FF) >= 'A' && (key & 0x00FF) <= 'Z' && ((key & 0x00FF) - 'A' + 9) < numitems)
  180.      {
  181.         line = (key & 0x00FF) - 'A' + 9;
  182.         ok = TRUE;
  183.      }
  184.      else if ((key & 0x00FF) >= 'a' && (key & 0x00FF) <= 'z' && ((key & 0x00FF) - 'a' + 9) < numitems)
  185.      {
  186.         line = (key & 0x00FF) - 'a' + 9;
  187.         ok = TRUE;
  188.      }
  189.      /* check the list of "hot keys" */
  190.      else if (okkeys)
  191.      {
  192.         for (line = 0; line < numitems; line++)
  193.            if (toupper( key) == okkeys[ line])
  194.           break;
  195.         if (line < numitems)
  196.            ok = TRUE;
  197.         else
  198.         {
  199.            line = oldline;
  200.            Beep();
  201.         }
  202.      }
  203.      /* other key */
  204.      else
  205.         Beep();
  206.       }
  207.       if (line != oldline)
  208.       {
  209.      if (oldline >= 0 && oldline < numitems)
  210.      {
  211.         SetColor( BLACK);
  212.         DisplayMenuText( x0, y0 + (menutitle ? 16 : 0), oldline, menustr[ oldline], highlight[ oldline], !okkeys);
  213.      }
  214.      if (line >= 0 && line < numitems)
  215.      {
  216.         SetColor( WHITE);
  217.         DisplayMenuText( x0, y0 + (menutitle ? 16 : 0), line, menustr[ line], highlight[ line], !okkeys);
  218.      }
  219.      oldline = line;
  220.       }
  221.    }
  222.    if (line >= 0 && line < numitems)
  223.       return (line + 1);
  224.    else
  225.       return 0;
  226. }
  227.  
  228.  
  229.  
  230. /*
  231.    display and execute a menu defined with variable arguments
  232. */
  233.  
  234. int DisplayMenu( int x0, int y0, char *menutitle, ...)
  235. {
  236.    va_list args;
  237.    int     num;
  238.    char   *menustr[ 30];
  239.    int     dummy[ 30];
  240.  
  241.    /* put the va_args in the menustr table */
  242.    num = 0;
  243.    va_start( args, menutitle);
  244.    while ((num < 30) && ((menustr[ num] = va_arg( args, char *)) != NULL))
  245.       num++;
  246.    va_end( args);
  247.  
  248.    /* display the menu */
  249.    return DisplayMenuArray( x0, y0, menutitle, num, NULL, menustr, dummy);
  250. }
  251.  
  252.  
  253.  
  254. /*
  255.    display and execute a dropdown menu (returns a key code)
  256. */
  257.  
  258. int PullDownMenu( int x0, int y0, ...)
  259. {
  260.    va_list args;
  261.    int     num;
  262.    char   *menustr[ 30];
  263.    int     retnkeys[ 30];
  264.    int     permkeys[ 30];
  265.    int     highlight[ 30];
  266.  
  267.    /* put the va_args in the menustr table and the two strings */
  268.    num = 0;
  269.    va_start( args, y0);
  270.    while ((num < 30) && ((menustr[ num] = va_arg( args, char *)) != NULL))
  271.    {
  272.       if ((retnkeys[ num] = va_arg( args, int)) == NULL)
  273.      ProgError( "BUG: PullDownMenu() called with invalid arguments");
  274.       if ((permkeys[ num] = va_arg( args, int)) == NULL)
  275.      ProgError( "BUG: PullDownMenu() called with invalid arguments");
  276.       if ((highlight[ num] = va_arg( args, int)) == NULL)
  277.      ProgError( "BUG: PullDownMenu() called with invalid arguments");
  278.       num++;
  279.    }
  280.    va_end( args);
  281.  
  282.    /* display the menu */
  283.    num = DisplayMenuArray( x0, y0, NULL, num, permkeys, menustr, highlight);
  284.    if (num >= 1)
  285.       return retnkeys[ num - 1]; /* return a valid key */
  286.    else
  287.       return 0; /* return an invalid key */
  288. }
  289.  
  290.  
  291.  
  292. /*
  293.    display the integer input box
  294. */
  295.  
  296. int InputInteger( int x0, int y0, int *valp, int minv, int maxv)
  297. {
  298.    int  key, val;
  299.    Bool neg, ok, firstkey;
  300.  
  301.    DrawScreenBoxHollow( x0, y0, x0 + 61, y0 + 13);
  302.    neg = (*valp < 0);
  303.    val = neg ? -(*valp) : *valp;
  304.    firstkey = TRUE;
  305.    for (;;)
  306.    {
  307.       ok = (neg ? -val : val) >= minv && (neg ? -val : val) <= maxv;
  308.       SetColor( BLACK);
  309.       DrawScreenBox( x0 + 1, y0 + 1, x0 + 60, y0 + 12);
  310.       if (ok)
  311.      SetColor( WHITE);
  312.       else
  313.      SetColor( LIGHTGRAY);
  314.       if (neg)
  315.      DrawScreenText( x0 + 3, y0 + 3, "-%d", val);
  316.       else
  317.      DrawScreenText( x0 + 3, y0 + 3, "%d", val);
  318.       key = bioskey( 0);
  319.       if (firstkey && (key & 0x00FF) > ' ')
  320.       {
  321.      val = 0;
  322.      neg = FALSE;
  323.       }
  324.       firstkey = FALSE;
  325.       if (val < 3275 && (key & 0x00FF) >= '0' && (key & 0x00FF) <= '9')
  326.      val = val * 10 + (key & 0x00FF) - '0';
  327.       else if (val > 0 && (key & 0x00FF) == 0x0008)
  328.      val = val / 10;
  329.       else if (neg && (key & 0x00FF) == 0x0008)
  330.      neg = FALSE;
  331.       else if ((key & 0x00FF) == '-')
  332.      neg = !neg;
  333.       else if (ok && (key & 0x00FF) == 0x000D)
  334.      break; /* return "val" */
  335.       else if ((key & 0xFF00) == 0x4800 || (key & 0xFF00) == 0x5000 ||
  336.            (key & 0xFF00) == 0x4B00 || (key & 0xFF00) == 0x4D00 ||
  337.            (key & 0x00FF) == 0x0009 || (key & 0xFF00) == 0x0F00)
  338.      break; /* return "val", even if not valid */
  339.       else if ((key & 0x00FF) == 0x001B)
  340.       {
  341.          neg = FALSE;
  342.      val = -32767; /* return a value out of range */
  343.      break;
  344.       }
  345.       else
  346.      Beep();
  347.    }
  348.    if (neg)
  349.       *valp = -val;
  350.    else
  351.       *valp = val;
  352.    return key;
  353. }
  354.  
  355.  
  356.  
  357. /*
  358.    ask for an integer value and check for minimum and maximum
  359. */
  360.  
  361. int InputIntegerValue( int x0, int y0, int minv, int maxv, int defv)
  362. {
  363.    int  val, key;
  364.    char prompt[ 80];
  365.  
  366.    if (UseMouse)
  367.       HideMousePointer();
  368.    sprintf( prompt, "Enter a decimal number between %d and %d:", minv, maxv);
  369.    if (x0 < 0)
  370.       x0 = (ScrMaxX - 25 - 8 * strlen( prompt)) / 2;
  371.    if (y0 < 0)
  372.       y0 = (ScrMaxY - 55) / 2;
  373.    DrawScreenBox3D( x0, y0, x0 + 25 + 8 * strlen( prompt), y0 + 55);
  374.    SetColor( WHITE);
  375.    DrawScreenText( x0 + 10, y0 + 8, prompt);
  376.    val = defv;
  377.    while (((key = InputInteger( x0 + 10, y0 + 28, &val, minv, maxv)) & 0x00FF) != 0x000D && (key & 0x00FF) != 0x001B)
  378.       Beep();
  379.    if (UseMouse)
  380.       ShowMousePointer();
  381.    return val;
  382. }
  383.  
  384.  
  385.  
  386. /*
  387.    ask for a name in a given list and call a function (for displaying objects, etc.)
  388.  
  389.    Arguments:
  390.       x0, y0  : where to draw the box.
  391.       prompt  : text to be displayed.
  392.       listsize: number of elements in the list.
  393.       list    : list of names (picture names, level names, etc.).
  394.       listdisp: number of lines that should be displayed.
  395.       name    : what we are editing...
  396.       width   : \ width and height of an optional window where a picture
  397.       height  : / can be displayed (used to display textures, sprites, etc.).
  398.       hookfunc: function that should be called to display a picture.
  399.         (x1, y1, x2, y2 = coordinates of the window in which the
  400.          picture must be drawn, name = name of the picture).
  401. */
  402.  
  403. void InputNameFromListWithFunc( int x0, int y0, char *prompt, int listsize, char **list, int listdisp, char *name, int width, int height, void (*hookfunc)(int px1, int py1, int px2, int py2, char *name))
  404. {
  405.    int  key, n, l;
  406.    int  x1, y1, x2, y2;
  407.    int  maxlen;
  408.    Bool ok, firstkey;
  409.  
  410.    /* compute maxlen */
  411.    maxlen = 1;
  412.    for (n = 0; n < listsize; n++)
  413.       if (strlen( list[ n]) > maxlen)
  414.      maxlen = strlen( list[ n]);
  415.    for (n = strlen(name) + 1; n <= maxlen; n++)
  416.       name[ n] = '\0';
  417.    /* compute the minimum width of the dialog box */
  418.    l = maxlen;
  419.    if (strlen( prompt) > l + 12)
  420.       l = strlen( prompt) - 12;
  421.    l = l * 8 + 110;
  422.    x1 = l + 3;
  423.    y1 = 10 + 1;
  424.    if (width > 0)
  425.       l += 10 + width;
  426.    if (height > 65)
  427.       n = height + 20;
  428.    else
  429.       n = 85;
  430.    if (x0 < 0)
  431.       x0 = (ScrMaxX - l) / 2;
  432.    if (y0 < 0)
  433.       y0 = (ScrMaxY - n) / 2;
  434.    x1 += x0;
  435.    y1 += y0;
  436.    if (x1 + width - 1 < ScrMaxX)
  437.       x2 = x1 + width - 1;
  438.    else
  439.       x2 = ScrMaxX;
  440.    if (y1 + height - 1 < ScrMaxY)
  441.       y2 = y1 + height - 1;
  442.    else
  443.       y2 = ScrMaxY;
  444.    /* draw the dialog box */
  445.    DrawScreenBox3D( x0, y0, x0 + l, y0 + n);
  446.    DrawScreenBoxHollow( x0 + 10, y0 + 28, x0 + 101, y0 + 41);
  447.    DrawScreenText( x0 + 10, y0 + 8, prompt);
  448.    if (width > 0)
  449.    {
  450.       DrawScreenBox( x1, y1, x2 + 1, y2 + 1);
  451.       SetColor( DARKGRAY);
  452.       DrawScreenBox( x1 - 1, y1 - 1, x2, y2);
  453.    }
  454.    firstkey = TRUE;
  455.    for (;;)
  456.    {
  457.       /* test if "name" is in the list */
  458.       for (n = 0; n < listsize; n++)
  459.      if (strcmp( name, list[ n]) <= 0)
  460.         break;
  461.       ok = n < listsize ? !strcmp( name, list[ n]) : FALSE;
  462.       if (n > listsize - 1)
  463.      n = listsize - 1;
  464.       /* display the "listdisp" next items in the list */
  465.       SetColor( LIGHTGRAY);
  466.       DrawScreenBox( x0 + 110, y0 + 30, x0 + 110 + 8 * maxlen, y0 + 30 + 10 * listdisp);
  467.       SetColor( BLACK);
  468.       for (l = 0; l < listdisp && n + l < listsize; l++)
  469.      DrawScreenText( x0 + 110, y0 + 30 + l * 10, list[ n + l]);
  470.       l = strlen( name);
  471.       DrawScreenBox( x0 + 11, y0 + 29, x0 + 100, y0 + 40);
  472.       if (ok)
  473.      SetColor( WHITE);
  474.       else
  475.      SetColor( LIGHTGRAY);
  476.       DrawScreenText( x0 + 13, y0 + 31, name);
  477.       /* call the function to display the picture, if any */
  478.       if (hookfunc)
  479.       {
  480.      /* clear the window */
  481.      SetColor( BLACK);
  482.      DrawScreenBox( x1, y1, x2, y2);
  483.      /* display the picture "name" */
  484.      hookfunc( x1, y1, x2, y2, name);
  485.       }
  486.       /* process user input */
  487.       key = bioskey( 0);
  488.       if (firstkey && (key & 0x00FF) > ' ')
  489.       {
  490.      for (l = 0; l <= maxlen; l++)
  491.         name[ l] = '\0';
  492.      l = 0;
  493.       }
  494.       firstkey = FALSE;
  495.       if (l < maxlen && (key & 0x00FF) >= 'a' && (key & 0x00FF) <= 'z')
  496.       {
  497.      name[ l] = key & 0x00FF + 'A' - 'a';
  498.      name[ l + 1] = '\0';
  499.       }
  500.       else if (l < maxlen && (key & 0x00FF) > ' ')
  501.       {
  502.      name[ l] = key & 0x00FF;
  503.      name[ l + 1] = '\0';
  504.       }
  505.       else if (l > 0 && (key & 0x00FF) == 0x0008)
  506.      name[ l - 1] = '\0';
  507.       else if (n < listsize - 1 && (key & 0xFF00) == 0x5000)
  508.      strcpy(name, list[ n + 1]);
  509.       else if (n > 0 && (key & 0xFF00) == 0x4800)
  510.      strcpy(name, list[ n - 1]);
  511.       else if (n < listsize - listdisp && (key & 0xFF00) == 0x5100)
  512.      strcpy(name, list[ n + listdisp]);
  513.       else if (n > 0 && (key & 0xFF00) == 0x4900)
  514.       {
  515.      if (n > listdisp)
  516.         strcpy(name, list[ n - listdisp]);
  517.      else
  518.         strcpy(name, list[ 0]);
  519.       }
  520.       else if ((key & 0xFF00) == 0x4F00)
  521.      strcpy(name, list[ listsize - 1]);
  522.       else if ((key & 0xFF00) == 0x4700)
  523.      strcpy(name, list[ 0]);
  524.       else if ((key & 0x00FF) == 0x0009)
  525.      strcpy(name, list[ n]);
  526.       else if (ok && (key & 0x00FF) == 0x000D)
  527.      break; /* return "name" */
  528.       else if ((key & 0x00FF) == 0x001B)
  529.       {
  530.      name[ 0] = '\0'; /* return an empty string */
  531.      break;
  532.       }
  533.       else
  534.      Beep();
  535.    }
  536. }
  537.  
  538.  
  539.  
  540. /*
  541.    ask for a name in a given list
  542. */
  543.  
  544. void InputNameFromList( int x0, int y0, char *prompt, int listsize, char **list, char *name)
  545. {
  546.    if (UseMouse)
  547.       HideMousePointer();
  548.    InputNameFromListWithFunc( x0, y0, prompt, listsize, list, 5, name, 0, 0, NULL);
  549.    if (UseMouse)
  550.       ShowMousePointer();
  551. }
  552.  
  553.  
  554.  
  555. /*
  556.    ask for a filename
  557. */
  558.  
  559. void InputFileName( int x0, int y0, char *prompt, int maxlen, char *filename)
  560. {
  561.    int   key, l, boxlen;
  562.    Bool  ok, firstkey;
  563.    char *p;
  564.  
  565.    if (UseMouse)
  566.       HideMousePointer();
  567.    for (l = strlen(filename) + 1; l <= maxlen; l++)
  568.       filename[ l] = '\0';
  569.    /* compute the width of the input box */
  570.    if (maxlen > 20)
  571.       boxlen = 20;
  572.    else
  573.       boxlen = maxlen;
  574.    /* compute the width of the dialog box */
  575.    if (strlen( prompt) > boxlen)
  576.       l = strlen( prompt);
  577.    else
  578.       l = boxlen;
  579.    if (x0 < 0)
  580.       x0 = (ScrMaxX - 26 - 8 * l) / 2;
  581.    if (y0 < 0)
  582.       y0 = (ScrMaxY - 50) / 2;
  583.    /* draw the dialog box */
  584.    DrawScreenBox3D( x0, y0, x0 + 26 + 8 * l, y0 + 50);
  585.    DrawScreenBoxHollow( x0 + 10, y0 + 28, x0 + 15 + 8 * boxlen, y0 + 41);
  586.    DrawScreenText( x0 + 10, y0 + 8, prompt);
  587.    firstkey = TRUE;
  588.    for (;;)
  589.    {
  590.       /* check that "filename" looks like a valid file name */
  591.       ok = TRUE;
  592.       if (filename[ 1] == ':')
  593.      p = filename + 2;
  594.       else
  595.      p = filename;
  596.       for (l = 8; *p; p++)
  597.       {
  598.      if (*p == '.')
  599.         l = 3;
  600.      else if (*p == '\\')
  601.         l = 8;
  602.      else
  603.         l--;
  604.      if (l < 0)
  605.      {
  606.         ok = FALSE;
  607.         break;
  608.      }
  609.       }
  610.  
  611.       l = strlen( filename);
  612.       SetColor( BLACK);
  613.       DrawScreenBox( x0 + 11, y0 + 29, x0 + 14 + 8 * boxlen, y0 + 40);
  614.       if (ok)
  615.      SetColor( WHITE);
  616.       else
  617.      SetColor( LIGHTGRAY);
  618.       if (l > boxlen)
  619.       {
  620.      DrawScreenText( x0 + 11, y0 + 31, "<");
  621.      DrawScreenText( x0 + 13, y0 + 31, "<%s", filename + (l - boxlen + 1));
  622.       }
  623.       else
  624.      DrawScreenText( x0 + 13, y0 + 31, filename);
  625.       key = bioskey( 0);
  626.       if (firstkey && (key & 0x00FF) > ' ')
  627.       {
  628.      for (l = 0; l <= maxlen; l++)
  629.         filename[ l] = '\0';
  630.      l = 0;
  631.       }
  632.       firstkey = FALSE;
  633.       if (l < maxlen && (key & 0x00FF) >= 'a' && (key & 0x00FF) <= 'z')
  634.       {
  635.      filename[ l] = key & 0x00FF + 'A' - 'a';
  636.      filename[ l + 1] = '\0';
  637.       }
  638.       else if (l < maxlen && (key & 0x00FF) > ' ')
  639.       {
  640.      filename[ l] = key & 0x00FF;
  641.      filename[ l + 1] = '\0';
  642.       }
  643.       else if (l > 0 && (key & 0x00FF) == 0x0008)
  644.      filename[ l - 1] = '\0';
  645.       else if (ok && (key & 0x00FF) == 0x000D)
  646.      break; /* return "filename" */
  647.       else if ((key & 0x00FF) == 0x001B)
  648.       {
  649.      filename[ 0] = '\0'; /* return an empty string */
  650.      break;
  651.       }
  652.       else
  653.      Beep();
  654.    }
  655.    if (UseMouse)
  656.       ShowMousePointer();
  657. }
  658.  
  659.  
  660.  
  661. /*
  662.    ask for confirmation (prompt2 may be NULL)
  663. */
  664.  
  665. Bool Confirm( int x0, int y0, char *prompt1, char *prompt2)
  666. {
  667.    int key;
  668.    int maxlen = 46;
  669.  
  670.    if (UseMouse)
  671.       HideMousePointer();
  672.    if (strlen( prompt1) > maxlen)
  673.       maxlen = strlen( prompt1);
  674.    if (prompt2 != NULL && strlen( prompt2) > maxlen)
  675.       maxlen = strlen( prompt2);
  676.    if (x0 < 0)
  677.       x0 = (ScrMaxX - 22 - 8 * maxlen) / 2;
  678.    if (y0 < 0)
  679.       y0 = (ScrMaxY - (prompt2 ? 53 : 43)) / 2;
  680.    DrawScreenBox3D( x0, y0, x0 + 22 + 8 * maxlen, y0 + (prompt2 ? 53 : 43));
  681.    SetColor( WHITE);
  682.    DrawScreenText( x0 + 10, y0 + 8, prompt1);
  683.    if (prompt2 != NULL)
  684.       DrawScreenText( x0 + 10, y0 + 18, prompt2);
  685.    SetColor( YELLOW);
  686.    DrawScreenText( x0 + 10, y0 + (prompt2 ? 38 : 28), "Press Y to confirm, or any other key to cancel");
  687.    key = bioskey( 0);
  688.    if (UseMouse)
  689.       ShowMousePointer();
  690.    return ((key & 0x00FF) == 'Y' || (key & 0x00FF) == 'y');
  691. }
  692.  
  693.  
  694.  
  695. /*
  696.    display a notification and wait for a key (prompt2 may be NULL)
  697. */
  698.  
  699. void Notify( int x0, int y0, char *prompt1, char *prompt2)
  700. {
  701.    int maxlen = 30;
  702.  
  703.    if (UseMouse)
  704.       HideMousePointer();
  705.    if (strlen( prompt1) > maxlen)
  706.       maxlen = strlen( prompt1);
  707.    if (prompt2 != NULL && strlen( prompt2) > maxlen)
  708.       maxlen = strlen( prompt2);
  709.    if (x0 < 0)
  710.       x0 = (ScrMaxX - 22 - 8 * maxlen) / 2;
  711.    if (y0 < 0)
  712.       y0 = (ScrMaxY - (prompt2 ? 53 : 43)) / 2;
  713.    DrawScreenBox3D( x0, y0, x0 + 22 + 8 * maxlen, y0 + (prompt2 ? 53 : 43));
  714.    SetColor( WHITE);
  715.    DrawScreenText( x0 + 10, y0 + 8, prompt1);
  716.    if (prompt2 != NULL)
  717.       DrawScreenText( x0 + 10, y0 + 18, prompt2);
  718.    SetColor( YELLOW);
  719.    DrawScreenText( x0 + 10, y0 + (prompt2 ? 38 : 28), "Press any key to continue...");
  720.    bioskey( 0);
  721.    if (UseMouse)
  722.       ShowMousePointer();
  723. }
  724.  
  725.  
  726.  
  727. /*
  728.    clear the screen and display a message
  729. */
  730.  
  731. void DisplayMessage( int x0, int y0, char *msg, ...)
  732. {
  733.    char prompt[ 120];
  734.    va_list args;
  735.  
  736.    va_start( args, msg);
  737.    vsprintf( prompt, msg, args);
  738.    va_end( args);
  739.  
  740.    if (UseMouse)
  741.       HideMousePointer();
  742.    ClearScreen();
  743.    if (x0 < 0)
  744.       x0 = (ScrMaxX - 40 - 8 * strlen( prompt)) / 2;
  745.    if (y0 < 0)
  746.       y0 = (ScrMaxY - 40) / 2;
  747.    DrawScreenBox3D( x0, y0, x0 + 40 + 8 * strlen( prompt), y0 + 40);
  748.    DrawScreenText( x0 + 20, y0 + 17, prompt);
  749.    if (UseMouse)
  750.       ShowMousePointer();
  751. }
  752.  
  753.  
  754.  
  755. /*
  756.    let's make the user angry...
  757. */
  758.  
  759. void NotImplemented()
  760. {
  761.    if (UseMouse)
  762.       HideMousePointer();
  763.    DrawScreenBox3D( 140, 220, 500, 260);
  764.    SetColor( RED);
  765.    DrawScreenText( 150, 230, "This function is not implemented... Yet!");
  766.    SetColor( YELLOW);
  767.    DrawScreenText( 150, 245, "Press any key to return to the editor...");
  768.    Beep();
  769.    bioskey( 0);
  770.    if (UseMouse)
  771.       ShowMousePointer();
  772. }
  773.  
  774.  
  775. /* end of file */
  776.