F
flmn
Unregistered / Unconfirmed
GUEST, unregistred user!
unit CoolProgressBar;
interface
uses
Windows, Messages,SysUtils, Classes, Controls,Graphics,Dialogs
,ExtCtrls;
type
TCoolProgressBar = class(TCustomControl)
private
{ Private declarations }
FTimer: TTimer;
FGradientStartColor:TColor;
FGradientEndColor:TColor;
FBorderColor:TColor;
FMax:Integer;
FMin:Integer;
FPosition:Integer;
procedure DrawGradientProgressImage(Canvas:TCanvas;ARect:TRect);
procedure OnTimer(Sender: TObject);
protected
{ Protected declarations }
procedure SetPosition(const Value:Integer);virtual;
procedure Paint;
override;
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
published
{ Published declarations }
property Position:Integer read FPosition write SetPosition ;
property Color;
property Font;
property Visible;
end;
implementation
//------------------------------------------------------------------------------
constructor TCoolProgressBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
do
ubleBuffered:=True;
FBorderColor:=$00E7976B;
FMax:=100;
FMin:=0;
FPosition:=20;
Color:=clWhite;
Height:=30;
Width:=300;
FGradientStartColor:=clWhite;
FGradientEndColor:=clBlue;
FTimer:=TTimer.Create(self);
FTimer.Enabled:=true;
FTimer.Interval:=10;
FTimer.OnTimer:=OnTimer;
end;
//------------------------------------------------------------------------------
destructor TCoolProgressBar.Destroy;
begin
FTimer.Free;
inherited;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.SetPosition(const Value:Integer);
begin
if(Value<>FPosition) then
begin
FPosition:=Value;
Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.Paint;
var
cR:TRect;
Percent:Integer;
begin
;
cR:=GetClientRect;
With Canvasdo
begin
Font:=Self.Font;
//draw Border
Brush.Color:=FBorderColor;
FrameRect(cR);
//Draw ProgressBar
try
Percent:=Trunc((FPosition-FMin) / (FMax-FMin) * 100.0);
except
Percent:=0;
end;
if Percent<0 then
Percent:=0;
if(FPosition>0) then
begin
if Percent>0 then
begin
if Position>FMax then
begin
InflateRect(cR,-2, -2);
cR.Left:=cR.Left+Round(cR.Right * (Percent-FMax) /100 )
end
else
begin
InflateRect(cR,-2, -2);
cR.Right:=cR.Left+Round(cR.Right * Percent /100 )
end;
DrawGradientProgressImage(Canvas,cR);
end;
end;
end;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.DrawGradientProgressImage(Canvas:TCanvas;ARect:TRect);
var
i:Integer;
f:Single;
begin
for i:=0 to (ARect.Right-ARect.Left)-1do
begin
f:=i/(ARect.Right-ARect.Left);
Canvas.Pen.Color:=rgb(Round(GetRValue(FGradientEndColor)*f+GetRValue(FGradientStartColor)*(1-f)),
Round(GetGValue(FGradientEndColor)*f+GetGValue(FGradientStartColor)*(1-f)),
Round(GetBValue(FGradientEndColor)*f+GetBValue(FGradientStartColor)*(1-f)));
Canvas.MoveTo(ARect.Left+i,ARect.Top);
Canvas.LineTo(ARect.Left+i,ARect.Top+(ARect.Bottom-ARect.Top));
end;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.OnTimer(Sender: TObject);
begin
if Position<FMax then
begin
Position:=Position+1;
end
else
begin
if Position>=(FMax*2) then
begin
Position:=0;
end
else
begin
Position:=Position+1;
end;
end;
end;
end.
interface
uses
Windows, Messages,SysUtils, Classes, Controls,Graphics,Dialogs
,ExtCtrls;
type
TCoolProgressBar = class(TCustomControl)
private
{ Private declarations }
FTimer: TTimer;
FGradientStartColor:TColor;
FGradientEndColor:TColor;
FBorderColor:TColor;
FMax:Integer;
FMin:Integer;
FPosition:Integer;
procedure DrawGradientProgressImage(Canvas:TCanvas;ARect:TRect);
procedure OnTimer(Sender: TObject);
protected
{ Protected declarations }
procedure SetPosition(const Value:Integer);virtual;
procedure Paint;
override;
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
published
{ Published declarations }
property Position:Integer read FPosition write SetPosition ;
property Color;
property Font;
property Visible;
end;
implementation
//------------------------------------------------------------------------------
constructor TCoolProgressBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
do
ubleBuffered:=True;
FBorderColor:=$00E7976B;
FMax:=100;
FMin:=0;
FPosition:=20;
Color:=clWhite;
Height:=30;
Width:=300;
FGradientStartColor:=clWhite;
FGradientEndColor:=clBlue;
FTimer:=TTimer.Create(self);
FTimer.Enabled:=true;
FTimer.Interval:=10;
FTimer.OnTimer:=OnTimer;
end;
//------------------------------------------------------------------------------
destructor TCoolProgressBar.Destroy;
begin
FTimer.Free;
inherited;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.SetPosition(const Value:Integer);
begin
if(Value<>FPosition) then
begin
FPosition:=Value;
Invalidate;
end;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.Paint;
var
cR:TRect;
Percent:Integer;
begin
;
cR:=GetClientRect;
With Canvasdo
begin
Font:=Self.Font;
//draw Border
Brush.Color:=FBorderColor;
FrameRect(cR);
//Draw ProgressBar
try
Percent:=Trunc((FPosition-FMin) / (FMax-FMin) * 100.0);
except
Percent:=0;
end;
if Percent<0 then
Percent:=0;
if(FPosition>0) then
begin
if Percent>0 then
begin
if Position>FMax then
begin
InflateRect(cR,-2, -2);
cR.Left:=cR.Left+Round(cR.Right * (Percent-FMax) /100 )
end
else
begin
InflateRect(cR,-2, -2);
cR.Right:=cR.Left+Round(cR.Right * Percent /100 )
end;
DrawGradientProgressImage(Canvas,cR);
end;
end;
end;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.DrawGradientProgressImage(Canvas:TCanvas;ARect:TRect);
var
i:Integer;
f:Single;
begin
for i:=0 to (ARect.Right-ARect.Left)-1do
begin
f:=i/(ARect.Right-ARect.Left);
Canvas.Pen.Color:=rgb(Round(GetRValue(FGradientEndColor)*f+GetRValue(FGradientStartColor)*(1-f)),
Round(GetGValue(FGradientEndColor)*f+GetGValue(FGradientStartColor)*(1-f)),
Round(GetBValue(FGradientEndColor)*f+GetBValue(FGradientStartColor)*(1-f)));
Canvas.MoveTo(ARect.Left+i,ARect.Top);
Canvas.LineTo(ARect.Left+i,ARect.Top+(ARect.Bottom-ARect.Top));
end;
end;
//------------------------------------------------------------------------------
procedure TCoolProgressBar.OnTimer(Sender: TObject);
begin
if Position<FMax then
begin
Position:=Position+1;
end
else
begin
if Position>=(FMax*2) then
begin
Position:=0;
end
else
begin
Position:=Position+1;
end;
end;
end;
end.