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