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