home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PRO2.ZIP / TUTOR3.C < prev    next >
Text File  |  1988-11-27  |  8KB  |  287 lines

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