home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / GRAPHICS / WINDOWPR.ZIP / TUTOR2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-29  |  16.9 KB  |  602 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.     char key[10];
  11.  
  12.     /*
  13.      * See tutor1.c for an explanation of this section.
  14.     */
  15.     
  16.     scroll_bars_on = FALSE;
  17.     method = DMA;
  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 five times so you get the effect.
  167.     */
  168.     
  169.     for (count = 0; count < 5; count++) {
  170.         wn_scrollvs(window_handle[2], 0, 1, 0);
  171.         getch();
  172.     }
  173.  
  174.     /* And then back again */
  175.  
  176.     for (count = 0; count < 5; count++) {
  177.         wn_scrollvs(window_handle[2], 0, -1, 0);
  178.         getch();
  179.     }
  180.     
  181.     /*
  182.      * Lesson 5: moving a window
  183.      *
  184.      * Again, moving a window is very similar to sizing a window.
  185.      * The columns parameter moves it to the right if positive, and
  186.      * the rows parameter moves the window down if positive.
  187.      *
  188.      * The syntax for the function is:
  189.      * wn_movew(window handle, columns, rows)
  190.      *
  191.      * For example:
  192.     */
  193.  
  194.     for (count = 0; count < 5; count++) {
  195.         wn_movew(window_handle[2], 1, 1);
  196.     }
  197.     getch();
  198.  
  199.     /* and back again */
  200.  
  201.     for (count = 0; count < 5; count++) {
  202.         wn_movew(window_handle[2], -1, -1);
  203.     }
  204.     getch();
  205.  
  206.     /*
  207.      * and again, exactly as with sizing a window there is a related
  208.      * range function with the syntax:
  209.      * wn_moverng(1st handle, 2nd handle, columns, rows)
  210.      *
  211.     */
  212.  
  213.     for (count = 0; count < 5; count++) {
  214.         wn_moverng(window_handle[0], window_handle[2], 1, 1);
  215.     }
  216.     getch();
  217.  
  218.     /* and back again */
  219.  
  220.     for (count = 0; count < 5; count++) {
  221.         wn_moverng(window_handle[0], window_handle[2], -1, -1);
  222.     }
  223.     getch();
  224.  
  225.     /*
  226.      * Lesson 6: flying boxes
  227.      *
  228.      * Flying boxes give the illusion that a box originates from a point
  229.      * on the screen, or that it retreats to a point on the screen.
  230.      * It is very effective at giving cognitive messages to the user
  231.      * that an action has been performed.  For example, in Ashton-Tate's
  232.      * Framework when the user saves a file you'll see a "ghost" box seem
  233.      * to move across the screen from the window to the file cabinets.
  234.      * It is also the technique used to make exploding boxes etc.
  235.      *
  236.      * Let's first look at how the basic function works, and then how
  237.      * to combine with other functions for different effects.
  238.      *
  239.      * The syntax is:
  240.      * wn_flybox(bx, by, br, bc, ex, ey, er, ec, granularity,
  241.      *    speed, boxchars, foreground, background)
  242.          *
  243.          * bx,by    define the upper left coordinate of the beginning box
  244.      * br,bc    define the outer dimensions of the beginning box
  245.      * ex,ey     define the upper left coordinate of the ending box
  246.      * er,ec    define the outer dimensions of the ending box
  247.      * granularity    defines the number of boxes to display in between
  248.      * speed    indicates how long to wait after displaying a box
  249.      * boxchars    defines the characters to use when creating the boxes
  250.      *        We already have setup some box character pointers
  251.      *        called box0, box1, box2, and box3.  Later
  252.      *        we'll show you how to make your own.
  253.      * foreground     the foreground color of the box
  254.      * background    the background color of the box
  255.      *
  256.      * So, to make a box of 1 row and column fly from the upper right
  257.      * hand corner and grow to a box of dimensions 10 by 10 in the
  258.      * lower left hand corner we execute the function with these
  259.      * parameters:
  260.     */
  261.  
  262.      wn_flybox(78, 1, 1, 1, 1, 14, 10, 10, 10, 5000, box4, LIGHTGRAY, BLACK);
  263.      getch();
  264.  
  265.     /*
  266.      * What we do is combine that with other features like opening a
  267.      * window for some special effects.
  268.      *
  269.      * So if we close window 2 but first precede it with
  270.      * with a flying box in front of it -- watch the effect.
  271.     */
  272.  
  273.     wn_flybox(window[window_handle[1]]->physical_x,
  274.         window[window_handle[1]]->physical_y,
  275.         window[window_handle[1]]->port_rows,
  276.         window[window_handle[1]]->port_columns,
  277.         78, 23, 1, 1, 10, 5000, box4, LIGHTGRAY, BLACK);
  278.  
  279.     wn_hidew(window_handle[1]);
  280.     getch();
  281.  
  282.     /* And of course we can bring it back again in the same way */
  283.  
  284.     wn_flybox(78, 23, 1, 1,
  285.         window[window_handle[1]]->physical_x,
  286.         window[window_handle[1]]->physical_y,
  287.         window[window_handle[1]]->port_rows,
  288.         window[window_handle[1]]->port_columns,
  289.         10, 5000, box4, LIGHTGRAY, BLACK);
  290.  
  291.     wn_hidew(window_handle[1]);
  292.     getch();
  293.  
  294.     /*
  295.      * Lesson 7: Scroll Bars
  296.      *
  297.      * Scroll bars are generally used for the mouse to point to
  298.      * to perform certain actions.  You can learn more about
  299.      * using the mouse in tutor3.c.  But I can show you how to
  300.      * turn the scroll bars on and off.  This is actually a tile
  301.      * related function.  But, since we aren't using tiles in these
  302.      * windows we'll just use a tile handle of 0.
  303.      *
  304.      * The syntax is:
  305.      * wn_togscroll(window handle, tile handle, TRUE or FALSE);
  306.      *
  307.      * So, to turn the scroll bars on:
  308.     */
  309.     
  310.     wn_togscroll(window_handle[1], 0, TRUE);
  311.     getch();
  312.  
  313.     /* and to turn them off */
  314.  
  315.     wn_togscroll(window_handle[1], 0, FALSE);
  316.     getch();
  317.  
  318.     /* Once again we have a range function for this: */
  319.  
  320.     wn_togscrollrng(window_handle[0], window_handle[2], TRUE);
  321.     getch();
  322.  
  323.     /* And to turn them all off */
  324.  
  325.     wn_togscrollrng(window_handle[0], window_handle[2], FALSE);
  326.     getch();
  327.  
  328.     /*
  329.      * Note that you can also control whether windows are created
  330.      * by default with scroll bars.  If scroll_bars_on == FALSE
  331.      * windows are initially created without scroll bars.
  332.     */
  333.  
  334.     /*
  335.      * Lesson 8:  Changing border characters
  336.      *
  337.      * The border characters of a box are determined by a 13 char
  338.      * array that each box points to.  This 13 char array contains
  339.      * the characters used to draw the box.  See reference manual
  340.      * for a complete description of the array.  Here, we'll just
  341.      * use some defaults that come with Window Pro.
  342.      *
  343.      * Window Pro has five predefined box character sets: box0,
  344.      * box1, box2, box3, and box4.  The bax character set pointer
  345.      * default_box determines what box characters a box is initially
  346.      * given.  default_box is initialized to be equivalent to box0.
  347.      *
  348.      * The syntax of the command is:
  349.      * wn_chgbord(window handle, box character pointer)
  350.      *
  351.      * For example:
  352.     */
  353.  
  354.     wn_chgbord(window_handle[0], box1);
  355.     getch();
  356.  
  357.     /* And as always, there is a range version of this function. */
  358.  
  359.     wn_chgbordrng(window_handle[0], window_handle[2], box1);
  360.     getch();
  361.  
  362.     /*
  363.      * Lesson 9: changing the color of the borders
  364.      *
  365.      * The color of the border is set as it is activated and deactivated.
  366.      * When a window is activated its border color is set to the value
  367.      * of the global variable active_attr, when it is de-activated its
  368.      * border color is set to the value of inactive_attr.
  369.      *
  370.      * You can change these values using this syntax:
  371.      * active_attr = foreground + (background << 4)
  372.      *
  373.      * You can also temporarily change the color of a window using
  374.      * the window pro function wn_chgcolor(window handle, foreground,
  375.      * background).
  376.      *
  377.      * For example:
  378.     */
  379.  
  380.     wn_chgcolor(window_handle[2], RED, BLACK);
  381.     getch();
  382.  
  383.     /* And of course there is a range version of this function also */
  384.  
  385.     wn_chgcolorrng(window_handle[0], window_handle[2], RED, BLACK);
  386.     getch();
  387.  
  388.     /*
  389.      * Lesson 10: Changing the style of borders and freezing.
  390.      *
  391.      * This allows you to create shadowing effects.  My personal
  392.      * preference with this is to use box4 character set and to
  393.      * not use window names, although you can.
  394.      *
  395.      * In addition, since I am going to do a lot of radical things
  396.      * to the windows, I will frezze the screen and then flash the
  397.      * results of all operations on the screen.
  398.      *
  399.      * First, let's freeze the screen.
  400.     */
  401.     wn_freeze();
  402.  
  403.     /* Now lets get rid of the names */
  404.  
  405.     for (count = 0; count < 3; count++) wn_namew(window_handle[count],NULL);
  406.  
  407.     /* Now lets change the box character sets */
  408.  
  409.     wn_chgbordrng(window_handle[0], window_handle[2], box4);
  410.  
  411.     /*
  412.      * We'll also need to fill the virtual screen with color to
  413.      * make this look decent.  See vs_fillattr in the reference
  414.      * manual for an explanation
  415.      *
  416.     */
  417.     
  418.     for (count = 0; count < 3; count++)
  419.         vs_fillattr(window_handle[count], 0, 1, 1, 80, 25, BLACK, LIGHTGRAY);
  420.     
  421.  
  422.     /*
  423.      * Now lets see what this looks like, before we do any shadowing.
  424.      * The defrost function needs an upper left and lower right coordinate
  425.      * of the portion of the screen to redraw.  It's safest to just use 1,1
  426.      * for the upper right and physical_columns, physical_rows for the
  427.      * lower left, although if you can limit the region to the portion
  428.      * of the physical screen which has changed you can spped up the
  429.      * operation (This doesn't matter too much unless you do a lot of
  430.      * freezing and defrosting in succession.)  You can also try
  431.      * suspending a window (if you are only working on one window) but
  432.      * this isn't too reliable if the window overlaps any other window,
  433.      * although it is faster than freeze/defrost.
  434.     */
  435.     wn_defrost(1, 1, physical_columns, physical_rows);
  436.     getch();
  437.  
  438.     /*
  439.      * OK, this is the real thing here.  There are five styles of window
  440.      * border, defined in PRO.H:
  441.      * UPPER_LEFT
  442.      * UPPER_RIGHT
  443.      * LOWER_LEFT
  444.      * LOWER_RIGHT
  445.      * NONE
  446.      * HEAD_ON
  447.      *
  448.      * These roughly represent some type of light source for a shadowing
  449.      * effect.
  450.      *
  451.      * You can see each of the different effects as follows:
  452.     */
  453.  
  454.     wn_togborder(window_handle[1], UPPER_LEFT);
  455.     getch();
  456.  
  457.     wn_togborder(window_handle[1], UPPER_RIGHT);
  458.     getch();
  459.  
  460.     wn_togborder(window_handle[1], LOWER_RIGHT);
  461.     getch();
  462.  
  463.     wn_togborder(window_handle[1], LOWER_LEFT);
  464.     getch();
  465.  
  466.     wn_togborder(window_handle[1], NONE);
  467.     getch();
  468.  
  469.     wn_togborder(window_handle[1], HEAD_ON);
  470.     getch();
  471.  
  472.  
  473.     /* And of course there is a range function for this */
  474.  
  475.     wn_togbordrng(window_handle[0], window_handle[2], UPPER_LEFT);
  476.     getch();
  477.  
  478.     wn_togbordrng(window_handle[0], window_handle[2], UPPER_RIGHT);
  479.     getch();
  480.  
  481.     wn_togbordrng(window_handle[0], window_handle[2], LOWER_RIGHT);
  482.     getch();
  483.  
  484.     wn_togbordrng(window_handle[0], window_handle[2], LOWER_LEFT);
  485.     getch();
  486.  
  487.     wn_togbordrng(window_handle[0], window_handle[2], NONE);
  488.     getch();
  489.  
  490.     wn_togbordrng(window_handle[0], window_handle[2], HEAD_ON);
  491.     getch();
  492.  
  493.  
  494.     /*
  495.      * Lesson 11: Zooming a window
  496.      *
  497.      * Zooming a window temporarily increases its size to the size of
  498.      * of the physical screen.  Zooming can only be done on the active
  499.      * window.
  500.      *
  501.      * For example, to zoom window 2:
  502.     */
  503.     
  504.     /* first activate it */    
  505.     wn_actw(window_handle[1]);
  506.  
  507.     /* then zoom it */
  508.     wn_zoomw();
  509.     getch();
  510.  
  511.     /* zoom is a toggle.  To unzoom just call the function again */
  512.     wn_zoomw();
  513.     getch();
  514.     
  515.     /* And we'll bring back the little window */
  516.     wn_actw(window_handle[2]);
  517.  
  518.     /*
  519.      * Lesson 12: The cursor.
  520.      *
  521.      * You can turn the cursor on and off using wn_hidecur and
  522.      * wn_showcur.  The cursor is turned on and off automatically
  523.      * by Window Pro during certain operations, but having used
  524.      * wn_hidecur suppresses turning the cursor on.  When Window
  525.      * Pro does turn the cursor on it uses the global variables
  526.      * cursor_e and cursor_b for the ending and beginning scan line
  527.      * values (So by doing this cursor_b = 1 and cursor_e = 14, for
  528.      * example, you can get a block cursor.)
  529.      *
  530.      * Let's change the values and then turn the cursor on and off
  531.      * a few times.
  532.     */
  533.  
  534.     cursor_b = 1;
  535.     cursor_e = 14;
  536.     wn_showcur();
  537.     getch();
  538.  
  539.     cursor_b = 3;
  540.     cursor_e = 14;
  541.     wn_hidecur();
  542.     wn_showcur();
  543.     getch();
  544.  
  545.     cursor_b = 5;
  546.     cursor_e = 14;
  547.     wn_hidecur();
  548.     wn_showcur();
  549.     getch();
  550.  
  551.  
  552.     cursor_b = 7;
  553.     cursor_e = 14;
  554.     wn_hidecur();
  555.     wn_showcur();
  556.     getch();
  557.  
  558.  
  559.     /*
  560.      * Lesson 13: deleting windows
  561.      *
  562.      * Deleting windows is exactly like closing windows, except
  563.      * that the window is gone forever, deleted from memory, and
  564.      * its handle returned to the pool of assignable handles.
  565.      *
  566.      * Lets get rid of all of the windows with a little pizzazz.
  567.      *
  568.     */
  569.  
  570.     for (count = 0; count < 3; count++) {
  571.         wn_flybox(window[window_handle[count]]->physical_x,
  572.             window[window_handle[count]]->physical_y,
  573.             window[window_handle[count]]->port_rows,
  574.             window[window_handle[count]]->port_columns,
  575.             window[window_handle[count]]->physical_x +
  576.             window[window_handle[count]]->port_columns/2,
  577.             window[window_handle[count]]->physical_y +
  578.             window[window_handle[count]]->port_rows/2,
  579.             1, 1, 5, 5000, box4, WHITE, BLACK);
  580.         wn_delw(window_handle[count]);
  581.     }
  582.     /*
  583.      * This is still only the beginning.  I haven't covered all of
  584.      * the functions.  Plus, once you understand the window record
  585.      * and the global variables you can do other "tricks."  Probably
  586.      * things that I never even conceived of.  This of course has not
  587.      * even discussed tile manipulation, or virtual screen manipulation.
  588.      * Proceed to TUTOR3.C for tile manipulation, TUTOR4.C for
  589.      * virtual screen manipulation, and TUTOR5.C for extended keyboard
  590.      * and mouse techniques.
  591.     */
  592.  
  593.     /* restore the characters to the original screen */
  594.         wn_restorescr();
  595.  
  596.     /* restore the cursor position */
  597.     v_gotoxy(oldx,oldy);
  598.  
  599.     /* restore the cursor shape */
  600.     v_curshape(oldb, olde);
  601.  
  602. }