home *** CD-ROM | disk | FTP | other *** search
/ PC World 1999 February / PCWorld_1999-02_cd.bin / temacd / HotKeys / AniIcon.pas < prev    next >
Pascal/Delphi Source File  |  1997-04-11  |  2KB  |  88 lines

  1. unit AniIcon;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, AniIcons;
  7.  
  8. type
  9.   TRepeatCount = 0..MAXINT;
  10.  
  11.   TAnimatedIcon = class(TComponent)
  12.   private
  13.     FAnimation  : TAnimatedIcons;
  14.     FPlaying    : Boolean;
  15.     FRepeatCount: TRepeatCount;
  16.     FOnNewFrame : TNewFrameEvent;
  17.     FOnStopped  : TNotifyEvent;
  18.     { Private declarations }
  19.     procedure SetAnimation(Value: TAnimatedIcons);
  20.     procedure SetPlaying(Value: Boolean);
  21.   protected
  22.     procedure NewFrame(Sender: TObject; Frame: Integer);
  23.     procedure Stopped(Sender: TObject);
  24.     procedure Loaded; override;
  25.     { Protected declarations }
  26.   public
  27.     constructor Create(AOwner: TComponent); override;
  28.     destructor Destroy; override;
  29.     { Public declarations }
  30.   published
  31.     property Playing    : Boolean        read FPlaying     write SetPlaying default False;
  32.     property Animation  : TAnimatedIcons read FAnimation   write SetAnimation;
  33.     property RepeatCount: TRepeatCount   read FRepeatCount write FRepeatCount default 0;
  34.     property OnNewFrame : TNewFrameEvent read FOnNewFrame  write FOnNewFrame;
  35.     property OnStopped  : TNotifyEvent   read FOnStopped   write FOnStopped;
  36.     { Published declarations }
  37.   end;
  38.  
  39. implementation
  40.  
  41. constructor TAnimatedIcon.Create(AOwner: TComponent);
  42. begin
  43.   inherited Create(AOwner);
  44.   FAnimation := TAnimatedIcons.Create(is32x32);
  45.   FAnimation.OnStopped := Stopped;
  46.   FAnimation.OnNewFrame := NewFrame;
  47.   FRepeatCount := 0;
  48.   FPlaying := False;
  49. end;
  50.  
  51. destructor TAnimatedIcon.Destroy;
  52. begin
  53.   FAnimation.Free;
  54.   inherited Destroy;
  55. end;
  56.  
  57. procedure TAnimatedIcon.Loaded;
  58. begin
  59.   inherited Loaded;
  60.   if FPlaying and not Animation.Playing then Animation.Play(RepeatCount);
  61. end;
  62.  
  63. procedure TAnimatedIcon.SetAnimation(Value: TAnimatedIcons);
  64. begin
  65.   FAnimation.Assign(Value);
  66. end;
  67.  
  68. procedure TAnimatedIcon.SetPlaying(Value: Boolean);
  69. begin
  70.   if FPlaying<>Value then
  71.    begin
  72.      FPlaying := Value;
  73.      if FPlaying then Animation.Play(RepeatCount) else Animation.Stop;
  74.    end;
  75. end;
  76.  
  77. procedure TAnimatedIcon.Stopped(Sender: TObject);
  78. begin
  79.   if Assigned(FOnStopped) then FOnStopped(Self);
  80. end;
  81.  
  82. procedure TAnimatedIcon.NewFrame(Sender: TObject; Frame: Integer);
  83. begin
  84.   if Assigned(FOnNewFrame) then FOnNewFrame(Self, Frame);
  85. end;
  86.  
  87. end.
  88.