VrScanner.pas
上传用户:hbszzs
上传日期:2008-08-20
资源大小:628k
文件大小:21k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*****************************************************}
  2. {                                                     }
  3. {     Varian Component Workshop                       }
  4. {                                                     }
  5. {     Varian Software NL (c) 1996-2000                }
  6. {     All Rights Reserved                             }
  7. {                                                     }
  8. {*****************************************************}
  9. unit VrScanner;
  10. {$I VRLIB.INC}
  11. interface
  12. uses
  13.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  14.   VrTypes, VrClasses, VrControls, VrSysUtils, VrThreads;
  15. type
  16.   TVrLedStyle = (lsRaised, lsLowered, lsNone, lsFlat);
  17.   TVrLedGroup = class(TVrGraphicImageControl)
  18.   private
  19.     FSpacing: Integer;
  20.     FStyle: TVrLedStyle;
  21.     FPlainColors: Boolean;
  22.     FColorWidth: Integer;
  23.     FOnChange: TNotifyEvent;
  24.     Collection: TVrCollection;
  25.     procedure SetSpacing(Value: Integer);
  26.     procedure SetStyle(Value: TVrLedStyle);
  27.     procedure SetPlainColors(Value: Boolean);
  28.     procedure SetColorWidth(Value: Integer);
  29.   protected
  30.     procedure Change; dynamic;
  31.   public
  32.     constructor Create(AOwner: TComponent); override;
  33.     destructor Destroy; override;
  34.     property Spacing: Integer read FSpacing write SetSpacing default 2;
  35.     property Style: TVrLedStyle read FStyle write SetStyle default lsRaised;
  36.     property PlainColors: Boolean read FPlainColors write SetPlainColors default false;
  37.     property ColorWidth: Integer read FColorWidth write SetColorWidth default 1;
  38.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  39.   end;
  40.   TVrScanDirection = (sdBoth, sdLeftRight, sdRightLeft);
  41.   TVrScanner = class;
  42.   TVrScannerLed = class(TVrCollectionItem)
  43.   private
  44.     FActive: Boolean;
  45.     procedure SetActive(Value: Boolean);
  46.   public
  47.     constructor Create(Collection: TVrCollection); override;
  48.     property Active: Boolean read FActive write SetActive;
  49.   end;
  50.   TVrScannerLeds = class(TVrCollection)
  51.   private
  52.     FOwner: TVrScanner;
  53.     function GetItem(Index: Integer): TVrScannerLed;
  54.   protected
  55.     procedure Update(Item: TVrCollectionItem); override;
  56.   public
  57.     constructor Create(AOwner: TVrScanner);
  58.     property Items[Index: Integer]: TVrScannerLed read GetItem;
  59.   end;
  60.   TVrScanner = class(TVrLedGroup)
  61.   private
  62.     FLeds: Integer;
  63.     FPalette: TVrPalette;
  64.     FActive: Boolean;
  65.     FPosition: Integer;
  66.     FDirection: TVrScanDirection;
  67.     FThreaded: Boolean;
  68.     ToLeft: Boolean;
  69.     PrevPosition: Integer;
  70.     FTimer: TVrTimer;
  71.     function GetTimeInterval: Integer;
  72.     procedure SetLeds(Value: Integer);
  73.     procedure SetActive(Value: Boolean);
  74.     procedure SetTimeInterval(Value: Integer);
  75.     procedure SetPosition(Value: Integer);
  76.     procedure SetPalette(Value: TVrPalette);
  77.     procedure SetThreaded(Value: Boolean);
  78.     procedure TimerEvent(Sender: TObject);
  79.     procedure PaletteModified(Sender: TObject);
  80.   protected
  81.     procedure CreateItems;
  82.     procedure UpdateLed(Index: Integer);
  83.     procedure UpdateLeds;
  84.     procedure UpdateLedState;
  85.     procedure Paint; override;
  86.     procedure GetItemRect(Index: Integer; var R: TRect);
  87.   public
  88.     constructor Create(AOwner: TComponent); override;
  89.     destructor Destroy; override;
  90.   published
  91.     property Threaded: Boolean read FThreaded write SetThreaded default True;
  92.     property Leds: Integer read FLeds write SetLeds default 7;
  93.     property Palette: TVrPalette read FPalette write SetPalette;
  94.     property Active: Boolean read FActive write SetActive default false;
  95.     property Direction: TVrScanDirection read FDirection write FDirection default sdBoth;
  96.     property TimeInterval: Integer read GetTimeInterval write SetTimeInterval default 100;
  97.     property Position: Integer read FPosition write SetPosition default 0;
  98.     property Spacing;
  99.     property Style;
  100.     property PlainColors;
  101.     property ColorWidth;
  102.     property Transparent default false;
  103.     property OnChange;
  104.     property Align;
  105. {$IFDEF VER110}
  106.     property Anchors;
  107.     property Constraints;
  108. {$ENDIF}
  109.     property Color;
  110.     property DragCursor;
  111. {$IFDEF VER110}
  112.     property DragKind;
  113. {$ENDIF}
  114.     property DragMode;
  115.     property Hint;
  116.     property ParentColor;
  117.     property ParentShowHint;
  118.     property PopupMenu;
  119.     property ShowHint;
  120.     property Visible;
  121.     property OnClick;
  122. {$IFDEF VER130}
  123.     property OnContextPopup;
  124. {$ENDIF}    
  125.     property OnDblClick;
  126.     property OnDragDrop;
  127.     property OnDragOver;
  128. {$IFDEF VER110}
  129.     property OnEndDock;
  130. {$ENDIF}
  131.     property OnEndDrag;
  132.     property OnMouseDown;
  133.     property OnMouseMove;
  134.     property OnMouseUp;
  135. {$IFDEF VER110}
  136.     property OnStartDock;
  137. {$ENDIF}
  138.     property OnStartDrag;
  139.   end;
  140.   TVrIndicator = class;
  141.   TVrIndicatorLed = class(TVrScannerLed)
  142.   private
  143.     FColorLow: TColor;
  144.     FColorHigh: TColor;
  145.   public
  146.     constructor Create(Collection: TVrCollection); override;
  147.     property ColorLow: TColor read FColorLow write FColorLow;
  148.     property ColorHigh: TColor read FColorHigh write FColorHigh;
  149.   end;
  150.   TVrIndicatorLeds = class(TVrCollection)
  151.   private
  152.     FOwner: TVrIndicator;
  153.     function GetItem(Index: Integer): TVrIndicatorLed;
  154.   protected
  155.     procedure Update(Item: TVrCollectionItem); override;
  156.   public
  157.     constructor Create(AOwner: TVrIndicator);
  158.     property Items[Index: Integer]: TVrIndicatorLed read GetItem;
  159.   end;
  160.   TVrIndicator = class(TVrLedGroup)
  161.   private
  162.     FPosition: Integer;
  163.     FMaxValue: Integer;
  164.     FMinValue: Integer;
  165.     FLedsLow: Integer;
  166.     FLedsMedium: Integer;
  167.     FLedsHigh: Integer;
  168.     FPalette1: TVrPalette;
  169.     FPalette2: TVrPalette;
  170.     FPalette3: TVrPalette;
  171.     FStep: Integer;
  172.     Leds: Integer;
  173.     function GetPercentDone: Longint;
  174.     procedure SetPosition(Value: Integer);
  175.     procedure SetMaxValue(Value: Integer);
  176.     procedure SetMinValue(Value: Integer);
  177.     procedure SetLedsLow(Value: Integer);
  178.     procedure SetLedsMedium(Value: Integer);
  179.     procedure SetLedsHigh(Value: Integer);
  180.     procedure SetPalette1(Value: TVrPalette);
  181.     procedure SetPalette2(Value: TVrPalette);
  182.     procedure SetPalette3(Value: TVrPalette);
  183.     procedure PaletteModified(Sender: TObject);
  184.   protected
  185.     procedure CreateItems;
  186.     procedure UpdateLed(Index: Integer);
  187.     procedure UpdateLeds;
  188.     procedure UpdatePosition;
  189.     procedure Paint; override;
  190.     procedure GetItemRect(Index: Integer; var R: TRect);
  191.   public
  192.     constructor Create(AOwner: TComponent); override;
  193.     procedure StepIt;
  194.     procedure StepBy(Delta: Integer);
  195.     property PercentDone: Longint read GetPercentDone;
  196.   published
  197.     property Palette1: TVrPalette read FPalette1 write SetPalette1;
  198.     property Palette2: TVrPalette read FPalette2 write SetPalette2;
  199.     property Palette3: TVrPalette read FPalette3 write SetPalette3;
  200.     property MaxValue: Integer read FMaxValue write SetMaxValue default 100;
  201.     property MinValue: Integer read FMinValue write SetMinValue default 0;
  202.     property Position: Integer read FPosition write SetPosition default 0;
  203.     property LedsLow: Integer read FLedsLow write SetLedsLow default 3;
  204.     property LedsMedium: Integer read FLedsMedium write SetLedsMedium default 2;
  205.     property LedsHigh: Integer read FLedsHigh write SetLedsHigh default 2;
  206.     property Step: Integer read FStep write FStep default 10;
  207.     property ColorWidth;
  208.     property Spacing;
  209.     property Style;
  210.     property PlainColors;
  211.     property Transparent default false;
  212.     property OnChange;
  213.     property Align;
  214. {$IFDEF VER110}
  215.     property Anchors;
  216.     property Constraints;
  217. {$ENDIF}
  218.     property Color;
  219.     property DragCursor;
  220. {$IFDEF VER110}
  221.     property DragKind;
  222. {$ENDIF}
  223.     property DragMode;
  224.     property Hint;
  225.     property ParentColor;
  226.     property ParentShowHint;
  227.     property PopupMenu;
  228.     property ShowHint;
  229.     property Visible;
  230.     property OnClick;
  231. {$IFDEF VER130}
  232.     property OnContextPopup;
  233. {$ENDIF}    
  234.     property OnDblClick;
  235.     property OnDragDrop;
  236.     property OnDragOver;
  237. {$IFDEF VER110}
  238.     property OnEndDock;
  239. {$ENDIF}
  240.     property OnEndDrag;
  241.     property OnMouseDown;
  242.     property OnMouseMove;
  243.     property OnMouseUp;
  244. {$IFDEF VER110}
  245.     property OnStartDock;
  246. {$ENDIF}
  247.     property OnStartDrag;
  248.   end;
  249. implementation
  250. { TVrLedGroup }
  251. constructor TVrLedGroup.Create(AOwner: TComponent);
  252. begin
  253.   inherited Create(AOwner);
  254.   ControlStyle := ControlStyle + [csOpaque];
  255.   Width := 250;
  256.   Height := 9;
  257.   FSpacing := 2;
  258.   FStyle := lsRaised;
  259.   FPlainColors := false;
  260.   FColorWidth := 1;
  261. end;
  262. destructor TVrLedGroup.Destroy;
  263. begin
  264.   Collection.Free;
  265.   inherited Destroy;
  266. end;
  267. procedure TVrLedGroup.SetSpacing(Value: Integer);
  268. begin
  269.   if FSpacing <> Value then
  270.   begin
  271.     FSpacing := Value;
  272.     UpdateControlCanvas;
  273.   end;
  274. end;
  275. procedure TVrLedGroup.SetStyle(Value: TVrLedStyle);
  276. begin
  277.   if FStyle <> Value then
  278.   begin
  279.     FStyle := Value;
  280.     UpdateControlCanvas;
  281.   end;
  282. end;
  283. procedure TVrLedGroup.SetPlainColors(Value: Boolean);
  284. begin
  285.   if FPlainColors <> Value then
  286.   begin
  287.     FPlainColors := Value;
  288.     UpdateControlCanvas;
  289.   end;
  290. end;
  291. procedure TVrLedGroup.SetColorWidth(Value: Integer);
  292. begin
  293.   if (FColorWidth <> Value) and (Value > 0) then
  294.   begin
  295.     FColorWidth := Value;
  296.     UpdateControlCanvas;
  297.   end;
  298. end;
  299. procedure TVrLedGroup.Change;
  300. begin
  301.   if Assigned(FOnChange) then
  302.     FOnChange(Self);
  303. end;
  304. { TVrScannerLed }
  305. constructor TVrScannerLed.Create(Collection: TVrCollection);
  306. begin
  307.   FActive := false;
  308.   inherited Create(Collection);
  309. end;
  310. procedure TVrScannerLed.SetActive(Value: Boolean);
  311. begin
  312.   if FActive <> Value then
  313.   begin
  314.     FActive := Value;
  315.     Changed(false);
  316.   end;
  317. end;
  318. { VrScannerLeds }
  319. constructor TVrScannerLeds.Create(AOwner: TVrScanner);
  320. begin
  321.   inherited Create;
  322.   FOwner := AOwner;
  323. end;
  324. function TVrScannerLeds.GetItem(Index: Integer): TVrScannerLed;
  325. begin
  326.   Result := TVrScannerLed(inherited Items[Index]);
  327. end;
  328. procedure TVrScannerLeds.Update(Item: TVrCollectionItem);
  329. begin
  330.   if Item <> nil then
  331.     FOwner.UpdateLed(Item.Index) else
  332.     FOwner.UpdateLeds;
  333. end;
  334. { TVrScanner }
  335. constructor TVrScanner.Create(AOwner: TComponent);
  336. begin
  337.   inherited Create(AOwner);
  338.   FLeds := 7;
  339.   FPalette := TVrPalette.Create;
  340.   FPalette.OnChange := PaletteModified;
  341.   FActive := false;
  342.   FPosition := -1;
  343.   FDirection := sdBoth;
  344.   FThreaded := True;
  345.   FTimer := TVrTimer.Create(Self);
  346.   FTimer.Enabled := false;
  347.   FTimer.Interval := 100;
  348.   FTimer.OnTimer := TimerEvent;
  349.   Collection := TVrScannerLeds.Create(Self);
  350.   CreateItems;
  351. end;
  352. destructor TVrScanner.Destroy;
  353. begin
  354.   FPalette.Free;
  355.   FTimer.Free;
  356.   inherited Destroy;
  357. end;
  358. procedure TVrScanner.CreateItems;
  359. var
  360.   I: Integer;
  361. begin
  362.   Collection.Clear;
  363.   for I := 0 to Pred(FLeds) do
  364.     TVrScannerLed.Create(Collection);
  365. end;
  366. procedure TVrScanner.PaletteModified(Sender: TObject);
  367. begin
  368.   UpdateControlCanvas;
  369. end;
  370. procedure TVrScanner.UpdateLed(Index: Integer);
  371. var
  372.   R: TRect;
  373.   AColor: TColor;
  374.   Item: TVrScannerLed;
  375. begin
  376.   Item := TVrScannerLeds(Collection).Items[Index];
  377.   AColor := FPalette.Colors[ord(Item.Active)];
  378.   GetItemRect(Index, R);
  379.   if not FPlainColors then
  380.     DrawGradientExt(DestCanvas, R, AColor, clBlack, gdUpDown, ColorWidth)
  381.   else
  382.   begin
  383.     DestCanvas.Brush.Color := AColor;
  384.     DestCanvas.FillRect(R);
  385.   end;
  386.   case FStyle of
  387.     lsRaised:
  388.       begin
  389.         DrawOutline3D(DestCanvas, R, clBlack, clBlack, 1);
  390.         if not FPlainColors then
  391.           DrawOutline3D(DestCanvas, R, AColor, clBlack, 1)
  392.         else
  393.         begin
  394.           if not Item.Active then
  395.             DrawOutline3D(DestCanvas, R, FPalette.High, FPalette.Low, 1)
  396.           else DrawOutline3D(DestCanvas, R, clBtnHighlight, FPalette.High, 1);
  397.         end;
  398.       end;
  399.     lsLowered:
  400.       begin
  401.         DrawOutline3D(DestCanvas, R, clBtnShadow, clBtnHighlight, 1);
  402.         DrawOutline3D(DestCanvas, R, clBlack, clBlack, 1);
  403.       end;
  404.     lsFlat:
  405.       DrawOutline3D(DestCanvas, R, clBlack, clBlack, 1);
  406.     lsNone:;
  407.   end;
  408. end;
  409. procedure TVrScanner.UpdateLeds;
  410. var
  411.   I: Integer;
  412. begin
  413.   for I := 0 to Collection.Count - 1 do UpdateLed(I);
  414. end;
  415. procedure TVrScanner.Paint;
  416. begin
  417.   ClearBitmapCanvas;
  418.   DestCanvas := BitmapCanvas;
  419.   try
  420.     UpdateLeds;
  421.     inherited Paint;
  422.   finally
  423.     DestCanvas := Self.Canvas;
  424.   end;
  425. end;
  426. procedure TVrScanner.GetItemRect(Index: Integer; var R: TRect);
  427. var
  428.   X, W, Gap: Integer;
  429. begin
  430.   Gap := Pred(FLeds) * FSpacing;
  431.   W := (Width - Gap) div FLeds;
  432.   X := (FLeds * W) + Gap;
  433.   X := (Width - X) div 2;
  434.   Inc(X, (W * Index) + (FSpacing * Index));
  435.   R := Bounds(X, 0, W, Height);
  436. end;
  437. procedure TVrScanner.SetLeds(Value: Integer);
  438. begin
  439.   if FLeds <> Value then
  440.   begin
  441.     FLeds := Value;
  442.     CreateItems;
  443.     FPosition := -1;
  444.     PrevPosition := -1;
  445.     UpdateControlCanvas;
  446.   end;
  447. end;
  448. function TVrScanner.GetTimeInterval: Integer;
  449. begin
  450.   Result := FTimer.Interval;
  451. end;
  452. procedure TVrScanner.SetActive(Value: Boolean);
  453. begin
  454.   if FActive <> Value then
  455.   begin
  456.     FActive := Value;
  457.     if Designing then Exit;
  458.     FTimer.Enabled := FActive;
  459.   end;
  460. end;
  461. procedure TVrScanner.SetTimeInterval(Value: Integer);
  462. begin
  463.   FTimer.Interval := Value;
  464. end;
  465. procedure TVrScanner.SetPosition(Value: Integer);
  466. begin
  467.   if FPosition <> Value then
  468.   begin
  469.     FPosition := Value;
  470.     UpdateLedState;
  471.     Change;
  472.   end;
  473. end;
  474. procedure TVrScanner.SetThreaded(Value: Boolean);
  475. begin
  476.   if FThreaded <> Value then
  477.   begin
  478.     FThreaded := Value;
  479.     if Value then FTimer.TimerType := ttThread
  480.     else FTimer.TimerType := ttSystem;
  481.   end;
  482. end;
  483. procedure TVrScanner.SetPalette(Value: TVrPalette);
  484. begin
  485.   FPalette.Assign(Value);
  486. end;
  487. procedure TVrScanner.UpdateLedState;
  488. begin
  489.   AdjustRange(FPosition, -1, Pred(FLeds));
  490.   if PrevPosition <> -1 then
  491.     TVrscannerLeds(Collection).Items[PrevPosition].Active := False;
  492.   if FPosition <> -1 then
  493.     TVrscannerLeds(Collection).Items[Position].Active := True;
  494.   PrevPosition := FPosition;
  495. end;
  496. procedure TVrScanner.TimerEvent(Sender: TObject);
  497. begin
  498.   case FDirection of
  499.     sdBoth:
  500.       begin
  501.         if (ToLeft) then
  502.         begin
  503.           if (FPosition > 0) then Position := Position - 1
  504.           else ToLeft := false;
  505.         end
  506.        else
  507.         begin
  508.           if (FPosition < FLeds - 1) then Position := Position + 1
  509.           else ToLeft := true;
  510.         end;
  511.       end;
  512.     sdLeftRight:
  513.       begin
  514.         if (FPosition < FLeds - 1) then
  515.           Position := Position + 1 else Position := 0;
  516.       end;
  517.     sdRightLeft:
  518.       begin
  519.         if FPosition > 0 then Position := Position - 1
  520.         else Position := FLeds - 1;
  521.       end;
  522.   end;
  523. end;
  524. { TVrIndicatorLed }
  525. constructor TVrIndicatorLed.Create(Collection: TVrCollection);
  526. begin
  527.   FColorLow := clGreen;
  528.   FColorHigh := clLime;
  529.   inherited Create(Collection);
  530. end;
  531. { TVrIndicatorLeds }
  532. constructor TVrIndicatorLeds.Create(AOwner: TVrIndicator);
  533. begin
  534.   inherited Create;
  535.   FOwner := AOwner;
  536. end;
  537. function TVrIndicatorLeds.GetItem(Index: Integer): TVrIndicatorLed;
  538. begin
  539.   Result := TVrIndicatorLed(inherited Items[Index]);
  540. end;
  541. procedure TVrIndicatorLeds.Update(Item: TVrCollectionItem);
  542. begin
  543.   if Item <> nil then
  544.     FOwner.UpdateLed(Item.Index) else
  545.     FOwner.UpdateLeds;
  546. end;
  547. { TVrIndicator }
  548. constructor TVrIndicator.Create(AOwner: TComponent);
  549. begin
  550.   inherited Create(AOwner);
  551.   FMaxValue := 100;
  552.   FMinValue := 0;
  553.   FLedsLow := 3;
  554.   FLedsMedium := 2;
  555.   FLedsHigh := 2;
  556.   FPosition := 0;
  557.   FStep := 10;
  558.   FPalette1 := TVrPalette.Create;
  559.   FPalette1.OnChange := PaletteModified;
  560.   FPalette2 := TVrPalette.Create;
  561.   with FPalette2 do
  562.   begin
  563.     Low := clOlive;
  564.     High := clYellow;
  565.     OnChange := PaletteModified;
  566.   end;
  567.   FPalette3 := TVrPalette.Create;
  568.   with FPalette3 do
  569.   begin
  570.     Low := clMaroon;
  571.     High := clRed;
  572.     OnChange := PaletteModified;
  573.   end;
  574.   Collection := TVrIndicatorLeds.Create(Self);
  575.   CreateItems;
  576. end;
  577. procedure TVrIndicator.CreateItems;
  578. var
  579.   I: Integer;
  580.   Item: TVrIndicatorLed;
  581. begin
  582.   Collection.Clear;
  583.   Leds := FLedsLow + FLedsMedium + FLedsHigh;
  584.   for I := 0 to Leds - 1 do
  585.   begin
  586.     Item := TVrIndicatorLed.Create(Collection);
  587.     if I < FLedsLow then
  588.     begin
  589.       Item.ColorLow := Palette1[0];
  590.       Item.ColorHigh := Palette1[1];
  591.     end
  592.     else
  593.     if I < FLedsLow + FLedsMedium then
  594.     begin
  595.       Item.ColorLow := Palette2[0];
  596.       Item.ColorHigh := Palette2[1];
  597.     end
  598.     else
  599.     begin
  600.       Item.ColorLow := Palette3[0];
  601.       Item.ColorHigh := Palette3[1];
  602.     end;
  603.   end;
  604. end;
  605. procedure TVrIndicator.PaletteModified(Sender: TObject);
  606. begin
  607.   CreateItems;
  608.   UpdateControlCanvas;
  609. end;
  610. procedure TVrIndicator.SetPalette1(Value: TVrPalette);
  611. begin
  612.   FPalette1.Assign(Value);
  613. end;
  614. procedure TVrIndicator.SetPalette2(Value: TVrPalette);
  615. begin
  616.   FPalette2.Assign(Value);
  617. end;
  618. procedure TVrIndicator.SetPalette3(Value: TVrPalette);
  619. begin
  620.   FPalette3.Assign(Value);
  621. end;
  622. procedure TVrIndicator.UpdatePosition;
  623. var
  624.   I, Ticks: Integer;
  625. begin
  626.   AdjustRange(FPosition, FMinValue, FMaxValue);
  627.   Ticks := SolveForX(PercentDone, Leds);
  628.   for I := 0 to Leds - 1 do
  629.     TVrIndicatorLeds(Collection).Items[I].Active := Succ(I) <= Ticks;
  630. end;
  631. procedure TVrIndicator.SetPosition(Value: Integer);
  632. begin
  633.   if FPosition <> Value then
  634.   begin
  635.     FPosition := Value;
  636.     UpdatePosition;
  637.     Change;
  638.   end;
  639. end;
  640. procedure TVrIndicator.SetMaxValue(Value: Integer);
  641. begin
  642.   if (FMaxValue <> Value) and (Value > FMinValue) then
  643.   begin
  644.     FMaxValue := Value;
  645.     UpdatePosition;
  646.   end;
  647. end;
  648. procedure TVrIndicator.SetMinValue(Value: Integer);
  649. begin
  650.   if (FMinValue <> Value) and (Value < FMaxValue) then
  651.   begin
  652.     FMinValue := Value;
  653.     UpdatePosition;
  654.   end;
  655. end;
  656. procedure TVrIndicator.SetLedsLow(Value: Integer);
  657. begin
  658.   if FLedsLow <> Value then
  659.   begin
  660.     FLedsLow := Value;
  661.     CreateItems;
  662.     UpdateControlCanvas;
  663.   end;
  664. end;
  665. procedure TVrIndicator.SetLedsMedium(Value: Integer);
  666. begin
  667.   if FLedsMedium <> Value then
  668.   begin
  669.     FLedsMedium := Value;
  670.     CreateItems;
  671.     UpdateControlCanvas;
  672.   end;
  673. end;
  674. procedure TVrIndicator.SetLedsHigh(Value: Integer);
  675. begin
  676.   if FLedsHigh <> Value then
  677.   begin
  678.     FLedsHigh := Value;
  679.     CreateItems;
  680.     UpdateControlCanvas;
  681.   end;
  682. end;
  683. procedure TVrIndicator.StepIt;
  684. begin
  685.   Position := Position + FStep;
  686. end;
  687. procedure TVrIndicator.StepBy(Delta: Integer);
  688. begin
  689.   Position := Position + Delta;
  690. end;
  691. function TVrIndicator.GetPercentDone: Longint;
  692. begin
  693.   Result := SolveForY(FPosition - FMinValue, FMaxValue - FMinValue);
  694. end;
  695. procedure TVrIndicator.UpdateLed(Index: Integer);
  696. var
  697.   R: TRect;
  698.   AColor: TColor;
  699.   Item: TVrIndicatorLed;
  700. begin
  701.   Item := TVrIndicatorLeds(Collection).Items[Index];
  702.   if Item.Active then AColor := Item.ColorHigh
  703.                  else AColor := Item.ColorLow;
  704.   GetItemRect(Index, R);
  705.   if not FPlainColors then
  706.     DrawGradientExt(DestCanvas, R, AColor, clBlack, gdUpDown, ColorWidth)
  707.   else
  708.   begin
  709.     DestCanvas.Brush.Color := AColor;
  710.     DestCanvas.FillRect(R);
  711.   end;
  712.   case FStyle of
  713.     lsRaised:
  714.       begin
  715.         DrawOutline3D(DestCanvas, R, clBlack, clBlack, 1);
  716.         if not FPlainColors then
  717.           DrawOutline3D(DestCanvas, R, AColor, clBlack, 1)
  718.         else
  719.         begin
  720.           if not Item.Active then
  721.             DrawOutline3D(DestCanvas, R, Item.ColorHigh, Item.ColorLow, 1)
  722.           else DrawOutline3D(DestCanvas, R, clBtnHighlight, Item.ColorHigh, 1);
  723.         end;
  724.       end;
  725.     lsLowered:
  726.       begin
  727.         DrawOutline3D(DestCanvas, R, clBtnShadow, clBtnHighlight, 1);
  728.         DrawOutline3D(DestCanvas, R, clBlack, clBlack, 1);
  729.       end;
  730.     lsFlat:
  731.       DrawOutline3D(DestCanvas, R, clBlack, clBlack, 1);
  732.     lsNone:;
  733.   end;
  734. end;
  735. procedure TVrIndicator.UpdateLeds;
  736. var
  737.   I: Integer;
  738. begin
  739.   for I := 0 to Collection.Count - 1 do UpdateLed(I);
  740. end;
  741. procedure TVrIndicator.Paint;
  742. begin
  743.   ClearBitmapCanvas;
  744.   DestCanvas := BitmapCanvas;
  745.   try
  746.     UpdateLeds;
  747.     inherited Paint;
  748.   finally
  749.     DestCanvas := Self.Canvas;
  750.   end;
  751.   UpdatePosition;
  752. end;
  753. procedure TVrIndicator.GetItemRect(Index: Integer; var R: TRect);
  754. var
  755.   X, W, Gap: Integer;
  756. begin
  757.   Gap := Pred(Leds) * FSpacing;
  758.   W := (ClientWidth - Gap) div Leds;
  759.   X := (Leds * W) + Gap;
  760.   X := (ClientWidth - X) div 2;
  761.   Inc(X, (W * Index) + (FSpacing * Index));
  762.   R := Bounds(X, 0, W, ClientHeight);
  763. end;
  764. end.