home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip: Shareware for Win 95
/
Chip-Shareware-Win95.bin
/
ostatni
/
delphi
/
delphi2
/
wowsrc.exe
/
BITMAP.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-03-28
|
5KB
|
135 lines
unit Bitmap;
interface
Uses
SysUtils, StdCtrls, WinTypes, WinProcs, Graphics, Classes, IniFiles;
Var
BitmapFile : string;
AnimatePic : Boolean;
ScreenWidth, ScreenHeight : Integer; { screen Width and Height }
xPicPos, yPicPos : Integer; { picture position }
xDirection, yDirection : Integer; { directions to move bitmap }
PicWidth, PicHeight : Integer; { width & height of picture }
Pic, PicHold : TBitmap; { Bitmap that is being displayed }
PicRect,
HoldRect,
ScrnRect,
OldScrnRect,
RectUnion,
RectUnionSize : TRect; { Rectangular area picture and
& new screen area displayed in. }
Procedure ReadPicDefaults; { Read any defaults }
Procedure InitPicture; { Startup }
Procedure MovePic; { Move the Message }
Procedure FreePic; { Free any resources }
implementation
Uses
Globals,
Ssave;
Procedure ReadPicDefaults; { Read Defaults }
Var
Ini : TiniFile;
Begin
Ini := TIniFile.Create('WOW.INI'); { Open the Ini File }
Apptitle := 'Bitmap'; { Set title }
BitmapFile := Ini.ReadString(Apptitle,
'Bitmap File Location',
#0); { bitmap filename }
Speed := Ini.ReadInteger(Apptitle,
'Speed',25); { Get the Speed }
AnimatePic := Boolean(Ini.ReadInteger(Apptitle,
'MoveOrPlot',1));{ Get the Speed }
Pwd := Ini.ReadString('Apptitle',
'Password',
''); { Read the Password, if any }
Ini.Free;
end;
procedure InitPicture;
begin
ReadPicDefaults; { Read the Default Settings }
Pic := TBitmap.Create; { Create the Bitmap }
PicHold := TBitmap.Create; { Create the Temp Hold Bitmap }
if FileExists(BitmapFile) then
Pic.LoadFromFile(BitmapFile)
else
Pic.Assign(Scrn.Image.Picture.Bitmap);
xPicPos := 0; { get starting x }
yPicPos := 0; { get starting y }
ScreenWidth := ScreenWd; { get Width }
ScreenHeight := ScreenHt; { Get Height }
PicWidth := Pic.Width;
PicHeight := Pic.Height;
PicRect := Rect(0, 0, PicWidth, PicHeight);
ScrnRect := Rect(xPicPos, yPicPos, xPicPos + PicWidth,
yPicPos + PicHeight);
xDirection := -1; { get speed: }
yDirection := -1; { xDirection, yDirection = 1 or -1 }
end;
Procedure FreePic;
Begin
Pic.Free; { Free the Bitmap }
PicHold.Free; { Free the Hold Bitmap }
end;
Procedure MovePic;
Begin
if AnimatePic then
begin { if Move }
if ((xPicPos <= 0) or (xPicPos + PicWidth >= ScreenWidth))
then xDirection := -xDirection; { bounce light at X edges }
if ((yPicPos <= 0) or (yPicPos + PicHeight >= ScreenHeight))
then yDirection := -yDirection; { bounce light at Y edges }
xPicPos := xPicPos + xDirection; { calculate new X position }
yPicPos := yPicPos + yDirection; { calculate new Y position }
OldScrnRect := ScrnRect;
ScrnRect := Rect(xPicPos, yPicPos, xPicPos + PicWidth, yPicPos + PicHeight);
(* (1) Caculate affected screen area. *)
UnionRect(RectUnion, OldScrnRect, ScrnRect);
(*RectUnion.left := (RectUnion.left - (RectUnion.left MOD 8));*)
RectUnionSize := Rect(0,
0,
RectUnion.right - RectUnion.left,
RectUnion.bottom - RectUnion.top);
(* (2) Copy affected area of screen to hold bitmap *)
PicHold.Width := RectUnionSize.right;
PicHold.Height := RectUnionSize.bottom;
PicHold.Canvas.CopyMode := cmSrcCopy;
PicHold.Canvas.CopyRect(RectUnionSize, Scrn.Canvas, RectUnion);
(* (3) Erase Bitmap in hold bitmap *)
PicHold.Canvas.CopyMode := cmBlackness;
PicHold.Canvas.CopyRect(RectUnionSize, PicHold.Canvas, PicRect);
(* (4) Copy Image to hold bitmap *)
PicHold.Canvas.CopyMode := cmSrcCopy;
HoldRect := Rect(PicRect.left + xDirection,
PicRect.Top + yDirection,
PicWidth,
PicHeight);
PicHold.Canvas.CopyRect(HoldRect, Pic.Canvas, PicRect);
(* (5) Copy New Image to screen *)
Scrn.Canvas.CopyMode := cmSrcCopy;
Scrn.Canvas.CopyRect(RectUnion, PicHold.Canvas, RectUnionSize);
Delay(Speed); { Delay a Bit }
end { if Move }
else
begin
xPicPos := random (ScreenWidth) + 1; { get starting x }
yPicPos := random (ScreenHeight) + 1; { get starting y }
ScrnRect := Rect(xPicPos, yPicPos, xPicPos + PicWidth, yPicPos + PicHeight);
Scrn.Canvas.CopyMode := cmSrcCopy;
Scrn.Canvas.CopyRect(ScrnRect, Pic.Canvas, PicRect);
Delay(Speed); { Delay a Bit }
end;
end;
end.