home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c329 / 2.img / EXAMPLES / TEXTWIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-21  |  7.0 KB  |  251 lines

  1. /*             Alpha-mode GREX function demonstration                   *\
  2.  *                                                                      *
  3.  *       Copyright (c) 1989 by MicroWay, Inc. All rights reserved.      *
  4. \*                                                                      */
  5.  
  6. #include <stdio.h>
  7. #include <grex.h>
  8.  
  9. char * malloc ();
  10.  
  11. #define up_arrow    -72
  12. #define down_arrow  -80
  13. #define left_arrow  -75
  14. #define right_arrow -77
  15. #define Home_key    -71
  16. #define End_key     -79
  17. #define PgUp_key    -73
  18. #define PgDn_key    -81
  19. #define Ins_key     -82
  20. #define Del_key     -83
  21.  
  22. main()
  23. {
  24.     int i,j,k,n;
  25.     int ix,iy,jx,jy;
  26.     int key;
  27.     char * background, * window;
  28.     int mode, max_row, max_column;
  29.  
  30.     /* The data to be scrolled consist, logically enough, of MicroWay *\
  31.     \* product names.                                                 */
  32.  
  33.     static char words [20][20] =
  34.     {
  35.         "NDP Fortran-386","NDP C-386","NDP Pascal-386","Monoputer",
  36.         "Quadputer","Videoputer","flickerFixer","SuperCache-286",
  37.         "287 TurboPlus","386/387 Turbo-AT","Number Smasher/ECM",
  38.         "87BASIC/INLINE","mW1167 (Weitek)","DCACHE V2.2","DOPTIMIZER",
  39.         "MATRIXPAK","OBJ-ASM V3.0","NDP/FFT-386","NDP Hoops","MicroWay Prolog"
  40.     };
  41.  
  42.     /* To try out the 43/50 line mode, activate the following lines */
  43.  
  44.     /* printf ("set43line() returns %d\n",set43line());     *\
  45.     \* pause();                                             */
  46.  
  47.     mode = get_video_mode ( &max_row, &max_column );
  48.     cls();
  49.     home();
  50.     printf("Video mode %d has %d rows, %d columns\n", mode, max_row, max_column);
  51.     pause();
  52.  
  53.     for (j=0; j <= max_row; j++)
  54.     {
  55.         for (i=0; i <= max_column; i++)
  56.         {
  57.             locate (i,j);
  58.             write_char_attr (i,1,i+1);
  59.         }
  60.     }
  61.     pause();
  62.  
  63.     background = malloc (512);
  64.     window = malloc (512);
  65.  
  66.     ix = 9;
  67.     iy = 5;
  68.     jx = 30;
  69.     jy = 11;
  70.  
  71.     n = save_text_window (ix,iy,jx,jy,background);
  72.  
  73.     place_string_at ( ix, iy+0, "┌───── MicroWay ─────┐");
  74.     place_string_at ( ix, iy+1, "│                    │");
  75.     place_string_at ( ix, iy+2, "│                    │");
  76.     place_string_at ( ix, iy+3, "│                    │");
  77.     place_string_at ( ix, iy+4, "│                    │");
  78.     place_string_at ( ix, iy+5, "│                    │");
  79.     place_string_at ( ix, iy+6, "└────────────────────┘");
  80.  
  81.     place_string_at ( ix+1, iy+1, words[0]);
  82.     place_string_at ( ix+1, iy+2, words[1]);
  83.     place_string_at ( ix+1, iy+3, words[2]);
  84.     place_string_at ( ix+1, iy+4, words[3]);
  85.     place_string_at ( ix+1, iy+5, words[4]);
  86.  
  87.     j = 0;
  88.     k = jy - iy - 2;
  89.  
  90.     while ( ( (key = pause()) != 13)
  91.            && (key            != 10)
  92.            && (key            != 27) )
  93.     {
  94.          if (key == up_arrow)
  95.          {
  96.              k--;
  97.              j--;
  98.              if (j >= 0 )
  99.              {
  100.                  scroll_active_page_down (ix+1, iy+1, jx-1, jy-1, 1, 7);
  101.                  place_string_at (ix+1, iy+1, words [j] );
  102.              }
  103.              if (j < 0)
  104.              {
  105.                  beep();
  106.                  j = 0;
  107.                  k++;
  108.              }
  109.          }
  110.          if (key == down_arrow)
  111.          {
  112.              j++;
  113.              k++;
  114.              if (k < 20)
  115.              {
  116.                  scroll_active_page_up (ix+1, iy+1, jx-1, jy-1, 1, 7);
  117.                  place_string_at (ix+1, jy-1, words [k] );
  118.              }
  119.              if (k > 20)
  120.              {
  121.                  beep();
  122.                  k = 20;
  123.                  j--;
  124.              }
  125.          }
  126.          if (key == left_arrow)
  127.          {
  128.             if (ix > 0)
  129.             {
  130.                 save_text_window (ix,iy,jx,jy,window);
  131.                 restore_text_window (ix,iy,background);
  132.                 ix--;
  133.                 jx--;
  134.                 save_text_window (ix,iy,jx,jy,background);
  135.                 restore_text_window (ix,iy,window);
  136.             }
  137.             else
  138.             {
  139.                 beep();
  140.             }
  141.          }
  142.          if (key == right_arrow)
  143.          {
  144.             if (jx < max_column)
  145.             {
  146.                 save_text_window (ix,iy,jx,jy,window);
  147.                 restore_text_window (ix,iy,background);
  148.                 ix++;
  149.                 jx++;
  150.                 save_text_window (ix,iy,jx,jy,background);
  151.                 restore_text_window (ix,iy,window);
  152.             }
  153.             else
  154.             {
  155.                 beep();
  156.             }
  157.          }
  158.          if (key == Home_key)
  159.          {
  160.             if (ix > 0 && iy > 0)
  161.             {
  162.                 save_text_window (ix,iy,jx,jy,window);
  163.                 restore_text_window (ix,iy,background);
  164.                 ix--;
  165.                 iy--;
  166.                 jx--;
  167.                 jy--;
  168.                 save_text_window (ix,iy,jx,jy,background);
  169.                 restore_text_window (ix,iy,window);
  170.             }
  171.             else
  172.             {
  173.                 beep();
  174.             }
  175.          }
  176.          if (key == End_key)
  177.          {
  178.             if (ix > 0 && jy < max_row)
  179.             {
  180.                 save_text_window (ix,iy,jx,jy,window);
  181.                 restore_text_window (ix,iy,background);
  182.                 ix--;
  183.                 iy++;
  184.                 jx--;
  185.                 jy++;
  186.                 save_text_window (ix,iy,jx,jy,background);
  187.                 restore_text_window (ix,iy,window);
  188.             }
  189.             else
  190.             {
  191.                 beep();
  192.             }
  193.          }
  194.          if (key == PgUp_key)
  195.          {
  196.             if (jx < max_column && iy > 0)
  197.             {
  198.                 save_text_window (ix,iy,jx,jy,window);
  199.                 restore_text_window (ix,iy,background);
  200.                 ix++;
  201.                 iy--;
  202.                 jx++;
  203.                 jy--;
  204.                 save_text_window (ix,iy,jx,jy,background);
  205.                 restore_text_window (ix,iy,window);
  206.             }
  207.             else
  208.             {
  209.                 beep();
  210.             }
  211.          }
  212.          if (key == PgDn_key)
  213.          {
  214.             if (jx < max_column && jy < max_row)
  215.             {
  216.                 save_text_window (ix,iy,jx,jy,window);
  217.                 restore_text_window (ix,iy,background);
  218.                 ix++;
  219.                 iy++;
  220.                 jx++;
  221.                 jy++;
  222.                 save_text_window (ix,iy,jx,jy,background);
  223.                 restore_text_window (ix,iy,window);
  224.             }
  225.             else
  226.             {
  227.                 beep();
  228.             }
  229.          }
  230.          if (key == Ins_key)
  231.          {
  232.             set25line();
  233.             pause();
  234.             set43line();
  235.          }
  236.     }
  237.  
  238.     restore_text_window (ix,iy,background);
  239.     free (background);
  240.     free (window);
  241.  
  242.     home();
  243.     /* If you activated set43line(), you may reset to 25 lines using
  244.        the following:
  245.        printf ("set25line() returns %d\n",set25line());
  246.      */
  247.  
  248.     pause();
  249.     cls();
  250. }
  251.