home *** CD-ROM | disk | FTP | other *** search
- /*#cdg#cursesdemo#******************************************************
- * *
- * Copyright 1987 Cygnus Development Group *
- * *
- * This software is a proprietary product of *
- * the Cygnus Development Group (CDG). *
- * ALL RIGHTS RESERVED *
- * *
- ************************************************************************
- * *
- * Purpose: *
- * The executable demonstration program may be freely *
- * distributed. The source code included on this disk, along *
- * with the 'readme.doc' file MUST be included with the *
- * program. This program and its source code remain the *
- * property of the Cygnus Development Group, and may not be *
- * redistributed for profit, in whole or in part, without *
- * the express WRITTEN permission of the Cygnus Development *
- * Group. *
- * *
- * *
- ***********************************************************************/
-
-
- #include <xcurses.h>
- #include <dostools.h>
- #include <xchars.h>
- #include <cmdline.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <signal.h>
-
-
- bool slow = TRUE;
-
- /*
- * Command-line arguments available for this program.
- * This generic command-line processor is part of the
- * ToolBox Library.
- */
- argument cl_args[] = {
- { 'l', integer_argument( LINES ), "Support for EGA multi-line modes" },
- { 'c', integer_argument( COLS ), "Support for EGA multi-column modes" },
- { 'b', boolean_argument( behave ), "Force well-behaved execution" },
- { 's', boolean_argument( slow ), "Slow down execution of the demo" },
- null_argument };
-
-
- #define N_BOXES 20
- #define LINE_LEN 131
-
- char line[LINE_LEN + 1];
- static int cl_behave;
- WINDOW *w[N_BOXES], *im[N_BOXES];
-
-
- /*----------------------------------------------------------------------
-
- exit_curses_demo
-
- ----------------------------------------------------------------------*/
-
- int exit_curses_demo()
- {
- /*
- * Signal handler for ^C or ^Break.
- */
- cursor_on();
- endwin();
- exit( 0 );
- }
-
-
- /*----------------------------------------------------------------------
-
- main
-
- ----------------------------------------------------------------------*/
-
- main( argc, argv)
- int argc;
- char **argv;
- {
- int i = 0, bottom, middle;
- WINDOW *info, *sinfo, *wch;
-
- parse_command_line( argc, argv, cl_args );
- instructions();
-
- cl_behave = behave;
-
- initscr();
- signal( SIGINT, exit_curses_demo );
- noecho();
- crmode();
- nl();
- cursor_off();
- clearok( curscr, FALSE );
- clearok( stdscr, FALSE );
-
- opening_sequence();
-
- /*
- * Create a window full of I/O information...
- */
- attrset( (ttymode == COLOR)
- ? (A_FG_CYAN | A_BG_BLUE)
- : A_REVERSE );
- fill( DOTS1 );
- info = newwin( 6, 50, 3, 4 );
- wattrset( info, (ttymode == COLOR) ? A_FG_GREEN : A_REVERSE );
- werase( info );
- box( info, VD_LINE, HS_LINE );
- sinfo = subwin( info, info->_maxy - 2, info->_maxx - 4,
- info->_begy + 1, info->_begx + 2 );
- if ( sinfo )
- {
- scrollok( sinfo, TRUE );
- wcrmode( sinfo );
- wwrap( sinfo );
- wnl( sinfo );
- }
- wattron( sinfo, A_BOLD );
- mvwaddstr( sinfo, 0, 0, "Curses" );
- wattroff( sinfo, A_BOLD );
- waddstr( sinfo, " gives the C programmer 'windows' for\n" );
- waddstr( sinfo, "both input and output. These windows are\n" );
- waddstr( sinfo, "created dynamically, and their attributes are\n" );
- waddstr( sinfo, "determined by the developer." );
- wshadow( info, stdscr );
- woverwrite( info, stdscr, info->_begy, info->_begx );
- pullover();
- if ( slow )
- sleep( 5.0 );
-
- build_eg_window();
-
- werase( sinfo );
- waddstr( sinfo, "That was an illustration of building a simple\n" );
- waddstr( sinfo, "window. Many characteristics are available\n" );
- waddstr( sinfo, "to the developer, which may be configured for\n" );
- waddstr( sinfo, "EACH individual window..." );
- attron( A_BG_L_GREY );
- erase();
- explode();
- travel_window( info, LINES - info->_maxy - 4,
- COLS - info->_maxx - 10 );
- mvwin( sinfo, info->_begy + 1, info->_begx + 2 );
- wrefresh( sinfo );
- if ( slow )
- sleep( 4.0 );
-
- show_io_skills( sinfo );
-
- erase();
- if ( ttymode == COLOR )
- wattrset( sinfo, A_FG_MAGENTA );
- werase( sinfo );
- waddstr( sinfo, "Video access is FAST; create windows easily,\n" );
- waddstr( sinfo, "and then 'pop' them onto the display with a\n" );
- waddstr( sinfo, "single function...\n" );
- woverwrite( info, stdscr, info->_begy, info->_begx );
- pullover();
-
- pop_boxes( sinfo );
-
- show_listing( info, sinfo );
- /*
- * Show interactive I/O through a window...
- */
- if ( ttymode == COLOR )
- attrset( A_FG_YELLOW | A_BG_BLUE );
- erase();
- box( stdscr, VS_LINE, HS_LINE );
- if ( ttymode == COLOR )
- wattrset( info, A_FG_RED | A_BG_L_GREY );
- werase( info );
- box( info, VS_LINE, HD_LINE );
- if ( ttymode == COLOR )
- wattrset( sinfo, A_FG_RED | A_BG_L_GREY );
- werase( sinfo );
- mvwin( info, LINES / 2, 8 );
- mvwin( sinfo, info->_begy + 1, info->_begx + 2 );
- waddstr( sinfo, "Input, in the style of 'fgets()' and\n" );
- waddstr( sinfo, "'scanf()', is also possible...\n" );
- woverwrite( info, stdscr, info->_begy, info->_begx );
- weave();
- if ( slow )
- sleep( 4.0 );
-
- do_curid_intro();
- monitor_kbd( sinfo );
-
- get_weird();
- show_window_on_curscr();
-
- erase();
- show_support();
- mesh();
- if ( slow )
- sleep( 15.0 );
- give_disclaimer();
- if ( slow )
- sleep( 15.0 );
- /*
- * Display the references, and close.
- */
- closing_sequence( info, sinfo );
- if ( slow )
- sleep( 15.0 );
-
- exit_curses_demo();
- }
-
-
- /*----------------------------------------------------------------------
-
- center_on_bottom
-
- ----------------------------------------------------------------------*/
-
- int center_on_bottom( w, str)
- WINDOW *w;
- char *str;
- {
- scroll( w );
- mvwaddstr( w, w->_maxy - 1, (w->_maxx - strlen( str)) / 2, str );
- wrefresh( w );
- if ( slow )
- sleep( 0.30 );
- }
-
-
- /*----------------------------------------------------------------------
-
- pop_boxes
-
- ----------------------------------------------------------------------*/
-
- int pop_boxes( words)
- WINDOW *words;
- {
- /*
- * Demonstrate putting randomly sized and placed
- * windows onto the screen.
- */
- int i, j, hei, wid;
- int num_boxes_here = 8;
-
- if ( slow )
- sleep( 5.5 );
-
- srand( (unsigned) (time( NULL) & 0xFF) );
- for ( i = 0 ; i < num_boxes_here ; i++ )
- {
- wid = rand() % (COLS / 2) + 20;
- hei = rand() % (LINES / 2) + 5;
- w[i] = newwin( hei, wid, rand() % (LINES - hei - 2),
- rand() % (COLS - wid - 2) );
- if ( !w[i] )
- {
- i--;
- continue;
- }
- wattrset( w[i], (ttymode == COLOR) ?
- (((rand() % 6) + 2) << 8) | ((rand() % 2) << 12) :
- ((rand() % 2) ? A_REVERSE : 0) );
- werase( w[i] );
- box( w[i], (rand() % 2) ? VS_LINE : VD_LINE,
- (rand() % 2) ? HS_LINE : HD_LINE );
- }
- for ( j = i ; j-- ; )
- {
- im[j] = save_image( w[j], im[j] );
- wrefresh( w[j] );
- if ( slow )
- sleep( (double) j * j * 0.006 );
- }
- if ( slow )
- sleep( 2.0 );
- for ( j = 0 ; j < i ; j++ )
- {
- wrefresh( im[j] );
- if ( slow )
- sleep( (double) (i - j) * (i - j) * 0.006 );
- }
- /*
- * Do the same, only go through the BIOS.
- */
- waddstr( words, "\nWell-behaved software (that uses the BIOS)\n" );
- waddstr( words, "is also fully supported. This allows " );
- wattron( words, A_BOLD );
- waddstr( words, "Curses\n" );
- wattroff( words, A_BOLD );
- waddstr( words, "applications to operate under Microsoft\n" );
- waddstr( words, "Windows (Tm), or Quarterdeck's Desqview (Tm)." );
- touchwin( words );
- wrefresh( words );
- if ( slow )
- sleep( 4.5 );
- behave = TRUE;
- for ( j = i ; j-- ; )
- {
- im[j] = save_image( w[j], im[j] );
- touchwin( w[j] );
- wrefresh( w[j] );
- if ( slow )
- sleep( (double) j * j * 0.006 );
- }
- if ( slow )
- sleep( 2.0 );
- for ( j = 0 ; j < i ; j++ )
- {
- touchwin( im[j] );
- wrefresh( im[j] );
- if ( slow )
- sleep( (double) (i - j) * (i - j) * 0.006 );
- }
- behave = cl_behave;
- if ( slow )
- sleep( 3.0 );
- }
-
-
- /*----------------------------------------------------------------------
-
- build_eg_window
-
- ----------------------------------------------------------------------*/
-
- int build_eg_window()
- {
- WINDOW *wch, *swch, *win;
-
- wch = newwin( 10, 42, LINES / 2 + 1, 36 );
- wattrset( wch, A_FG_L_GREY | A_BG_BLACK );
- werase( wch );
- box( wch, VD_LINE, HS_LINE );
- swch = subwin( wch, wch->_maxy - 2, wch->_maxx - 4,
- wch->_begy + 1, wch->_begx + 2 );
- if ( swch ) {
- scrollok( swch, TRUE );
- wnowrap( swch );
- }
- wpulldown( wch );
- /*
- * Build a window while describing it...
- */
- waddstr( swch, "/* Get a small window */\n" );
- waddstr( swch, "win = newwin( 12, 30, LINES - 14, 6);\n" );
- wrefresh( swch );
- win = newwin( 12, 30, LINES - 14, 5 );
- leaveok( win, TRUE );
- wrefresh( win );
- if ( slow )
- sleep( 4.0 );
-
- waddstr( swch, "/* Set the fg color to " );
- waddstr( swch, (ttymode == COLOR) ? "white,\n" : "bold,\n" );
- waddstr( swch, " and the bg to " );
- waddstr( swch, (ttymode == COLOR) ? "red" : "black" );
- waddstr( swch, " */\n" );
- waddstr( swch, "wattrset( win, " );
- waddstr( swch, (ttymode == COLOR)
- ? "A_FG_WHITE | A_BG_RED);\n"
- : "A_BOLD);\n" );
- wrefresh( swch );
- wattrset( win, (ttymode == COLOR)
- ? (A_BOLD | A_FG_L_GREY | A_BG_RED)
- : A_BOLD );
- wrefresh( win );
- if ( slow )
- sleep( 3.0 );
-
- waddstr( swch, "/* clear to set the style... */\n" );
- waddstr( swch, "werase( win);\n" );
- wrefresh( swch );
- werase( win );
- wrefresh( win );
- if ( slow )
- sleep( 4.0 );
-
- waddstr( swch, "/* double-box the window */\n" );
- waddstr( swch, "box( win, VD_LINE, HD_LINE);\n" );
- wrefresh( swch );
- box( win, VD_LINE, HD_LINE );
- wrefresh( win );
- if ( slow )
- sleep( 4.0 );
-
- waddstr( swch, "/* and put up the window... */\n" );
- waddstr( swch, "wrefresh( win);\n" );
- wrefresh( swch );
- if ( slow )
- sleep( 4.0 );
-
- delwin( swch );
- delwin( wch );
- delwin( win );
- }
-
-
- /*----------------------------------------------------------------------
-
- show_io_skills
-
- ----------------------------------------------------------------------*/
-
- int show_io_skills( words)
- WINDOW *words;
- {
- WINDOW *wch;
-
- wch = newwin( 11, 60, 3, 16 );
- if ( wch )
- {
- wattrset( wch, (ttymode == COLOR)
- ? (A_FG_RED | A_BG_L_GREY)
- : A_REVERSE );
- werase( wch );
- box( wch, VS_LINE, HS_LINE );
- mvwaddstr( wch, 1, 2, "Attributes:" );
- wattron( wch, A_BOLD );
- mvwaddstr( wch, 2, 6, "Foreground Color" );
- wattroff( wch, A_BOLD );
- wstandout( wch );
- mvwaddstr( wch, 3, 6, "Background Color" );
- wstandend( wch );
- blinkok( wch, TRUE );
- mvwaddstr( wch, 4, 6, "Character Blink" );
- blinkok( wch, FALSE );
- wrefresh( wch );
- wrefresh( words );
- }
- if ( slow )
- sleep( 3.0 );
-
- if ( wch )
- {
- mvwaddstr( wch, 1, 27, "Character Sets:" );
- mvwaddstr( wch, 2, 27, " Unix-Compatible un-Control" );
- mvwaddstr( wch, 3, 27, " IBM Extended Character Set" );
- wrefresh( wch );
- }
- if ( ttymode == COLOR )
- wattrset( words, A_FG_CYAN );
- werase( words );
- waddstr( words, "\nAlso, various methods of output are\n" );
- waddstr( words, "available...." );
- wrefresh( words );
- if ( slow )
- sleep( 5.0 );
-
- if ( wch )
- {
- mvwaddstr( wch, 6, 2, "Output:" );
- mvwaddstr( wch, 7, 2, " Automatic Scrolling" );
- mvwaddstr( wch, 8, 2, " Margin Wrap-around" );
- mvwaddstr( wch, 9, 2, " Newline Mapping" );
- wrefresh( wch );
- }
- wrefresh( words );
- if ( slow )
- sleep( 5.0 );
-
- if ( wch )
- {
- mvwaddstr( wch, 5, 27, "Input:" );
- mvwaddstr( wch, 6, 27, " Keyboard Sampling" );
- mvwaddstr( wch, 7, 27, " 'getchar()'-Style Input" );
- mvwaddstr( wch, 8, 27, " Selectable Echo" );
- mvwaddstr( wch, 9, 27, " Full IBM Keyboard" );
- wrefresh( wch );
- }
- if ( ttymode == COLOR )
- wattrset( words, A_FG_YELLOW );
- werase( words );
- waddstr( words, "\nas is input THROUGH the window." );
- wrefresh( words );
-
- delwin( wch );
- wch = NULL;
- if ( slow )
- sleep( 10.0 );
- }
-
-
- /*----------------------------------------------------------------------
-
- show_listing
-
- ----------------------------------------------------------------------*/
-
- int show_listing( outside, words)
- WINDOW *outside, *words;
- {
- /*
- * List a part of this demo program...
- */
- int i;
- WINDOW *wch;
- FILE *dfp;
-
- wattrset( outside, A_FG_CYAN | A_BG_BLUE );
- werase( outside );
- box( outside, VS_LINE, HD_LINE );
- wattrset( words, A_FG_L_BLUE | A_BG_BLUE );
- werase( words );
- mvwin( outside, LINES - outside->_maxy - 1, COLS - outside->_maxx - 8 );
- mvwin( words, outside->_begy + 1, outside->_begx + 2 );
- waddstr( words, "Output to a window is as EASY as using\n" );
- waddstr( words, "printf, and faster. Scrolling, newlines,\n" );
- waddstr( words, "and tabs are all handled by " );
- wattron( words, A_FG_L_CYAN );
- waddstr( words, "Curses" );
- wattron( words, A_FG_L_BLUE );
- waddch( words, '.' );
- erase();
- woverwrite( outside, stdscr, outside->_begy, outside->_begx );
- pulldown();
- if ( slow )
- sleep( 5.0 );
-
- strcpy( line, Iam );
- strcpy( strchr( line, '.'), ".c" );
- if ( dfp = fopen( line, "r") )
- {
-
- if ( wch = newwin( LINES / 2, 70, 2, 5) )
- {
- wnl( wch );
- scrollok( wch, TRUE );
- wattrset( wch, A_FG_BROWN | A_BG_BLACK );
- werase( wch );
- wexplode( wch );
- }
-
- i = 60;
- while ( fgets( line, LINE_LEN, dfp) && i-- )
- {
- waddstr( wch, line );
- wrefresh( wch );
- }
- fclose( dfp );
- delwin( wch );
- wch = NULL;
- if ( slow )
- sleep( 5.0 );
- }
- }
-
-
- /*----------------------------------------------------------------------
-
- monitor_kbd
-
- ----------------------------------------------------------------------*/
-
- int monitor_kbd( words)
- WINDOW *words;
- {
- /*
- * Monitor the keyboard for a while...
- */
- long start, t;
-
- werase( words );
- wattron( words, A_BOLD );
- waddstr( words, "Curses" );
- wattroff( words, A_BOLD );
- waddstr( words, " monitors the status of the keyboard\n" );
- waddstr( words, "automatically, including the shift/lock keys.\n" );
- waddstr( words, "(See for yourself during the next 20 seconds)\n" );
- wrefresh( words );
-
- build_status_window();
- if ( words )
- {
- wnoecho( words );
- nodelay( words, TRUE );
- scrollok( words, FALSE );
- }
- time( &start );
- while ( (time( &t) - start) < 20l )
- {
- wgetch( words );
- waddch( words, '\r' );
- waddstr( words, ctime( &t) );
- wrefresh( words );
- }
- if ( words )
- scrollok( words, TRUE );
- delete_status_window();
- }
-
-
- /*----------------------------------------------------------------------
-
- opening_sequence
-
- ----------------------------------------------------------------------*/
-
- int opening_sequence()
- {
- /*
- * Opening sequence...
- */
- int n_boxes, i = 0, j;
- int rows, columns, brow, bcolumn;
- WINDOW *title;
-
- n_boxes = (LINES - 3) / 2;
- while ( i < n_boxes )
- {
-
- rows = stdscr->_maxy - i * 2;
- columns = stdscr->_maxx - i * 6;
- brow = stdscr->_begy + i;
- bcolumn = stdscr->_begx + i * 3;
- if ( !rows || !columns )
- {
- n_boxes = i;
- break;
- }
-
- w[i] = newwin( rows, columns, brow, bcolumn );
-
- if ( w[i] )
- {
- if ( i )
- im[i - 1] = save_image( w[i], NULL );
- if ( ttymode == COLOR )
- wattrset( w[i], ((i + 1) << 8) & 0x0F00 );
- box( w[i], VS_LINE, HS_LINE );
- wpopdown( w[i++] );
- } else {
- n_boxes = i;
- break;
- }
- }
- if ( slow )
- sleep( 2.0 );
- for ( i = n_boxes - 1 ; w[i]->_maxx < 46 ; )
- {
- wrefresh( im[--i] );
- if ( slow )
- sleep( 0.1 );
- }
-
- j = i;
- i++;
- while ( (ttymode == COLOR) && i-- )
- {
- wchng_text_color( curscr, ((i + 1) << 8), A_FG_D_GREY );
- wrefresh( curscr );
- }
-
- wattrset( w[j], (ttymode == COLOR) ? A_FG_BLUE : A_BOLD );
- box( w[j], VS_LINE, HD_LINE );
- wpullover( w[j] );
- /*
- * Show the credits...
- */
- title = subwin( w[j], w[j]->_maxy - 2, w[j]->_maxx - 4,
- w[j]->_begy + 1, w[j]->_begx + 2 );
- if ( title )
- {
- scrollok( title, TRUE );
- if ( ttymode == COLOR )
- wattrset( title, A_FG_MAGENTA );
- werase( title );
- center_on_bottom( title, "The" );
- center_on_bottom( title, "Cygnus Development Group" );
- center_on_bottom( title, "Presents" );
- center_on_bottom( title, "" );
- wattron( title, A_BOLD );
- center_on_bottom( title, "CURSES" );
- wattroff( title, A_BOLD );
- center_on_bottom( title, "UNIX-compatible Windowing Software" );
- center_on_bottom( title, "" );
- delwin( title );
- }
- if ( slow )
- sleep( 6.0 );
-
- for ( i = n_boxes ; i-- ; )
- {
- delwin( w[i] );
- w[i] = NULL;
- }
- for ( i = n_boxes - 1 ; i-- ; )
- {
- delwin( im[i] );
- im[i] = NULL;
- }
- }
-
-
- /*----------------------------------------------------------------------
-
- show_support
-
- ----------------------------------------------------------------------*/
-
- int show_support()
- {
- /*
- * Display a window listing all of the supported adapters...
- */
-
- WINDOW *w;
-
-
- w = newwin( 3 * LINES / 4, 60, 3, 8 );
- wattrset( w, A_FG_L_BLUE | A_FG_BLACK );
- werase( w );
- mvwaddstr( w, 1, 2,
- "Curses AUTOMATICALLY supports a variety of video" );
- mvwaddstr( w, 2, 2, "adapters, including:" );
- mvwaddstr( w, 4, 2,
- "Monochrome Display Adapter Video-7 VEGA Deluxe" );
- mvwaddstr( w, 5, 2,
- "Color Graphics Adapter 25 lines x 80 columns" );
- mvwaddstr( w, 6, 2,
- "Enhanced Graphics Adapter 43 lines x 80 columns" );
- mvwaddstr( w, 7, 6,
- "25 lines x 80 columns 25 lines x 120 columns" );
- mvwaddstr( w, 8, 6,
- "43 lines x 80 columns 43 lines x 120 columns" );
- box( w, VS_LINE, HS_LINE );
- /*
- * Copy it onto the standard screen...
- */
- woverwrite( w, stdscr, w->_begy, w->_begx );
- delwin( w );
- }
-
-
- /*----------------------------------------------------------------------
-
- give_disclaimer
-
- ----------------------------------------------------------------------*/
-
- int give_disclaimer()
- {
- /*
- * Display another small window with a discussion of the
- * versatility of the library...
- */
-
- WINDOW *w;
-
-
- w = newwin( 7, 61, LINES - 9, COLS - 63 );
- wattron( w, A_FG_RED );
- werase( w );
- mvwaddstr( w, 1, 2,
- "With proper programming, applications can be built around" );
- mvwaddstr( w, 2, 2, "the " );
- wattron( w, A_BOLD );
- waddstr( w, "curses" );
- wattroff( w, A_BOLD );
- waddstr( w, " library, and transported with ease to a UNIX" );
- mvwaddstr( w, 3, 2, "environment. " );
- wattron( w, A_BOLD );
- waddstr( w, "Curses" );
- wattroff( w, A_BOLD );
- waddstr( w, " provides unparalleled opportunities" );
- mvwaddstr( w, 4, 2,
- "for the application developer, while supporting the " );
- mvwaddstr( w, 5, 2,
- "enhanced display abilities of the personal computer." );
- wattron( w, A_BOLD );
- box( w, VD_LINE, HD_LINE );
- wrefresh( w );
- delwin( w );
- }
-
-
- /*----------------------------------------------------------------------
-
- get_weird
-
- ----------------------------------------------------------------------*/
-
- #define N_SUB_WINS 3
-
- int get_weird()
- {
- /*
- * Put up a window with some text, then 'slide' (using the
- * XCurses function 'travel_window()') portions of this
- * window to other parts of the screen. This demonstrates that
- * the physical display of the window can be disjoint from it's
- * virtual representation. Note that all 4 displayed windows
- * show the same virtual window. All sub-windows need to be
- * touched each time they are updated, or the Curses system
- * thinks that the first update is all that is necessary.
- */
-
- int i, j, k;
- WINDOW *mw, *smw, *sw[N_SUB_WINS];
-
-
- if ( ttymode == COLOR )
- attron( A_BG_BLACK );
- else
- attroff( A_REVERSE );
- erase();
- pullover();
- if ( !(mw = newwin( 8, 46, 15, 25)) )
- return( 1 );
-
- wattrset( mw, (ttymode == COLOR)
- ? (A_FG_L_CYAN | A_BG_BLUE)
- : A_BOLD );
- werase( mw );
- box( mw, VS_LINE, HS_LINE );
- wpulldown( mw );
- smw = subwin( mw, mw->_maxy - 2, mw->_maxx - 4,
- mw->_begy + 1, mw->_begx + 2 );
- if ( smw )
- scrollok( smw, TRUE );
- wmove( smw, smw->_maxy - 1, 0 );
- werase( smw );
- waddstr( smw, "Through an extensive set of functions,\nCurses" );
- waddstr( smw, " provides ABSOLUTE control over\nthe display...\n" );
- wrefresh( smw );
-
-
- /*
- * Tell the user what is being demonstrated here...
- *
- Using subwindows, a given window can be segmented for easier
- management. This approach provides the ability to create
- fields or areas which have their own attributes, yet access
- the same virtual window. Writing to, and updating, a
- configured window is then a simple matter.
-
- With clever programming, subwindows can also provide some
- very interesting effects...
- */
- move( 0, 0 );
- addstr( "very interesting effects..." );
- refresh();
- move( 0, 0 );
- insertln();
- addstr( "With clever programming, subwindows can also provide some" );
- refresh();
- move( 0, 0 );
- insertln();
- refresh();
- move( 0, 0 );
- insertln();
- addstr( "configured window is then a simple matter." );
- refresh();
- move( 0, 0 );
- insertln();
- addstr( "the same virtual window. Writing to, and updating, a" );
- refresh();
- move( 0, 0 );
- insertln();
- addstr( "fields or areas which have their own attributes, yet access" );
- refresh();
- move( 0, 0 );
- insertln();
- addstr( "management. This approach provides the ability to create" );
- refresh();
- move( 0, 0 );
- insertln();
- addstr( "Using subwindows, a window can be segmented for easier" );
- refresh();
-
- if ( slow )
- sleep( 8.0 );
-
- for ( i = 0 ; i < N_SUB_WINS ; i++ )
- {
- sw[i] = subwin( mw, rand() % 5 + 3, rand() % 35 + 10,
- 15 + rand() % 4, 25 + rand() % 20 );
- if ( !sw[i] )
- {
- i--;
- continue;
- }
- travel_window( sw[i], rand() % (LINES - sw[i]->_begy),
- rand() % (COLS - sw[i]->_maxx) );
- }
- if ( slow )
- sleep( 4.0 );
-
- wattroff( smw, A_BOLD );
- for ( j = 0 ; j < 255 ; j += k )
- {
- for ( k = 0 ; k < 40 ; k++ )
- {
- wputch( smw, j + k );
- for ( i = 0 ; i < N_SUB_WINS ; )
- {
- touchwin( sw[i] );
- wrefresh( sw[i++] );
- }
- touchwin( smw );
- wrefresh( smw );
- if ( slow )
- sleep( 0.1 );
- }
- waddch( smw, '\n' );
- }
-
- for ( i = 0 ; i < N_SUB_WINS ; delwin( sw[i++]) );
- delwin( smw );
- delwin( mw );
- if ( slow )
- sleep( 3.0 );
- }
-
-
- /*----------------------------------------------------------------------
-
- get_image_of_curscr
-
- ----------------------------------------------------------------------*/
-
- int hr, hc;
-
- int get_image_of_curscr( win, r, c)
- WINDOW *win;
- int r, c;
- {
- static WINDOW *w = NULL;
-
- mvwin( win, r, c );
- w = wsave_image( curscr, win, w );
- mvwin( w, hr, hc );
- wrefresh( w );
- if ( slow )
- sleep( 0.06 );
- }
-
-
- /*----------------------------------------------------------------------
-
- show_window_on_curscr
-
- ----------------------------------------------------------------------*/
-
- int show_window_on_curscr()
- {
- /*
- * Create a (small) window, through which we will view
- * areas of the current screen. Repeatedly, an area the size
- * of our little window is copied from curscr, and displayed
- * in our window. The upper left corner of this area is move
- * from lower right to lower left to upper left, and diagonally
- * back to lower right. Note that some recursion is a result
- * of trying to view the window which contains the view.
- */
- int r = 8, c = 30;
- WINDOW *area, *w = NULL;
-
- hr = LINES - (r + 2);
- hc = COLS - (c + 4);
- area = newwin( r, c, hr, hc );
- w = newwin( area->_maxy + 2, area->_maxx + 2,
- area->_begy - 1, area->_begx - 1 );
- wattrset( w, (ttymode == COLOR)
- ? (A_FG_WHITE | A_BG_BLACK)
- : A_BOLD );
- box( w, VD_LINE, HD_LINE );
- wweave( w );
- delwin( w );
-
- for ( c = area->_begx ; c > 5 ; c-- )
- get_image_of_curscr( area, area->_begy, c );
-
- for ( r = area->_begy ; r > 0 ; r-- )
- get_image_of_curscr( area, r, area->_begx );
-
- for ( r = area->_begy, c = area->_begx ;
- (r < hr - 2) && (c < hc) ; r++, c++ )
- get_image_of_curscr( area, r, c );
-
- for ( c = area->_begx ; c <= hc ; c++ )
- get_image_of_curscr( area, area->_begy, c );
-
- for ( r = area->_begy ; r <= hr ; r++ )
- get_image_of_curscr( area, r, area->_begx );
-
- delwin( area );
- if ( slow )
- sleep( 1.0 );
- }
-
-
- /*----------------------------------------------------------------------
-
- instructions
-
- ----------------------------------------------------------------------*/
-
- int instructions()
- {
- /*
- * Type, to standard error, a small set of instructions on
- * how to get the usage message.
- */
- fprintf( stderr,
- "\n\tThis demonstration program can be run on both color\n" );
- fprintf( stderr,
- "\tand monochrome displays, and on certain adapters that\n" );
- fprintf( stderr,
- "\tsupport more than 80 columns and/or 25 lines. To\n" );
- fprintf( stderr,
- "\tdetermine the command switches, type:\n\n" );
- fprintf( stderr,
- "\t\t%s --\n\n", strupr( Iam) );
- fprintf( stderr,
- "\tat the DOS prompt. Then use the options shown in the\n" );
- fprintf( stderr,
- "\t'usage' message.\n\n" );
- fprintf( stderr,
- "(Type CONTROL-BREAK now to halt this program)\n\n" );
- if ( slow )
- sleep( 10.0 );
- kbhit();
- }
-
-
- /*----------------------------------------------------------------------
-
- do_curid_intro
-
- ----------------------------------------------------------------------*/
-
- int do_curid_intro()
- {
- /*
- * A medium-sized, brown window for getting the user's name
- * and illustrating string input.
- */
- WINDOW *wch;
-
- wch = newwin( 10, 55, 1, 24 );
- if ( wch )
- {
- wnl( wch );
- wecho( wch );
- scrollok( wch, TRUE );
- leaveok( wch, FALSE );
- }
- wattrset( wch, (ttymode == COLOR)
- ? (A_FG_BLACK | A_BG_BROWN)
- : A_REVERSE );
- werase( wch );
- wmove( wch, wch->_maxy - 1, 0 );
- wpullover( wch );
-
- wprintw( wch, "Curses Interactive Demonstration\n" );
- wprintw( wch, "(C)1987 Cygnus Development Group\n" );
- wprintw( wch, "\nWelcome to CurID!\n" );
- wprintw( wch, "\nEnter your name, please: " );
- wrefresh( wch );
-
- /*
- * Turn the cursor on while doing string input.
- */
- cursor_on();
- wgetstr( wch, line );
- cursor_off();
-
- werase( wch );
- waddstr( wch,
- "Now, watch the 'Keyboard Status' window while pressing\n" );
- waddstr( wch,
- "and releasing the shift keys, the 'num-lock', 'scroll-\n" );
- waddstr( wch, "lock', or 'caps-lock' keys. Notice that the clock\n" );
- waddstr( wch, "continuously runs. " );
- wstandout( wch );
- waddstr( wch, " Curses " );
- wstandend( wch );
- waddstr( wch, " always knows what keys\n" );
- waddstr( wch, "on the keyboard are being pressed." );
- wrefresh( wch );
-
- if ( slow )
- sleep( 15.0 );
- delwin( wch );
- }
-
-
- /*----------------------------------------------------------------------
-
- closing_sequence
-
- ----------------------------------------------------------------------*/
-
- int closing_sequence( border, win)
- WINDOW *border, *win;
- {
- /*
- * Scroll a magenta screen down, and scroll a message about
- * how this demo was created.
- */
-
- WINDOW *wch;
-
-
- attrset( (ttymode == COLOR)
- ? (A_FG_YELLOW | A_BG_MAGENTA)
- : A_BOLD );
- erase();
- box( stdscr, VD_LINE, HS_LINE );
-
- if ( ttymode == COLOR )
- wattrset( border, A_FG_BLUE | A_BG_L_GREY );
- werase( border );
- box( border, VS_LINE, HS_LINE );
- if ( ttymode == COLOR )
- wattrset( win, A_FG_BLUE | A_BG_L_GREY );
- werase( win );
- mvwin( border, 5, (COLS - border->_maxx) / 2 );
- mvwin( win, border->_begy + 1, border->_begx + 2 );
- woverwrite( border, stdscr, border->_begy, border->_begx );
- popdown();
- center_on_bottom( win,
- "This demonstration was produced entirely with" );
- wstandout( win );
- center_on_bottom( win, " CDG Curses, and CDG XCurses, " );
- wstandend( win );
- center_on_bottom( win, "extensions to the Curses library, using the" );
- center_on_bottom( win, "Microsoft C Compiler, V4.0, compact model." );
- if ( slow )
- sleep( 8.0 );
-
- if ( wch = newwin( 10, 55, LINES - 12, 5) )
- {
- wnl( wch );
- wecho( wch );
- leaveok( wch, FALSE );
- }
- wattrset( wch, (ttymode == COLOR)
- ? (A_FG_L_CYAN | A_BG_MAGENTA)
- : A_BOLD );
- werase( wch );
- box( wch, VS_LINE, HD_LINE );
- mvwaddstr( wch, 1, 2, "For more information on Curses," );
- mvwaddstr( wch, 2, 2, "and other operating-system independant" );
- mvwaddstr( wch, 3, 2, "software, contact:" );
- wattron( wch, (ttymode == COLOR) ? A_FG_WHITE : A_REVERSE );
- mvwaddstr( wch, 5, 2, " Cygnus Development Group " );
- mvwaddstr( wch, 6, 2, " Dept. DC " );
- mvwaddstr( wch, 7, 2, " 13000 Roma N.E. " );
- mvwaddstr( wch, 8, 2, " Albuquerque, New Mexico 87123 " );
- wexplode( wch );
-
- delwin( wch );
- }
-