{$I KOLDEF.inc}
unit KOLQProgBar;
{
("`-''-/").___..--''"`-._
`6_ 6 ) `-. ( ).`-.__.`)
(_Y_.)' ._ ) `._ `. ``-..-'
_..`--'_..-_/ /--'_.' ,'
(il).-'' (li).' ((!.-'
QnnO Progress Bar (KOL)
The component that provides a set of various progress bars.
Ported to KOL © 2007 Danger
E-Mail: Certainly you can use the 'MCK mirror' provided with component to manage control properties at design time
(this still actually for Delphi versions earlier than Delphi 2005). In this case the visual component will
draws itself in design time with one of two available painting methods (see Readme.txt for details).
Note that control appearance at design time isn't depends on any of KOLCtrlWrapper routines and uses native VCL stuff.
| Known problem:
In the demo, the four vertical bars illustrate this. They should slide all together, but the first one lags, unless
|I add the Form.ProcessMessages like this:
!procedure TForm1.TrackBar2Scroll( Sender: PTrackbar; Code: Integer );
!begin
! Form.ProcessMessages; // Avoids the lag.
! QProgressBar7.Progress:= Sender.Position;
! QProgressBar8.Progress:= Sender.Position;
! QProgressBar9.Progress:= Sender.Position;
! QProgressBar10.Progress:= Sender.Position;
!end;
| }
interface
// ----------------------------------------------------------
uses
Windows, Messages, KOL;
// ----------------------------------------------------------
type
TQBarKind = ( bkFlat, bkCylinder );
{* Progress bar style. }
TQBarLook = ( blMetal, blGlass );
{* Progress bar appearance. }
TQBarOrientation = ( boHorizontal, boVertical );
{* Visual control orientation. }
TRGBArray = array[0..2] of Byte;
TCLRArray = array of TColor;
THLSRange = 0..240;
THLSRec = record // Color conversion -> RgbToHls and return
hue: THLSRange;
lum: THLSRange;
sat: THLSRange;
end;
TPosDescr = record // Bar description, rows or column ...
isInBlock: Boolean; // ... depending on orientation
blkLimit : Integer;
end;
// ----------------------------------------------------------
PQProgressBar = ^TQProgressBar;
TKOLQProgressBar = PQProgressBar;
TOnQProgressBar = procedure( Sender: PQProgressBar ) of object;
{* |Event to be called when Progress value is changed. }
PQDataObj = ^TQDataObj;
// ----------------------------------------------------------
TQDataObj = object( TObj )
fPosDescr : array of TPosDescr; // Bar description, blocks and spaces
fPixDescr : array of TCLRArray; // Bar description, pixels colors
fInactDescr : TCLRArray; // Bar description, inactive positions colors (if reversed gradient);
fBarKind : TQBarKind; // flat or rounded
fBarLook : TQBarLook; // blMetal or blGlass
fOrientation : TQBarOrientation; // horizontal or vertical
fInternalBorder, // space between the shape and the bar itself (1 or two pixels)
fUSefullDrawSpace, // size of the bar minus border
fBorderSize : Integer; // 2*(border+shape)
fHasShape : Boolean; // the surrounding line
fShapeClr : TColor; // above' color
fCorner : Integer; // shape' corner
fStartClr, // left (or bottom) color
fFinalClr, // right (or top) color
fBkgClr : TColor; // background color.
fMonoClr : Boolean; // True if StartColor = FinalColor.
fInvInactPos, // If true, and gradient, -> inverted;
fShowInactPos : Boolean; // Bars corresp. to positions above actual are drawn in fInactPosClr
fInactPosClr : TColor; // Above's color
fUSerPosPct : Real; // same as below, as percent, for displays
fUserPos, // value sent by user
fPosition, // above, normalized to width or height, and max;
fMinVisPos, // Minimum position to send to Paint(), to see at least one bar
fMaxPos : Integer; // max position as sent by user.
fByBlock, // if true, alternates colored and not colored pixels
fFullBlock : Boolean; // if true, blocks are drawn only when their max position is reached;
fSpaceSize, // space between two blocks
fBlockSize : Integer; // width (or height) of a block
fHideOnTerm : Boolean; // Hides the bar a tenth of a second after the painting of the last pixel row/column;
fCapAlign : TTextAlign; // left - right - centered
fCapPos : TPoint; // Internal - caption's top and left, based on canvas' current font
fHasCaption : Boolean; // Internal
fShowPosAsPct : Boolean; // If True, Hint and/or caption will show the value as a percent of the maximum.
fCaptionOvr : Boolean; // id. below;
fHintOvr : Boolean; // if True, each position changes => Hint <- fUserPos or fUSerPosPct dep. on ShowPosAsPct True/false;
fOnProgChange : TOnQProgressBar; // ProgressBar changing event
destructor Destroy; virtual;
end;
// ----------------------------------------------------------
TQProgressBar = object( TControl )
{* This object implements all functionality of component.
|TKOLQProgressBar is similar to a standard progress bar control and tries to emulate many of its features:
| Has the same properties. Obviously you can use Progress, MaxProgress and Caption derived from
PControl with some specific caused by the component. Here its short description:
| Progress is the position to be drawn on the bar. This should be the only thing changing, once setup is complete; MaxProgress is the maximum value you may send to the bar. It will be used to normalize positions sent compared to
|the size of the bar's drawspace; Caption - the control may display a basic caption. This caption's appearance depends on the bar canvas' font property.
It is neither XOR'ed nor anything like that: authors couldn't succeed at it. Moreover, despite a caption appears correctly within
horizontal bars, it certainly will give poor results within vertical bars as long as the caption stays horizontal.
|
|Copyright (C) 2004 Olivier Touzot "QnnO" and TQProgressBar contributors.
|It can be found on the web at http://mapage.noos.fr/qnno/delphi_en.htm.
|Copyright (C) 2007 Danger (danger@artline.kz).
|
|TKOLQProgressBar coming under the form of a KOL library unit, it can be simply used
by creating bars at runtime, setting the necessary properties:
!uses Windows, Messages, KOL, ..., KOLQProgBar;
! //...
!var aPBar : PQProgressBar;
! //...
!aPBar := NewQProgressBar( AParentForm );
!aPBar.Progress:= 55;
!aPBar. ...
|
It's latency in the drawing of the first of a series of bars. The laging one is the first one updated, if
|ShowInactivePos is set to True, and whatever are it's other characteristics (size, appearence, aso).
The problem appears only under XP (despite a high cpu speed). A workaround is to call
|Form.ProcessMessages just after the change of the position value of the first bar.
Can handle progress bar control's specific messages. You can send messages to control or receive from it (see the MSDN documentation for details) thus it behaves as an usual progress bar control: |
PBM_GETPOS retrieves the current position of the progress bar;
PBM_SETPOS sets the current position for a progress bar and redraws the bar to reflect the new position;
PBM_GETRANGE retrieves information about the current high and low limits of a given progress bar control;
PBM_SETRANGE sets the maximum value for a progress bar and redraws the bar to reflect the new range;
PBM_SETRANGE32 Sets the range of a progress bar control to a 32-bit value.