home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c003 / 1.ddi / DEMOS / DEM_CMOV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-01  |  11.5 KB  |  256 lines

  1. /*dem_cmov  -- demonstration of the capabilities of Windows for C to save
  2.            and move window images and to manage color displays.
  3.  
  4.     ************* Copyright 1985 by Vermont Creative Software **************
  5.  
  6. COMMENT
  7.  
  8. This program shows how the functions of Windows for C can be used to create
  9. motion in programs.  The ability to rapidly save, move, and restore images is
  10. important to all programs.  Because of this ability, screen displays change
  11. crisply when you use Windows for C.
  12.  
  13. This program was written using physical attributes.  It illustrates the steps
  14. necessary to use physical attributes within your program.  Note that our logical
  15. attribute system can accomplish the same end result much more simply, without
  16. requiring any conditional code in your programs.
  17.  
  18. Terminal based do not use colors in this demo.
  19.  
  20. */
  21.  
  22. /* #define WN_DEBUG            commented out when debugging completed*/
  23. #include <wfc.h>
  24. #undef ATT_LOGIC
  25. #include <wfc_glob.h>
  26.  
  27. #define BOXQ  4
  28.  
  29. #define SCR_UPDATE v_tv
  30.  
  31. char box_att[BOXQ] = {RED, GREEN, MAGENTA, YELLOW};
  32.  
  33. int row_delta[BOXQ] = {1, -1, 1, -1};    /*delta rows to move each box          */
  34. int col_delta[BOXQ] = {2, -3, 3, -1};    /*delta columns to move each box      */
  35.  
  36. /*----------------------------------------------------------------------------*/
  37. /*   character string contains message put to window on exit              */
  38. /*----------------------------------------------------------------------------*/
  39.  
  40. char *sign_off[] = {
  41.     "\n                          WINDOWS FOR C\n\n",
  42.     "  For more information contact Vermont Creative Software, (802) 848-7738."
  43.     };
  44.  
  45. main()
  46. {
  47.     WINDOW wn, msg_wn, box_wn[BOXQ];
  48.     int rw, co;
  49.     int brb, bcb;
  50.     register int j;
  51.     int key;
  52.     char ttv;
  53. #if MSDOS
  54.     int vmode;                /*current video mode              */
  55. #endif
  56.     char c_bgrnd;
  57.  
  58. /*----------------------------------------------------------------------------*/
  59. /*  Initialize the Windows for C System                       */
  60. /*----------------------------------------------------------------------------*/
  61.     init_wfc();
  62.  
  63.     cls();                /*clear the screen              */
  64.     csr_hide();             /*hide the cursor off screen          */
  65.  
  66.     ttv = tv_upd;
  67.     tv_upd = OFF;
  68.  
  69. /*----------------------------------------------------------------------------*/
  70. /*  Initialize a window                               */
  71. /*----------------------------------------------------------------------------*/
  72.     defs_wn(&wn, 0, 0, 20, 80, BDR_LNP);
  73.     sw_margin(3, 3, &wn);        /*set some margins              */
  74.  
  75. /*----------------------------------------------------------------------------*/
  76. /*define window for messages.  This will be just below first window          */
  77. /*----------------------------------------------------------------------------*/
  78.     def_wn(&msg_wn, wn.re + 1, wn.re + 4, wn.cb, wn.ce, 3, 3, &bdr_dln);
  79.     sw_att((NORMAL + HIGH_INT), &msg_wn);
  80.  
  81.  
  82.     set_wn(&wn);            /*set windows                  */
  83.     set_wn(&msg_wn);
  84.  
  85. /*----------------------------------------------------------------------------*/
  86. /*  Write text into window using v_st to insure all text written.  Use          */
  87. /*  ki() to pause at appropriate moment.                      */
  88. /*----------------------------------------------------------------------------*/
  89.     sw_att((NORMAL + HIGH_INT), &wn);           /*change attribute          */
  90.     v_plst(0, CENTER_TEXT, "WINDOWS FOR C COLOR AND MOVEMENT CAPABILITIES",&wn);
  91.     wn.r += 2;                /*skip 1 blank line              */
  92.     wn.c = 0;
  93.     sw_att(NORMAL, &wn);        /*change attribute back           */
  94.  
  95.     v_st("Windows for C makes moving windows easy.  Window images on the screen can be moved anywhere ",&wn);
  96.     v_st("on the screen by a simple function call.  The image is temporarily stored in user memory, erased from ",&wn);
  97.     v_st("the screen, and moved to a new location.  Memory management is automatic.\n\n",&wn);
  98.     v_st("Because the video functions of Windows for C use ASM direct memory addressing, ",&wn);
  99.     v_st("screen output is fast.  This Demonstration shows the speed with which ", &wn);
  100.     v_st("windows can be moved off and on the screen.\n\n", &wn);
  101.     v_st("This demonstration program moves 4 character-filled windows about the screen randomly.  ", &wn);
  102.     v_st("The windows could equally be filled with text or figures drawn with block-graphics ", &wn);
  103.     v_st("characters.  The store and overlay capabilities of Windows for C simplify and enhance ", &wn);
  104.     v_st("programs for business or play.", &wn);
  105.  
  106. /*----------------------------------------------------------------------------*/
  107. /* place message in message window                          */
  108. /*----------------------------------------------------------------------------*/
  109.     v_plst(0, CENTER_TEXT, "Press any key to proceed ", &msg_wn);
  110.  
  111.     if (ttv == ON)
  112.     SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
  113.  
  114.     ki();                /*provide pause               */
  115.  
  116. /*----------------------------------------------------------------------------*/
  117. /*  Clear window and write new information.  Use ki() to pause again.          */
  118. /*----------------------------------------------------------------------------*/
  119.     cl_wn(&wn);
  120.     sw_att((NORMAL + HIGH_INT), &wn);
  121.     v_plst(0, CENTER_TEXT, "COLOR CONTROL",&wn) ;
  122.     wn.r += 2;                /*skip some blank lines           */
  123.     wn.c = 0;
  124.     sw_att(NORMAL, &wn);
  125.     v_st("This demonstration program also illustrates the color-control capabilities of ",&wn);
  126.     v_st("of Windows for C.  Functions are provided to set the color of the screen border ",&wn);
  127.     v_st("and the foreground, background, and border colors of individual windows.\n\n", &wn);
  128.     v_st("For good legibility, this program uses different 'colors' for color and ", &wn);
  129.     v_st("non-color displays.\n\n", &wn);
  130.     v_st("If you have more than one monitor connected to your system, this program ", &wn);
  131.     v_st("allows you to switch to color within the demo.  It returns to the original ", &wn);
  132.     v_st("mode upon exit.\n\n", &wn);
  133.     v_st("Color management is made simple by Windows for C's use of C structures ", &wn);
  134.     v_st("to hold information required for window management.\n\n\n\n\n\n", &wn);
  135.     if (ttv == ON)
  136.     SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
  137.  
  138.     ki();                /*pause until user ready to proceed   */
  139.  
  140.     unset_wn(&wn);            /* get rid of text window          */
  141. /*----------------------------------------------------------------------------*/
  142. /* find out if viewer has a monitor that displays color               */
  143. /*----------------------------------------------------------------------------*/
  144.     cl_wn(&msg_wn);
  145.     sw_plcsr(ON, &msg_wn);        /*set cursor placement switch ON      */
  146.     v_st("Do you have a monitor that displays colors?  Please answer y or n: ",&msg_wn);
  147.  
  148.     if (ttv == ON)
  149.     SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
  150.  
  151.     while((key = ki()) != 'y' && key != 'n' && key != 'Y' && key != 'N')
  152.     bell();
  153.     sw_plcsr(OFF, &msg_wn);        /*turn cursor placement switch OFF    */
  154.     csr_hide();             /*hide cursor                  */
  155.  
  156. /*----------------------------------------------------------------------------*/
  157. /*  If color monitor, used colored background; otherwise use BLACK          */
  158. /*----------------------------------------------------------------------------*/
  159.     c_bgrnd = BLACK;
  160.     vmode = rd_mode();            /*store current video mode          */
  161.     if(key == 'y' || key == 'Y')
  162.     {
  163.     vid_mode(CO80);         /*set to color mode              */
  164.     c_bgrnd = BLUE;
  165.     color_sc(c_bgrnd);        /*blue background for screen clear    */
  166.     vid_bdr(LIGHT + BLUE);        /*screen border               */
  167.     color_wn(YELLOW, c_bgrnd, &wn);      /*colors for text window          */
  168.     color_wn(YELLOW, c_bgrnd, &msg_wn);  /*colors for message window      */
  169.     }
  170.     unset_wn(&msg_wn);            /*unset message window              */
  171.     cls();                /*clear screen with current background*/
  172.     mod_wn(v_rwq - 1, 0, 1, v_coq, &msg_wn);  /*change size and location of wn*/
  173.     csr_hide();             /*move cursor off screen          */
  174.  
  175. /*----------------------------------------------------------------------------*/
  176. /*  Set four windows with different text characters, save the images.          */
  177. /*----------------------------------------------------------------------------*/
  178.     for(j = 0; j < BOXQ; j++)
  179.     {
  180.     defs_wn(&box_wn[j], (5 + 2 * j), (13 + 10 * j), 3, (8 + j), BDR_0P);
  181.     color_wn(box_att[j], c_bgrnd, &box_wn[j]);     /*set colors for boxes */
  182.     if(set_wn(&box_wn[j]) == 0)               /*set boxes on screen  */
  183.         v_st("Error in dimensions of box_wn[j]", &wn0);
  184.     v_rw(220 + j, 100, &box_wn[j]);     /*fill each box with unique char  */
  185.     dim_wn(FULL, &box_wn[j]);        /*Need full dimensions          */
  186.     sav_wi(&box_wn[j]);
  187.  
  188.     }
  189.  
  190.     sw_csadv(OFF, &msg_wn);        /*turn off cursor advance          */
  191.     v_plst(0, CENTER_TEXT, "--------------- Press any key to exit ---------------", &msg_wn);
  192.  
  193.     if (ttv == ON)
  194.     SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
  195.  
  196. /*----------------------------------------------------------------------------*/
  197. /*  Erase the images, move the window locations, and restore the windows.     */
  198. /*  Do this repeatedly, until exit is requested.                  */
  199. /*----------------------------------------------------------------------------*/
  200.     while(ki_chk() == 0 )        /*pressing any key will break loop    */
  201.     {
  202.     for(j = 0; j < BOXQ; j++)
  203.     {
  204.         cl_wn(&box_wn[j]);        /*erase this box from screen          */
  205.         brb = box_wn[j].rb;     /*place beginning row into temp var   */
  206.         bcb = box_wn[j].cb;     /*place beginning col into temp var   */
  207.         rw = brb + row_delta[j];    /*determine new beginning row          */
  208.         co = bcb + col_delta[j];    /*determine new beginning col          */
  209.         pl_wn(rw, co, &box_wn[j]);    /*adjust wn members to new coord's    */
  210.         repl_wi(&box_wn[j]);    /*place window image in new location  */
  211.         if(box_wn[j].re == v_rwq - 2 || box_wn[j].rb == 0)
  212.                            /*if reached boundary move */
  213.         row_delta[j] = -row_delta[j];       /*in opposite direction    */
  214.         if(box_wn[j].cb == bcb)
  215.         col_delta[j] = -col_delta[j];
  216.  
  217.     }
  218.     if (ttv == ON)
  219.         SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
  220.     }
  221.  
  222. /*----------------------------------------------------------------------------*/
  223. /*  User has pressed a key to end the demonstration                  */
  224. /*----------------------------------------------------------------------------*/
  225.     ki();                /*pull keystroke from buffer          */
  226.     vid_mode(vmode);            /*restore original mode           */
  227.     cl_att = NORMAL;            /*restore standard cl_att          */
  228.     tv_upd = ttv;
  229.     cls();                /*clear screen with standard attribute*/
  230.     tv_upd = OFF;
  231.  
  232. /*----------------------------------------------------------------------------*/
  233. /* Change size, location, and attribute of window.                  */
  234. /* Present exit message.                              */
  235. /*----------------------------------------------------------------------------*/
  236.     mod_wn(9, 0, 7, 80, &wn);        /*change size and location of window  */
  237.     sw_margin(1, 1, &wn);        /*set margin sizes              */
  238.     sw_border(BDR_LNP, &wn);        /*change border               */
  239.     sw_csadv(ON, &wn);            /*turn on cursor advance          */
  240.                     /*otherwise sign off message          */
  241.                     /*gets garbled.               */
  242.     sw_att(REVERSE, &wn);        /*window attribute is REVERSE          */
  243.     sw_bdratt(NORMAL, &wn);        /*border attribute is NORMAL          */
  244.     set_wn(&wn);            /*set window on screen              */
  245.     v_st(sign_off[0],&wn);        /*Windows for C         */
  246.     sw_att((NORMAL + HIGH_INT), &wn);
  247.     v_st(sign_off[1],&wn);        /*For more information ...  */
  248.  
  249.     if ((tv_upd = ttv) == ON)
  250.     SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
  251.     mv_csr(v_rwq - 2, 0, &wn0);     /*Place cursor at bottom of screen    */
  252.  
  253.     exit_wfc();
  254.     return(0);
  255. }
  256.