home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 March
/
Chip_1999-03_cd.bin
/
zkuste
/
delphi
/
D234
/
AR_COMPS.ZIP
/
CCLabel.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1999-01-24
|
4KB
|
153 lines
{##############################################################################
# Name: TCCLabel - Cycle Color Label #
# Author: Adrian Roberto Barbosa #
# Created: 19/01/1999 #
# UpDated: 20/01/1999 #
# Version: 1.1 alphabetagamma... #
# Description: This is a simple component derivated from a TLabel that #
# cycles their color using the RGB colors. #
# It has only two "new" properties: Active & Interval: #
# Active initiate or stops cycle, and #
# Interval sets the speed of the cycle. It's all! #
# Revisions: 1.0 beta Date: 11/11/1998 #
# 1.1 Date: 11/12/1998 #
# 1.2 Date: 12/02/1998 #
# Delphi: Delphi 2 (tested) or later (developed in Delphi 4) #
# Copyright: None!!! It's free, so comments are welcome... #
# Contact: adrianrb@netsite.com.br OR adrianrb@base.com.br #
##############################################################################}
unit CCLabel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TCCLabel = class(TLabel)
private
{ Private declarations }
Timer: TTimer;
fInterval: Integer;
fActive: Boolean;
protected
{ Protected declarations }
procedure SetInterval(Value: Integer);
procedure SetActive(Value: Boolean);
public
{ Public declarations }
constructor Create(AOwner: TComponent);override;
destructor Destroy;
procedure AtTime(Sender: TObject);
published
{ Published declarations }
property Active: Boolean read fActive write SetActive;
property Interval: Integer read fInterval write SetInterval;
end;
procedure Register;
implementation
var RedCount, GreenCount, BlueCount: Integer;
RedDir, GreenDir, BlueDir: Boolean;
procedure Register;
begin
RegisterComponents('Samples', [TCCLabel]);
end;
constructor TCCLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Timer := TTimer.Create(Self);
Randomize;
Font.Size := 26;
fInterval := 100;
RedCount := Random(255);
GreenCount := Random(255);
BlueCount := Random(255);
RedDir := Boolean(Random(2));
GreenDir := Boolean(Random(2));
BlueDir := Boolean(Random(2));
end;
destructor TCCLabel.Destroy;
begin
Timer.Free;
end;
procedure TCCLabel.SetActive(Value: Boolean);
begin
fActive := Value;
if Value then
Timer.Enabled := True
else
Timer.Enabled := False;
SetInterval(fInterval);
end;
procedure TCCLabel.SetInterval(Value: Integer);
begin
if Value > 0 then
begin
fInterval := Value;
if fActive then
begin
Timer.Interval := fInterval;
Timer.OnTimer := AtTime;
end;
end;
end;
procedure TCCLabel.AtTime(Sender: TObject);
begin
if RedDir then
Inc(RedCount,2)
else
Dec(RedCount,2);
if GreenDir then
Inc(GreenCount,1)
else
Dec(GreenCount,1);
if BlueDir then
Inc(BlueCount,3)
else
Dec(BlueCount,3);
if RedCount <= 0 then
begin
RedCount := 0;
RedDir := True;
end;
if RedCount >= 255 then
begin
RedCount := 255;
RedDir := False;
end;
if GreenCount <= 0 then
begin
GreenCount := 0;
GreenDir := True;
end;
if GreenCount >= 255 then
begin
GreenCount := 255;
GreenDir := False;
end;
if BlueCount <= 0 then
begin
BlueCount := 0;
BlueDir := True;
end;
if BlueCount >= 255 then
begin
BlueCount := 255;
BlueDir := False;
end;
Font.Color := RGB(RedCount,GreenCount,BlueCount);
end;
end.