destructor TRLed.Destroy;
begin
inherited Destroy;
end;
function TRLed.inHi;
begin
result:=i<Round(BarCount/100*Pro);
end;
function TRLed.InPos(i: Integer): boolean;
var bTemp:byte;
begin
bTemp:=round((FPosition / FMaxValue) * 100);
result:=i>BarCount-Round(BarCount/100*bTemp);
end;
procedure TRLed.Paint;
var TB:TBitmap;
i:word;
begin
TB:=TBitmap.create;
tb.Width:=Width;
tb.Height:=Height;
tb.Canvas.Brush.Color:=BAckColor;
tb.Canvas.FillRect(rect(0,0,Width,Height));
RecalcBarCount;
case FOrientation of
trVertical:begin
for i:=1 to BarCount do
begin
if inHi(i,FBreakPos) then if not InPos(i) then tb.Canvas.Brush.Color:=BlendCOlor(ColorHi)
else tb.Canvas.Brush.Color:=ColorHi
else if not InPos(i) then tb.Canvas.Brush.Color:=BlendCOlor(ColorLow)
else tb.Canvas.Brush.Color:=ColorLow;
tb.Canvas.FillRect(rect(2,(i-1)*barSize+2,width-2,(i-1)*barSize+BarSize));
end;
end;
trHorizontal:begin
for i:=1 to BarCount do
begin
if inHi(BarCount-i,FBreakPos) then if not InPos(BarCount-i+1) then tb.Canvas.Brush.Color:=BlendCOlor(ColorHi)
else tb.Canvas.Brush.Color:=ColorHi
else if not InPos(BarCount-i+1) then tb.Canvas.Brush.Color:=BlendCOlor(ColorLow)
else tb.Canvas.Brush.Color:=ColorLow;
tb.Canvas.FillRect(rect((i-1)*barSize+2,2,(i-1)*barSize+BarSize,height-2));
end;
end;
end;
Canvas.CopyRect(Rect(0,0,width,height),tb.canvas,Rect(0,0,width,height));
TB.free;
end;
procedure TRLed.RecalcBarCount;
begin
if FOrientation=trVertical then
BarCount:=(Height-2) div (FBarSize)
else
BarCount:=(Width-2) div (FBarSize)
end;
procedure TRLed.SetBackColor(const Value: TColor);
begin
FBackColor := Value;
paint;
end;
procedure TRLed.SetBarSize(const Value: word);
begin
if (FBarSize <> Value) and
((FOrientation=trVertical)
and
(Value<Height-4))
or
((FOrientation=trHorizontal)
and
(Value<Width-4))
then
begin
FBarSize := Value;
RecalcBarCount;
Paint;
end;
end;
procedure TRLed.SetBreakPos(const Value: byte);
begin
if not Value>100 then
begin
FBreakPos := Value;
Paint;
end;
end;
procedure TRLed.SetColorHi(const Value: TColor);
begin
FColorHi := Value;
Paint;
end;
procedure TRLed.SetColorLow(const Value: TColor);
begin
if FColorLow <>Value then
begin
FColorLow := Value;
Paint;
end;
end;
procedure TRLed.SetMaxValue(const Value: Longint);
begin
if FMaxValue <> Value then
begin
FMaxValue := Value;
Paint;
end;
end;
procedure TRLed.SetOrientation(const Value: TTrackBarOrientation);
begin
if FOrientation <> Value then
begin
FOrientation := Value;
//Change Orientation
if ComponentState * [csLoading, csUpdating] = [] then
SetBounds(Left, Top, Height, Width);
Paint;
end;
end;
procedure TRLed.SetPosition(const Value: longint);
begin
if Value<=FMaxValue then
begin
FPosition := Value;
Paint;
end;
end;