home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PRO2.ZIP / TUTOR4.C < prev    next >
Text File  |  1989-01-02  |  12KB  |  389 lines

  1. #include "pro.h"
  2. #include "xglobals.h"
  3. #include "vs.h"
  4. #include "video.h"
  5. #include "colors.h"
  6.  
  7. char string[2000];
  8.  
  9. int main()
  10. {
  11.     unsigned int window_handle[3], count, row, column, count1;
  12.     unsigned char tile_handle[10];
  13.  
  14.     /*
  15.      * See tutors 1-3 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 = FALSE;
  22.     method = ANSI;
  23.     wn_init();
  24.  
  25.     window_handle[0] = wn_createw(25,80,2,3,1,1,20,70,FALSE,HEAD_ON,"Virtual Screen TUTORIAL",NULL);
  26.  
  27.     tile_handle[0] = 0;
  28.     wn_namet(window_handle[0], tile_handle[0], "tile number 1");
  29.  
  30.     tile_handle[1] = wn_createt(window_handle[0], "tile number 2", 80, 25, 1, 1);
  31.     wn_opent(window_handle[0], tile_handle[1]);
  32.     wn_openw(window_handle[0]);
  33.     getchar();
  34.  
  35.  
  36.     /*
  37.      * Lesson 1: vs_printf, the logical cursor, and activating tiles
  38.      *
  39.      * vs_printf is similar to printf except that you specify a
  40.      * virtual screen and a foreground and background color.
  41.      * Printing begins at the virtual screen's logical cursor
  42.      * location and the cursor is advanced for each character output.
  43.      * TABS are expanded to 8, CR are ignored and LF puts the cursor
  44.      * at the beginning of the next row.  If the string extends beyond
  45.      * the right side of the virtual screen it wraps around, and if
  46.      * string extends beyond the bottom of the virtual screen the virtual
  47.      * screen is scrolled up.  Pretty much like using regular printf
  48.      * on the physical screen.
  49.      *
  50.      * Let's try counting to 5.
  51.      */
  52.  
  53.     for (count = 1; count < 6; count++) {
  54.  
  55.         vs_printf(window_handle[0], tile_handle[0], white, black,
  56.             "This is the number %d\n", count);
  57.  
  58.     }
  59.     getchar();
  60.  
  61.     /* and now in the other tile */
  62.  
  63.     for (count = 1; count < 6; count++) {
  64.  
  65.         vs_printf(window_handle[0], tile_handle[1], white, black,
  66.             "This is the number %d\n", count);
  67.  
  68.     }
  69.     getchar();
  70.  
  71.     /*
  72.      * Notice that the cursor doesn't move down to tile 2.  The logical
  73.      * was advanced, but the hardware cursor is only displayed in the
  74.      * active tile.  We can display the cursor by activating tile 2
  75.     */
  76.  
  77.     wn_actt(window_handle[0], tile_handle[1]);
  78.     getchar();
  79.  
  80.  
  81.     /*
  82.      * Lesson 2: vs_puts, vs_putc, and vs_clrvs.
  83.      *
  84.      * vs_puts is similar to vs_format.  It doesn't except a variable
  85.      * argument list, just a single string.  But, it also does not
  86.      * do TAB expansion or CR/LF conversion (it outputs the IBM
  87.      * extended character in its place.)  In addition although
  88.      * it does do wrapping at the right edge of the virtual screen
  89.      * it will not automatically scroll the virtual screen if the
  90.      * string extends beyond the bottom of the virtual screen.  Instead
  91.      * it merrily continues writing to whatever memory is above the virtual
  92.      * screen.  Because this is not a good idea, you can set a maximum
  93.      * string length, which will clip the string output if it goes
  94.      * beyond the maximum length.  If the string is less than the maximum
  95.      * length it pads spaces. Lastly, it is not dependent on the logical
  96.      * cursor location, nor does it advance the logical cursor.
  97.      *
  98.      * But, before we do that lets clear tile 1.
  99.      *
  100.      */
  101.  
  102.     vs_clrvs(window_handle[0], tile_handle[0], white, black);
  103.     getchar();
  104.  
  105.     /*
  106.      * There are a whole series of vs_clr?? functions for clearing
  107.      * the virtual screen from the logical cursor to beginning of a line
  108.      * to the end of a line, etc.  See the reference manual for more
  109.      * info.
  110.     */
  111.  
  112.     #define MAXLEN        60
  113.     #define ROW        1
  114.     #define COLUMN        1
  115.  
  116.     vs_puts(window_handle[0], tile_handle[0], COLUMN, ROW, MAXLEN, black,
  117.         lightgray, "vs_puts works \n <--- but newline looks funny");
  118.     getchar();
  119.  
  120.     /*    
  121.      * vs_putc is identical to vs_puts except it outputs single characters.
  122.      * So, it doesn't need that maximum length stuff.
  123.      * Let's output the whole IBM character set
  124.     */
  125.  
  126.     row = column = 1;
  127.     vs_clrvs(window_handle[0], tile_handle[1], white, black);
  128.  
  129.     for (count = 0; count < 255; count++) {
  130.         vs_putc(window_handle[0], tile_handle[1], column++, row,
  131.             black, lightgray, (char) count);
  132.         if (column > wdw[window_handle[0]]->port_columns) {
  133.             column =1;
  134.             row++;
  135.         }
  136.     }
  137.     getchar();
  138.  
  139.     /*
  140.      * Lesson 3: fill
  141.      *
  142.      * WINDOW PRO let's you define a rectangular region by its
  143.      * upper left and lower right coordinates.
  144.      *
  145.      * Then, with vs_fillchar you can fill in that region with both
  146.      * a character and an attribute, or with vs_fillattr you can keep
  147.      * the existing characters but fill in the region with a new
  148.      * attribute.
  149.      *
  150.      * Lets clear out the top tile and see how it works.
  151.      */
  152.  
  153.     vs_clrvs(window_handle[0], tile_handle[0], black, lightgray);
  154.     getchar();
  155.     
  156.     vs_fillchar(window_handle[0], tile_handle[0],
  157.         15,3, 30,8, 'x', white, black);
  158.     getchar();
  159.  
  160.     /* now we can change the attribute of that same region */
  161.  
  162.     vs_fillattr(window_handle[0],tile_handle[0],15,3,30,8,lightgray,black);
  163.     getchar();
  164.  
  165.     /*
  166.      * Lesson 4: Inserting and deleting rows and columns
  167.      *
  168.      * These functions: vs_insrow, vs_inscolumn, vs_delrow, vs_delcolumn,
  169.      * let you define a rectangular region as discussed in the fill
  170.      * functions and then insert and delete rows and columns in that
  171.      * region.
  172.      *
  173.      * First, vs_insrow, it inserts rows at the top of the rectangular
  174.      * region and pushes all of the other rows down.  The new blank
  175.      * row at the top of the region has an attribute of your choosing.
  176.      *
  177.      * For example,
  178.     /*
  179.  
  180.     /* First lets file tile 2 with some text */
  181.     for (count1 = 1; count1 <= 25; count1++) {
  182.         for (count = 1; count <= 80; count++) {
  183.             vs_putc(window_handle[0], tile_handle[1], count,
  184.                 count1, white, black,
  185.                 (char) (count1 + count + 63));
  186.         }
  187.     }
  188.     getchar();
  189.  
  190.     /*
  191.      * And now change the attribute of the region so you can see it more
  192.      * clearly
  193.     */
  194.  
  195.     vs_fillattr(window_handle[0], tile_handle[1], 15,3, 30,8, lightgray, black);
  196.     getchar();
  197.  
  198.     /* Now let's insert 5 rows one at a time */
  199.  
  200.     #define NUMBER_OF_ROWS            1
  201.  
  202.     for (count = 0; count < 5; count++) {
  203.         vs_insrow(window_handle[0], tile_handle[1], 15,3,
  204.             30,8, NUMBER_OF_ROWS, lightgray, black);
  205.         getchar();
  206.     }
  207.  
  208.     /*
  209.      * Deleting rows is inentical to inserting rows except that the
  210.      * rows at the top of the region are 'deleted' and the blank lines
  211.      * appear at the bottom of the region.
  212.      *
  213.      * Now lets setup tile 1 and delete 5 rows one at a time.
  214.     */
  215.  
  216.     for (count1 = 1; count1 <= 25; count1++) {
  217.         for (count = 1; count <= 80; count++) {
  218.             vs_putc(window_handle[0], tile_handle[0], count,
  219.                 count1, white, black,
  220.                 (char) (count1 + count + 63));
  221.         }
  222.     }
  223.     getchar();
  224.  
  225.     /*
  226.      * And now change the attribute of the region so you can see it more
  227.      * clearly
  228.     */
  229.  
  230.     vs_fillattr(window_handle[0], tile_handle[0], 15,3, 30,8, lightgray, black);
  231.     getchar();
  232.  
  233.     /* Now let's delete 5 rows one at a time */
  234.  
  235.     for (count = 0; count < 5; count++) {
  236.         vs_delrow(window_handle[0], tile_handle[0], 15,3,
  237.             30,8, NUMBER_OF_ROWS, lightgray, black);
  238.         getchar();
  239.     }
  240.  
  241.     /*
  242.      * vs_inscolumn works the same as vs_insrow except that it inserts
  243.      * a blank column at the left side of the region and pushes the rest
  244.      * of the columns in the region to the right.
  245.      *
  246.      * We'll use the same technique as before to demonstrate.
  247.     */
  248.  
  249.     /* here's a trick to speed up a bunch of vs_putc functions */
  250.     wn_suspendt(window_handle[0], tile_handle[1]);
  251.  
  252.     for (count1 = 1; count1 <= 25; count1++) {
  253.         for (count = 1; count <= 80; count++) {
  254.             vs_putc(window_handle[0], tile_handle[1], count,
  255.                 count1, white, black,
  256.                 (char) (count1 + count + 63));
  257.         }
  258.     }
  259.     wn_suspendt(window_handle[0], tile_handle[1]);
  260.     getchar();
  261.  
  262.     /*
  263.      * And now change the attribute of the region so you can see it more
  264.      * clearly
  265.     */
  266.     vs_fillattr(window_handle[0], tile_handle[1], 15,3, 30,8, lightgray, black);
  267.     getchar();
  268.  
  269.     /* Now let's insert 10 columns one at a time */
  270.  
  271.     for (count = 0; count < 10; count++) {
  272.         vs_inscolumn(window_handle[0], tile_handle[1], 15,3,
  273.             30,8, NUMBER_OF_ROWS, lightgray, black);
  274.         getchar();
  275.     }
  276.  
  277.     /*
  278.      * And finally, the vs_delcolumn function (if you haven't already
  279.      * guessed) deletes the column on the left side of the region and
  280.      * leaves blank lines on the right side
  281.      *
  282.      * Let's see how that might work.
  283.     */
  284.  
  285.     wn_suspendt(window_handle[0], tile_handle[0]);
  286.  
  287.     for (count1 = 1; count1 <= 25; count1++) {
  288.         for (count = 1; count <= 80; count++) {
  289.             vs_putc(window_handle[0], tile_handle[0], count,
  290.                 count1, white, black,
  291.                 (char) (count1 + count + 63));
  292.         }
  293.     }
  294.     wn_suspendt(window_handle[0], tile_handle[0]);
  295.     getchar();
  296.  
  297.     /*
  298.      * And now change the attribute of the region so you can see it more
  299.      * clearly
  300.     */
  301.  
  302.     vs_fillattr(window_handle[0], tile_handle[0], 15,3, 30,8, lightgray, black);
  303.     getchar();
  304.  
  305.     /* Now let's delete 10 columns one at a time */
  306.  
  307.     for (count = 0; count < 10; count++) {
  308.         vs_delcolumn(window_handle[0], tile_handle[0], 15,3,
  309.             30,8, NUMBER_OF_ROWS, lightgray, black);
  310.         getchar();
  311.     }
  312.  
  313.     /*
  314.      * Lesson 5: vs_gets
  315.      *
  316.      * vs_gets is a gets-like function for virtual screens.  It echoes
  317.      * characters typed at the keyboard to a virtual screen, starting at
  318.      * the virtual screen's logical cursor and for each character input
  319.      * outputs the character (in the attribute of your choice) and advances
  320.      * the logical cursor.  If the cursor is advanced to an area outside of
  321.      * the viewport you can elect to automatically readjust the viewport, or
  322.      * not.  If the string exceeds the length of the line it automatically
  323.      * wraps to the beginning of the next line.  If the string exceeds the
  324.      * number of rows in the virtual screen all of the text in the virtual
  325.      * screen scrolls up.  You must specify a pointer to the storage location
  326.      * and vs_gets does not determine if the pointer has sufficient
  327.      * memory allocated to it to hold the input string.  Instead you
  328.      * pass a maximum length parameter.
  329.      *
  330.      * For example:
  331.     */
  332.  
  333.     /* Lets set up the screen first */
  334.     vs_clrvs(window_handle[0], tile_handle[0], white, black);
  335.     wn_sizet(window_handle[0], tile_handle[0], -20, 0);
  336.     vs_locatecur(window_handle[0], tile_handle[0], 1,2);
  337.     vs_puts(window_handle[0], tile_handle[0], 1, 1, 50, white, black,
  338.         "Type in a few sentences. (Scroll is on.)");
  339.     
  340.     /* You don't have to do this, but you won't see the cursor otherwise */
  341.     wn_actt(window_handle[0], tile_handle[0]);
  342.  
  343.     #define SCROLL_OPTION_ON    1
  344.     #define SCROLL_OPTION_OFF    0
  345.     #define MAXIMUM_LENGTH        2000
  346.  
  347.     /* Here is vs_gets */
  348.     vs_gets(window_handle[0], tile_handle[0], SCROLL_OPTION_ON, string,
  349.         white, black, MAXIMUM_LENGTH);
  350.     getchar();
  351.  
  352.     /* Now lets do the whole thing over again but with the scroll option off */
  353.  
  354.     /* Lets set up the screen first */
  355.     vs_clrvs(window_handle[0], tile_handle[0], white, black);
  356.     vs_locatecur(window_handle[0], tile_handle[0], 1,2);
  357.     vs_puts(window_handle[0], tile_handle[0], 1, 1, 50, white, black,
  358.         "Type in a few sentences. (Scroll is off.)");
  359.     
  360.     /* Here is vs_gets */
  361.     vs_gets(window_handle[0], tile_handle[0], SCROLL_OPTION_OFF, string,
  362.         white, black, MAXIMUM_LENGTH);
  363.     getchar();
  364.  
  365.  
  366.     /* finish up with some pizzazzzzzzzzzzzzzzzz............ */
  367.  
  368.     wn_flybox(wdw[window_handle[0]]->physical_x,
  369.         wdw[window_handle[0]]->physical_y,
  370.         wdw[window_handle[0]]->port_rows,
  371.         wdw[window_handle[0]]->port_columns,
  372.         wdw[window_handle[0]]->physical_x +
  373.         wdw[window_handle[0]]->port_columns/2,
  374.         wdw[window_handle[0]]->physical_y +
  375.         wdw[window_handle[0]]->port_rows/2,
  376.         1, 1, 5, 50, box4, white, black);
  377.     wn_delw(window_handle[0]);
  378.  
  379.     /* restore the characters to the original screen */
  380.         wn_restorescr();
  381.  
  382.     /* restore the cursor position */
  383.     v_gotoxy(oldx,oldy);
  384.  
  385.     /* restore the cursor shape */
  386.     v_curshape(oldb, olde);
  387.  
  388. }
  389.