home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / obero / oberon-a / examples / libraries / intuition / doublebuffer.mod < prev    next >
Encoding:
Text File  |  1994-08-08  |  5.7 KB  |  214 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: DoubleBuffer.mod $
  4.   Description: Port of doublebuffer.c from the RKM:Libraries.
  5.  
  6.                Shows the use of a double-buffered screen.
  7.  
  8.    Created by: fjc (Frank Copeland)
  9.     $Revision: 1.2 $
  10.       $Author: fjc $
  11.         $Date: 1994/08/08 16:55:25 $
  12.  
  13.   Copyright © 1994, Frank Copeland.
  14.   This example program is part of Oberon-A.
  15.   See Oberon-A.doc for conditions of use and distribution.
  16.  
  17.   Log entries are at the end of the file.
  18.  
  19. *************************************************************************)
  20.  
  21. MODULE DoubleBuffer;
  22.  
  23. (*
  24. ** $C= CaseChk       $I= IndexChk  $L= LongAdr   $N= NilChk
  25. ** $P- PortableCode  $R= RangeChk  $S= StackChk  $T= TypeChk
  26. ** $V= OvflChk       $Z= ZeroVars
  27. *)
  28.  
  29. IMPORT SYS := SYSTEM, gfx := Graphics, i := Intuition;
  30.  
  31. CONST
  32.   VersionTag = "\0$VER: DoubleBuffer 1.0 (16.6.94)\r\n";
  33.   VersionStr = "DoubleBuffer 1.0 (16 Jun 1994)\r\n";
  34.   CopyrightStr = "Copyright © 1994 Frank Copeland\n\n";
  35.  
  36. CONST
  37.  
  38.   (* characteristics of the screen *)
  39.   scrWidth = 320;
  40.   scrHeight = 200;
  41.   scrDepth = 2;
  42.  
  43. VAR
  44.  
  45.   myBitMaps : ARRAY 2 OF gfx.BitMapPtr;
  46.  
  47. (*------------------------------------*)
  48. PROCEDURE FreePlanes ( bitMap : gfx.BitMapPtr );
  49.  
  50.   VAR planeNum : INTEGER;
  51.  
  52. BEGIN (* FreePlanes *)
  53.   FOR planeNum := 0 TO scrDepth - 1 DO
  54.     IF bitMap.planes [planeNum] # NIL THEN
  55.       gfx.base.FreeRaster (bitMap.planes [planeNum], scrWidth, scrHeight)
  56.     END
  57.   END
  58. END FreePlanes;
  59.  
  60. (*------------------------------------*)
  61. PROCEDURE SetupPlanes ( bitMap : gfx.BitMapPtr ) : BOOLEAN;
  62.  
  63.   VAR planeNum : INTEGER;
  64.  
  65. BEGIN (* SetupPlanes *)
  66.   FOR planeNum := 0 TO scrDepth - 1 DO
  67.     bitMap.planes [planeNum] :=
  68.       gfx.base.AllocRaster (scrWidth, scrHeight);
  69.     IF bitMap.planes [planeNum] # NIL THEN
  70.       gfx.base.BltClear
  71.         ( bitMap.planes [planeNum], (scrWidth DIV 8) * scrHeight, {0} )
  72.     ELSE
  73.       FreePlanes (bitMap);
  74.       RETURN FALSE
  75.     END
  76.   END;
  77.   RETURN TRUE
  78. END SetupPlanes;
  79.  
  80. (*------------------------------------*)
  81. PROCEDURE FreeBitMaps ();
  82.  
  83. BEGIN (* FreeBitMaps *)
  84.   FreePlanes (myBitMaps [0]); myBitMaps [0] := NIL;
  85.   FreePlanes (myBitMaps [1]); myBitMaps [0] := NIL
  86. END FreeBitMaps;
  87.  
  88. (*------------------------------------*)
  89. PROCEDURE SetupBitMaps () : BOOLEAN;
  90.  
  91. BEGIN (* SetupBitMaps *)
  92.   NEW (myBitMaps [0]);
  93.   NEW (myBitMaps [1]);
  94.   gfx.base.InitBitMap (myBitMaps [0]^, scrDepth, scrWidth, scrHeight);
  95.   gfx.base.InitBitMap (myBitMaps [1]^, scrDepth, scrWidth, scrHeight);
  96.   IF SetupPlanes (myBitMaps [0]) THEN
  97.     RETURN SetupPlanes (myBitMaps [1])
  98.   END;
  99.   RETURN FALSE
  100. END SetupBitMaps;
  101.  
  102. (*------------------------------------*)
  103. PROCEDURE RunDBuf (screen : i.ScreenPtr);
  104.  
  105.   VAR
  106.     ktr, xpos, ypos : INTEGER;
  107.     toggleFrame : INTEGER;
  108.  
  109. BEGIN (* RunDBuf *)
  110.   toggleFrame := 0;
  111.   gfx.base.SetAPen (SYS.ADR (screen.rastPort), 1);
  112.   FOR ktr := 1 TO 199 DO
  113.     (* Calculate a position to place the object, these
  114.     ** calculations insure the object will stay on the screen
  115.     ** given the range of ktr and the size of the object,
  116.     *)
  117.     xpos := ktr;
  118.     IF (ktr MOD 100) >= 50 THEN
  119.       ypos := 50 - (ktr MOD 50)
  120.     ELSE
  121.       ypos := ktr MOD 50
  122.     END;
  123.  
  124.     (* switch the bitmap so that we are drawing into the correct place *)
  125.     screen.rastPort.bitMap := myBitMaps [toggleFrame];
  126.     screen.viewPort.rasInfo.bitMap := myBitMaps [toggleFrame];
  127.  
  128.     (* Draw the objects.
  129.     ** Here we clear the old frame and draw a simple filled rectangle.
  130.     *)
  131.     gfx.base.SetRast (SYS.ADR (screen.rastPort), 0);
  132.     gfx.base.RectFill
  133.       (SYS.ADR (screen.rastPort), xpos, ypos, xpos+100, ypos+100);
  134.  
  135.     (* update the physical display to match the newly drawn bitmap *)
  136.     i.base.MakeScreen (screen); (* Tell Intuition to do its stuff.      *)
  137.     i.base.RethinkDisplay (); (* Intuition compatible MrgCop & LoadView *)
  138.                               (*               it also does a WaitTOF() *)
  139.  
  140.     IF toggleFrame = 0 THEN toggleFrame := 1
  141.     ELSE toggleFrame := 0
  142.     END
  143.   END
  144. END RunDBuf;
  145.  
  146. (*------------------------------------*)
  147. PROCEDURE* Cleanup ();
  148.  
  149. BEGIN (* Cleanup *)
  150.   IF myBitMaps [0] # NIL THEN FreePlanes (myBitMaps [0]) END;
  151.   IF myBitMaps [1] # NIL THEN FreePlanes (myBitMaps [1]) END;
  152. END Cleanup;
  153.  
  154. (*------------------------------------*)
  155. PROCEDURE Init ();
  156.  
  157. BEGIN (* Init *)
  158.   myBitMaps [0] := NIL; myBitMaps [1] := NIL;
  159.   SYS.SETCLEANUP (Cleanup);
  160. END Init;
  161.  
  162. (*------------------------------------*)
  163. PROCEDURE Main ();
  164.  
  165.   VAR
  166.     screen : i.ScreenPtr;
  167.     myNewScreen : i.NewScreen;
  168.  
  169. BEGIN (* Main *)
  170.   IF SetupBitMaps() THEN
  171.     (* Open a simple quiet screen that is using the first
  172.     ** of the two bitmaps.
  173.     *)
  174.     myNewScreen.leftEdge := 0;
  175.     myNewScreen.topEdge := 0;
  176.     myNewScreen.width := scrWidth;
  177.     myNewScreen.height := scrHeight;
  178.     myNewScreen.depth := scrDepth;
  179.     myNewScreen.detailPen := 0;
  180.     myNewScreen.blockPen := 1;
  181.     myNewScreen.viewModes := {gfx.hires};
  182.     myNewScreen.type := i.customScreen + {i.customBitmap, i.screenQuiet};
  183.     myNewScreen.font := NIL;
  184.     myNewScreen.defaultTitle := NIL;
  185.     myNewScreen.gadgets := NIL;
  186.     myNewScreen.customBitMap := myBitMaps [0];
  187.  
  188.     screen := i.base.OpenScreen (myNewScreen);
  189.     IF screen # NIL THEN
  190.       (* Indicate that the rastport is double buffered *)
  191.       screen.rastPort.flags := {gfx.dBuffer};
  192.       RunDBuf (screen);
  193.       i.base.OldCloseScreen (screen)
  194.     END;
  195.   END;
  196. END Main;
  197.  
  198. BEGIN (* DoubleBuffer *)
  199.   Init ();
  200.   Main ();
  201. END DoubleBuffer.
  202.  
  203. (*************************************************************************
  204.  
  205.   $Log: DoubleBuffer.mod $
  206.   Revision 1.2  1994/08/08  16:55:25  fjc
  207.   Release 1.4
  208.  
  209.   Revision 1.1  1994/06/17  18:17:33  fjc
  210.   Initial revision
  211.  
  212. *************************************************************************)
  213.  
  214.