|
|
@@ -20,44 +20,41 @@ unit BGRAFlashProgressBar;
|
|
|
interface
|
|
|
|
|
|
uses
|
|
|
- Classes, SysUtils, {$IFDEF FPC}LResources, LMessages,{$ENDIF} Types, Forms, Controls, Graphics,
|
|
|
+ Classes, SysUtils, {$IFDEF FPC}LResources, LMessages,{$ENDIF} Forms, Controls, Graphics,
|
|
|
{$IFNDEF FPC}Messages, Windows, BGRAGraphics, GraphType, FPImage, {$ENDIF}
|
|
|
- BCBaseCtrls, Dialogs, BGRABitmap, Math;
|
|
|
+ BCBaseCtrls, Dialogs, BGRABitmap, BGRADrawerFlashProgressBar;
|
|
|
|
|
|
type
|
|
|
-
|
|
|
- TBGRAProgressBarRedrawEvent = procedure(Sender: TObject; Bitmap: TBGRABitmap; xpos: integer) of object;
|
|
|
-
|
|
|
{ TBGRAFlashProgressBar }
|
|
|
|
|
|
TBGRAFlashProgressBar = class(TBGRAGraphicCtrl)
|
|
|
private
|
|
|
- FBackgroundRandomize: boolean;
|
|
|
- FBackgroundRandomizeMaxIntensity: word;
|
|
|
- FBackgroundRandomizeMinIntensity: word;
|
|
|
- FColor: TColor;
|
|
|
- FMaxValue: integer;
|
|
|
- FMinValue: integer;
|
|
|
- FValue: integer;
|
|
|
- FBmp: TBGRABitmap;
|
|
|
- FRandSeed: integer;
|
|
|
+ FBGRA: TBGRABitmap;
|
|
|
+ FDrawer: TBGRADrawerFlashProgressBar;
|
|
|
FOnRedraw: TBGRAProgressBarRedrawEvent;
|
|
|
- procedure SetFBackgroundRandomize(AValue: boolean);
|
|
|
- procedure SetFBackgroundRandomizeMaxIntensity(AValue: word);
|
|
|
- procedure SetFBackgroundRandomizeMinIntensity(AValue: word);
|
|
|
- procedure SetFColor(AValue: TColor);
|
|
|
+ function GetBackgroundColor: TColor;
|
|
|
+ function GetBackgroundRandomize: boolean;
|
|
|
+ function GetBackgroundRandomizeMaxIntensity: word;
|
|
|
+ function GetBackgroundRandomizeMinIntensity: word;
|
|
|
+ function GetBarColor: TColor;
|
|
|
+ function GetMaxValue: integer;
|
|
|
+ function GetMinValue: integer;
|
|
|
+ function GetValue: integer;
|
|
|
+ procedure OnChangeDrawer(Sender: TObject);
|
|
|
+ procedure SetBackgroundColor(AValue: TColor);
|
|
|
+ procedure SetBackgroundRandomize(AValue: boolean);
|
|
|
+ procedure SetBackgroundRandomizeMaxIntensity(AValue: word);
|
|
|
+ procedure SetBackgroundRandomizeMinIntensity(AValue: word);
|
|
|
+ procedure SetBarColor(AValue: TColor);
|
|
|
procedure SetMaxValue(const AValue: integer);
|
|
|
procedure SetMinValue(const AValue: integer);
|
|
|
procedure SetValue(const AValue: integer);
|
|
|
- { Private declarations }
|
|
|
protected
|
|
|
- { Protected declarations }
|
|
|
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
|
|
|
WithThemeSpace: boolean); override;
|
|
|
- procedure Paint; override;
|
|
|
procedure WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBkgnd{$ELSE}TWMEraseBkgnd{$ENDIF}); message {$IFDEF FPC}LM_ERASEBKGND{$ELSE}WM_ERASEBKGND{$ENDIF};
|
|
|
+ procedure Paint; override;
|
|
|
public
|
|
|
- { Public declarations }
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
destructor Destroy; override;
|
|
|
public
|
|
|
@@ -65,16 +62,12 @@ type
|
|
|
{$IFDEF FPC}
|
|
|
procedure SaveToFile(AFileName: string);
|
|
|
procedure LoadFromFile(AFileName: string);
|
|
|
- {$ENDIF}
|
|
|
procedure OnFindClass({%H-}Reader: TReader; const AClassName: string;
|
|
|
var ComponentClass: TComponentClass);
|
|
|
+ {$ENDIF}
|
|
|
published
|
|
|
- { Published declarations }
|
|
|
property Align;
|
|
|
property Anchors;
|
|
|
- property MinValue: integer Read FMinValue Write SetMinValue;
|
|
|
- property MaxValue: integer Read FMaxValue Write SetMaxValue;
|
|
|
- property Value: integer Read FValue Write SetValue;
|
|
|
property OnClick;
|
|
|
property OnMouseDown;
|
|
|
property OnMouseEnter;
|
|
|
@@ -84,19 +77,23 @@ type
|
|
|
property OnMouseWheel;
|
|
|
property OnMouseWheelUp;
|
|
|
property OnMouseWheelDown;
|
|
|
+ property MinValue: integer Read GetMinValue Write SetMinValue;
|
|
|
+ property MaxValue: integer Read GetMaxValue Write SetMaxValue;
|
|
|
+ property Value: integer Read GetValue Write SetValue;
|
|
|
+ property Color; deprecated 'User BarColor instead';
|
|
|
+ property BarColor: TColor read GetBarColor write SetBarColor;
|
|
|
+ property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor;
|
|
|
+ property BackgroundRandomizeMinIntensity: word read GetBackgroundRandomizeMinIntensity write SetBackgroundRandomizeMinIntensity;
|
|
|
+ property BackgroundRandomizeMaxIntensity: word read GetBackgroundRandomizeMaxIntensity write SetBackgroundRandomizeMaxIntensity;
|
|
|
+ property BackgroundRandomize: boolean read GetBackgroundRandomize write SetBackgroundRandomize;
|
|
|
property OnRedraw: TBGRAProgressBarRedrawEvent read FOnredraw write FOnRedraw;
|
|
|
- property Color;
|
|
|
- property BackgroundColor: TColor read FColor write SetFColor;
|
|
|
- property BackgroundRandomizeMinIntensity: word read FBackgroundRandomizeMinIntensity write SetFBackgroundRandomizeMinIntensity;
|
|
|
- property BackgroundRandomizeMaxIntensity: word read FBackgroundRandomizeMaxIntensity write SetFBackgroundRandomizeMaxIntensity;
|
|
|
- property BackgroundRandomize: boolean read FBackgroundRandomize write SetFBackgroundRandomize;
|
|
|
end;
|
|
|
|
|
|
{$IFDEF FPC}procedure Register;{$ENDIF}
|
|
|
|
|
|
implementation
|
|
|
|
|
|
-uses BGRABitmapTypes, BGRAGradients;
|
|
|
+uses BGRABitmapTypes;
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
procedure Register;
|
|
|
@@ -106,30 +103,14 @@ begin
|
|
|
end;
|
|
|
{$ENDIF}
|
|
|
|
|
|
-{ TBGRAFlashProgressBar }
|
|
|
-
|
|
|
procedure TBGRAFlashProgressBar.SetMinValue(const AValue: integer);
|
|
|
begin
|
|
|
- if FMinValue = AValue then
|
|
|
- exit;
|
|
|
- FMinValue := AValue;
|
|
|
- if FValue < FMinValue then
|
|
|
- FValue := FMinValue;
|
|
|
- if FMaxValue < FMinValue then
|
|
|
- FMaxValue := FMinValue;
|
|
|
- Invalidate;
|
|
|
+ FDrawer.MinValue := AValue;
|
|
|
end;
|
|
|
|
|
|
procedure TBGRAFlashProgressBar.SetValue(const AValue: integer);
|
|
|
begin
|
|
|
- if FValue = AValue then
|
|
|
- exit;
|
|
|
- FValue := AValue;
|
|
|
- if FValue < FMinValue then
|
|
|
- FValue := FMinValue;
|
|
|
- if FValue > FMaxValue then
|
|
|
- FValue := FMaxValue;
|
|
|
- Invalidate;
|
|
|
+ FDrawer.Value := AValue;
|
|
|
end;
|
|
|
|
|
|
{$hints off}
|
|
|
@@ -143,82 +124,13 @@ end;
|
|
|
{$hints on}
|
|
|
|
|
|
procedure TBGRAFlashProgressBar.Paint;
|
|
|
-var
|
|
|
- content: TRect;
|
|
|
- xpos, y, tx, ty: integer;
|
|
|
- bgColor: TBGRAPixel;
|
|
|
-
|
|
|
- function ApplyLightness(c: TBGRAPixel; lightness: word): TBGRAPixel;
|
|
|
- begin
|
|
|
- Result := GammaCompression(SetLightness(GammaExpansion(c), lightness));
|
|
|
- end;
|
|
|
-
|
|
|
- procedure DrawBar(bounds: TRect);
|
|
|
- var
|
|
|
- lCol: TBGRAPixel;
|
|
|
- begin
|
|
|
- lCol := Color;
|
|
|
-
|
|
|
- DoubleGradientAlphaFill(FBmp, bounds,
|
|
|
- ApplyLightness(lCol, 37000), ApplyLightness(lCol, 29000),
|
|
|
- ApplyLightness(lCol, 26000), ApplyLightness(lCol, 18000),
|
|
|
- gdVertical, gdVertical, gdVertical, 0.53);
|
|
|
-
|
|
|
- InflateRect(bounds, -1, -1);
|
|
|
-
|
|
|
- DoubleGradientAlphaFill(FBmp, bounds,
|
|
|
- ApplyLightness(lCol, 28000), ApplyLightness(lCol, 22000),
|
|
|
- ApplyLightness(lCol, 19000), ApplyLightness(lCol, 11000),
|
|
|
- gdVertical, gdVertical, gdVertical, 0.53);
|
|
|
- end;
|
|
|
-
|
|
|
begin
|
|
|
- tx := ClientWidth;
|
|
|
- ty := ClientHeight;
|
|
|
- if Assigned(FBmp) and ((FBmp.Width <> tx) or (FBmp.Height <> ty)) then
|
|
|
- FreeAndNil(FBmp);
|
|
|
-
|
|
|
- if not Assigned(FBmp) then
|
|
|
- FBmp := TBGRABitmap.Create(tx, ty)
|
|
|
- else
|
|
|
- FBmp.FillTransparent;
|
|
|
-
|
|
|
- FBmp.Rectangle(0, 0, tx, ty, BGRA(255, 255, 255, 6), BackgroundColor, dmSet);
|
|
|
- if (tx > 2) and (ty > 2) then
|
|
|
- FBmp.Rectangle(1, 1, tx - 1, ty - 1, BGRA(29, 29, 29), dmSet);
|
|
|
-
|
|
|
- if (tx > 4) and (ty > 4) then
|
|
|
- begin
|
|
|
- content := Rect(2, 2, tx - 2, ty - 2);
|
|
|
- randseed := FRandSeed;
|
|
|
- if BackgroundRandomize then
|
|
|
- for y := content.Top to content.Bottom - 1 do
|
|
|
- begin
|
|
|
- bgColor := BackgroundColor;
|
|
|
- bgColor.Intensity := RandomRange(BackgroundRandomizeMinIntensity, BackgroundRandomizeMaxIntensity);
|
|
|
- FBmp.HorizLine(content.Left, y, content.Right - 1, bgColor, dmSet);
|
|
|
- end;
|
|
|
- if tx >= 6 then
|
|
|
- FBmp.DrawVertLine(content.Right - 1, content.Top, content.Bottom - 1,
|
|
|
- BGRA(0, 0, 0, 32));
|
|
|
- if FMaxValue > FMinValue then
|
|
|
- begin
|
|
|
- xpos := round((FValue - FMinValue) / (FMaxValue - FMinValue) *
|
|
|
- (content.right - content.left)) + content.left;
|
|
|
- if xpos > content.left then
|
|
|
- begin
|
|
|
- DrawBar(rect(content.left, content.top, xpos, content.bottom));
|
|
|
- if xpos < content.right then
|
|
|
- begin
|
|
|
- FBmp.SetPixel(xpos, content.top, BGRA(62, 62, 62));
|
|
|
- FBmp.SetVertLine(xpos, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
|
|
|
- end;
|
|
|
- end;
|
|
|
- end;
|
|
|
- end;
|
|
|
+ if (ClientWidth <> FBGRA.Width) or (ClientHeight <> FBGRA.Height) then
|
|
|
+ FBGRA.SetSize(ClientWidth, ClientHeight);
|
|
|
+ FDrawer.Draw(FBGRA);
|
|
|
if Assigned(OnRedraw) then
|
|
|
- OnRedraw(Self, FBmp, {%H-}xpos);
|
|
|
- FBmp.Draw(Canvas, 0, 0, False);
|
|
|
+ OnRedraw(Self, FBGRA, {%H-}FDrawer.XPosition);
|
|
|
+ FBGRA.Draw(Canvas, 0, 0, False);
|
|
|
end;
|
|
|
|
|
|
{$hints off}
|
|
|
@@ -226,7 +138,6 @@ procedure TBGRAFlashProgressBar.WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBk
|
|
|
begin
|
|
|
//do nothing
|
|
|
end;
|
|
|
-
|
|
|
{$hints on}
|
|
|
|
|
|
constructor TBGRAFlashProgressBar.Create(AOwner: TComponent);
|
|
|
@@ -236,13 +147,19 @@ begin
|
|
|
with GetControlClassDefaultSize do
|
|
|
SetInitialBounds(0, 0, CX, 33);
|
|
|
|
|
|
- FMinValue := 0;
|
|
|
- FMaxValue := 100;
|
|
|
- FValue := 30;
|
|
|
- FBmp := nil;
|
|
|
- randomize;
|
|
|
- FRandSeed := randseed;
|
|
|
- Color := BGRA(102, 163, 226);
|
|
|
+ // Bitmap and Drawer
|
|
|
+ FBGRA := TBGRABitmap.Create(Width, Height);
|
|
|
+ FDrawer := TBGRADrawerFlashProgressBar.Create;
|
|
|
+ FDrawer.OnChange := OnChangeDrawer;
|
|
|
+ // Functionality
|
|
|
+ MinValue := 0;
|
|
|
+ MaxValue := 100;
|
|
|
+ Value := 30;
|
|
|
+ // Functionality and Style
|
|
|
+ Randomize;
|
|
|
+ FDrawer.RandSeed := RandSeed;
|
|
|
+ // Style
|
|
|
+ BarColor := BGRA(102, 163, 226);
|
|
|
BackgroundColor := BGRA(47,47,47);
|
|
|
BackgroundRandomize := True;
|
|
|
BackgroundRandomizeMinIntensity := 4000;
|
|
|
@@ -251,7 +168,8 @@ end;
|
|
|
|
|
|
destructor TBGRAFlashProgressBar.Destroy;
|
|
|
begin
|
|
|
- FreeAndNil(FBmp);
|
|
|
+ FreeAndNil(FBGRA);
|
|
|
+ FDrawer.Free;
|
|
|
inherited Destroy;
|
|
|
end;
|
|
|
{$IFDEF FPC}
|
|
|
@@ -280,7 +198,6 @@ begin
|
|
|
AStream.Free;
|
|
|
end;
|
|
|
end;
|
|
|
-{$ENDIF}
|
|
|
|
|
|
procedure TBGRAFlashProgressBar.OnFindClass(Reader: TReader;
|
|
|
const AClassName: string; var ComponentClass: TComponentClass);
|
|
|
@@ -288,47 +205,83 @@ begin
|
|
|
if CompareText(AClassName, 'TBGRAFlashProgressBar') = 0 then
|
|
|
ComponentClass := TBGRAFlashProgressBar;
|
|
|
end;
|
|
|
+{$ENDIF}
|
|
|
|
|
|
procedure TBGRAFlashProgressBar.SetMaxValue(const AValue: integer);
|
|
|
begin
|
|
|
- if FMaxValue = AValue then
|
|
|
- exit;
|
|
|
- FMaxValue := AValue;
|
|
|
- if FValue > FMaxValue then
|
|
|
- FValue := FMaxValue;
|
|
|
- if FMinValue > FMaxValue then
|
|
|
- FMinValue := FMaxValue;
|
|
|
- Invalidate;
|
|
|
+ FDrawer.MaxValue := AValue;
|
|
|
end;
|
|
|
|
|
|
-procedure TBGRAFlashProgressBar.SetFColor(AValue: TColor);
|
|
|
+procedure TBGRAFlashProgressBar.OnChangeDrawer(Sender: TObject);
|
|
|
begin
|
|
|
- if FColor=AValue then Exit;
|
|
|
- FColor:=AValue;
|
|
|
Invalidate;
|
|
|
end;
|
|
|
|
|
|
-procedure TBGRAFlashProgressBar.SetFBackgroundRandomize(AValue: boolean);
|
|
|
+function TBGRAFlashProgressBar.GetBackgroundColor: TColor;
|
|
|
begin
|
|
|
- if FBackgroundRandomize=AValue then Exit;
|
|
|
- FBackgroundRandomize:=AValue;
|
|
|
- Invalidate;
|
|
|
+ Result := FDrawer.BackgroundColor;
|
|
|
+end;
|
|
|
+
|
|
|
+function TBGRAFlashProgressBar.GetBackgroundRandomize: boolean;
|
|
|
+begin
|
|
|
+ Result := FDrawer.BackgroundRandomize;
|
|
|
+end;
|
|
|
+
|
|
|
+function TBGRAFlashProgressBar.GetBackgroundRandomizeMaxIntensity: word;
|
|
|
+begin
|
|
|
+ Result := FDrawer.BackgroundRandomizeMaxIntensity;
|
|
|
+end;
|
|
|
+
|
|
|
+function TBGRAFlashProgressBar.GetBackgroundRandomizeMinIntensity: word;
|
|
|
+begin
|
|
|
+ Result := FDrawer.BackgroundRandomizeMinIntensity;
|
|
|
+end;
|
|
|
+
|
|
|
+function TBGRAFlashProgressBar.GetBarColor: TColor;
|
|
|
+begin
|
|
|
+ Result := FDrawer.BarColor;
|
|
|
+end;
|
|
|
+
|
|
|
+function TBGRAFlashProgressBar.GetMaxValue: integer;
|
|
|
+begin
|
|
|
+ Result := FDrawer.MaxValue;
|
|
|
+end;
|
|
|
+
|
|
|
+function TBGRAFlashProgressBar.GetMinValue: integer;
|
|
|
+begin
|
|
|
+ Result := FDrawer.MinValue;
|
|
|
end;
|
|
|
|
|
|
-procedure TBGRAFlashProgressBar.SetFBackgroundRandomizeMaxIntensity(AValue: word
|
|
|
+function TBGRAFlashProgressBar.GetValue: integer;
|
|
|
+begin
|
|
|
+ Result := FDrawer.Value;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TBGRAFlashProgressBar.SetBackgroundColor(AValue: TColor);
|
|
|
+begin
|
|
|
+ FDrawer.BackgroundColor := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TBGRAFlashProgressBar.SetBackgroundRandomize(AValue: boolean);
|
|
|
+begin
|
|
|
+ FDrawer.BackgroundRandomize := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMaxIntensity(AValue: word
|
|
|
);
|
|
|
begin
|
|
|
- if FBackgroundRandomizeMaxIntensity=AValue then Exit;
|
|
|
- FBackgroundRandomizeMaxIntensity:=AValue;
|
|
|
- Invalidate;
|
|
|
+ FDrawer.BackgroundRandomizeMaxIntensity := AValue;
|
|
|
end;
|
|
|
|
|
|
-procedure TBGRAFlashProgressBar.SetFBackgroundRandomizeMinIntensity(AValue: word
|
|
|
+procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMinIntensity(AValue: word
|
|
|
);
|
|
|
begin
|
|
|
- if FBackgroundRandomizeMinIntensity=AValue then Exit;
|
|
|
- FBackgroundRandomizeMinIntensity:=AValue;
|
|
|
- Invalidate;
|
|
|
+ FDrawer.BackgroundRandomizeMinIntensity := AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TBGRAFlashProgressBar.SetBarColor(AValue: TColor);
|
|
|
+begin
|
|
|
+ FDrawer.BarColor := AValue;
|
|
|
end;
|
|
|
|
|
|
end.
|