home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / CURSES.ZIP / DEMO.C next >
Encoding:
C/C++ Source or Header  |  1987-11-11  |  29.1 KB  |  1,161 lines

  1. /*#cdg#cursesdemo#******************************************************
  2. *                                                                      *
  3. *               Copyright 1987 Cygnus Development Group                *
  4. *                                                                      *
  5. *               This software is a proprietary product of              *
  6. *               the Cygnus Development Group (CDG).                    *
  7. *               ALL RIGHTS RESERVED                                    *
  8. *                                                                      *
  9. ************************************************************************
  10. *                                                                      *
  11. *       Purpose:                                                       *
  12. *                The executable demonstration program may be freely    *
  13. *       distributed.  The source code included on this disk, along     *
  14. *       with the 'readme.doc' file MUST be included with the           *
  15. *       program.  This program and its source code remain the          *
  16. *       property of the Cygnus Development Group, and may not be       *
  17. *       redistributed for profit, in whole or in part, without         *
  18. *       the express WRITTEN permission of the Cygnus Development       *
  19. *       Group.                                                         *
  20. *                                                                      *
  21. *                                                                      *
  22. ***********************************************************************/
  23.  
  24.  
  25. #include <xcurses.h>
  26. #include <dostools.h>
  27. #include <xchars.h>
  28. #include <cmdline.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <signal.h>
  33.  
  34.  
  35. bool    slow = TRUE;
  36.  
  37. /*
  38.  *    Command-line arguments available for this program.
  39.  *    This generic command-line processor is part of the
  40.  *    ToolBox Library.
  41.  */
  42. argument  cl_args[] = {
  43.         { 'l', integer_argument( LINES ), "Support for EGA multi-line modes" },
  44.         { 'c', integer_argument( COLS ), "Support for EGA multi-column modes" },
  45.         { 'b', boolean_argument( behave ), "Force well-behaved execution" },
  46.         { 's', boolean_argument( slow ), "Slow down execution of the demo" },
  47.         null_argument };
  48.  
  49.  
  50. #define    N_BOXES    20
  51. #define    LINE_LEN    131
  52.  
  53. char    line[LINE_LEN + 1];
  54. static    int    cl_behave;
  55. WINDOW  *w[N_BOXES], *im[N_BOXES];
  56.  
  57.  
  58. /*----------------------------------------------------------------------
  59.  
  60.         exit_curses_demo
  61.  
  62. ----------------------------------------------------------------------*/
  63.  
  64. int    exit_curses_demo()
  65. {
  66. /*
  67.  *    Signal handler for ^C or ^Break.
  68.  */
  69.     cursor_on();
  70.         endwin();
  71.     exit( 0 );
  72. }
  73.  
  74.  
  75. /*----------------------------------------------------------------------
  76.  
  77.         main
  78.  
  79. ----------------------------------------------------------------------*/
  80.  
  81. main( argc, argv)
  82. int    argc;
  83. char    **argv;
  84. {
  85.         int     i = 0, bottom, middle;
  86.     WINDOW    *info, *sinfo, *wch;
  87.  
  88.     parse_command_line( argc, argv, cl_args );
  89.     instructions();
  90.  
  91.     cl_behave = behave;
  92.  
  93.         initscr();
  94.     signal( SIGINT, exit_curses_demo );
  95.         noecho();
  96.         crmode();
  97.     nl();
  98.     cursor_off();
  99.     clearok( curscr, FALSE );
  100.     clearok( stdscr, FALSE );
  101.  
  102.     opening_sequence();
  103.  
  104. /*
  105.  *    Create a window full of I/O information...
  106.  */
  107.     attrset( (ttymode == COLOR)
  108.             ? (A_FG_CYAN | A_BG_BLUE)
  109.             : A_REVERSE );
  110.     fill( DOTS1 );
  111.     info = newwin( 6, 50, 3, 4 );
  112.     wattrset( info, (ttymode == COLOR) ? A_FG_GREEN : A_REVERSE );
  113.     werase( info );
  114.     box( info, VD_LINE, HS_LINE );
  115.     sinfo = subwin( info, info->_maxy - 2, info->_maxx - 4,
  116.                   info->_begy + 1, info->_begx + 2 );
  117.     if ( sinfo )
  118.     {
  119.         scrollok( sinfo, TRUE );
  120.         wcrmode( sinfo );
  121.         wwrap( sinfo );
  122.         wnl( sinfo );
  123.     }
  124.     wattron( sinfo, A_BOLD );
  125.     mvwaddstr( sinfo, 0, 0, "Curses" );
  126.     wattroff( sinfo, A_BOLD );
  127.     waddstr( sinfo, " gives the C programmer 'windows' for\n" );
  128.     waddstr( sinfo, "both input and output.  These windows are\n" );
  129.     waddstr( sinfo, "created dynamically, and their attributes are\n" );
  130.     waddstr( sinfo, "determined by the developer." );
  131.     wshadow( info, stdscr  );
  132.     woverwrite( info, stdscr, info->_begy, info->_begx );
  133.     pullover();
  134.     if ( slow )
  135.         sleep( 5.0 );
  136.  
  137.     build_eg_window();
  138.  
  139.     werase( sinfo );
  140.     waddstr( sinfo, "That was an illustration of building a simple\n" );
  141.     waddstr( sinfo, "window.  Many characteristics are available\n" );
  142.     waddstr( sinfo, "to the developer, which may be configured for\n" );
  143.     waddstr( sinfo, "EACH individual window..." );
  144.     attron( A_BG_L_GREY );
  145.     erase();
  146.     explode();
  147.     travel_window( info, LINES - info->_maxy - 4,
  148.                COLS - info->_maxx - 10 );
  149.     mvwin( sinfo, info->_begy + 1, info->_begx + 2 );
  150.     wrefresh( sinfo );
  151.     if ( slow )
  152.         sleep( 4.0 );
  153.  
  154.     show_io_skills( sinfo );
  155.  
  156.     erase();
  157.     if ( ttymode == COLOR )
  158.         wattrset( sinfo, A_FG_MAGENTA );
  159.     werase( sinfo );
  160.     waddstr( sinfo, "Video access is FAST; create windows easily,\n" );
  161.     waddstr( sinfo, "and then 'pop' them onto the display with a\n" );
  162.     waddstr( sinfo, "single function...\n" );
  163.     woverwrite( info, stdscr, info->_begy, info->_begx );
  164.     pullover();
  165.  
  166.     pop_boxes( sinfo );
  167.  
  168.     show_listing( info, sinfo );
  169. /*
  170.  *    Show interactive I/O through a window...
  171.  */
  172.     if ( ttymode == COLOR )
  173.         attrset( A_FG_YELLOW | A_BG_BLUE );
  174.     erase();
  175.     box( stdscr, VS_LINE, HS_LINE );
  176.     if ( ttymode == COLOR )
  177.         wattrset( info, A_FG_RED | A_BG_L_GREY );
  178.     werase( info );
  179.     box( info, VS_LINE, HD_LINE );
  180.     if ( ttymode == COLOR )
  181.         wattrset( sinfo, A_FG_RED | A_BG_L_GREY );
  182.     werase( sinfo );
  183.     mvwin( info, LINES / 2, 8 );
  184.     mvwin( sinfo, info->_begy + 1, info->_begx + 2 );
  185.     waddstr( sinfo, "Input, in the style of 'fgets()' and\n" );
  186.     waddstr( sinfo, "'scanf()', is also possible...\n" );
  187.     woverwrite( info, stdscr, info->_begy, info->_begx );
  188.     weave();
  189.     if ( slow )
  190.         sleep( 4.0 );
  191.  
  192.     do_curid_intro();
  193.     monitor_kbd( sinfo );
  194.  
  195.     get_weird();
  196.     show_window_on_curscr();
  197.  
  198.     erase();
  199.     show_support();
  200.     mesh();
  201.     if ( slow )
  202.         sleep( 15.0 );
  203.     give_disclaimer();
  204.     if ( slow )
  205.         sleep( 15.0 );
  206. /*
  207.  *    Display the references, and close.
  208.  */
  209.     closing_sequence( info, sinfo );
  210.     if ( slow )
  211.         sleep( 15.0 );
  212.  
  213.     exit_curses_demo();
  214. }
  215.  
  216.  
  217. /*----------------------------------------------------------------------
  218.  
  219.         center_on_bottom
  220.  
  221. ----------------------------------------------------------------------*/
  222.  
  223. int    center_on_bottom( w, str)
  224. WINDOW    *w;
  225. char    *str;
  226. {
  227.     scroll( w );
  228.     mvwaddstr( w, w->_maxy - 1, (w->_maxx - strlen( str)) / 2, str );
  229.     wrefresh( w );
  230.     if ( slow )
  231.         sleep( 0.30 );
  232. }
  233.  
  234.  
  235. /*----------------------------------------------------------------------
  236.  
  237.         pop_boxes
  238.  
  239. ----------------------------------------------------------------------*/
  240.  
  241. int    pop_boxes( words)
  242. WINDOW    *words;
  243. {
  244. /*
  245.  *    Demonstrate putting randomly sized and placed
  246.  *    windows onto the screen.
  247.  */
  248.     int    i, j, hei, wid;
  249.     int    num_boxes_here = 8;
  250.  
  251.     if ( slow )
  252.         sleep( 5.5 );
  253.  
  254.         srand( (unsigned) (time( NULL) & 0xFF) );
  255.     for ( i = 0 ; i < num_boxes_here ; i++ )
  256.     {
  257.         wid = rand() % (COLS / 2) + 20;
  258.         hei = rand() % (LINES / 2) + 5;
  259.         w[i] = newwin( hei, wid, rand() % (LINES - hei - 2),
  260.                      rand() % (COLS - wid - 2) );
  261.         if ( !w[i] )
  262.         {
  263.             i--;
  264.             continue;
  265.         }
  266.         wattrset( w[i], (ttymode == COLOR) ?
  267.               (((rand() % 6) + 2) << 8) | ((rand() % 2) << 12) :
  268.               ((rand() % 2) ? A_REVERSE : 0) );
  269.         werase( w[i] );
  270.         box( w[i], (rand() % 2) ? VS_LINE : VD_LINE,
  271.                (rand() % 2) ? HS_LINE : HD_LINE );
  272.     }
  273.     for ( j = i ; j-- ; )
  274.     {
  275.         im[j] = save_image( w[j], im[j] );
  276.         wrefresh( w[j] );
  277.         if ( slow )
  278.              sleep( (double) j * j * 0.006 );
  279.     }
  280.     if ( slow )
  281.         sleep( 2.0 );
  282.     for ( j = 0 ; j < i ; j++ )
  283.     {
  284.         wrefresh( im[j] );
  285.         if ( slow )
  286.             sleep( (double) (i - j) * (i - j) * 0.006 );
  287.     }
  288. /*
  289.  *    Do the same, only go through the BIOS.
  290.  */
  291.     waddstr( words, "\nWell-behaved software (that uses the BIOS)\n" );
  292.     waddstr( words, "is also fully supported.  This allows " );
  293.     wattron( words, A_BOLD );
  294.     waddstr( words, "Curses\n" );
  295.     wattroff( words, A_BOLD );
  296.     waddstr( words, "applications to operate under Microsoft\n" );
  297.     waddstr( words, "Windows (Tm), or Quarterdeck's Desqview (Tm)." );
  298.     touchwin( words );
  299.     wrefresh( words );
  300.     if ( slow )
  301.         sleep( 4.5 );
  302.     behave = TRUE;
  303.     for ( j = i ; j-- ; )
  304.     {
  305.         im[j] = save_image( w[j], im[j] );
  306.         touchwin( w[j] );
  307.         wrefresh( w[j] );
  308.         if ( slow )
  309.             sleep( (double) j * j * 0.006 );
  310.     }
  311.     if ( slow )
  312.         sleep( 2.0 );
  313.     for ( j = 0 ; j < i ; j++ )
  314.     {
  315.         touchwin( im[j] );
  316.         wrefresh( im[j] );
  317.         if ( slow )
  318.             sleep( (double) (i - j) * (i - j) * 0.006 );
  319.     }
  320.     behave = cl_behave;
  321.     if ( slow )
  322.         sleep( 3.0 );
  323. }
  324.  
  325.  
  326. /*----------------------------------------------------------------------
  327.  
  328.         build_eg_window
  329.  
  330. ----------------------------------------------------------------------*/
  331.  
  332. int    build_eg_window()
  333. {
  334.     WINDOW    *wch, *swch, *win;
  335.  
  336.     wch = newwin( 10, 42, LINES / 2 + 1, 36 );
  337.     wattrset( wch, A_FG_L_GREY | A_BG_BLACK );
  338.     werase( wch );
  339.     box( wch, VD_LINE, HS_LINE );
  340.     swch = subwin( wch, wch->_maxy - 2, wch->_maxx - 4,
  341.                 wch->_begy + 1, wch->_begx + 2 );
  342.     if ( swch ) {
  343.         scrollok( swch, TRUE );
  344.         wnowrap( swch );
  345.     }
  346.     wpulldown( wch );
  347. /*
  348.  *    Build a window while describing it...
  349.  */
  350.     waddstr( swch, "/*    Get a small window    */\n" );
  351.     waddstr( swch, "win = newwin( 12, 30, LINES - 14, 6);\n" );
  352.     wrefresh( swch );
  353.         win = newwin( 12, 30, LINES - 14, 5 );
  354.         leaveok( win, TRUE );
  355.         wrefresh( win );
  356.     if ( slow )
  357.         sleep( 4.0 );
  358.  
  359.     waddstr( swch, "/*    Set the fg color to " );
  360.     waddstr( swch, (ttymode == COLOR) ? "white,\n" : "bold,\n" );
  361.     waddstr( swch, "      and the bg to " );
  362.     waddstr( swch, (ttymode == COLOR) ? "red" : "black" );
  363.     waddstr( swch, "             */\n" );
  364.     waddstr( swch, "wattrset( win, " );
  365.     waddstr( swch, (ttymode == COLOR)
  366.                 ? "A_FG_WHITE | A_BG_RED);\n"
  367.                 : "A_BOLD);\n" );
  368.     wrefresh( swch );
  369.         wattrset( win, (ttymode == COLOR)
  370.                 ? (A_BOLD | A_FG_L_GREY | A_BG_RED)
  371.                 : A_BOLD );
  372.         wrefresh( win );
  373.     if ( slow )
  374.         sleep( 3.0 );
  375.  
  376.     waddstr( swch, "/*    clear to set the style...  */\n" );
  377.     waddstr( swch, "werase( win);\n" );
  378.     wrefresh( swch );
  379.         werase( win );
  380.         wrefresh( win );
  381.     if ( slow )
  382.         sleep( 4.0 );
  383.  
  384.     waddstr( swch, "/*    double-box the window    */\n" );
  385.     waddstr( swch, "box( win, VD_LINE, HD_LINE);\n" );
  386.     wrefresh( swch );
  387.         box( win, VD_LINE, HD_LINE );
  388.         wrefresh( win );
  389.     if ( slow )
  390.         sleep( 4.0 );
  391.  
  392.     waddstr( swch, "/*    and put up the window... */\n" );
  393.     waddstr( swch, "wrefresh( win);\n" );
  394.     wrefresh( swch );
  395.     if ( slow )
  396.         sleep( 4.0 );
  397.  
  398.     delwin( swch );
  399.     delwin( wch );
  400.     delwin( win );
  401. }
  402.  
  403.  
  404. /*----------------------------------------------------------------------
  405.  
  406.         show_io_skills
  407.  
  408. ----------------------------------------------------------------------*/
  409.  
  410. int    show_io_skills( words)
  411. WINDOW    *words;
  412. {
  413.     WINDOW    *wch;
  414.  
  415.     wch = newwin( 11, 60, 3, 16 );
  416.     if ( wch )
  417.     {
  418.         wattrset( wch, (ttymode == COLOR)
  419.                 ? (A_FG_RED | A_BG_L_GREY)
  420.                 : A_REVERSE );
  421.         werase( wch );
  422.         box( wch, VS_LINE, HS_LINE );
  423.         mvwaddstr( wch, 1, 2, "Attributes:" );
  424.         wattron( wch, A_BOLD );
  425.         mvwaddstr( wch, 2, 6, "Foreground Color" );
  426.         wattroff( wch, A_BOLD );
  427.         wstandout( wch );
  428.         mvwaddstr( wch, 3, 6, "Background Color" );
  429.         wstandend( wch );
  430.         blinkok( wch, TRUE );
  431.         mvwaddstr( wch, 4, 6, "Character Blink" );
  432.         blinkok( wch, FALSE );
  433.         wrefresh( wch );
  434.         wrefresh( words );
  435.     }
  436.     if ( slow )
  437.         sleep( 3.0 );
  438.  
  439.     if ( wch )
  440.     {
  441.         mvwaddstr( wch, 1, 27, "Character Sets:" );
  442.         mvwaddstr( wch, 2, 27, "    Unix-Compatible un-Control" );
  443.         mvwaddstr( wch, 3, 27, "    IBM Extended Character Set" );
  444.         wrefresh( wch );
  445.     }
  446.     if ( ttymode == COLOR )
  447.         wattrset( words, A_FG_CYAN );
  448.     werase( words );
  449.     waddstr( words, "\nAlso, various methods of output are\n" );
  450.     waddstr( words, "available...." );
  451.     wrefresh( words );
  452.     if ( slow )
  453.         sleep( 5.0 );
  454.  
  455.     if ( wch )
  456.     {
  457.         mvwaddstr( wch, 6, 2, "Output:" );
  458.         mvwaddstr( wch, 7, 2, "    Automatic Scrolling" );
  459.         mvwaddstr( wch, 8, 2, "    Margin Wrap-around" );
  460.         mvwaddstr( wch, 9, 2, "    Newline Mapping" );
  461.         wrefresh( wch );
  462.     }
  463.     wrefresh( words );
  464.     if ( slow )
  465.         sleep( 5.0 );
  466.  
  467.     if ( wch )
  468.     {
  469.         mvwaddstr( wch, 5, 27, "Input:" );
  470.         mvwaddstr( wch, 6, 27, "    Keyboard Sampling" );
  471.         mvwaddstr( wch, 7, 27, "    'getchar()'-Style Input" );
  472.         mvwaddstr( wch, 8, 27, "    Selectable Echo" );
  473.         mvwaddstr( wch, 9, 27, "    Full IBM Keyboard" );
  474.         wrefresh( wch );
  475.     }
  476.     if ( ttymode == COLOR )
  477.         wattrset( words, A_FG_YELLOW );
  478.     werase( words );
  479.     waddstr( words, "\nas is input THROUGH the window." );
  480.     wrefresh( words );
  481.  
  482.     delwin( wch );
  483.     wch = NULL;
  484.     if ( slow )
  485.         sleep( 10.0 );
  486. }
  487.  
  488.  
  489. /*----------------------------------------------------------------------
  490.  
  491.         show_listing
  492.  
  493. ----------------------------------------------------------------------*/
  494.  
  495. int    show_listing( outside, words)
  496. WINDOW    *outside, *words;
  497. {
  498. /*
  499.  *    List a part of this demo program...
  500.  */
  501.     int    i;
  502.     WINDOW    *wch;
  503.     FILE    *dfp;
  504.  
  505.     wattrset( outside, A_FG_CYAN | A_BG_BLUE );
  506.     werase( outside );
  507.     box( outside, VS_LINE, HD_LINE );
  508.     wattrset( words, A_FG_L_BLUE | A_BG_BLUE );
  509.     werase( words );
  510.     mvwin( outside, LINES - outside->_maxy - 1, COLS - outside->_maxx - 8 );
  511.     mvwin( words, outside->_begy + 1, outside->_begx + 2 );
  512.     waddstr( words, "Output to a window is as EASY as using\n" );
  513.     waddstr( words, "printf, and faster.  Scrolling, newlines,\n" );
  514.     waddstr( words, "and tabs are all handled by " );
  515.     wattron( words, A_FG_L_CYAN );
  516.     waddstr( words, "Curses" );
  517.     wattron( words, A_FG_L_BLUE );
  518.     waddch( words, '.' );
  519.     erase();
  520.     woverwrite( outside, stdscr, outside->_begy, outside->_begx );
  521.     pulldown();
  522.     if ( slow )
  523.         sleep( 5.0 );
  524.  
  525.     strcpy( line, Iam );
  526.     strcpy( strchr( line, '.'), ".c" );
  527.     if ( dfp = fopen( line, "r") )
  528.     {
  529.  
  530.         if ( wch = newwin( LINES / 2, 70, 2, 5) )
  531.         {
  532.             wnl( wch );
  533.             scrollok( wch, TRUE );
  534.             wattrset( wch, A_FG_BROWN | A_BG_BLACK );
  535.             werase( wch );
  536.             wexplode( wch );
  537.         }
  538.  
  539.         i = 60;
  540.         while ( fgets( line, LINE_LEN, dfp) && i-- )
  541.         {
  542.             waddstr( wch, line );
  543.             wrefresh( wch );
  544.         }
  545.         fclose( dfp );
  546.         delwin( wch );
  547.         wch = NULL;
  548.         if ( slow )
  549.             sleep( 5.0 );
  550.     }
  551. }
  552.  
  553.  
  554. /*----------------------------------------------------------------------
  555.  
  556.         monitor_kbd
  557.  
  558. ----------------------------------------------------------------------*/
  559.  
  560. int    monitor_kbd( words)
  561. WINDOW    *words;
  562. {
  563. /*
  564.  *    Monitor the keyboard for a while...
  565.  */
  566.     long    start, t;
  567.  
  568.     werase( words );
  569.     wattron( words, A_BOLD );
  570.     waddstr( words, "Curses" );
  571.     wattroff( words, A_BOLD );
  572.     waddstr( words, " monitors the status of the keyboard\n" );
  573.     waddstr( words, "automatically, including the shift/lock keys.\n" );
  574.     waddstr( words, "(See for yourself during the next 20 seconds)\n" );
  575.     wrefresh( words );
  576.  
  577.     build_status_window();
  578.     if ( words )
  579.     {
  580.         wnoecho( words );
  581.         nodelay( words, TRUE );
  582.         scrollok( words, FALSE );
  583.     }
  584.     time( &start );
  585.     while ( (time( &t) - start) < 20l )
  586.     {
  587.         wgetch( words );
  588.         waddch( words, '\r' );
  589.         waddstr( words, ctime( &t) );
  590.         wrefresh( words );
  591.     }
  592.     if ( words )
  593.         scrollok( words, TRUE );
  594.     delete_status_window();
  595. }
  596.  
  597.  
  598. /*----------------------------------------------------------------------
  599.  
  600.         opening_sequence
  601.  
  602. ----------------------------------------------------------------------*/
  603.  
  604. int    opening_sequence()
  605. {
  606. /*
  607.  *    Opening sequence...
  608.  */
  609.     int    n_boxes, i = 0, j;
  610.     int    rows, columns, brow, bcolumn;
  611.     WINDOW    *title;
  612.  
  613.     n_boxes = (LINES - 3) / 2;
  614.     while ( i < n_boxes )
  615.     {
  616.  
  617.         rows = stdscr->_maxy - i * 2;
  618.         columns = stdscr->_maxx - i * 6;
  619.         brow = stdscr->_begy + i;
  620.         bcolumn = stdscr->_begx + i * 3;
  621.         if ( !rows || !columns )
  622.         {
  623.             n_boxes = i;
  624.             break;
  625.         }
  626.  
  627.         w[i] = newwin(    rows, columns, brow, bcolumn );
  628.  
  629.         if ( w[i] )
  630.         {
  631.             if ( i )
  632.                 im[i - 1] = save_image( w[i], NULL );
  633.             if ( ttymode == COLOR )
  634.                 wattrset( w[i], ((i + 1) << 8) & 0x0F00 );
  635.             box( w[i], VS_LINE, HS_LINE );
  636.             wpopdown( w[i++] );
  637.         } else {
  638.             n_boxes = i;
  639.             break;
  640.         }
  641.     }
  642.     if ( slow )
  643.         sleep( 2.0 );
  644.     for ( i = n_boxes - 1 ; w[i]->_maxx < 46 ; )
  645.     {
  646.         wrefresh( im[--i] );
  647.         if ( slow )
  648.             sleep( 0.1 );
  649.     }
  650.  
  651.     j = i;
  652.     i++;
  653.     while ( (ttymode == COLOR) && i-- )
  654.     {
  655.         wchng_text_color( curscr, ((i + 1) << 8), A_FG_D_GREY );
  656.         wrefresh( curscr );
  657.     }
  658.  
  659.     wattrset( w[j], (ttymode == COLOR) ? A_FG_BLUE : A_BOLD );
  660.     box( w[j], VS_LINE, HD_LINE );
  661.     wpullover( w[j] );
  662. /*
  663.  *    Show the credits...
  664.  */
  665.     title = subwin( w[j], w[j]->_maxy - 2, w[j]->_maxx - 4,
  666.                   w[j]->_begy + 1, w[j]->_begx + 2 );
  667.     if ( title )
  668.     {
  669.         scrollok( title, TRUE );
  670.         if ( ttymode == COLOR )
  671.             wattrset( title, A_FG_MAGENTA );
  672.         werase( title );
  673.         center_on_bottom( title, "The" );
  674.         center_on_bottom( title, "Cygnus Development Group" );
  675.         center_on_bottom( title, "Presents" );
  676.         center_on_bottom( title, "" );
  677.         wattron( title, A_BOLD );
  678.         center_on_bottom( title, "CURSES" );
  679.         wattroff( title, A_BOLD );
  680.         center_on_bottom( title, "UNIX-compatible Windowing Software" );
  681.         center_on_bottom( title, "" );
  682.         delwin( title );
  683.     }
  684.     if ( slow )
  685.         sleep( 6.0 );
  686.  
  687.     for ( i = n_boxes ; i-- ; )
  688.     {
  689.         delwin( w[i] );
  690.         w[i] = NULL;
  691.     }
  692.     for ( i = n_boxes - 1 ; i-- ; )
  693.     {
  694.         delwin( im[i] );
  695.         im[i] = NULL;
  696.     }
  697. }
  698.  
  699.  
  700. /*----------------------------------------------------------------------
  701.  
  702.         show_support
  703.  
  704. ----------------------------------------------------------------------*/
  705.  
  706. int    show_support()
  707. {
  708. /*
  709.  *    Display a window listing all of the supported adapters...
  710.  */
  711.  
  712.     WINDOW    *w;
  713.  
  714.  
  715.     w = newwin( 3 * LINES / 4, 60, 3, 8 );
  716.     wattrset( w, A_FG_L_BLUE | A_FG_BLACK );
  717.     werase( w );
  718.     mvwaddstr( w, 1, 2,
  719.            "Curses AUTOMATICALLY supports a variety of video" );
  720.     mvwaddstr( w, 2, 2, "adapters, including:" );
  721.     mvwaddstr( w, 4, 2,
  722.            "Monochrome Display Adapter    Video-7 VEGA Deluxe" );
  723.     mvwaddstr( w, 5, 2,
  724.            "Color Graphics Adapter            25 lines x 80 columns" );
  725.     mvwaddstr( w, 6, 2,
  726.            "Enhanced Graphics Adapter         43 lines x 80 columns" );
  727.     mvwaddstr( w, 7, 6,
  728.            "25 lines x 80 columns         25 lines x 120 columns" );
  729.     mvwaddstr( w, 8, 6,
  730.            "43 lines x 80 columns         43 lines x 120 columns" );
  731.     box( w, VS_LINE, HS_LINE );
  732. /*
  733.  *    Copy it onto the standard screen...
  734.  */
  735.     woverwrite( w, stdscr, w->_begy, w->_begx );
  736.     delwin( w );
  737. }
  738.  
  739.  
  740. /*----------------------------------------------------------------------
  741.  
  742.         give_disclaimer
  743.  
  744. ----------------------------------------------------------------------*/
  745.  
  746. int    give_disclaimer()
  747. {
  748. /*
  749.  *    Display another small window with a discussion of the
  750.  *    versatility of the library...
  751.  */
  752.  
  753.     WINDOW    *w;
  754.  
  755.  
  756.     w = newwin( 7, 61, LINES - 9, COLS - 63 );
  757.     wattron( w, A_FG_RED );
  758.     werase( w );
  759.     mvwaddstr( w, 1, 2,
  760.            "With proper programming, applications can be built around" );
  761.     mvwaddstr( w, 2, 2, "the " );
  762.     wattron( w, A_BOLD );
  763.     waddstr( w, "curses" );
  764.     wattroff( w, A_BOLD );
  765.     waddstr( w, " library, and transported with ease to a UNIX" );
  766.     mvwaddstr( w, 3, 2, "environment.  " );
  767.     wattron( w, A_BOLD );
  768.     waddstr( w, "Curses" );
  769.     wattroff( w, A_BOLD );
  770.     waddstr( w, " provides unparalleled opportunities" );
  771.     mvwaddstr( w, 4, 2,
  772.            "for the application developer, while supporting the " );
  773.     mvwaddstr( w, 5, 2,
  774.            "enhanced display abilities of the personal computer." );
  775.     wattron( w, A_BOLD );
  776.     box( w, VD_LINE, HD_LINE );
  777.     wrefresh( w );
  778.     delwin( w );
  779. }
  780.  
  781.  
  782. /*----------------------------------------------------------------------
  783.  
  784.         get_weird
  785.  
  786. ----------------------------------------------------------------------*/
  787.  
  788. #define    N_SUB_WINS    3
  789.  
  790. int    get_weird()
  791. {
  792. /*
  793.  *    Put up a window with some text, then 'slide' (using the
  794.  *    XCurses function 'travel_window()') portions of this
  795.  *    window to other parts of the screen.  This demonstrates that
  796.  *    the physical display of the window can be disjoint from it's
  797.  *    virtual representation.  Note that all 4 displayed windows
  798.  *    show the same virtual window.  All sub-windows need to be
  799.  *    touched each time they are updated, or the Curses system
  800.  *    thinks that the first update is all that is necessary.
  801.  */
  802.  
  803.     int    i, j, k;
  804.     WINDOW    *mw, *smw, *sw[N_SUB_WINS];
  805.  
  806.  
  807.     if ( ttymode == COLOR )
  808.         attron( A_BG_BLACK );
  809.     else
  810.         attroff( A_REVERSE );
  811.     erase();
  812.     pullover();
  813.     if ( !(mw = newwin( 8, 46, 15, 25)) )
  814.         return( 1 );
  815.  
  816.     wattrset( mw, (ttymode == COLOR)
  817.             ? (A_FG_L_CYAN | A_BG_BLUE)
  818.             : A_BOLD );
  819.     werase( mw );
  820.     box( mw, VS_LINE, HS_LINE );
  821.     wpulldown( mw );
  822.     smw = subwin( mw, mw->_maxy - 2, mw->_maxx - 4,
  823.               mw->_begy + 1, mw->_begx + 2 );
  824.     if ( smw )
  825.         scrollok( smw, TRUE );
  826.     wmove( smw, smw->_maxy - 1, 0 );
  827.     werase( smw );
  828.     waddstr( smw, "Through an extensive set of functions,\nCurses" );
  829.     waddstr( smw, " provides ABSOLUTE control over\nthe display...\n" );
  830.     wrefresh( smw );
  831.  
  832.  
  833. /*
  834.  *    Tell the user what is being demonstrated here...
  835.  *
  836. Using subwindows, a given window can be segmented for easier
  837. management.  This approach provides the ability to create
  838. fields or areas which have their own attributes, yet access 
  839. the same virtual window.  Writing to, and updating, a
  840. configured window is then a simple matter.
  841.  
  842. With clever programming, subwindows can also provide some
  843. very interesting effects...
  844. */
  845.     move( 0, 0 );
  846.     addstr( "very interesting effects..." );
  847.     refresh();
  848.     move( 0, 0 );
  849.     insertln();
  850.     addstr( "With clever programming, subwindows can also provide some" );
  851.     refresh();
  852.     move( 0, 0 );
  853.     insertln();
  854.     refresh();
  855.     move( 0, 0 );
  856.     insertln();
  857.     addstr( "configured window is then a simple matter." );
  858.     refresh();
  859.     move( 0, 0 );
  860.     insertln();
  861.     addstr( "the same virtual window.  Writing to, and updating, a" );
  862.     refresh();
  863.     move( 0, 0 );
  864.     insertln();
  865.     addstr( "fields or areas which have their own attributes, yet access" );
  866.     refresh();
  867.     move( 0, 0 );
  868.     insertln();
  869.     addstr( "management.  This approach provides the ability to create" );
  870.     refresh();
  871.     move( 0, 0 );
  872.     insertln();
  873.     addstr( "Using subwindows, a window can be segmented for easier" );
  874.     refresh();
  875.  
  876.     if ( slow )
  877.         sleep( 8.0 );
  878.  
  879.     for ( i = 0 ; i < N_SUB_WINS ; i++ )
  880.     {
  881.         sw[i] = subwin( mw, rand() % 5 + 3, rand() % 35 + 10,
  882.                     15 + rand() % 4, 25 + rand() % 20 );
  883.         if ( !sw[i] )
  884.         {
  885.             i--;
  886.             continue;
  887.         }
  888.         travel_window( sw[i], rand() % (LINES - sw[i]->_begy),
  889.                       rand() % (COLS - sw[i]->_maxx) );
  890.     }
  891.     if ( slow )
  892.         sleep( 4.0 );
  893.  
  894.     wattroff( smw, A_BOLD );
  895.     for ( j = 0 ; j < 255 ; j += k )
  896.     {
  897.         for ( k = 0 ; k < 40 ; k++ )
  898.         {
  899.             wputch( smw, j + k );
  900.             for ( i = 0 ; i < N_SUB_WINS ; )
  901.             {
  902.                 touchwin( sw[i] );
  903.                 wrefresh( sw[i++] );
  904.             }
  905.             touchwin( smw );
  906.             wrefresh( smw );
  907.             if ( slow )
  908.                 sleep( 0.1 );
  909.         }
  910.         waddch( smw, '\n' );
  911.     }
  912.  
  913.     for ( i = 0 ; i < N_SUB_WINS ; delwin( sw[i++]) );
  914.     delwin( smw );
  915.     delwin( mw );
  916.     if ( slow )
  917.         sleep( 3.0 );
  918. }
  919.  
  920.  
  921. /*----------------------------------------------------------------------
  922.  
  923.         get_image_of_curscr
  924.  
  925. ----------------------------------------------------------------------*/
  926.  
  927. int    hr, hc;
  928.  
  929. int    get_image_of_curscr( win, r, c)
  930. WINDOW    *win;
  931. int    r, c;
  932. {
  933.     static    WINDOW    *w = NULL;
  934.  
  935.     mvwin( win, r, c );
  936.     w = wsave_image( curscr, win, w );
  937.     mvwin( w, hr, hc );
  938.     wrefresh( w );
  939.     if ( slow )
  940.         sleep( 0.06 );
  941. }
  942.  
  943.  
  944. /*----------------------------------------------------------------------
  945.  
  946.         show_window_on_curscr
  947.  
  948. ----------------------------------------------------------------------*/
  949.  
  950. int    show_window_on_curscr()
  951. {
  952. /*
  953.  *    Create a (small) window, through which we will view
  954.  *    areas of the current screen.  Repeatedly, an area the size
  955.  *    of our little window is copied from curscr, and displayed
  956.  *    in our window.  The upper left corner of this area is move
  957.  *    from lower right to lower left to upper left, and diagonally
  958.  *    back to lower right.  Note that some recursion is a result
  959.  *    of trying to view the window which contains the view.
  960.  */
  961.     int    r = 8, c = 30;
  962.     WINDOW    *area, *w = NULL;
  963.  
  964.     hr = LINES - (r + 2);
  965.     hc = COLS - (c + 4);
  966.     area = newwin( r, c, hr, hc );
  967.     w = newwin( area->_maxy + 2, area->_maxx + 2,
  968.             area->_begy - 1, area->_begx - 1 );
  969.     wattrset( w, (ttymode == COLOR)
  970.             ? (A_FG_WHITE | A_BG_BLACK)
  971.             : A_BOLD );
  972.     box( w, VD_LINE, HD_LINE );
  973.     wweave( w );
  974.     delwin( w );
  975.  
  976.     for ( c = area->_begx ; c > 5 ; c-- )
  977.         get_image_of_curscr( area, area->_begy, c );
  978.  
  979.     for ( r = area->_begy ; r > 0 ; r-- )
  980.         get_image_of_curscr( area, r, area->_begx );
  981.  
  982.     for ( r = area->_begy, c = area->_begx ;
  983.           (r < hr - 2) && (c < hc) ; r++, c++ )
  984.         get_image_of_curscr( area, r, c );
  985.  
  986.     for ( c = area->_begx ; c <= hc ; c++ )
  987.         get_image_of_curscr( area, area->_begy, c );
  988.  
  989.     for ( r = area->_begy ; r <= hr ; r++ )
  990.         get_image_of_curscr( area, r, area->_begx );
  991.  
  992.     delwin( area );
  993.     if ( slow )
  994.         sleep( 1.0 );
  995. }
  996.  
  997.  
  998. /*----------------------------------------------------------------------
  999.  
  1000.         instructions
  1001.  
  1002. ----------------------------------------------------------------------*/
  1003.  
  1004. int    instructions()
  1005. {
  1006. /*
  1007.  *    Type, to standard error, a small set of instructions on
  1008.  *    how to get the usage message.
  1009.  */
  1010.     fprintf( stderr,
  1011.          "\n\tThis demonstration program can be run on both color\n" );
  1012.     fprintf( stderr,
  1013.          "\tand monochrome displays, and on certain adapters that\n" );
  1014.     fprintf( stderr,
  1015.          "\tsupport more than 80 columns and/or 25 lines.  To\n" );
  1016.     fprintf( stderr,
  1017.          "\tdetermine the command switches, type:\n\n" );
  1018.     fprintf( stderr,
  1019.          "\t\t%s --\n\n", strupr( Iam) );
  1020.     fprintf( stderr,
  1021.          "\tat the DOS prompt.  Then use the options shown in the\n" );
  1022.     fprintf( stderr,
  1023.          "\t'usage' message.\n\n" );
  1024.     fprintf( stderr,
  1025.          "(Type CONTROL-BREAK now to halt this program)\n\n" );
  1026.     if ( slow )
  1027.         sleep( 10.0 );
  1028.     kbhit();
  1029. }
  1030.  
  1031.  
  1032. /*----------------------------------------------------------------------
  1033.  
  1034.         do_curid_intro
  1035.  
  1036. ----------------------------------------------------------------------*/
  1037.  
  1038. int    do_curid_intro()
  1039. {
  1040. /*
  1041.  *    A medium-sized, brown window for getting the user's name
  1042.  *    and illustrating string input.
  1043.  */
  1044.     WINDOW    *wch;
  1045.  
  1046.     wch = newwin( 10, 55, 1, 24 );
  1047.     if ( wch )
  1048.     {
  1049.         wnl( wch );
  1050.         wecho( wch );
  1051.         scrollok( wch, TRUE );
  1052.         leaveok( wch, FALSE );
  1053.     }
  1054.     wattrset( wch, (ttymode == COLOR)
  1055.             ? (A_FG_BLACK | A_BG_BROWN)
  1056.             : A_REVERSE );
  1057.     werase( wch );
  1058.     wmove( wch, wch->_maxy - 1, 0 );
  1059.     wpullover( wch );
  1060.  
  1061.     wprintw( wch, "Curses Interactive Demonstration\n" );
  1062.     wprintw( wch, "(C)1987 Cygnus Development Group\n" );
  1063.     wprintw( wch, "\nWelcome to CurID!\n" );
  1064.     wprintw( wch, "\nEnter your name, please: " );
  1065.     wrefresh( wch );
  1066.  
  1067. /*
  1068.  *    Turn the cursor on while doing string input.
  1069.  */
  1070.     cursor_on();
  1071.     wgetstr( wch, line );
  1072.     cursor_off();
  1073.  
  1074.     werase( wch );
  1075.     waddstr( wch,
  1076.          "Now, watch the 'Keyboard Status' window while pressing\n" );
  1077.     waddstr( wch,
  1078.          "and releasing the shift keys, the 'num-lock', 'scroll-\n" );
  1079.     waddstr( wch, "lock', or 'caps-lock' keys.  Notice that the clock\n" );
  1080.     waddstr( wch, "continuously runs.  " );
  1081.     wstandout( wch );
  1082.     waddstr( wch, " Curses " );
  1083.     wstandend( wch );
  1084.     waddstr( wch, " always knows what keys\n" );
  1085.     waddstr( wch, "on the keyboard are being pressed." );
  1086.     wrefresh( wch );
  1087.  
  1088.     if ( slow )
  1089.         sleep( 15.0 );
  1090.     delwin( wch );
  1091. }
  1092.  
  1093.  
  1094. /*----------------------------------------------------------------------
  1095.  
  1096.         closing_sequence
  1097.  
  1098. ----------------------------------------------------------------------*/
  1099.  
  1100. int    closing_sequence( border, win)
  1101. WINDOW    *border, *win;
  1102. {
  1103. /*
  1104.  *    Scroll a magenta screen down, and scroll a message about
  1105.  *    how this demo was created.
  1106.  */
  1107.  
  1108.     WINDOW    *wch;
  1109.  
  1110.  
  1111.     attrset( (ttymode == COLOR)
  1112.             ? (A_FG_YELLOW | A_BG_MAGENTA)
  1113.             : A_BOLD );
  1114.     erase();
  1115.     box( stdscr, VD_LINE, HS_LINE );
  1116.  
  1117.     if ( ttymode == COLOR )
  1118.         wattrset( border, A_FG_BLUE | A_BG_L_GREY );
  1119.     werase( border );
  1120.     box( border, VS_LINE, HS_LINE );
  1121.     if ( ttymode == COLOR )
  1122.         wattrset( win, A_FG_BLUE | A_BG_L_GREY );
  1123.     werase( win );
  1124.     mvwin( border, 5, (COLS - border->_maxx) / 2 );
  1125.     mvwin( win, border->_begy + 1, border->_begx + 2 );
  1126.     woverwrite( border, stdscr, border->_begy, border->_begx );
  1127.     popdown();
  1128.     center_on_bottom( win, 
  1129.               "This demonstration was produced entirely with" );
  1130.     wstandout( win );
  1131.     center_on_bottom( win, " CDG Curses, and CDG XCurses, " );
  1132.     wstandend( win );
  1133.     center_on_bottom( win, "extensions to the Curses library, using the" );
  1134.     center_on_bottom( win, "Microsoft C Compiler, V4.0, compact model." );
  1135.     if ( slow )
  1136.         sleep( 8.0 );
  1137.  
  1138.     if ( wch = newwin( 10, 55, LINES - 12, 5) )
  1139.     {
  1140.         wnl( wch );
  1141.         wecho( wch );
  1142.         leaveok( wch, FALSE );
  1143.     }
  1144.     wattrset( wch, (ttymode == COLOR)
  1145.             ? (A_FG_L_CYAN | A_BG_MAGENTA)
  1146.             : A_BOLD );
  1147.     werase( wch );
  1148.     box( wch, VS_LINE, HD_LINE );
  1149.     mvwaddstr( wch, 1, 2, "For more information on Curses," );
  1150.     mvwaddstr( wch, 2, 2, "and other operating-system independant" );
  1151.     mvwaddstr( wch, 3, 2, "software, contact:" );
  1152.     wattron( wch, (ttymode == COLOR) ? A_FG_WHITE : A_REVERSE );
  1153.     mvwaddstr( wch, 5, 2, " Cygnus Development Group      " );
  1154.     mvwaddstr( wch, 6, 2, " Dept. DC                      " );
  1155.     mvwaddstr( wch, 7, 2, " 13000 Roma N.E.               " );
  1156.     mvwaddstr( wch, 8, 2, " Albuquerque, New Mexico 87123 " );
  1157.     wexplode( wch );
  1158.  
  1159.     delwin( wch );
  1160. }
  1161.