home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER54.ZIP / DEMOSRC.ARC / WINEXMPL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-10  |  9.5 KB  |  339 lines

  1. {$S-,R-,V-,I-,B-,F-}
  2.  
  3. {*********************************************************}
  4. {*                  WINEXMPL.PAS 5.07                    *}
  5. {*     An example program for Turbo Professional 5.0     *}
  6. {*        Copyright (c) TurboPower Software 1987.        *}
  7. {* Portions copyright (c) Sunny Hill Software 1985, 1986 *}
  8. {*     and used under license to TurboPower Software     *}
  9. {*                 All rights reserved.                  *}
  10. {*********************************************************}
  11.  
  12. program WinExample;
  13.   {-This demonstrates windowing techniques using virtual screens.}
  14.  
  15. uses
  16.   TpCrt,                     {basic screen routines}
  17.   Dos,                       {needed by TpScreen}
  18.   TpScreen;                  {virtual screen routines}
  19.  
  20. var
  21.   X, Y : Byte;
  22.   Key,
  23.   ScanLines : Word;
  24.   NeedDelay : Boolean;
  25.  
  26.   procedure WindowAll;
  27.     {-Selects a window the size of the selected screen.}
  28.   begin
  29.     Window(1, 1, CurrentCols, CurrentRows);
  30.   end;
  31.  
  32.   procedure WindowRel(X, Y, Cols, Rows : Byte);
  33.     {-Creates a window with an upper left corner of X,Y and Cols columns and
  34.       Rows rows.  Any part of the window which is out of bounds is clipped.}
  35.   var
  36.     X1, Y1 : Byte;
  37.   begin
  38.     X1 := Pred(X+Cols);
  39.     Y1 := Pred(Y+Rows);
  40.     if X1 > CurrentCols then
  41.       X1 := CurrentCols;
  42.     if Y1 > CurrentRows then
  43.       Y1 := CurrentRows;
  44.     Window(X, Y, X1, Y1);
  45.   end;
  46.  
  47.   procedure DisplayFromBuf(BufNum, X, Y : Byte);
  48.     {-Displays as much as possible of screen buffer number bufnum in the current
  49.     screen window. The coordinate X,Y on the source buffer is mapped to the
  50.     upper left hand corner of the currently selected window on the real screen.
  51.     Any of the source extending outside the current window coordinates is
  52.     clipped.}
  53.   begin
  54.     SelectScreen(BufNum);
  55.     WindowRel(X, Y, Succ(CurrentCols-X), Succ(CurrentRows-Y));
  56.     SelectScreen(0);
  57.     CopyWindow(BufNum);
  58.   end;
  59.  
  60.   procedure CreateBackDisplay;
  61.     {-Creates our TURBO PROFESSIONAL display.}
  62.   var
  63.     I : Byte;
  64.   begin
  65.     {This selects an 80 x 25 RAM screen for us}
  66.     SelectScreen(1);
  67.  
  68.     {write to our ram screen background}
  69.     TextBackGround(White);
  70.     TextColor(Black);
  71.     SetFrameChars('║', '═', '╝', '╗', '╚', '╔');
  72.     FrameWindow(1, 1, 80, 25, TextAttr, TextAttr,
  73.       ' TURBO PROFESSIONAL 5.0, Copyright (c) TurboPower Software 1987. ');
  74.     TextColor(Yellow);
  75.     TextBackGround(Blue);
  76.     for I := 1 to 11 do begin
  77.       Gotoxy(1, I shl 1);
  78.       SpeedWrite(' TURBO PROFESSIONAL TURBO PROFESSIONAL TURBO PROFESSIONAL TURBO PROFESSIONAL  ');
  79.     end;
  80.     for I := 0 to 11 do begin
  81.       Gotoxy(1, Succ(I shl 1));
  82.       SpeedWrite(' PROFESSIONAL TURBO PROFESSIONAL TURBO PROFESSIONAL TURBO PROFESSIONAL TURBO  ');
  83.     end;
  84.     Gotoxy(1, 1);
  85.   end;
  86.  
  87.   procedure CreateSmallWindow;
  88.     {-Sets up the display in a small window.}
  89.   var
  90.     I : Word;
  91.   begin
  92.     {Write to our small screen}
  93.     SelectScreen(3);
  94.     HighVideo;
  95.     TextBackGround(Blue);
  96.     FrameWindow(1, 1, 30, 12, TextAttr, TextAttr, ' Fast windows. ');
  97.     TextBackGround(LightGray);
  98.     TextColor(Green);
  99.     ClrScr;
  100.     for I := 1 to 10 do begin
  101.       Gotoxy(1, I);
  102.       CenterWrite('FAST FAST FAST FAST FAST');
  103.     end;
  104.     Gotoxy(1, 1);
  105.     {Select the full window that we'll copy to the screen}
  106.     WindowAll;
  107.   end;
  108.  
  109.   procedure FlashSmallWindows;
  110.     {-Flashes lots of small windows on the screen.}
  111.   var
  112.     FC : Char;
  113.     UPx, UPy, I : Word;
  114.   begin
  115.     I := 1;
  116.     while (I < 100) and (not Keypressed) do begin
  117.  
  118.       {Select our small screen buffer.}
  119.       SelectScreen(3);
  120.  
  121.       {Set our frame to a random block style.  By mixing background
  122.        foreground and background colors using blocks, you can achieve
  123.        hundreds of colors on a standard color monitor.}
  124.       FC := Chr(Random(4)+176);
  125.       if FC = #179 then
  126.         FC := ' ';
  127.       SetFrameChars(FC, FC, FC, FC, FC, FC);
  128.  
  129.       {Set a random color for background and foreground.}
  130.       TextBackGround(Succ(Random(15)));
  131.       TextColor(Succ(Random(31)));
  132.  
  133.       {Add a frame with a different color every time.}
  134.       FrameWindow(1, 1, 30, 12, TextAttr, TextAttr, ' Fast windows. ');
  135.  
  136.       SelectScreen(0);
  137.       {Select a random window on the real screen to display}
  138.       UPx := Succ(Random(51));
  139.       UPy := Succ(Random(14));
  140.       WindowRel(UPx, UPy, 30, 12);
  141.  
  142.       {Display our small screen on it}
  143.       DisplayFromBuf(3, 1, 1);
  144.  
  145.       {Increment I counter}
  146.       Inc(I);
  147.     end;
  148.  
  149.     {Leave a window just inside the frame}
  150.     WindowRel(Succ(UPx), Succ(UPy), 28, 10);
  151.   end;
  152.  
  153.   procedure ScrollOrigScreen;
  154.     {-Scrolls the original screen around in a window.}
  155.   var
  156.     I : Word;
  157.   begin
  158.     if (not Keypressed) then begin
  159.  
  160.       {Select our fourth screen buffer (it holds the real screen)}
  161.       SelectScreen(4);
  162.       {Define a window the size of our small window less the frame.}
  163.       WindowRel(1, 1, 28, 10);
  164.  
  165.       {Copy the window onto the real screen.}
  166.       SelectScreen(0);
  167.       CopyWindow(4);
  168.  
  169.       {Move the original screen around.}
  170.       Delay(500);
  171.  
  172.       {First to the right}
  173.       for I := 1 to 52 do begin
  174.         {If monochrome monitor, then delay so its visible}
  175.         if NeedDelay then
  176.           Delay(20);
  177.         DisplayFromBuf(4, Succ(I), 1);
  178.       end;
  179.  
  180.       {Then down the right side}
  181.       for I := 1 to 15 do begin
  182.         {For horizontal moves, delay on all screens}
  183.         Delay(20);
  184.         DisplayFromBuf(4, 53, Succ(I));
  185.       end;
  186.  
  187.       {Move it across the bottom}
  188.       for I := 1 to 52 do begin
  189.         {If monochrome monitor, then delay so its visible}
  190.         if NeedDelay then
  191.           Delay(20);
  192.         DisplayFromBuf(4, 53-I, 16);
  193.       end;
  194.  
  195.       {Then up the left}
  196.       for I := 1 to 15 do begin
  197.         Delay(20);
  198.         DisplayFromBuf(4, 1, 16-I);
  199.       end;
  200.     end;
  201.   end;
  202.  
  203.   procedure MoveSmallWindowAround;
  204.     {-Moves our small buffer, non-destructively over the real screen, then
  205.     restores the TURBO PROFESSIONAL buffer.}
  206.   var
  207.     I, J : Word;
  208.   begin
  209.     if (not Keypressed) then begin
  210.  
  211.       {Select our small window}
  212.       SelectScreen(3);
  213.       {Frame it}
  214.       FrameWindow(1, 1, 30, 12, TextAttr, TextAttr, ' Motion ');
  215.       {Window the whole thing}
  216.       WindowAll;
  217.  
  218.       {Select real screen}
  219.       SelectScreen(0);
  220.       {Create a window the size of our small buffer on it}
  221.       Window(1, 1, 30, 12);
  222.  
  223.       {Copy small buffer to upper left corner of our real screen.}
  224.       CopyWindow(3);
  225.  
  226.       {Move the window non-destructively over the current screen}
  227.       for I := 1 to 13 do
  228.         MoveWindowVertical(2, 1, True);
  229.       for I := 1 to 10 do
  230.         MoveWindowHorizontal(2, 5, True);
  231.       for I := 1 to 13 do
  232.         MoveWindowVertical(2, 1, False);
  233.       for I := 1 to 10 do
  234.         MoveWindowHorizontal(2, 5, False);
  235.     end;
  236.  
  237.     {Move the window over the old buffer, to restore TURBO PROFESSIONAL}
  238.     I := 1;
  239.     if not Keypressed then
  240.       while (I < 6) and (not Keypressed) do begin
  241.         for J := 1 to 13 do
  242.           MoveWindowVertical(1, 1, True);
  243.         MoveWindowHorizontal(1, 5, True);
  244.         for J := 1 to 13 do
  245.           MoveWindowVertical(1, 1, False);
  246.         MoveWindowHorizontal(1, 5, True);
  247.         I := Succ(I);
  248.       end;
  249.     for I := 1 to 13 do
  250.       MoveWindowVertical(1, 1, True);
  251.     if (not Keypressed) then
  252.       Delay(1500);
  253.   end;
  254.  
  255. begin
  256.   Turbo3StyleColors := True;
  257.   CheckBreak := False;
  258.  
  259.   {smooth scrolling on CGA's}
  260.   BiosScroll := False;
  261.  
  262.   {make sure we can run under a multitasking environment}
  263.   DetectMultitasking := True;
  264.   ReinitScreen;
  265.  
  266.   {turn blinking off to get more colors}
  267.   SetBlink(False);
  268.  
  269.   {save screen info}
  270.   X := WhereX;
  271.   Y := WhereY;
  272.   ScanLines := CursorTypeSL;
  273.   NeedDelay := (CurrentMode = 7) or not CheckSnow;
  274.  
  275.   if CurrentMode in [2, 3, 7] then begin
  276.     if (AllocateScreen(1, 80, 25) and AllocateScreen(2, 80, 25))
  277.     and (AllocateScreen(3, 30, 12) and AllocateScreen(4, 80, 25)) then begin
  278.  
  279.       {Make our background buffer}
  280.       CreateBackDisplay;
  281.  
  282.       {Make a little buffer}
  283.       CreateSmallWindow;
  284.  
  285.       {This selects one of our 80 x 25 RAM screens}
  286.       SelectScreen(4);
  287.  
  288.       {Copy the real screen to buffer number 4}
  289.       CopyScreen(0);
  290.  
  291.       {This selects our real video screen}
  292.       SelectScreen(0);
  293.  
  294.       {hide the cursor}
  295.       SetCursorSize($20, 0);
  296.  
  297.       {This loops forever until a key is pressed.}
  298.       repeat
  299.         {Copy our TURBO PROFESSIONAL background to it first}
  300.         CopyScreen(1);
  301.  
  302.         {This is so you can see it in monochrome as well as color}
  303.         Delay(1000);
  304.  
  305.         {Flash lots of small windows that say "FAST WINDOWS" on the screen.}
  306.         FlashSmallWindows;
  307.  
  308.         {Scroll original screen around.}
  309.         ScrollOrigScreen;
  310.  
  311.         {store the current screen to our background.}
  312.         SelectScreen(2);
  313.         CopyScreen(0);
  314.  
  315.         MoveSmallWindowAround;
  316.  
  317.       until Keypressed;
  318.  
  319.       {Clear out key from keyboard buffer.}
  320.       Key := ReadKeyWord;
  321.  
  322.       {Select the real screen}
  323.       SelectScreen(0);
  324.  
  325.       {Restore the original screen}
  326.       CopyScreen(4);
  327.       WindowAll;
  328.       Gotoxy(X, Y);
  329.       SetCursorSize(Hi(ScanLines), Lo(ScanLines));
  330.  
  331.       {Deallocate our buffers -- not really necessary for this program}
  332.       DeallocateScreen(1);
  333.       DeallocateScreen(2);
  334.       DeallocateScreen(3);
  335.       DeallocateScreen(4);
  336.     end;
  337.   end;
  338. end.
  339.