home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_PAS
/
ANIDIAL.ZIP
/
ANIMATED.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-01-15
|
5KB
|
195 lines
unit AnimateDialog;
interface
uses Objects,Dialogs,Views,Drivers,Crt,DOS;
const cmUpDateDialog=7863;
AniNone=0;
AniBounceBack=1;
AniBounceAround=2;
type
PAniItem=^TAniItem;
TAniItem=object(TObject)
P:PView;
Bounds,Original:TRect;
Param:Word;
DelayTime:Word;
LastUpdated:LongInt;
XStep,YStep:Integer;
constructor Init(TheView:PView; R:TRect; AParam,ADelay:Word;
AXStep,AYStep:Integer);
end; {object}
PAnimateDialog=^TAnimateDialog;
TAnimateDialog=object(TDialog)
AniList:PCollection;
UpDateOn,MouseDown:Boolean;
SpecialKey:Word;
SpecialView:PView;
constructor Init(var Bounds: TRect; ATitle: TTitleStr);
procedure UpDate;
procedure AdjustRect(var Bounds,R:TRect; Param:Word;
var XStep,YStep:Integer);
procedure HandleEvent(var Event:TEvent); virtual;
procedure RestoreViews;
function TimeToHunds:LongInt;
destructor Done; virtual;
end; {object}
implementation
{******}
constructor TAniItem.Init(TheView:PView; R:TRect; AParam,ADelay:Word;
AXStep,AYStep:Integer);
var H,M,S,HS:Word;
begin
inherited Init;
P:=TheView;
Bounds:=R;
Original.A.X:=P^.Origin.X; Original.A.Y:=P^.Origin.Y;
Original.B.X:=P^.Origin.X+P^.Size.X; Original.B.Y:=P^.Origin.Y+P^.Size.Y;
Param:=AParam;
DelayTime:=ADelay;
XStep:=AXStep;
YStep:=AYStep;
GetTime(H,M,S,HS); LastUpDated:=100*(60*(60*H+M)+S)+HS;
end;
{******}
constructor TAnimateDialog.Init(var Bounds:TRect; ATitle:TTitleStr);
begin
inherited Init(Bounds,ATitle);
AniList:=New(PCollection,Init(10,1));
UpDateOn:=True;
SpecialKey:=kbNoKey;
SpecialView:=nil;
end;
{******}
procedure TAnimateDialog.AdjustRect(var Bounds,R:TRect; Param:Word;
var XStep,YStep:Integer);
var HitTop,HitBottom,HitRight,HitLeft:Boolean;
Temp:TRect;
begin
Temp:=R;
HitTop:=R.A.Y<=Bounds.A.Y+abs(YStep)-1;
HitBottom:=R.B.Y>=Bounds.B.Y-abs(YStep)+1;
HitRight:=R.B.X>=Bounds.B.X-abs(XStep)+1;
HitLeft:=R.A.X<=Bounds.A.X+abs(XStep)-1;
case Param of
AniNone:
begin
if HitTop and (YStep<0) then R.Move(0,Bounds.B.Y-Bounds.A.Y-R.B.Y+R.A.Y);
if HitBottom and (YStep>0) then R.Move(0,Bounds.A.Y-Bounds.B.Y+R.B.Y-R.A.Y);
if HitRight and (XStep>0) then R.Move(Bounds.A.X-Bounds.B.X+R.B.X-R.A.X,0);
if HitLeft and (XStep<0) then R.Move(Bounds.B.X-Bounds.A.X+R.A.X-R.B.X,0);
end; {AniNone}
AniBounceBack:
begin
if (HitTop and (YStep<0)) or
(HitBottom and (YStep>0)) or
(HitRight and (XStep>0)) or
(HitLeft and (XStep<0))
then begin XStep:=-XStep; YStep:=-YStep; end;
end; {AniNone}
AniBounceAround:
begin
if (HitTop and (YStep<0)) or (HitBottom and (YStep>0))
then YStep:=-YStep;
if (HitRight and (XStep>0)) or (HitLeft and (XStep<0))
then XStep:=-XStep;
end; {AniNone}
end; {case}
if R.Equals(Temp) then R.Move(XStep,YStep);
end;
{******}
procedure TAnimateDialog.UpDate;
var Counter:Integer;
R:TRect;
CurrentTime:LongInt;
begin
if not UpdateOn or MouseDown then Exit;
CurrentTime:=TimeToHunds;
for Counter:=1 to AniList^.Count do
with PAniItem(AniList^.At(Counter-1))^ do {After Midnight!}
if (CurrentTime>=LastUpDated+DelayTime) or (CurrentTime<LastUpDated) then
begin
P^.GetBounds(R);
AdjustRect(Bounds,R,Param,XStep,YStep);
P^.Locate(R);
LastUpDated:=CurrentTime;
end; {if}
end;
{******}
procedure TAnimateDialog.RestoreViews;
var Counter:Integer;
begin
UpDateOn:=False;
for Counter:=1 to AniList^.Count do
with PAniItem(AniList^.At(Counter-1))^ do
P^.Locate(Original);
end;
{******}
procedure TAnimateDialog.HandleEvent(var Event:TEvent);
begin
MouseDown:=Event.What=evMouseDown;
if (Event.What=evKeyDown) and (Event.KeyCode=SpecialKey)
then begin UpDateOn:=not UpDateOn;
if not UpDateOn then RestoreViews; end;
if (SpecialView<>nil) and (Event.What=evMouseDown) and
(Event.Buttons=mbLeftButton) and (Event.Double) and
SpecialView^.MouseInView(MouseWhere) then
begin UpDateOn:=not UpDateOn;
if not UpDateOn then RestoreViews; end;
inherited HandleEvent(Event);
end;
{******}
function TAnimateDialog.TimeToHunds:LongInt;
var H,M,S,HS:Word;
begin
GetTime(H,M,S,HS);
TimeToHunds:=100*(60*(60*H+M)+S)+HS;
end;
{******}
destructor TAnimateDialog.Done;
begin
Dispose(AniList,Done);
inherited Done;
end;
{******}
end.