home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
new
/
dev
/
obero
/
oberon-a
/
examples
/
libraries
/
intuition
/
doublebuffer.mod
< prev
next >
Wrap
Text File
|
1995-07-02
|
5KB
|
195 lines
(*************************************************************************
$RCSfile: DoubleBuffer.mod $
Description: Port of doublebuffer.c from the RKM:Libraries.
Shows the use of a double-buffered screen.
Created by: fjc (Frank Copeland)
$Revision: 1.4 $
$Author: fjc $
$Date: 1995/01/25 23:52:19 $
Copyright © 1994, Frank Copeland.
This example program is part of Oberon-A.
See Oberon-A.doc for conditions of use and distribution.
*************************************************************************)
<* STANDARD- *>
MODULE DoubleBuffer;
IMPORT SYS := SYSTEM, Kernel, gfx := Graphics, i := Intuition;
CONST
VersionTag = "$VER: DoubleBuffer 1.2 (19.9.94)\r\n";
VersionStr = "DoubleBuffer 1.2 (19.9.94)\r\n";
CopyrightStr = "Copyright © 1994 Frank Copeland\n\n";
CONST
(* characteristics of the screen *)
scrWidth = 320;
scrHeight = 200;
scrDepth = 2;
VAR
myBitMaps : ARRAY 2 OF gfx.BitMapPtr;
(*------------------------------------*)
PROCEDURE FreePlanes ( bitMap : gfx.BitMapPtr );
VAR planeNum : INTEGER;
BEGIN (* FreePlanes *)
FOR planeNum := 0 TO scrDepth - 1 DO
IF bitMap.planes [planeNum] # NIL THEN
gfx.FreeRaster (bitMap.planes [planeNum], scrWidth, scrHeight)
END
END
END FreePlanes;
(*------------------------------------*)
PROCEDURE SetupPlanes ( bitMap : gfx.BitMapPtr ) : BOOLEAN;
VAR planeNum : INTEGER;
BEGIN (* SetupPlanes *)
FOR planeNum := 0 TO scrDepth - 1 DO
bitMap.planes [planeNum] := gfx.AllocRaster (scrWidth, scrHeight);
IF bitMap.planes [planeNum] # NIL THEN
gfx.BltClear
( bitMap.planes [planeNum], (scrWidth DIV 8) * scrHeight, {0} )
ELSE
FreePlanes (bitMap);
RETURN FALSE
END
END;
RETURN TRUE
END SetupPlanes;
(*------------------------------------*)
PROCEDURE FreeBitMaps ();
BEGIN (* FreeBitMaps *)
FreePlanes (myBitMaps [0]); myBitMaps [0] := NIL;
FreePlanes (myBitMaps [1]); myBitMaps [0] := NIL
END FreeBitMaps;
(*------------------------------------*)
PROCEDURE SetupBitMaps () : BOOLEAN;
BEGIN (* SetupBitMaps *)
NEW (myBitMaps [0]);
NEW (myBitMaps [1]);
gfx.InitBitMap (myBitMaps [0]^, scrDepth, scrWidth, scrHeight);
gfx.InitBitMap (myBitMaps [1]^, scrDepth, scrWidth, scrHeight);
IF SetupPlanes (myBitMaps [0]) THEN
RETURN SetupPlanes (myBitMaps [1])
END;
RETURN FALSE
END SetupBitMaps;
(*------------------------------------*)
PROCEDURE RunDBuf (screen : i.ScreenPtr);
VAR
ktr, xpos, ypos : INTEGER;
toggleFrame : INTEGER;
BEGIN (* RunDBuf *)
toggleFrame := 0;
gfx.SetAPen (SYS.ADR (screen.rastPort), 1);
FOR ktr := 1 TO 199 DO
(* Calculate a position to place the object, these
** calculations insure the object will stay on the screen
** given the range of ktr and the size of the object,
*)
xpos := ktr;
IF (ktr MOD 100) >= 50 THEN
ypos := 50 - (ktr MOD 50)
ELSE
ypos := ktr MOD 50
END;
(* switch the bitmap so that we are drawing into the correct place *)
screen.rastPort.bitMap := myBitMaps [toggleFrame];
screen.viewPort.rasInfo.bitMap := myBitMaps [toggleFrame];
(* Draw the objects.
** Here we clear the old frame and draw a simple filled rectangle.
*)
gfx.SetRast (SYS.ADR (screen.rastPort), 0);
gfx.RectFill
(SYS.ADR (screen.rastPort), xpos, ypos, xpos+100, ypos+100);
(* update the physical display to match the newly drawn bitmap *)
i.MakeScreen (screen); (* Tell Intuition to do its stuff. *)
i.RethinkDisplay (); (* Intuition compatible MrgCop & LoadView *)
(* it also does a WaitTOF() *)
IF toggleFrame = 0 THEN toggleFrame := 1
ELSE toggleFrame := 0
END
END
END RunDBuf;
(*------------------------------------*)
PROCEDURE* Cleanup (VAR rc : LONGINT);
BEGIN (* Cleanup *)
IF myBitMaps [0] # NIL THEN FreePlanes (myBitMaps [0]) END;
IF myBitMaps [1] # NIL THEN FreePlanes (myBitMaps [1]) END;
END Cleanup;
(*------------------------------------*)
PROCEDURE Init ();
BEGIN (* Init *)
myBitMaps [0] := NIL; myBitMaps [1] := NIL;
Kernel.SetCleanup (Cleanup);
END Init;
(*------------------------------------*)
PROCEDURE Main ();
VAR
screen : i.ScreenPtr;
myNewScreen : i.NewScreen;
BEGIN (* Main *)
IF SetupBitMaps() THEN
(* Open a simple quiet screen that is using the first
** of the two bitmaps.
*)
myNewScreen.leftEdge := 0;
myNewScreen.topEdge := 0;
myNewScreen.width := scrWidth;
myNewScreen.height := scrHeight;
myNewScreen.depth := scrDepth;
myNewScreen.detailPen := 0;
myNewScreen.blockPen := 1;
myNewScreen.viewModes := {gfx.hires};
myNewScreen.type := i.customScreen + {i.customBitmap, i.screenQuiet};
myNewScreen.font := NIL;
myNewScreen.defaultTitle := NIL;
myNewScreen.gadgets := NIL;
myNewScreen.customBitMap := myBitMaps [0];
screen := i.OpenScreen (myNewScreen);
IF screen # NIL THEN
(* Indicate that the rastport is double buffered *)
screen.rastPort.flags := {gfx.dBuffer};
RunDBuf (screen);
i.OldCloseScreen (screen)
END;
END;
END Main;
BEGIN (* DoubleBuffer *)
Init ();
Main ();
END DoubleBuffer.