home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / turbo_c / mcwint20.arc / QDEMO20.C < prev    next >
Text File  |  1988-01-11  |  12KB  |  335 lines

  1. #define USE_LOCAL
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <dos.h>
  7. #include <conio.h>
  8. #include <w1.h>
  9. #include <windprot.h>
  10. #include <color.h>
  11.  
  12. #define WAIT 15000
  13. /*===============================================================================*/
  14. /*  Qdemo20.c - Demonstration program for Qwik write utilities  ver 2.0, 1-1-88      */
  15. /*  Demo has been programmed for All Cards and any column mode.  If you want to  */
  16. /*  try 40 column mode, set crtcolumns to 40 in main. This does not set your     */
  17. /*  machine to 40 column mode. This must be done by the DOS mode command.        */
  18. /*                                                                               */
  19. /* AUTHORS: Turbo Pascal version -- (C) 86,87 Jim H. Lemay                       */
  20. /*          Turbo C version -- (C) 1987,1988 Mike Mlachak                             */
  21. /*          Microsoft version -- (C) 1987,1988 Mike Mlachak
  22. /* DATE:    6-1-87                                                               */
  23. /* VERSION: 2.0                                                                  */
  24. /* REVISIONS: Modified source to use new function 2.0 calls 1-1-88
  25. /* COMMENTS: Must be compiled in SMALL model and linked with T1xwin20.lib          */
  26. /*===============================================================================*/
  27.  
  28. typedef char str80[80];
  29.  
  30.     int          row, rows, col, cols, ctr, step, rstep, colmax, count,
  31.                  attrib, i, j, crtcols;
  32.     int          hidecursor, oldcursor, fgrnd, bgrnd;
  33.     int          brdrattr, wndwattr;
  34.     char         savedblock[4000], popupblock[4000];
  35.     int          blkrow, blkcol;
  36.     int          crtcolumns;               /*  number of CRT columns  */
  37.     int          tattr;
  38.     int          coll[3], colr[3];
  39.     char         strng[75], numstr[75];
  40.     double       rnum;
  41.  
  42.     int random(int);
  43.  
  44.  
  45.    static str80 data[9] = {
  46.        "1",
  47.        "22",
  48.        "333",
  49.        "Qwik-Write Utilities",
  50.        "Odd  Length",
  51.        "Even  Length",
  52.        "18 characters wide",
  53.        "19 characters width",
  54.        "Margin to Margin width"};
  55.  
  56. static str80 vers = "Qwik-Write Utilities (Version 2.0)";
  57. void main(void)
  58. {
  59. /*  --- Set up data ---  */
  60.   qinit(); /*  << <<  Required intializing statement !!  */
  61.   crtcolumns = 80;
  62.   crtcols = crtcolumns;
  63.   hidecursor = 8192;
  64.  
  65. /*  --- Initial screen ---  */
  66.   oldcursor = cursorchange(hidecursor);
  67.   qfill(1, 1, 25, crtcols, (BLUE << 4) + WHITE, ' '); /*   Clear Screen  */
  68.   qwritec(11, 1, crtcols, (BLUE << 4) + YELLOW, vers);
  69.   qwritec(13, 1, crtcols, -1, "Your screen is about to explode.");
  70.   qwritec(14, 1, crtcols, -1, "Hold on to your seat ...");
  71.   wsleep(6*18);
  72.  
  73. /*  --- Explosion of Boxes ---  */
  74.   qfill(11, 1, 4, crtcols, -1, ' '); /*   Clear Lines  */
  75.   qattr(1, 1, 25, crtcols, LIGHTGRAY << 4); /*   Change screen attribute  */
  76.   ctr = crtcols / 2;
  77.   for (step = 2; step <= ctr - 2; step++) {
  78.      if (step > 24)
  79.         rstep = 12;
  80.      else
  81.         rstep = step >> 1;
  82.      for (count = 1; count <= 20; count++) {
  83.         row = 13 - rstep + random(rstep + 2);
  84.         rows = rstep;
  85.         cols = rstep + rstep + (rstep >> 2);
  86.         if (step <= 24)
  87.            col = ctr - cols + random(cols + 1);
  88.         else
  89.            col = ctr - 1 - step + random(step + step - 22);
  90.       fgrnd = random(16);
  91.       bgrnd = random(8);
  92.       if (bgrnd == fgrnd)
  93.          fgrnd = fgrnd + 1;
  94.       attrib = (bgrnd << 4) + fgrnd;
  95.       qfill(row,col,row,cols,attrib,'▓');
  96.     }  /* for count = 1*/
  97.   } /* for step = 2,..etc */
  98.  
  99.   qfillc(10, 1, crtcols, 6, 34, RED << 4, ' ');
  100.   qfillc(11, 1, crtcols, 4, 30, BROWN << 4, ' ');
  101.   tattr = (RED << 4) + YELLOW;
  102.   qwritec(12, 1, crtcols, tattr, vers);
  103.   qwritec(13, 1, crtcols, tattr, "Turbo-C (1.0)");
  104.  
  105.   /*  --- Save Screen for Page Demo ---  */
  106.   if (maxpage > 0)
  107.   {
  108.     qstore(1, 1, 25, crtcols, savedblock);
  109.     qwritepage(1);
  110.     qrestore(1, 1, 25, crtcols, savedblock);
  111.     qwritepage(0);
  112.   }
  113.   /*  --- End of Save Screen ---  */
  114.   wsleep(4*18);
  115.   tattr = (BLUE << 4) + WHITE;
  116.   qwritec(6, 1, crtcols, tattr, " qwrite will write with new attributes ");
  117.   qwritec(7, 1, crtcols, tattr, " that you specify direct to the screen.");
  118.   wsleep(5*18);
  119.   qwritec(18, 1, crtcols, -1, " qwrite will also use existing attributes ");
  120.   qwritec(19, 1, crtcols, -1, "    when you do not even know or care.    ");
  121.                         /*  highlight the word 'existing'  */
  122.   qattrc(18, 6, crtcols + 5, 1, 10, (LIGHTRED << 4) + WHITE);
  123.   wsleep(6*18);
  124.   qwritec(21, 1, crtcols, tattr, " Say Goodbye to this screen. ");
  125.   wsleep(4*18);
  126.   /*  --- Disintigrate Screen ---  */
  127.  
  128.   for (i = 1; i <=7500; i++) {
  129.     row = random(25) +1;
  130.     col = random(crtcols) + 1;
  131.     qfill(row,col,1,1,BLACK, ' ');
  132.   }
  133.  
  134. /*  --- Qwrite with Reals Demo ---  */
  135.   qfill(1, 1, 25, crtcols, YELLOW, ' '); /*   Clear Screen  */
  136.   qwritec(2, 1, crtcols, -1, "qwrite with TURBO-C's sprintf will write");
  137.   qwritec(3, 1, crtcols, -1, "reals and integers faster:");
  138.   wsleep(6*18);
  139.   rnum = 1.2345678901;
  140.   for (col = 0; col <= (crtcols / 20) - 1; col++)  {
  141.      for (row = 5; row <= 24; row++) {
  142.         rnum = rnum + 20.0;
  143.         sprintf(numstr,"%e",rnum);
  144.         qwrite(row, col * 20 + 4, -1, numstr);
  145.      }
  146.   }
  147.   wsleep(7*18);
  148.  
  149. /*  --- Centering Demo ---  */
  150.   qfill(1, 1, 25, crtcols, LIGHTGRAY << 4, ' '); /*   Clear Screen  */
  151.   qwritec(2, 1, crtcols, -1, "qwritec  will automatically");
  152.   qwritec(3, 1, crtcols, -1, "center your data ...");
  153.   qwritec(4, 1, crtcols, -1, "(ODD breaks are shifted to the left.)");
  154.   wsleep(6*18);
  155.  
  156.   /*  - Set up columns for varying column modes -  */
  157.   coll[1] = 1;
  158.   colr[1] = crtcols;
  159.   if (crtcols < 80) {
  160.      coll[0] = coll[1];
  161.      coll[2] = crtcols / 2;
  162.      colr[0] = colr[1];
  163.      colr[2] = crtcols / 2;
  164.   }
  165.   else {
  166.      coll[0] = 3;
  167.      colr[0] = 26;
  168.      coll[2] = crtcols - 14;
  169.      colr[2] = crtcols - 14;
  170.   }
  171.  
  172.   qwritec(7, coll[0], colr[0], -1, "between margins ...");
  173.   qbox(8, (coll[0] + (colr[0] >> 1)) - 14, 15, 26, WHITE, LIGHTGRAY, doublebrdr);
  174.   wsleep(4*18);
  175.   for (row = 11; row <= 19; row++)
  176.      qwritec(row, coll[0], colr[0], -1, data[row - 11]);
  177.   wsleep(4*18);
  178.  
  179.   qwritec(7, coll[1], colr[1], -1, "between two columns ...");
  180.   qfillc(9, coll[1], colr[1], 13, 24, YELLOW, ' '); /*   Clear window  */
  181.   for (row = 9; row <= 21; row++)
  182.      qwritec(row, coll[1], colr[1], -1, "><"); /*   Show two columns   */
  183.   wsleep(4*18);
  184.   for (row = 11; row <= 19; row++)
  185.      qwritec(row, coll[1], colr[1], LIGHTRED, data[row - 11]);
  186.   wsleep(4*18);
  187.  
  188.   qwritec(7, coll[2], colr[2], -1, "or on a center line ...");
  189.   qfillc(8, coll[2], colr[2], 15, 27, LIGHTGRAY << 4, ' '); /*   Clear window  */
  190.   for (row = 9; row <= 21; row++) /*   Show center line   */
  191.      qwritec(row, coll[2], colr[2], (LIGHTGRAY << 4) + WHITE, "|");
  192.   wsleep(4*18);
  193.   for (row = 11; row <= 19; row++)
  194.      qwritec(row, coll[2], colr[2], -1, data[row - 11]);
  195.   wsleep(7*18);
  196.  
  197. /*  --- Qfill Demo ---  */
  198.   qfill(1, 1, 25, crtcols, WHITE, ' '); /*   Clear Screen  */
  199.   qwritec(2, 1, crtcols, -1, "qfill as well as qattr can fill");
  200.   qwritec(3, 1, crtcols, -1, "your screen in several ways.");
  201.   wsleep(5*18);
  202.  
  203.   qwritec(7, 1, crtcols, -1, "by rows ...");
  204.   wsleep(4*18);
  205.   for (row = 9; row <= 24; row++)
  206.      qfill(row, 2, 1, crtcols - 2, 9 + row, (char)(row + 56));
  207.   wsleep(5*18);
  208.  
  209.   qfill(7, 1, 19, crtcols, WHITE, ' '); /*   Clear Lines  */
  210.   qwritec(7, 1, crtcols, -1, "by columns ...");
  211.   wsleep(4*18);
  212.   for (col = 2; col <= crtcols - 2; col++)
  213.      qfill(9, col, 16, 1, 16 + col, (char)(col + 63));
  214.   wsleep(5*18);
  215.  
  216.   qfill(7, 1, 19, crtcols, WHITE, ' '); /*   Clear Lines  */
  217.   qwritec(7, 1, crtcols, -1, "or by row-by-column blocks ...");
  218.   wsleep(4*18);
  219.   qfill(9, 2, 16, crtcols - 2, (BLUE << 4) + YELLOW, '!');
  220.   wsleep(6*18);
  221.  
  222. /*  --- Qbox demo ---  */
  223.   qfill(1, 1, 25, crtcols, LIGHTGRAY << 4, ' '); /*   Clear Screen  */
  224.   qwritec(2, 1, crtcols, -1, "qbox is an application procedure made");
  225.   qwritec(3, 1, crtcols, -1, "from qwrite and qfill.  Together they");
  226.   qwritec(4, 1, crtcols, -1, "can make windows with borders easy.");
  227.   wsleep(5*18);
  228.   qwritec(14, 1, crtcols, -1, "How about 1000 of them? ... ");
  229.   wsleep(4*18);
  230.   colmax = crtcols - 21;
  231.   for (i = 1; i <= 1000; i++) {
  232.      row = random(10) + 6;
  233.      col = random(colmax) + 2;
  234.      brdrattr = random(128);
  235.      wndwattr = random(128);
  236.      qbox(row, col, 10, 20, brdrattr, wndwattr, doublebrdr);
  237.   }
  238.   wsleep(7*18);
  239.  
  240. /*  --- Block Transfer and PopUp Demo ---  */
  241.   qfill(1, 1, 25, crtcols, YELLOW, '?'); /*   Clear Screen  */
  242.   qfillc(10, 1, crtcols, 6, 40, BROWN << 4, ' '); /*   Clear Block  */
  243.   qwritec(11, 1, crtcols, -1, "qstore will save and restore");
  244.   qwritec(12, 1, crtcols, -1, "Row-by-Column blocks on your display.");
  245.   qwritec(13, 1, crtcols, -1, "It is so fast, I have to slow it down");
  246.   qwritec(14, 1, crtcols, -1, "so you can see it.");
  247.   wsleep(6*18);
  248.   blkrow = 8;
  249.   blkcol = (crtcols / 2) - 9;
  250.   qstore(blkrow, blkcol, 10, 20, savedblock);
  251.   /*  --- Make a Pop Up Menu ---  */
  252.   qbox(blkrow, blkcol, 10, 20, (BLUE << 4) + YELLOW, (BLUE << 4) + BROWN, doublebrdr);
  253.   qwritec(blkrow + 4, blkcol, blkcol + 20, -1, "Pop Up");
  254.   qwritec(blkrow + 5, blkcol, blkcol + 20, -1, "Menu");
  255.   /*  --- End of Pop Up Menu ---  */
  256.   qstore(blkrow, blkcol, 10, 20, popupblock);
  257.   wsleep(3*18);
  258.   colmax = crtcols - 20;
  259.   for (i = 1; i <= 30; i++) {
  260.     for (j = 0; j <=WAIT; j++);
  261.      qrestore(blkrow, blkcol, 10, 20, savedblock);
  262.      blkrow = random(15) + 1;
  263.      blkcol = random(colmax) + 1;
  264.      qstore(blkrow, blkcol, 10, 20, savedblock);
  265.      qrestore(blkrow, blkcol, 10, 20, popupblock);
  266.   }
  267.  
  268. /*  --- Page Demo ---  */
  269.   if (maxpage > 0) {
  270.      qpage(1);
  271.      qwritepage(1);
  272.      tattr = (BLUE << 4) + YELLOW;
  273.      qwritec(20, 1, crtcols, tattr, " Remember this page?  ");
  274.      qwritec(21, 1, crtcols, tattr, " It wasn't destroyed, but saved using ");
  275.      qwritec(22, 1, crtcols, tattr, " qstore/qrestore and placed on a new page. ");
  276.      wsleep(6*18);
  277.      qwritepage(0);
  278.      qpage(0);
  279.   }
  280.  
  281. /*  --- Attribute Demo ---  */
  282.   qfill(1, 1, 25, crtcols, (GREEN << 4) + GREEN, ' '); /*   Clear Screen  */
  283.   tattr = (GREEN << 4) + WHITE;
  284.   qwritec(2, 1, crtcols, tattr, "Qwik-Write Utilities is hiding strings on");
  285.   qwritec(3, 1, crtcols, tattr, "your screen ...");
  286.   cols = crtcols / 20;
  287.   if (qwait == 0)
  288.      tattr = 0;
  289.   else
  290.      tattr = (GREEN << 4) + GREEN;
  291.   for (col = 0; col <= cols - 1; col++)
  292.      for (row = 5; row <= 20; row++)
  293.         qwrite(row, 20 * col + 1, tattr, data[3]);
  294.   wsleep(3*18);
  295.  
  296.   qfill(2, 1, 2, crtcols, -1, ' '); /*   Clear Lines  */
  297.   tattr = (GREEN << 4) + BLACK;
  298.   qwritec(2, 1, crtcols, tattr, "qattr can show them -");
  299.   qwritec(3, 1, crtcols, tattr, "by merely changing the attribute!");
  300.   wsleep(5*18);
  301.  
  302.   /*  --- Try using Turbo's color procedures this time ---  */
  303.   qattr(5, 1, 16, crtcols, tattr); /*   Reveal Data  */
  304.   wsleep(3*18);
  305.  
  306.   qfill(2, 1, 2, crtcols, -1, ' '); /*   Clear Lines  */
  307.   qwritec(2, 1, crtcols, tattr, "Or even just emphasize what's seen ...");
  308.   for (i = 1; i <= 100; i++) {
  309.     row = random(16) + 5;
  310.     col = random(cols) * 20 + 1;
  311.     qattr(row, col, 1, 20, 46);
  312.     for (j=0; j<=WAIT-7500; j++);
  313.     qattr(row, col, 1, 20, 32);
  314.   }
  315.   for (i = 1; i <= cols; i++) /*   Emphasize Data  */
  316.     qattr(5 * i, (i - 1) * 20 + 1, 1, 20, (LIGHTGREEN << 4) + YELLOW);
  317.   tattr = wiattr(YELLOW,GREEN);
  318.   qwritec(22, 1, crtcols, tattr,
  319.            " TURBO-C Version (C) 1987,1988 Michael G. Mlachak & Brian L. Cassista");
  320.   gotorc(24, 1);
  321.   oldcursor = cursorchange(oldcursor);
  322. }
  323.  
  324. int random(seed)
  325. {
  326.   int hold;
  327.  
  328.      hold= rand();
  329.      if (hold > 127)
  330.        hold = hold % 127;
  331.      hold = hold % seed;
  332.    return(hold);
  333. }
  334.  
  335.