home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / progjour / 1991 / 04 / viewport.c < prev    next >
C/C++ Source or Header  |  1991-05-03  |  3KB  |  110 lines

  1. /*    Routine- Test */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <tools/viewport.h>
  7.  
  8. char    *get_prompt( char *str, viewport *prompt )
  9. {
  10.     int c;
  11.     char *startstr = str;
  12.     v_clear  ( prompt );
  13.     v_gotorc ( prompt, 0, 0 );
  14.     while( (c = getch()) != '\r' )
  15.     {
  16.         *str ++ = c;
  17.         v_putc( prompt, c, 1 );
  18.     }
  19.     *str = '\0';
  20.     return startstr;
  21. }
  22.  
  23. int main()
  24. {
  25.     static int c;
  26.     static char buf[256];
  27.     static viewport v, prompt;
  28.  
  29.  
  30.     v_startup( C4350 );
  31.  
  32.     v_construct  ( &v );
  33.     v_saveok     ( &v, 1 );
  34.     v_clearok    ( &v, 1 );
  35.     v_size       ( &v, 10, 10 );
  36.     v_foreground ( &v, CYAN );
  37.     v_background ( &v, RED  );
  38.  
  39.     v_open      ( &v );
  40.  
  41.     getch(); v_move    ( &v,  5, 5 );   // move to (5,5)
  42.     getch(); v_move_rel( &v,  0, 1);    // left
  43.     getch(); v_move_rel( &v,  1, 0);    // up
  44.     getch(); v_move_rel( &v,  0, -1);   // right
  45.     getch(); v_move_rel( &v, -1, 0);    // down
  46.     getch(); v_move( &v, 100, 100 );    // lower-right corner
  47.  
  48.     getch(); v_gotorc   (&v, 1,   2 );  // Write a few characters
  49.              v_putc     (&v, '1', 0 );
  50.     getch();
  51.     c =      v_getc     (&v);           // and read them
  52.              v_puts     (&v, "got " ); // overwrite with message
  53.              v_putc     (&v, c,   0 );
  54.  
  55.     getch(); v_gotorc   (&v, 100, 100 ); // (deliberately large)
  56.              v_putc     (&v, '2', 1   );
  57.  
  58.     getch(); v_gotorc   (&v, 0, 0 );
  59.              v_puts     (&v, "This.is.a.longish.string" );
  60.  
  61.     getch();            // Test scrolling:
  62.  
  63.     v_move  ( &v, 0, 0 );
  64.     v_gotorc( &v, 0, 0 ); v_puts(&v, "+--------+");
  65.     v_gotorc( &v, 1, 0 ); v_puts(&v, "|23456789|");
  66.     v_gotorc( &v, 2, 0 ); v_puts(&v, "|23456789|");
  67.     v_gotorc( &v, 3, 0 ); v_puts(&v, "|23456789|");
  68.     v_gotorc( &v, 4, 0 ); v_puts(&v, "|23456789|");
  69.     v_gotorc( &v, 5, 0 ); v_puts(&v, "|23456789|");
  70.     v_gotorc( &v, 6, 0 ); v_puts(&v, "|23456789|");
  71.     v_gotorc( &v, 7, 0 ); v_puts(&v, "|23456789|");
  72.     v_gotorc( &v, 8, 0 ); v_puts(&v, "|23456789|");
  73.     v_gotorc( &v, 9, 0 ); v_puts(&v, "+--------+");
  74.  
  75.     getch(); v_scroll_region( &v,  0,  1, 1, 1, 8, 8 ); // left
  76.     getch(); v_scroll_region( &v,  1,  0, 1, 1, 8, 8 ); // up
  77.     getch(); v_scroll_region( &v,  0, -1, 1, 1, 8, 8 ); // down
  78.     getch(); v_scroll_region( &v,  -1, 0, 1, 1, 8, 8 ); // right
  79.     getch(); v_scroll       ( &v,  0,  1 );             // left
  80.     getch(); v_scroll       ( &v,  1,  0 );             // up
  81.     getch(); v_scroll       ( &v,  0, -1 );             // down
  82.     getch(); v_scroll       ( &v,  -1, 0 );             // right
  83.     getch();
  84.  
  85.     v_close     ( &v );
  86.     v_destroy   ( &v );
  87.  
  88.     v_construct (&v);                   // Test prompt line
  89.     v_construct (&prompt);
  90.     v_saveok     ( &v, 1 );
  91.     v_clearok    ( &v, 1 );
  92.     v_size       ( &v, 20, 20 );
  93.     v_foreground ( &v, RED  );
  94.     v_background ( &v, CYAN );
  95.     v_open       ( &v );
  96.  
  97.     v_clearok    ( &prompt, 1 );
  98.     v_size       ( &prompt, 1, 80 );
  99.     v_move       ( &prompt, 40, 0 );
  100.     v_open       ( &prompt );
  101.  
  102.     while( *get_prompt( buf, &prompt ) )
  103.         ;
  104.  
  105.     v_destroy(&v);
  106.     v_destroy(&prompt);
  107.  
  108.     return 0;
  109. }
  110.