home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PRO2.ZIP / TUTOR2.C < prev    next >
Text File  |  1988-12-02  |  17KB  |  605 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.  
  13.     /*
  14.      * See tutor1.c for an explanation of this section.
  15.     */
  16.     
  17.     scroll_bars_on = BOTH_BARS;
  18.     active_attr = white + (black << 4);
  19.     inactive_attr = lightgray + (black << 4);
  20.  
  21.     wn_init();
  22.  
  23.     /* Let's turn off the cursor -- its annoying */
  24.     wn_hidecur();
  25.  
  26.     window_handle[0] = wn_createw(25,80,2,3,1,1,15,20,FALSE,HEAD_ON,"1",NULL);
  27.     vs_puts(window_handle[0],0,1,1,10,white,blue,"Window Pro");
  28.     wn_openw(window_handle[0]);
  29.     getch();
  30.  
  31.     /*
  32.      * Now let's create a second window that overlaps the first
  33.      *
  34.     */
  35.  
  36.     window_handle[1] = wn_createw(25,80,5,5,1,1,15,20,FALSE,HEAD_ON,"2",NULL);
  37.     vs_puts(window_handle[1],0,1,1,10,white,blue,"Window Pro");
  38.     wn_openw(window_handle[1]);
  39.     getch();
  40.  
  41.  
  42.     /*
  43.      * Now let's create a third window that overlaps the second
  44.      *
  45.     */
  46.  
  47.     window_handle[2] = wn_createw(25,80,12,7,1,1,11,24,FALSE,HEAD_ON,"3",NULL);
  48.     vs_puts(window_handle[2],0,1,1,10,white,blue,"Window Pro");
  49.     wn_openw(window_handle[2]);
  50.     getch();
  51.  
  52.     /*
  53.      * Now that we've got some windows on the screen let's look at some of the
  54.      * ways we can manipulate windows.
  55.     */
  56.  
  57.  
  58.     /*
  59.      * Lesson 1: Closing and Opening windows
  60.      *
  61.      * Closing a window takes it off of the screen, but does not
  62.      * delete it from memory.  So, it we close window_handle[1] it
  63.      * should remove it from the screen.
  64.     */
  65.  
  66.     wn_closew(window_handle[1]);
  67.     getch();
  68.  
  69.     /*
  70.      * But, when we bring it back it will be on top of the screen.
  71.     */
  72.  
  73.     wn_openw(window_handle[1]);
  74.     getch();
  75.  
  76.     /*
  77.      * We can even open windows which are already on the screen to
  78.      * bring them to the top.  So, if we want to bring window 3 back
  79.      * to the top we can also open it.
  80.     */
  81.  
  82.     wn_openw(window_handle[2]);
  83.     getch();
  84.  
  85.     /*
  86.      * Lesson 2: Hiding Windows
  87.      *
  88.      * Hiding is similar to closing, except that the window retains
  89.      * its original position in the list.  So, if we hide and un-hide
  90.      * window 2, we'll get the same effect as in Lesson 1 but in fewer
  91.      * steps.
  92.     */
  93.  
  94.     wn_hidew(window_handle[1]);
  95.     getch();
  96.  
  97.     wn_hidew(window_handle[1]);
  98.     getch();
  99.  
  100.     /*
  101.      * Lesson 3: Sizing a window.
  102.      *
  103.      * Sizing a window is always performed relative to its current size.
  104.      * So the columns and rows parameters are indicate how many columns
  105.      * and rows to increase or decrease the window size by.
  106.      * Note that if the resulting size is larger than the physical screen
  107.      * or smaller than 1 row by 1 column that the function is executed
  108.      * but returns a value of MODIFIED.
  109.      *
  110.      * We are actually changin the size of a tile, so we'll have to
  111.      * specify a tile handle also (in a window with no tiles just use 0.)
  112.      *
  113.      *      window handle, tile handle, columns, rows
  114.      *        |              |           |       |
  115.      *          |              |  +--------+       |
  116.      *          V              V  V   V----------- +
  117.     */
  118.  
  119.     wn_sizet(window_handle[2], 0, -5, -4);
  120.     getch();
  121.  
  122.     /*
  123.      * You can also size ranges of windows using the wn_sizerng function.
  124.      * The function will apply itself to the first item in the range and
  125.      * work up towards the top of the screen until it applies itself to
  126.      * the second item in the range or reaches the top of screen.
  127.      *
  128.      * The syntax is very similar to the above.
  129.      * wn_sizerng(1st handle, 2nd handle, columns, rows)
  130.      *
  131.      * For example:
  132.     */
  133.  
  134.     for (count = 0; count < 5; count++) {
  135.         wn_sizerng(window_handle[0],window_handle[2], 1, 1);
  136.     }
  137.     getch();
  138.  
  139.     /* And then back again */
  140.  
  141.     for (count = 0; count < 5; count++) {
  142.         wn_sizerng(window_handle[0],window_handle[2], -1, -1);
  143.     }
  144.     getch();
  145.  
  146.     /*
  147.      * Lesson 4: scrolling a window
  148.      *
  149.      * Scrolling a window refers to repositioning the viewport over
  150.      * the virtual screen (giving the illusion of scrolling information
  151.      * through the window.)
  152.      *
  153.      * As with size, this is actually a tile function.  But, since
  154.      * there are no tiles we'll use 0 for the tile handle.
  155.      *
  156.      * Likewise, if the result of the function is to place the
  157.      * viewport so that it is not completely filled by the virtual
  158.      * screen the result of the function is modified, but executed
  159.      * and the function returns the value MODIFIED.
  160.      *
  161.      * The syntax of this function is identical to the wn_sizet, except
  162.      * that a postive columns parameter moves the virtual screen to
  163.      * the left, and a positive rows parameter moves the virtual screen
  164.      * up.
  165.      *
  166.      * We'll do it fifteen times so you get the effect.
  167.     */
  168.     
  169.     for (count = 0; count < 15; count++) {
  170.         wn_scrollvs(window_handle[2], 0, 1, 0);
  171.         wn_sync_tw_to_vs(window_handle[2], 0);
  172.         getch();
  173.     }
  174.  
  175.     /* And then back again */
  176.  
  177.     for (count = 0; count < 15; count++) {
  178.         wn_scrollvs(window_handle[2], 0, -1, 0);
  179.         wn_sync_tw_to_vs(window_handle[2], 0);
  180.         getch();
  181.     }
  182.     
  183.     /*
  184.      * Lesson 5: moving a window
  185.      *
  186.      * Again, moving a window is very similar to sizing a window.
  187.      * The columns parameter moves it to the right if positive, and
  188.      * the rows parameter moves the window down if positive.
  189.      *
  190.      * The syntax for the function is:
  191.      * wn_movew(window handle, columns, rows)
  192.      *
  193.      * For example:
  194.     */
  195.  
  196.     for (count = 0; count < 5; count++) {
  197.         wn_movew(window_handle[2], 1, 1);
  198.     }
  199.     getch();
  200.  
  201.     /* and back again */
  202.  
  203.     for (count = 0; count < 5; count++) {
  204.         wn_movew(window_handle[2], -1, -1);
  205.     }
  206.     getch();
  207.  
  208.     /*
  209.      * and again, exactly as with sizing a window there is a related
  210.      * range function with the syntax:
  211.      * wn_moverng(1st handle, 2nd handle, columns, rows)
  212.      *
  213.     */
  214.  
  215.     for (count = 0; count < 5; count++) {
  216.         wn_moverng(window_handle[0], window_handle[2], 1, 1);
  217.     }
  218.     getch();
  219.  
  220.     /* and back again */
  221.  
  222.     for (count = 0; count < 5; count++) {
  223.         wn_moverng(window_handle[0], window_handle[2], -1, -1);
  224.     }
  225.     getch();
  226.  
  227.     /*
  228.      * Lesson 6: flying boxes
  229.      *
  230.      * Flying boxes give the illusion that a box originates from a point
  231.      * on the screen, or that it retreats to a point on the screen.
  232.      * It is very effective at giving cognitive messages to the user
  233.      * that an action has been performed.  For example, in Ashton-Tate's
  234.      * Framework when the user saves a file you'll see a "ghost" box seem
  235.      * to move across the screen from the window to the file cabinets.
  236.      * It is also the technique used to make exploding boxes etc.
  237.      *
  238.      * Let's first look at how the basic function works, and then how
  239.      * to combine with other functions for different effects.
  240.      *
  241.      * The syntax is:
  242.      * wn_flybox(bx, by, br, bc, ex, ey, er, ec, granularity,
  243.      *    speed, boxchars, foreground, background)
  244.          *
  245.          * bx,by    define the upper left coordinate of the beginning box
  246.      * br,bc    define the outer dimensions of the beginning box
  247.      * ex,ey     define the upper left coordinate of the ending box
  248.      * er,ec    define the outer dimensions of the ending box
  249.      * granularity    defines the number of boxes to display in between
  250.      * speed    indicates how long to wait after displaying a box
  251.      * boxchars    defines the characters to use when creating the boxes
  252.      *        We already have setup some box character pointers
  253.      *        called box0, box1, box2, and box3.  Later
  254.      *        we'll show you how to make your own.
  255.      * foreground     the foreground color of the box
  256.      * background    the background color of the box
  257.      *
  258.      * So, to make a box of 1 row and column fly from the upper right
  259.      * hand corner and grow to a box of dimensions 10 by 10 in the
  260.      * lower left hand corner we execute the function with these
  261.      * parameters:
  262.     */
  263.  
  264.      wn_flybox(78, 1, 1, 1, 1, 14, 10, 10, 10, 50, box4, lightgray, black);
  265.      getch();
  266.  
  267.     /*
  268.      * What we do is combine that with other features like opening a
  269.      * window for some special effects.
  270.      *
  271.      * So if we close window 2 but first precede it with
  272.      * with a flying box in front of it -- watch the effect.
  273.     */
  274.  
  275.     wn_flybox(wdw[window_handle[1]]->physical_x,
  276.         wdw[window_handle[1]]->physical_y,
  277.         wdw[window_handle[1]]->port_rows,
  278.         wdw[window_handle[1]]->port_columns,
  279.         78, 23, 1, 1, 10, 50, box4, lightgray, black);
  280.  
  281.     wn_hidew(window_handle[1]);
  282.     getch();
  283.  
  284.     /* And of course we can bring it back again in the same way */
  285.  
  286.     wn_flybox(78, 23, 1, 1,
  287.         wdw[window_handle[1]]->physical_x,
  288.         wdw[window_handle[1]]->physical_y,
  289.         wdw[window_handle[1]]->port_rows,
  290.         wdw[window_handle[1]]->port_columns,
  291.         10, 50, box4, lightgray, black);
  292.  
  293.     wn_hidew(window_handle[1]);
  294.     getch();
  295.  
  296.     /*
  297.      * Lesson 7: Scroll Bars
  298.      *
  299.      * Scroll bars are generally used for the mouse to point to
  300.      * to perform certain actions.  You can learn more about
  301.      * using the mouse in tutor3.c.  But I can show you how to
  302.      * turn the scroll bars on and off.  This is actually a tile
  303.      * related function.  But, since we aren't using tiles in these
  304.      * windows we'll just use a tile handle of 0.
  305.      *
  306.      * The syntax is:
  307.      * wn_togscroll(window handle, tile handle, TRUE or FALSE);
  308.      *
  309.      * So, to turn the scroll bars on:
  310.     */
  311.     
  312.     wn_togscroll(window_handle[1], 0, TRUE);
  313.     getch();
  314.  
  315.     /* and to turn them off */
  316.  
  317.     wn_togscroll(window_handle[1], 0, FALSE);
  318.     getch();
  319.  
  320.     /* Once again we have a range function for this: */
  321.  
  322.     wn_togscrollrng(window_handle[0], window_handle[2], TRUE);
  323.     getch();
  324.  
  325.     /* And to turn them all off */
  326.  
  327.     wn_togscrollrng(window_handle[0], window_handle[2], FALSE);
  328.     getch();
  329.  
  330.     /*
  331.      * Note that you can also control whether windows are created
  332.      * by default with scroll bars.  If scroll_bars_on == FALSE
  333.      * windows are initially created without scroll bars.
  334.     */
  335.  
  336.     /*
  337.      * Lesson 8:  Changing border characters
  338.      *
  339.      * The border characters of a box are determined by a 13 char
  340.      * array that each box points to.  This 13 char array contains
  341.      * the characters used to draw the box.  See reference manual
  342.      * for a complete description of the array.  Here, we'll just
  343.      * use some defaults that come with Window Pro.
  344.      *
  345.      * Window Pro has five predefined box character sets: box0,
  346.      * box1, box2, box3, and box4.  The bax character set pointer
  347.      * default_box determines what box characters a box is initially
  348.      * given.  default_box is initialized to be equivalent to box0.
  349.      *
  350.      * The syntax of the command is:
  351.      * wn_chgbord(window handle, box character pointer)
  352.      *
  353.      * For example:
  354.     */
  355.  
  356.     wn_chgbord(window_handle[0], box1);
  357.     getch();
  358.  
  359.     /* And as always, there is a range version of this function. */
  360.  
  361.     wn_chgbordrng(window_handle[0], window_handle[2], box1);
  362.     getch();
  363.  
  364.     /*
  365.      * Lesson 9: changing the color of the borders
  366.      *
  367.      * The color of the border is set as it is activated and deactivated.
  368.      * When a window is activated its border color is set to the value
  369.      * of the global variable active_attr, when it is de-activated its
  370.      * border color is set to the value of inactive_attr.
  371.      *
  372.      * You can change these values using this syntax:
  373.      * active_attr = foreground + (background << 4)
  374.      *
  375.      * You can also temporarily change the color of a window using
  376.      * the window pro function wn_chgcolor(window handle, foreground,
  377.      * background).
  378.      *
  379.      * For example:
  380.     */
  381.  
  382.     wn_chgcolor(window_handle[2], red, black);
  383.     getch();
  384.  
  385.     /* And of course there is a range version of this function also */
  386.  
  387.     wn_chgcolorrng(window_handle[0], window_handle[2], red, black);
  388.     getch();
  389.  
  390.     /*
  391.      * Lesson 10: Changing the style of borders and freezing.
  392.      *
  393.      * This allows you to create shadowing effects.  My personal
  394.      * preference with this is to use box4 character set and to
  395.      * not use window names, although you can.
  396.      *
  397.      * In addition, since I am going to do a lot of radical things
  398.      * to the windows, I will frezze the screen and then flash the
  399.      * results of all operations on the screen.
  400.      *
  401.      * First, let's freeze the screen.
  402.     */
  403.     wn_freeze();
  404.  
  405.     /* Now lets get rid of the names */
  406.  
  407.     for (count = 0; count < 3; count++) wn_namew(window_handle[count],NULL);
  408.  
  409.     /* Now lets change the box character sets */
  410.  
  411.     wn_chgbordrng(window_handle[0], window_handle[2], box4);
  412.  
  413.     /*
  414.      * We'll also need to fill the virtual screen with color to
  415.      * make this look decent.  See vs_fillattr in the reference
  416.      * manual for an explanation
  417.      *
  418.     */
  419.     
  420.     for (count = 0; count < 3; count++)
  421.         vs_fillattr(window_handle[count], 0, 1, 1, 80, 25, black, lightgray);
  422.     
  423.  
  424.     /*
  425.      * Now lets see what this looks like, before we do any shadowing.
  426.      * The defrost function needs an upper left and lower right coordinate
  427.      * of the portion of the screen to redraw.  It's safest to just use 1,1
  428.      * for the upper right and physical_columns, physical_rows for the
  429.      * lower left, although if you can limit the region to the portion
  430.      * of the physical screen which has changed you can spped up the
  431.      * operation (This doesn't matter too much unless you do a lot of
  432.      * freezing and defrosting in succession.)  You can also try
  433.      * suspending a window (if you are only working on one window) but
  434.      * this isn't too reliable if the window overlaps any other window,
  435.      * although it is faster than freeze/defrost.
  436.     */
  437.     wn_defrost(1, 1, physical_columns, physical_rows);
  438.     getch();
  439.  
  440.     /*
  441.      * OK, this is the real thing here.  There are five styles of window
  442.      * border, defined in PRO.H:
  443.      * UPPER_LEFT
  444.      * UPPER_RIGHT
  445.      * LOWER_LEFT
  446.      * LOWER_RIGHT
  447.      * NONE
  448.      * HEAD_ON
  449.      *
  450.      * These roughly represent some type of light source for a shadowing
  451.      * effect.
  452.      *
  453.      * You can see each of the different effects as follows:
  454.     */
  455.  
  456.     wn_togborder(window_handle[1], UPPER_LEFT);
  457.     getch();
  458.  
  459.     wn_togborder(window_handle[1], UPPER_RIGHT);
  460.     getch();
  461.  
  462.     wn_togborder(window_handle[1], LOWER_RIGHT);
  463.     getch();
  464.  
  465.     wn_togborder(window_handle[1], LOWER_LEFT);
  466.     getch();
  467.  
  468.     wn_togborder(window_handle[1], NONE);
  469.     getch();
  470.  
  471.     wn_togborder(window_handle[1], HEAD_ON);
  472.     getch();
  473.  
  474.  
  475.     /* And of course there is a range function for this */
  476.  
  477.     wn_togbordrng(window_handle[0], window_handle[2], UPPER_LEFT);
  478.     getch();
  479.  
  480.     wn_togbordrng(window_handle[0], window_handle[2], UPPER_RIGHT);
  481.     getch();
  482.  
  483.     wn_togbordrng(window_handle[0], window_handle[2], LOWER_RIGHT);
  484.     getch();
  485.  
  486.     wn_togbordrng(window_handle[0], window_handle[2], LOWER_LEFT);
  487.     getch();
  488.  
  489.     wn_togbordrng(window_handle[0], window_handle[2], NONE);
  490.     getch();
  491.  
  492.     wn_togbordrng(window_handle[0], window_handle[2], HEAD_ON);
  493.     getch();
  494.  
  495.  
  496.     /*
  497.      * Lesson 11: Zooming a window
  498.      *
  499.      * Zooming a window temporarily increases its size to the size of
  500.      * of the physical screen.  Zooming can only be done on the active
  501.      * window.
  502.      *
  503.      * For example, to zoom window 2:
  504.     */
  505.     
  506.     /* first activate it */    
  507.     wn_actw(window_handle[1]);
  508.  
  509.     /* then zoom it */
  510.     wn_zoomw();
  511.     getch();
  512.  
  513.     /* zoom is a toggle.  To unzoom just call the function again */
  514.     wn_zoomw();
  515.     getch();
  516.     
  517.     /* And we'll bring back the little window */
  518.     wn_actw(window_handle[2]);
  519.  
  520.     /*
  521.      * Lesson 12: The cursor.
  522.      *
  523.      * You can turn the cursor on and off using wn_hidecur and
  524.      * wn_showcur.  The cursor is turned on and off automatically
  525.      * by Window Pro during certain operations, but having used
  526.      * wn_hidecur suppresses turning the cursor on.  When Window
  527.      * Pro does turn the cursor on it uses the global variables
  528.      * cursor_e and cursor_b for the ending and beginning scan line
  529.      * values (So by doing this cursor_b = 1 and cursor_e = 14, for
  530.      * example, you can get a block cursor.)
  531.      *
  532.      * Let's change the values and then turn the cursor on and off
  533.      * a few times.
  534.     */
  535.  
  536.     cursor_b = 1;
  537.     cursor_e = 14;
  538.     wn_showcur();
  539.     getch();
  540.  
  541.     cursor_b = 3;
  542.     cursor_e = 14;
  543.     wn_hidecur();
  544.     wn_showcur();
  545.     getch();
  546.  
  547.     cursor_b = 5;
  548.     cursor_e = 14;
  549.     wn_hidecur();
  550.     wn_showcur();
  551.     getch();
  552.  
  553.  
  554.     cursor_b = 7;
  555.     cursor_e = 14;
  556.     wn_hidecur();
  557.     wn_showcur();
  558.     getch();
  559.  
  560.  
  561.     /*
  562.      * Lesson 13: deleting windows
  563.      *
  564.      * Deleting windows is exactly like closing windows, except
  565.      * that the window is gone forever, deleted from memory, and
  566.      * its handle returned to the pool of assignable handles.
  567.      *
  568.      * Lets get rid of all of the windows with a little pizzazz.
  569.      *
  570.     */
  571.  
  572.     for (count = 0; count < 3; count++) {
  573.         wn_flybox(wdw[window_handle[count]]->physical_x,
  574.             wdw[window_handle[count]]->physical_y,
  575.             wdw[window_handle[count]]->port_rows,
  576.             wdw[window_handle[count]]->port_columns,
  577.             wdw[window_handle[count]]->physical_x +
  578.             wdw[window_handle[count]]->port_columns/2,
  579.             wdw[window_handle[count]]->physical_y +
  580.             wdw[window_handle[count]]->port_rows/2,
  581.             1, 1, 5, 50, box4, white, black);
  582.         wn_delw(window_handle[count]);
  583.     }
  584.     /*
  585.      * This is still only the beginning.  I haven't covered all of
  586.      * the functions.  Plus, once you understand the window record
  587.      * and the global variables you can do other "tricks."  Probably
  588.      * things that I never even conceived of.  This of course has not
  589.      * even discussed tile manipulation, or virtual screen manipulation.
  590.      * Proceed to TUTOR3.C for tile manipulation, TUTOR4.C for
  591.      * virtual screen manipulation, and TUTOR5.C for extended keyboard
  592.      * and mouse techniques.
  593.     */
  594.  
  595.     /* restore the characters to the original screen */
  596.         wn_restorescr();
  597.  
  598.     /* restore the cursor position */
  599.     v_gotoxy(oldx,oldy);
  600.  
  601.     /* restore the cursor shape */
  602.     v_curshape(oldb, olde);
  603.  
  604. }
  605.