home *** CD-ROM | disk | FTP | other *** search
- /*dem_cmov -- demonstration of the capabilities of Windows for C to save
- and move window images and to manage color displays.
-
- ************* Copyright 1985 by Vermont Creative Software **************
-
- COMMENT
-
- This program shows how the functions of Windows for C can be used to create
- motion in programs. The ability to rapidly save, move, and restore images is
- important to all programs. Because of this ability, screen displays change
- crisply when you use Windows for C.
-
- This program was written using physical attributes. It illustrates the steps
- necessary to use physical attributes within your program. Note that our logical
- attribute system can accomplish the same end result much more simply, without
- requiring any conditional code in your programs.
-
- Terminal based do not use colors in this demo.
-
- */
-
- /* #define WN_DEBUG commented out when debugging completed*/
- #include <wfc.h>
- #undef ATT_LOGIC
- #include <wfc_glob.h>
-
- #define BOXQ 4
-
- #define SCR_UPDATE v_tv
-
- char box_att[BOXQ] = {RED, GREEN, MAGENTA, YELLOW};
-
- int row_delta[BOXQ] = {1, -1, 1, -1}; /*delta rows to move each box */
- int col_delta[BOXQ] = {2, -3, 3, -1}; /*delta columns to move each box */
-
- /*----------------------------------------------------------------------------*/
- /* character string contains message put to window on exit */
- /*----------------------------------------------------------------------------*/
-
- char *sign_off[] = {
- "\n WINDOWS FOR C\n\n",
- " For more information contact Vermont Creative Software, (802) 848-7738."
- };
-
- main()
- {
- WINDOW wn, msg_wn, box_wn[BOXQ];
- int rw, co;
- int brb, bcb;
- register int j;
- int key;
- char ttv;
- #if MSDOS
- int vmode; /*current video mode */
- #endif
- char c_bgrnd;
-
- /*----------------------------------------------------------------------------*/
- /* Initialize the Windows for C System */
- /*----------------------------------------------------------------------------*/
- init_wfc();
-
- cls(); /*clear the screen */
- csr_hide(); /*hide the cursor off screen */
-
- ttv = tv_upd;
- tv_upd = OFF;
-
- /*----------------------------------------------------------------------------*/
- /* Initialize a window */
- /*----------------------------------------------------------------------------*/
- defs_wn(&wn, 0, 0, 20, 80, BDR_LNP);
- sw_margin(3, 3, &wn); /*set some margins */
-
- /*----------------------------------------------------------------------------*/
- /*define window for messages. This will be just below first window */
- /*----------------------------------------------------------------------------*/
- def_wn(&msg_wn, wn.re + 1, wn.re + 4, wn.cb, wn.ce, 3, 3, &bdr_dln);
- sw_att((NORMAL + HIGH_INT), &msg_wn);
-
-
- set_wn(&wn); /*set windows */
- set_wn(&msg_wn);
-
- /*----------------------------------------------------------------------------*/
- /* Write text into window using v_st to insure all text written. Use */
- /* ki() to pause at appropriate moment. */
- /*----------------------------------------------------------------------------*/
- sw_att((NORMAL + HIGH_INT), &wn); /*change attribute */
- v_plst(0, CENTER_TEXT, "WINDOWS FOR C COLOR AND MOVEMENT CAPABILITIES",&wn);
- wn.r += 2; /*skip 1 blank line */
- wn.c = 0;
- sw_att(NORMAL, &wn); /*change attribute back */
-
- v_st("Windows for C makes moving windows easy. Window images on the screen can be moved anywhere ",&wn);
- v_st("on the screen by a simple function call. The image is temporarily stored in user memory, erased from ",&wn);
- v_st("the screen, and moved to a new location. Memory management is automatic.\n\n",&wn);
- v_st("Because the video functions of Windows for C use ASM direct memory addressing, ",&wn);
- v_st("screen output is fast. This Demonstration shows the speed with which ", &wn);
- v_st("windows can be moved off and on the screen.\n\n", &wn);
- v_st("This demonstration program moves 4 character-filled windows about the screen randomly. ", &wn);
- v_st("The windows could equally be filled with text or figures drawn with block-graphics ", &wn);
- v_st("characters. The store and overlay capabilities of Windows for C simplify and enhance ", &wn);
- v_st("programs for business or play.", &wn);
-
- /*----------------------------------------------------------------------------*/
- /* place message in message window */
- /*----------------------------------------------------------------------------*/
- v_plst(0, CENTER_TEXT, "Press any key to proceed ", &msg_wn);
-
- if (ttv == ON)
- SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
-
- ki(); /*provide pause */
-
- /*----------------------------------------------------------------------------*/
- /* Clear window and write new information. Use ki() to pause again. */
- /*----------------------------------------------------------------------------*/
- cl_wn(&wn);
- sw_att((NORMAL + HIGH_INT), &wn);
- v_plst(0, CENTER_TEXT, "COLOR CONTROL",&wn) ;
- wn.r += 2; /*skip some blank lines */
- wn.c = 0;
- sw_att(NORMAL, &wn);
- v_st("This demonstration program also illustrates the color-control capabilities of ",&wn);
- v_st("of Windows for C. Functions are provided to set the color of the screen border ",&wn);
- v_st("and the foreground, background, and border colors of individual windows.\n\n", &wn);
- v_st("For good legibility, this program uses different 'colors' for color and ", &wn);
- v_st("non-color displays.\n\n", &wn);
- v_st("If you have more than one monitor connected to your system, this program ", &wn);
- v_st("allows you to switch to color within the demo. It returns to the original ", &wn);
- v_st("mode upon exit.\n\n", &wn);
- v_st("Color management is made simple by Windows for C's use of C structures ", &wn);
- v_st("to hold information required for window management.\n\n\n\n\n\n", &wn);
- if (ttv == ON)
- SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
-
- ki(); /*pause until user ready to proceed */
-
- unset_wn(&wn); /* get rid of text window */
- /*----------------------------------------------------------------------------*/
- /* find out if viewer has a monitor that displays color */
- /*----------------------------------------------------------------------------*/
- cl_wn(&msg_wn);
- sw_plcsr(ON, &msg_wn); /*set cursor placement switch ON */
- v_st("Do you have a monitor that displays colors? Please answer y or n: ",&msg_wn);
-
- if (ttv == ON)
- SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
-
- while((key = ki()) != 'y' && key != 'n' && key != 'Y' && key != 'N')
- bell();
- sw_plcsr(OFF, &msg_wn); /*turn cursor placement switch OFF */
- csr_hide(); /*hide cursor */
-
- /*----------------------------------------------------------------------------*/
- /* If color monitor, used colored background; otherwise use BLACK */
- /*----------------------------------------------------------------------------*/
- c_bgrnd = BLACK;
- vmode = rd_mode(); /*store current video mode */
- if(key == 'y' || key == 'Y')
- {
- vid_mode(CO80); /*set to color mode */
- c_bgrnd = BLUE;
- color_sc(c_bgrnd); /*blue background for screen clear */
- vid_bdr(LIGHT + BLUE); /*screen border */
- color_wn(YELLOW, c_bgrnd, &wn); /*colors for text window */
- color_wn(YELLOW, c_bgrnd, &msg_wn); /*colors for message window */
- }
- unset_wn(&msg_wn); /*unset message window */
- cls(); /*clear screen with current background*/
- mod_wn(v_rwq - 1, 0, 1, v_coq, &msg_wn); /*change size and location of wn*/
- csr_hide(); /*move cursor off screen */
-
- /*----------------------------------------------------------------------------*/
- /* Set four windows with different text characters, save the images. */
- /*----------------------------------------------------------------------------*/
- for(j = 0; j < BOXQ; j++)
- {
- defs_wn(&box_wn[j], (5 + 2 * j), (13 + 10 * j), 3, (8 + j), BDR_0P);
- color_wn(box_att[j], c_bgrnd, &box_wn[j]); /*set colors for boxes */
- if(set_wn(&box_wn[j]) == 0) /*set boxes on screen */
- v_st("Error in dimensions of box_wn[j]", &wn0);
- v_rw(220 + j, 100, &box_wn[j]); /*fill each box with unique char */
- dim_wn(FULL, &box_wn[j]); /*Need full dimensions */
- sav_wi(&box_wn[j]);
-
- }
-
- sw_csadv(OFF, &msg_wn); /*turn off cursor advance */
- v_plst(0, CENTER_TEXT, "--------------- Press any key to exit ---------------", &msg_wn);
-
- if (ttv == ON)
- SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
-
- /*----------------------------------------------------------------------------*/
- /* Erase the images, move the window locations, and restore the windows. */
- /* Do this repeatedly, until exit is requested. */
- /*----------------------------------------------------------------------------*/
- while(ki_chk() == 0 ) /*pressing any key will break loop */
- {
- for(j = 0; j < BOXQ; j++)
- {
- cl_wn(&box_wn[j]); /*erase this box from screen */
- brb = box_wn[j].rb; /*place beginning row into temp var */
- bcb = box_wn[j].cb; /*place beginning col into temp var */
- rw = brb + row_delta[j]; /*determine new beginning row */
- co = bcb + col_delta[j]; /*determine new beginning col */
- pl_wn(rw, co, &box_wn[j]); /*adjust wn members to new coord's */
- repl_wi(&box_wn[j]); /*place window image in new location */
- if(box_wn[j].re == v_rwq - 2 || box_wn[j].rb == 0)
- /*if reached boundary move */
- row_delta[j] = -row_delta[j]; /*in opposite direction */
- if(box_wn[j].cb == bcb)
- col_delta[j] = -col_delta[j];
-
- }
- if (ttv == ON)
- SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
- }
-
- /*----------------------------------------------------------------------------*/
- /* User has pressed a key to end the demonstration */
- /*----------------------------------------------------------------------------*/
- ki(); /*pull keystroke from buffer */
- vid_mode(vmode); /*restore original mode */
- cl_att = NORMAL; /*restore standard cl_att */
- tv_upd = ttv;
- cls(); /*clear screen with standard attribute*/
- tv_upd = OFF;
-
- /*----------------------------------------------------------------------------*/
- /* Change size, location, and attribute of window. */
- /* Present exit message. */
- /*----------------------------------------------------------------------------*/
- mod_wn(9, 0, 7, 80, &wn); /*change size and location of window */
- sw_margin(1, 1, &wn); /*set margin sizes */
- sw_border(BDR_LNP, &wn); /*change border */
- sw_csadv(ON, &wn); /*turn on cursor advance */
- /*otherwise sign off message */
- /*gets garbled. */
- sw_att(REVERSE, &wn); /*window attribute is REVERSE */
- sw_bdratt(NORMAL, &wn); /*border attribute is NORMAL */
- set_wn(&wn); /*set window on screen */
- v_st(sign_off[0],&wn); /*Windows for C */
- sw_att((NORMAL + HIGH_INT), &wn);
- v_st(sign_off[1],&wn); /*For more information ... */
-
- if ((tv_upd = ttv) == ON)
- SCR_UPDATE(0, v_rwq - 1, 0, v_coq - 1, &wn0);
- mv_csr(v_rwq - 2, 0, &wn0); /*Place cursor at bottom of screen */
-
- exit_wfc();
- return(0);
- }