Hello. I recently made a custom progress bar, but it's kinda slow and I
figure I'd need to use assembly to speed it up. Even if assembly is used i'm
not sure if it'd do any good, what slows it down is the drawing of the
progress bar and the caption on it. During the increment phase, it has to
redraw all the graphics on the control. I had to turn on double buffering to
reduce flicker. I did a bench mark with a TProgressBar and my
TtsxProgressBar and the timing ratio is 2:27 / 2:43 so mine was 16 seconds
slower, at other tests it would be over a minute slower. But I think the
trade off is having a visual on the progress bar which works very well for
my project (the user can turn it off). Do you have any suggestions on how I
can increase performance? In my SetPos and StepIt code I call Repaint after
i do the calculation.
Here is my Paint code. the Gradient function DrawImage paints a gradient
effect if turned on. It's rather fast since it uses math but I havnt noticed
any performance degrade between turning gradient on and off.
procedure TtsxProgressBar.Paint;
var
cx, cy, p: integer;
r: TRect;
t: string;
begin
Inherited Paint;
with Canvas do begin
// draw outer border
Pen.Color:= RGB(150, 107, 48);
MoveTo(0, Height - 2);
LineTo(0, 0);
LineTo(Width - 2, 0);
Pen.Color:= RGB(245, 241, 224);
MoveTo(Width - 1, 0);
LineTo(Width - 1, Height - 1);
LineTo(0, Height - 1);
// draw progress
p:= 0;
r.Left:= 3;
r.Top:= 2;
r.Right:= Width - 3;
r.Bottom:= Height - 3;
case FOrientation of
pbHorizontal:
p:= Round((FPos - FMin) / (FMax - FMin) * (r.Right - r.Left) +
r.Left);
pbVertical:
p:= Round((FPos - FMax) / (FMin - FMax) * (r.Bottom - r.Top) +
r.Top);
end;
if Gradient.Apply then
Gradient.DrawImage(Canvas, r)
else begin
Brush.Color:= FPColor;
FillRect(r);
end;
case FOrientation of
pbHorizontal: r.Left:= p;
pbVertical: r.Bottom:= p;
end;
Brush.Color:= Self.Color;
FillRect(r);
// draw caption
t:= Caption;
if FShowValue then
t:= t + ' : ' + Format('%d / %d', [FPos, FMax]);
Brush.Style:= bsClear;
cx:= Width div 2 - TextWidth(t) div 2;
cy:= Height div 2 - TextHeight(t) div 2;
if (not Enabled) then begin
Font.Color:= RGB(245, 241, 244);
cx:= cx + 1;
cy:= cy + 1;
end
else
Font.Color:= Self.Font.Color;
TextOut(cx, cy, t);
if (not Enabled) then begin
cx:= cx - 1;
cy:= cy - 1;
Font.Color:= RGB(150, 107, 48);
TextOut(cx, cy, t);
end;
Brush.Style:= bsSolid;
end;
end;
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk