home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / GRAPHICS / WINDOWPR.ZIP / TUTOR3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-29  |  7.7 KB  |  282 lines

  1. #include "pro.h"
  2. #include "xglobals.h"
  3. #include "vs.h"
  4. #include "colors.h"
  5.  
  6.  
  7. int main()
  8. {
  9.     unsigned int window_handle[3], count;
  10.     unsigned char tile_handle[10];
  11.     char key[10];
  12.  
  13.     /*
  14.      * See tutor1.c for an explanation of this section.
  15.     */
  16.     active_attr = WHITE + (BLACK << 4);
  17.     inactive_attr = LIGHTGRAY + (BLACK << 4);
  18.     active_tile_attr = LIGHTGREEN + (BLACK << 4);
  19.     inactive_tile_attr = RED + (BLACK << 4);
  20.     scroll_bars_on = FALSE;
  21.     method = DMA;
  22.     wn_init();
  23.  
  24.     /* Let's turn off the cursor -- its annoying */
  25.     wn_hidecur();
  26.  
  27.     window_handle[0] = wn_createw(25,80,2,3,1,1,20,70,FALSE,HEAD_ON,"TILE TUTORIAL",NULL);
  28.     wn_openw(window_handle[0]);
  29.     getch();
  30.  
  31.  
  32.     /*
  33.      * Lesson 1:  Naming a tile
  34.      *
  35.      * Even though this window is not divided, it has one tile.  Every
  36.      * window has at least one tile.  If its divided it has at least two
  37.      * tiles.  We can give this tile a name using the
  38.      * wn_namet(window handle, tile handle, new name) function.
  39.      *
  40.     */
  41.  
  42.     /*
  43.      * We'll establish this as pointing to the first tile.
  44.      * The first tile in a new window always has a handle of 0
  45.     */
  46.  
  47.     tile_handle[0] = 0;
  48.  
  49.     /* and give it a name */
  50.     wn_namet(window_handle[0], tile_handle[0], "tile number 1");
  51.     getch();
  52.  
  53.     /*
  54.      * Lesson 2: Creating a tile
  55.      *
  56.      * You can create a second tile in a window using the wn_createt
  57.      * function.  This function is similar to the wn_createw function
  58.      * in that simply creating a tile does not put it onto the
  59.      * physical screen you will also have to open it.  For starters,
  60.      * lets just create one.  The syntax is:
  61.      * wn_createt(window handle, tile name, virtual screen columns,
  62.      * virtual screen rows, virtual x, virtual y)
  63.      *
  64.      * virtual x, virtual y refer to the coordinate of the virtual
  65.      * screen which will map to the upper left corner of the viewport
  66.      * (when it is displayed on the physical screen.)
  67.      *
  68.      * wn_createt returns a tile handle similar to the way wn_createw
  69.      * returns a window handle.
  70.     */
  71.  
  72.     tile_handle[1] = wn_createt(window_handle[0], "tile number 2", 80, 25, 1, 1);
  73.  
  74.     /*
  75.      * And now we can open it.  When it is opened the active tile
  76.      * will be split into two parts.  The lower half will be taken
  77.      * by the new tile.  This is the only real significance of the
  78.      * active tile.  You can change the active tile using the
  79.      * wn_actt function.
  80.      *
  81.     */
  82.  
  83.     wn_opent(window_handle[0], tile_handle[1]);
  84.     getch();
  85.  
  86.     /*
  87.      * Notice that the name of the active tile is displayed in a
  88.      * different color.  When a tile is activated its name is given
  89.      * the attribute value of the global variable active_tile_attr.
  90.      * When it is de-activated it is given the value of the global
  91.      * variable inactive_tile_attr.
  92.     */
  93.  
  94.     /*
  95.      * Lesson 2: Sizing tiles
  96.      *
  97.      * If you increase or decrease the number of rows in a tile
  98.      * that has a tile below it.  The tile below the tile being sized
  99.      * is also adjusted in size so that the overall dimensions of the
  100.      * window do not change.
  101.      *
  102.      * If the size of any tile is adjusted columnwise the entire window
  103.      * is effected.  And if you ajust the size of the last tile rowwise
  104.      * the window is also increased or decreased in size.
  105.      *
  106.      * Watch---
  107.      *
  108.      * First, lets adjust the top tile row wise.
  109.     */
  110.  
  111.     for (count = 0; count < 5; count++) {
  112.         wn_sizet(window_handle[0], tile_handle[0], 0, 1);
  113.     }
  114.     getch();
  115.  
  116.     /* And bring it back */
  117.  
  118.     for (count = 0; count < 5; count++) {
  119.         wn_sizet(window_handle[0], tile_handle[0], 0, -1);
  120.     }
  121.     getch();
  122.  
  123.     /* Now we'll adjust it column wise */
  124.  
  125.     for (count = 0; count < 5; count++) {
  126.         wn_sizet(window_handle[0], tile_handle[0], 1, 0);
  127.     }
  128.     getch();
  129.     
  130.     /* And bring it back */
  131.  
  132.     for (count = 0; count < 5; count++) {
  133.         wn_sizet(window_handle[0], tile_handle[0], -1, 0);
  134.     }
  135.     getch();
  136.  
  137.     /* Now watch what happens when you adjust the last tile rowwise */
  138.  
  139.  
  140.     for (count = 0; count < 2; count++) {
  141.         wn_sizet(window_handle[0], tile_handle[1], 0, 1);
  142.     }
  143.     getch();
  144.     
  145.     /* And bring it back */
  146.  
  147.     for (count = 0; count < 2; count++) {
  148.         wn_sizet(window_handle[0], tile_handle[1], 0, -1);
  149.     }
  150.     getch();
  151.  
  152.     /*
  153.      * Lesson 3: Swapping tiles.
  154.      *
  155.      * You can swap the name and virtual screen of any two tiles, even
  156.      * tiles in different windows.
  157.     */
  158.  
  159.     /* first lets put some color in each so we can tell then apart */
  160.     vs_fillchar(window_handle[0], tile_handle[0], 1, 1, 80, 25, 'x', BLUE, RED);
  161.     vs_fillchar(window_handle[0], tile_handle[1], 1, 1, 80, 25, 'o', LIGHTRED, BLUE);
  162.     getch();
  163.  
  164.     /* Now we'll swap them */
  165.     wn_swapt(window_handle[0], tile_handle[0], window_handle[0], tile_handle[1]);
  166.     getch();
  167.  
  168.     /*
  169.      * Lesson 4: Revisiting scroll bars
  170.      *
  171.      * Scroll bars can be turned on and off for individual tiles.
  172.      *
  173.     */
  174.     wn_togscroll(window_handle[0], tile_handle[0], TRUE);
  175.     getch();
  176.  
  177.     /* And off */
  178.     wn_togscroll(window_handle[0], tile_handle[0], FALSE);
  179.     getch();
  180.  
  181.     /*
  182.      * With imaginative use of the wn_togscrollrng function discussed
  183.      * in TUTOR2 you can also turn the scroll bars on and off for all
  184.      * tiles in a single window.
  185.     */
  186.  
  187.     wn_togscrollrng(window_handle[0], window_handle[0], TRUE);
  188.     getch();
  189.  
  190.     /*
  191.      * Lesson 5: Using wn_redraw and wn_draww
  192.      *
  193.      * The effect of changing certain variables will not be immediately
  194.      * seen on the screen (unless you do it via a WINDOW PRO function.)
  195.      * So, to cover this situation we've included some functions to
  196.      * force redrawing of the windows.
  197.      * wn_redraw will redraw all of the windows and
  198.      * wn_draww will redraw a single window
  199.      *
  200.      * For example if we change the scroll bar characters to an
  201.      * alternate arrow type (let's say we're on a terminal that
  202.      * doesn't support the IBM extended character set.)
  203.     */
  204.     sbu = '^';
  205.     sbd = 'v';
  206.     sbr = '>';
  207.     sbl = '<';
  208.  
  209.     /*
  210.      * You won't see the effect of this until all of the windows are
  211.      * redrawn.  If you use wn_redraw you effectively redraw all of
  212.      * the windows.  You may do this in a buffer (to avoid blinking)
  213.      * and then selectively
  214.      * update a region of the physical screen from the buffer by freezing
  215.      * and defrosting before and after the wn_redraw.  The region
  216.      * is expressed as the upper left coordinate followed by the
  217.      * lower right coordinate.  To be safe we'll just use the upper
  218.      * and lower bounds of the whole screen.
  219.     */
  220.  
  221.     wn_freeze();
  222.     wn_redraw();
  223.     wn_defrost(1, 1, physical_columns, physical_rows);
  224.     getch();
  225.     
  226.     /*
  227.      * And we can redefine the scroll bar characters again and
  228.      * then reforce the updating of just a single window
  229.     */
  230.  
  231.     sbu = 0x1E;
  232.     sbd = 0x1F;
  233.     sbr = 0x10;
  234.     sbl = 0x11;
  235.  
  236.     wn_draww(window_handle[0]);
  237.  
  238.     /*
  239.      * Lesson 6: closing and deleting tiles
  240.      *
  241.      * When a tile is closed the tile below it inherits the
  242.      * left over space, except when there is no tile below.
  243.      * Then the tile above gets the left over space.  You can't close
  244.      * the last tile in a window.  A window must have at least one
  245.      * tile.
  246.      *
  247.      * Before we go on lets create one more tile and then we'll close it.
  248.     */
  249.  
  250.     scroll_bars_on = TRUE;
  251.     tile_handle[2] = wn_createt(window_handle[0], "tile number 3", 80, 25, 1, 1);
  252.     wn_opent(window_handle[0], tile_handle[2]);
  253.     getch();
  254.  
  255.     wn_closet(window_handle[0], tile_handle[2]);
  256.     getch();
  257.  
  258.     /* Now lets open it up in the other tile */
  259.     
  260.     /* first active tile 1 */
  261.     wn_actt(window_handle[0], tile_handle[1]);
  262.     getch();
  263.  
  264.     /* then open the new tile */
  265.     wn_opent(window_handle[0], tile_handle[2]);
  266.     getch();
  267.  
  268.     /* Now get rid of it for good! */
  269.     wn_delt(window_handle[0], tile_handle[2]);
  270.     getch();
  271.  
  272.     /* restore the characters to the original screen */
  273.         wn_restorescr();
  274.  
  275.     /* restore the cursor position */
  276.     v_gotoxy(oldx,oldy);
  277.  
  278.     /* restore the cursor shape */
  279.     v_curshape(oldb, olde);
  280.  
  281. }
  282.