home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kompon / d56 / SCLED10.ZIP / SCLED10 / SCLED.pas < prev   
Pascal/Delphi Source File  |  2001-12-30  |  26KB  |  920 lines

  1. {======================================================================
  2. TSCLED 1.0
  3. Dec 29, 2001
  4.  
  5. by Safak Cinar
  6. scinar@shaw.ca
  7. http://members.shaw.ca/safak/
  8.  
  9. Based on the component TDynaLED 1.0 by Samson Fu 
  10. ======================================================================}
  11.  
  12. Unit SCLED;
  13.  
  14. Interface
  15.  
  16. Uses
  17.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  18.   ExtCtrls, Math;
  19.  
  20. Type
  21.  
  22.   TSCLEDStyle = (sclsSquare, sclsRound);
  23.   TSCClipMode = (sccmText, sccmDisplay);
  24.   TSCVerticalAlignment = (scvaTop, scvaCenter, scvaBottom);
  25.   TSCHorizontalAlignment = (schaLeft, schaCenter, schaRight);
  26.  
  27.   TSCLED = Class(TGraphicControl)
  28.   Private
  29.     FBuffer: TBitmap;
  30.  
  31.     FForeColor: TColor;
  32.     FBackColor: TColor;
  33.  
  34.     FLEDSize: Byte;
  35.     FLEDDistance: Byte;
  36.     FLEDStyle: TSCLEDStyle;
  37.  
  38.     FLines: TStringList;
  39.     FOffsetX, FOffsetY: Integer;
  40.     FClipMode: TSCClipMode;
  41.  
  42.     FAlignmentH: TSCHorizontalAlignment;
  43.     FAlignmentV: TSCVerticalAlignment;
  44.  
  45.     FFilterTimer : TTimer;
  46.     FFilterStyle : Integer;
  47.     FFilterSteps : Integer;
  48.     FFilterP1,FFilterP2,FFilterP3:Integer;
  49.  
  50.     FOnStop: TNotifyEvent;
  51.     FOnAfterDrawText : TNotifyEvent;
  52.     FOnCustomDraw: TNotifyEvent;
  53.  
  54.     FBitmapW,FBitmapH : Integer;
  55.     FAnim1,FAnim2 : Single;
  56.     FAutosize: Boolean;
  57.  
  58.     Procedure SetForeColor(const value: TColor);
  59.     Procedure SetBackColor(const value: TColor);
  60.     Procedure SetLEDSize(const value: Byte);
  61.     Procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  62.     Procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  63.     Procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
  64.     Procedure SetLines(const Value: TStringList);
  65.     Procedure LinesChanged (Sender: TObject);
  66.     Procedure DoResize(Sender: TObject);
  67.     Procedure SetLEDDistance(const Value: Byte);
  68.     Procedure SetOffsetX(const Value: Integer);
  69.     Procedure SetOffsetY(const Value: Integer);
  70.     Procedure ReDrawText;
  71.     Procedure SetLEDStyle(const Value: TSCLEDStyle);
  72.     Procedure SetClipMode(const Value: TSCClipMode);
  73.     Procedure SetOnAfterDrawText(const Value: TNotifyEvent);
  74.     procedure SetAlignmentH(const Value: TSCHorizontalAlignment);
  75.     procedure SetAlignmentV(const Value: TSCVerticalAlignment);
  76.     Function GetLEDAt(u,v:Integer):Boolean;
  77.     Procedure DoFilterTimer (Sender: TObject);
  78.     procedure SetOnCustomDraw(const Value: TNotifyEvent);
  79.     function GetLEDCountX: Integer;
  80.     function GetLEDCountY: Integer;
  81.     procedure SetLEDCountX(const Value: Integer);
  82.     procedure SetLEDCountY(const Value: Integer);
  83.     Procedure PreProcessAnimation;
  84.     procedure SetAutosize(const Value: Boolean);
  85.   Protected
  86.     Procedure ReDrawLED; virtual;
  87.     Procedure Paint; override;
  88.   Public
  89.     Bitmap: TBitmap;
  90.     Constructor Create(AOwner: TComponent); override;
  91.     Destructor Destroy; override;
  92.     Procedure BitmapChanged;
  93.     Procedure Animate(Style,Interval,Steps:Integer;P1,P2,P3:Integer);
  94.     Procedure StopAnimate;
  95.   Published
  96.     Property Lines:TStringList Read FLines Write SetLines;
  97.     Property ForeColor: TColor read FForeColor write SetForeColor default clLime;
  98.     Property BackColor: TColor read FBackColor write SetBackColor default clGreen;
  99.     Property LEDSize: Byte read FLEDSize write SetLEDSize Default 2;
  100.     Property LEDDistance: Byte Read FLEDDistance Write SetLEDDistance Default 1;
  101.     Property OffsetX : Integer read FOffsetX write SetOffsetX default 0;
  102.     Property OffsetY : Integer read FOffsetY write SetOffsetY default 0;
  103.     Property LEDCountX : Integer Read GetLEDCountX Write SetLEDCountX;
  104.     Property LEDCountY : Integer Read GetLEDCountY Write SetLEDCountY;
  105.     Property LEDStyle : TSCLEDStyle Read FLEDStyle write SetLEDStyle default sclsSquare;
  106.     Property ClipMode : TSCClipMode Read FClipMode write SetClipMode default sccmText;
  107.     Property AlignmentH : TSCHorizontalAlignment Read FAlignmentH Write SetAlignmentH;
  108.     Property AlignmentV : TSCVerticalAlignment Read FAlignmentV Write SetAlignmentV;
  109.     Property OnAfterDrawText : TNotifyEvent Read FOnAfterDrawText write SetOnAfterDrawText;
  110.     Property OnCustomDraw : TNotifyEvent Read FOnCustomDraw write SetOnCustomDraw;
  111.     Property OnStop : TNotifyEvent Read FOnStop Write FOnStop;
  112.     Property AutoSize : Boolean Read FAutosize Write SetAutosize Default True;
  113.     Property Caption;
  114.     Property Color;
  115.     Property Font;
  116.     Property ParentFont;
  117.     Property ParentColor;
  118.     Property Align;
  119.     Property Anchors;
  120.     Property Constraints;
  121.     Property DragCursor;
  122.     Property DragKind;
  123.     Property DragMode;
  124.     Property Enabled;
  125.     Property ParentShowHint;
  126.     Property PopupMenu;
  127.     Property ShowHint;
  128.     Property Visible;
  129.     Property OnClick;
  130.     Property OnContextPopup;
  131.     Property OnDblClick;
  132.     Property OnDragDrop;
  133.     Property OnDragOver;
  134.     Property OnEndDock;
  135.     Property OnEndDrag;
  136.     Property OnMouseDown;
  137.     Property OnMouseMove;
  138.     Property OnMouseUp;
  139.     Property OnStartDock;
  140.     Property OnStartDrag;
  141.   End;
  142.  
  143. Procedure Register;
  144.  
  145. Implementation
  146.  
  147. {$R SCLED.DCR}
  148.  
  149. {==============================================================================
  150. }
  151. constructor TSCLED.Create(AOwner: TComponent);
  152. Begin
  153.   Inherited;
  154.   ControlStyle := ControlStyle + [csOpaque];
  155.  
  156.   Width:=160;
  157.   Height:=40;
  158.  
  159.   FAlignmentH:=schaCenter;
  160.   FAlignmentV:=scvaCenter;
  161.   FFilterStyle:=0;
  162.   FAutoSize:=True;
  163.   
  164.   FForeColor:= clLime;
  165.   FBackColor:= clGreen;
  166.   FLEDSize:= 2;
  167.   FLEDDistance:= 1;
  168.   FOffsetX:=0;
  169.   FOffsetY:=0;
  170.   FLEDStyle:=sclsSquare;
  171.  
  172.   FLines:=TStringList.Create;
  173.   FLines.OnChange:=LinesChanged;
  174.  
  175.   FOnStop:=NIL;
  176.   
  177.   FBuffer:= TBitmap.Create;
  178.   FBuffer.HandleType:= bmDIB;
  179.  
  180.   Bitmap:= TBitmap.Create;
  181.   Bitmap.PixelFormat:= pf1Bit;
  182.   Bitmap.Monochrome:= True;
  183.   Bitmap.HandleType:= bmDIB;
  184.  
  185.   OnResize:=DoResize;
  186.  
  187.   FFilterTimer := TTimer.Create(NIL);
  188.   FFilterTimer.Enabled:=False;
  189.   FFilterTimer.OnTimer:=DoFilterTimer;
  190.  
  191.   DoResize(Self);
  192.   ReDrawLED;
  193.   Invalidate;
  194. End;
  195.  
  196. {==============================================================================
  197. }
  198. destructor TSCLED.Destroy;
  199. Begin
  200.   Bitmap.Free;
  201.   FBuffer.Free;
  202.   FLines.Free;
  203.   FFilterTimer.Free;
  204.   Inherited;
  205. End;
  206.  
  207. {==============================================================================
  208. }
  209. Procedure TSCLED.ReDrawText;
  210. Var
  211.   R : TRect;
  212.   A : Integer;
  213.   S : String;
  214.   Y : Integer;
  215. Begin
  216.   Bitmap.Assign(nil);
  217.   Bitmap.Canvas.Brush.Color:= clBlack;
  218.   Bitmap.Canvas.Font.Color:= clWhite;
  219.   If Assigned(FOnCustomDraw) Then
  220.   Begin
  221.     Bitmap.Width:=GetLEDCountX;
  222.     Bitmap.Height:=GetLEDCountY;
  223.     FBitmapW:=Bitmap.Width;
  224.     FBitmapH:=Bitmap.Height;
  225.     FOnCustomDraw(Self);
  226.     Exit;
  227.   End;
  228.   Case FAlignmentH Of
  229.     schaLeft : A:=DT_LEFT;
  230.     schaCenter : A:=DT_CENTER;
  231.     schaRight : A:=DT_RIGHT;
  232.   End;
  233.   If Lines.Count=0 Then
  234.     S:=Caption
  235.   Else
  236.   Begin
  237.     S:=Lines.Text;
  238.     If Length(S)>2 Then SetLength(S,Length(S)-2);
  239.   End;
  240.   R:= Rect(0,0,0,0);
  241.   DrawTextEx(Bitmap.Canvas.Handle, PChar(S), -1, R, A Or DT_NOCLIP or DT_NOPREFIX or DT_CALCRECT, nil);
  242.   Case FClipMode Of
  243.     sccmText :
  244.     Begin
  245.       Bitmap.Width:=R.Right-R.Left;
  246.       Bitmap.Height:=R.Bottom-R.Top;
  247.     End;
  248.     sccmDisplay :
  249.     Begin
  250.       Case FAlignmentV Of
  251.         scvaTop : Y:=0;
  252.         scvaCenter : Y:=(GetLEDCountY-(R.Bottom-R.Top)) Div 2;
  253.         scvaBottom : Y:=(GetLEDCountY-(R.Bottom-R.Top));
  254.       End;
  255.       Bitmap.Width:=GetLEDCountX;
  256.       Bitmap.Height:=GetLEDCountY;
  257.       R:= Rect(0,Y,Bitmap.Width,Bitmap.Height+Y);
  258.     End;
  259.   End;
  260.   FBitmapW:=Bitmap.Width;
  261.   FBitmapH:=Bitmap.Height;
  262.   DrawTextEx(Bitmap.Canvas.Handle, PChar(S), -1, R, A Or DT_NOCLIP or DT_NOPREFIX, nil);
  263.   If Assigned(FOnAfterDrawText) Then FOnAfterDrawText(Self);
  264. End;
  265.  
  266. {==============================================================================
  267. }
  268. Function MidColor(A,B:TColor):TColor;
  269. Var
  270.   R1,G1,B1, R2,G2,B2, R0,G0,B0 : Byte;
  271. Begin
  272.   R1 := (A And $000000FF);
  273.   G1 := (A And $0000FF00) SHR 8;
  274.   B1 := (A And $00FF0000) SHR 16;
  275.  
  276.   R2 := (B And $000000FF);
  277.   G2 := (B And $0000FF00) SHR 8;
  278.   B2 := (B And $00FF0000) SHR 16;
  279.  
  280.   R0 := (R1+R2) Div 2;
  281.   G0 := (G1+G2) Div 2;
  282.   B0 := (B1+B2) Div 2;
  283.  
  284.   Result:=B0 SHL 16 + G0 SHL 8 + R0;
  285.  
  286. End;
  287.  
  288. {==============================================================================
  289. }
  290. Procedure TSCLED.ReDrawLED;
  291. Var
  292.   X, Y, U, V : Integer;
  293.   R : TRect;
  294.   K : Integer;
  295.   AOffX,AOffY : Integer;
  296.   CB,CF : TColor;
  297. Begin
  298.  
  299.   CB:= MidColor(FBackColor,Color);
  300.   CF:= MidColor(FForeColor,FBackColor);
  301.  
  302.   K:=FLEDSize+FLEDDistance;
  303.  
  304.   If (FBuffer.Width<>Width) Or (FBuffer.Height<>Height) Then
  305.   Begin
  306.     FBuffer.Assign(nil);
  307.     FBuffer.Width:= Width;
  308.     FBuffer.Height:= Height;
  309.   End;
  310.  
  311.   FBuffer.Canvas.Brush.Color:= Color;
  312.   FBuffer.Canvas.FillRect(Rect(0,0,FBuffer.Width,FBuffer.Height));
  313.  
  314.   Case FAlignmentH Of
  315.     schaLeft : AOffX:=0;
  316.     schaCenter : AOffX:=(GetLEDCountX-FBitmapW) Div 2;
  317.     schaRight : AOffX:=(GetLEDCountX-FBitmapW);
  318.   End;
  319.   Case FAlignmentV Of
  320.     scvaTop : AOffY:=0;
  321.     scvaCenter : AOffY:=(GetLEDCountY-FBitmapH) Div 2;
  322.     scvaBottom : AOffY:=(GetLEDCountY-FBitmapH);
  323.   End;
  324.  
  325.   PreProcessAnimation;
  326.  
  327.   Case FLEDSize Of
  328.     1 :
  329.     Begin
  330.       For x:=0 to GetLEDCountX-1 do
  331.       Begin
  332.         For y:=0 to GetLEDCountY-1 do
  333.         Begin
  334.           u:=x-FOffsetX-AOffX; v:=y-FOffsety-AOffY;
  335.           If GetLEDAt(u,v) Then
  336.             FBuffer.Canvas.Pixels[x*K+FLEDDistance,y*K+FLEDDistance]:=FForeColor
  337.           Else
  338.             FBuffer.Canvas.Pixels[x*K+FLEDDistance,y*K+FLEDDistance]:=FBackColor;
  339.         End; // For Y
  340.       End; // For X
  341.     End; // Case FLEDSize 1
  342.     2 :
  343.     Begin
  344.       For x:=0 to GetLEDCountX-1 do
  345.       Begin
  346.         For y:=0 to GetLEDCountY-1 do
  347.         Begin
  348.           R:= Rect(x*K+FLEDDistance,y*K+FLEDDistance,(x+1)*K,(y+1)*K);
  349.           u:=x-FOffsetX-AOffX; v:=y-FOffsety-AOffY;
  350.           If GetLEDAt(u,v) Then FBuffer.Canvas.Brush.Color:= FForeColor Else FBuffer.Canvas.Brush.Color:= FBackColor;
  351.           FBuffer.Canvas.FillRect(R);
  352.         End; //For Y
  353.       End; //For X
  354.     End; // Case FLEDSize 2
  355.     3 :
  356.     Begin
  357.       For x:=0 to GetLEDCountX-1 do
  358.       Begin
  359.         For y:=0 to GetLEDCountY-1 do
  360.         Begin
  361.           u:=x-FOffsetX-AOffX; v:=y-FOffsety-AOffY;
  362.           Case FLEDStyle of
  363.             sclsSquare : Begin
  364.               If GetLEDAt(u,v) Then FBuffer.Canvas.Brush.Color:= FForeColor Else FBuffer.Canvas.Brush.Color:= FBackColor;
  365.               R:= Rect(x*K+FLEDDistance,y*K+FLEDDistance,(x+1)*K,(y+1)*K);
  366.               FBuffer.Canvas.FillRect(R);
  367.             End;
  368.             sclsRound : Begin
  369.               If GetLEDAt(u,v) Then
  370.               Begin
  371.                 u:=x*K+FLEDDistance; v:=y*K+FLEDDistance;
  372.                 With FBuffer.Canvas Do
  373.                 Begin
  374.                   Pixels[u,v]:=CF; Pixels[u+2,v]:=CF; Pixels[u,v+2]:=CF; Pixels[u+2,v+2]:=CF;
  375.                   Pen.Color:=FForeColor;
  376.                   MoveTo(u+1,v); LineTo(u+1,v+3); MoveTo(u,v+1); LineTo(u+3,v+1);
  377.                 End;
  378.               End
  379.               Else
  380.               Begin
  381.                 u:=x*K+FLEDDistance; v:=y*K+FLEDDistance;
  382.                 With FBuffer.Canvas Do
  383.                 Begin
  384.                   Pixels[u,v]:=CB; Pixels[u+2,v]:=CB; Pixels[u,v+2]:=CB; Pixels[u+2,v+2]:=CB;
  385.                   Pen.Color:=FBackColor;
  386.                   MoveTo(u+1,v); LineTo(u+1,v+3); MoveTo(u,v+1); LineTo(u+3,v+1);
  387.                 End; //with
  388.               End; //else
  389.             End; //case FLEDStyle sclsRound
  390.           End; // Case FLEDStyle
  391.         End; //For Y
  392.       End; //For X
  393.     End; //Case FLEDSize 3
  394.     Else
  395.     Begin
  396.       For x:=0 to GetLEDCountX-1 do
  397.       Begin
  398.         For y:=0 to GetLEDCountY-1 do
  399.         Begin
  400.           R:= Rect(x*K+FLEDDistance,y*K+FLEDDistance,(x+1)*K,(y+1)*K);
  401.           u:=x-FOffsetX-AOffX; v:=y-FOffsety-AOffY;
  402.           If GetLEDAt(u,v) Then FBuffer.Canvas.Brush.Color:= FForeColor Else FBuffer.Canvas.Brush.Color:= FBackColor;
  403.           Case FLEDStyle of
  404.             sclsSquare : FBuffer.Canvas.FillRect(R);
  405.             sclsRound : Begin
  406.                           FBuffer.Canvas.Pen.Color:=FBuffer.Canvas.Brush.Color;
  407.                           FBuffer.Canvas.Ellipse(R);
  408.                         End;
  409.           End; // Case FLEDStyle
  410.         End; //For Y
  411.       End; //For X
  412.     End; //Case FLEDSize Else
  413.   End; //Case FLEDSize
  414.  
  415. End;
  416.  
  417. {==============================================================================
  418. }
  419. Procedure TSCLED.SetForeColor(const value: TColor);
  420. Begin
  421.   If FForeColor<>Value then
  422.   Begin
  423.     FForeColor:= Value;
  424.     ReDrawLED;
  425.     Invalidate;
  426.   End;
  427. End;
  428.  
  429. {==============================================================================
  430. }
  431. Procedure TSCLED.SetBackColor(const value: TColor);
  432. Begin
  433.   If FBackColor<>Value then
  434.   Begin
  435.     FBackColor:= Value;
  436.     ReDrawLED;
  437.     Invalidate;
  438.   End;
  439. End;
  440.  
  441. {==============================================================================
  442. }
  443. Procedure TSCLED.SetLEDSize(Const value: Byte);
  444. Begin
  445.   If (FLEDSize<>Value) And (Value>0) then
  446.   Begin
  447.     If FAutoSize Then
  448.     Begin
  449.       Width:=GetLEDCountX*(Value+FLEDDistance)+FLEDDistance;
  450.       Height:=GetLEDCountY*(Value+FLEDDistance)+FLEDDistance;
  451.     End;
  452.     FLEDSize:= Value;
  453.     ReDrawText;
  454.     ReDrawLED;
  455.     Invalidate;
  456.   End;
  457. End;
  458.  
  459. {==============================================================================
  460. }
  461. Procedure TSCLED.SetLEDDistance(Const Value: Byte);
  462. Begin
  463.   If (Value<>FLEDDistance) Then
  464.   Begin
  465.     If FAutoSize Then
  466.     Begin
  467.       Width:=GetLEDCountX*(FLEDSize+Value)+FLEDDistance;
  468.       Height:=GetLEDCountY*(FLEDSize+Value)+FLEDDistance;
  469.     End;
  470.     FLEDDistance := Value;
  471.     ReDrawText;
  472.     ReDrawLED;
  473.     Invalidate;
  474.   End;
  475. End;
  476.  
  477. {==============================================================================
  478. }
  479. procedure TSCLED.CMTextChanged(var Message: TMessage);
  480. Begin
  481.   ReDrawText;
  482.   ReDrawLED;
  483.   Invalidate;
  484. End;
  485.  
  486. {==============================================================================
  487. }
  488. procedure TSCLED.CMFontChanged(var Message: TMessage);
  489. Begin
  490.   Bitmap.Canvas.Font.Assign(Font);
  491.   ReDrawText;
  492.   ReDrawLED;
  493.   Invalidate;
  494. End;
  495.  
  496. {==============================================================================
  497. }
  498. procedure TSCLED.CMColorChanged(var Message: TMessage);
  499. Begin
  500.   ReDrawLED;
  501.   Invalidate;
  502. End;
  503.  
  504. {==============================================================================
  505. }
  506. procedure TSCLED.Paint;
  507. Begin
  508.   Canvas.Draw(0,0,FBuffer);
  509. End;
  510.  
  511. {==============================================================================
  512. }
  513. procedure Register;
  514. begin
  515.   RegisterComponents('SAFAK', [TSCLED]);
  516. end;
  517.  
  518. {==============================================================================
  519. }
  520. Procedure TSCLED.SetLines(const Value: TStringList);
  521. Begin
  522.   FLines.Text:=Value.Text;
  523.   ReDrawText;
  524.   ReDrawLED;
  525.   Invalidate;
  526. End;
  527.  
  528. {==============================================================================
  529. }
  530. procedure TSCLED.LinesChanged(Sender: TObject);
  531. begin
  532.   ReDrawText;
  533.   ReDrawLED;
  534.   Invalidate;
  535. end;
  536.  
  537. {==============================================================================
  538. }
  539. procedure TSCLED.DoResize(Sender: TObject);
  540. begin
  541.   ReDrawText;
  542.   ReDrawLED;
  543.   Invalidate;
  544. end;
  545.  
  546. {==============================================================================
  547. }
  548. procedure TSCLED.SetOffsetX(const Value: Integer);
  549. begin
  550.   If (FOffsetX<>Value) Then
  551.   Begin
  552.     FOffsetX := Value;
  553.     ReDrawLED;
  554.     Invalidate;
  555.   End;
  556. end;
  557.  
  558. {==============================================================================
  559. }
  560. procedure TSCLED.SetOffsetY(const Value: Integer);
  561. begin
  562.   If (FOffsetY<>Value) Then
  563.   Begin
  564.     FOffsetY := Value;
  565.     ReDrawLED;
  566.     Invalidate;
  567.   End;
  568. end;
  569.  
  570. {==============================================================================
  571. }
  572. procedure TSCLED.SetLEDStyle(const Value: TSCLEDStyle);
  573. begin
  574.   If (Value<>FLEDStyle) Then
  575.   Begin
  576.     FLEDStyle := Value;
  577.     ReDrawLED;
  578.     Invalidate;
  579.   End;
  580. End;
  581.  
  582. {==============================================================================
  583. }
  584. procedure TSCLED.BitmapChanged;
  585. begin
  586.   ReDrawLED;
  587.   Invalidate;
  588. end;
  589.  
  590. {==============================================================================
  591. }
  592. procedure TSCLED.SetClipMode(const Value: TSCClipMode);
  593. begin
  594.   If Value<>FClipMode Then
  595.   Begin
  596.     FClipMode := Value;
  597.     ReDrawText;
  598.     ReDrawLED;
  599.     Invalidate;
  600.   End;
  601. end;
  602.  
  603. {==============================================================================
  604. }
  605. procedure TSCLED.SetOnAfterDrawText(const Value: TNotifyEvent);
  606. begin
  607.   FOnAfterDrawText := Value;
  608.   ReDrawText;
  609.   ReDrawLED;
  610.   Invalidate;
  611. end;
  612.  
  613. {==============================================================================
  614. }
  615. procedure TSCLED.SetAlignmentH(const Value: TSCHorizontalAlignment);
  616. begin
  617.   If Value<>FAlignmentH Then
  618.   Begin
  619.     FAlignmentH := Value;
  620.     ReDrawText;
  621.     ReDrawLED;
  622.     Invalidate;
  623.   End;
  624. End;
  625.  
  626. {==============================================================================
  627. }
  628. procedure TSCLED.SetAlignmentV(const Value: TSCVerticalAlignment);
  629. begin
  630.   If (Value<>FAlignmentV) Then
  631.   Begin
  632.     FAlignmentV := Value;
  633.     ReDrawText;
  634.     ReDrawLED;
  635.     Invalidate;
  636.   End;
  637. end;
  638.  
  639. {==============================================================================
  640. }
  641. Procedure TSCLED.StopAnimate;
  642. Begin
  643.   If Not FFilterTimer.Enabled Then Exit;
  644.   FFilterTimer.Enabled:=False;
  645.   FFilterStyle:=0;
  646.   ReDrawLED;
  647.   Invalidate;
  648.   If Assigned(FOnStop) Then FOnStop(Self);
  649. End;
  650.  
  651. {==============================================================================
  652. }
  653. Procedure TSCLED.PreProcessAnimation;
  654. Begin
  655.   Case FFilterStyle Of
  656.     4,
  657.     5,
  658.     6,
  659.     7 : FAnim1:=Cos((FFilterTimer.Tag*FFilterP1 Mod 360)*Pi/180);
  660.     8 : FAnim1:=Abs(Cos((FFilterTimer.Tag*FFilterP1 Mod 360)*Pi/180));
  661.     9 : Begin
  662.           FAnim1:=Cos((FFilterTimer.Tag*FFilterP1 Mod 360)*Pi/180);
  663.           FAnim2:=Sin((FFilterTimer.Tag*FFilterP1 Mod 360)*Pi/180);
  664.         End;
  665.   End;
  666. End;
  667.  
  668. {==============================================================================
  669. }
  670. Function TSCLED.GetLEDAt(u,v:Integer):Boolean;
  671. Var
  672.   Inside : Boolean;
  673.   N : Integer;
  674. Begin
  675.   Case FFilterStyle Of
  676.     0 : Begin  // Normal
  677.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  678.           If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  679.         End;
  680.     1 : Begin  // Blink FG
  681.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  682.           Case FFilterTimer.Tag Mod 2 Of
  683.             0 : Result:=False;
  684.             1 : If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  685.           End;
  686.         End;
  687.     2 : Begin // Blink BG
  688.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  689.           Case FFilterTimer.Tag Mod 2 Of
  690.             0 : Result:=True;
  691.             1 : If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  692.           End;
  693.         End;
  694.     3 : Begin // Blink FG/BG
  695.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  696.           Case FFilterTimer.Tag Mod 2 Of
  697.             0 : If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]<>clWhite Else Result:=True;
  698.             1 : If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  699.           End;
  700.         End;
  701.     4 : Begin // Stretch X
  702.           u:=Round(FFilterP2+(u-FFilterP2)*FAnim1);
  703.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  704.           If Inside Then
  705.             Result:=Bitmap.Canvas.Pixels[u,v]=clWhite
  706.           Else
  707.             Result:=False;
  708.         End;
  709.     5 : Begin // Stretch Y
  710.           v:=Round(FFilterP2+(v-FFilterP2)*FAnim1);
  711.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  712.           If Inside Then
  713.             Result:=Bitmap.Canvas.Pixels[u,v]=clWhite
  714.           Else
  715.             Result:=False;
  716.         End;
  717.     6 : Begin // Rotate Y
  718.           If Abs(FAnim1)<1E-8 Then
  719.           Begin
  720.             Result:=False;
  721.             Exit;
  722.           End;
  723.           u:=Round(FFilterP2+(u-FFilterP2)/FAnim1);
  724.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  725.           If Inside Then
  726.             Result:=Bitmap.Canvas.Pixels[u,v]=clWhite
  727.           Else
  728.             Result:=False;
  729.         End;
  730.     7 : Begin // Rotate X
  731.           If Abs(FAnim1)<1E-8 Then
  732.           Begin
  733.             Result:=False;
  734.             Exit;
  735.           End;
  736.           v:=Round(FFilterP2+(v-FFilterP2)/FAnim1);
  737.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  738.           If Inside Then
  739.             Result:=Bitmap.Canvas.Pixels[u,v]=clWhite
  740.           Else
  741.             Result:=False;
  742.         End;
  743.     8 : Begin // Pulse
  744.           If Abs(FAnim1)<1E-8 Then
  745.           Begin
  746.             Result:=False;
  747.             Exit;
  748.           End;
  749.           u:=Round(FFilterP2+(u-FFilterP2)/FAnim1);
  750.           v:=Round(FFilterP3+(v-FFilterP3)/FAnim1);
  751.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  752.           If Inside Then
  753.             Result:=Bitmap.Canvas.Pixels[u,v]=clWhite
  754.           Else
  755.             Result:=False;
  756.         End;
  757.     9 : Begin // Rotate
  758.           u:=u-FFilterP2;
  759.           v:=v-FFilterP3;
  760.           N:=Round(u*FAnim1+v*FAnim2);
  761.           v:=FFilterP3+Round(-u*FAnim2+v*FAnim1);
  762.           u:=FFilterP2+N;
  763.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  764.           If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  765.         End;
  766.    10 : Begin // Scroll X
  767.           u:=(u+FFilterP1*FFilterTimer.Tag) Mod FFilterP2; If u<0 Then u:=u+FFilterP2;
  768.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  769.           If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  770.         End;
  771.    11 : Begin // Scroll Y
  772.           v:=(v+FFilterP1*FFilterTimer.Tag) Mod FFilterP2; If v<0 Then v:=v+FFilterP2;
  773.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  774.           If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  775.         End;
  776.    12 : Begin //Wipe X
  777.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  778.           If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  779.           N:=FFilterTimer.Tag*FFilterP1;
  780.           If (N Div FBitmapW) Mod 2 = 0 Then
  781.           Begin
  782.             N:=N Mod FBitmapW;
  783.             If N>u Then Result:=Not Result;
  784.           End
  785.           Else
  786.           Begin
  787.             N:=N Mod FBitmapW;
  788.             If N<u Then Result:=Not Result;
  789.           End;
  790.         End;
  791.    13 : Begin //Wipe Y
  792.           Inside:=(u>=0) And (u<FBitmapW) And (v>=0) And (v<FBitmapH);
  793.           If Inside Then Result:=Bitmap.Canvas.Pixels[u,v]=clWhite Else Result:=False;
  794.           N:=FFilterTimer.Tag*FFilterP1;
  795.           If (N Div FBitmapH) Mod 2 = 0 Then
  796.           Begin
  797.             N:=N Mod FBitmapH;
  798.             If N>v Then Result:=Not Result;
  799.           End
  800.           Else
  801.           Begin
  802.             N:=N Mod FBitmapH;
  803.             If N<v Then Result:=Not Result;
  804.           End;
  805.         End;
  806.   End;
  807. End;
  808.  
  809. {==============================================================================
  810. }
  811. procedure TSCLED.Animate(Style,Interval,Steps: Integer; P1,P2,P3: Integer);
  812. begin
  813.   If Style=0 Then
  814.   Begin
  815.     StopAnimate;
  816.     Exit;
  817.   End;
  818.   If (Style<0) Or (Style>100) Then Exit;
  819.   If Interval<1 Then Exit;
  820.   If Steps<1 Then Exit;
  821.   StopAnimate;
  822.   FFilterTimer.Interval:=Interval;
  823.   FFilterTimer.Tag:=0;
  824.   FFilterStyle:=Style;
  825.   FFilterSteps:=Steps;
  826.   FFilterP1:=P1;
  827.   FFilterP2:=P2;
  828.   FFilterP3:=P3;
  829.   FFilterTimer.Enabled:=True;
  830. End;
  831.  
  832. {==============================================================================
  833. }
  834. procedure TSCLED.DoFilterTimer(Sender: TObject);
  835. begin
  836.   FFilterTimer.Tag:=FFilterTimer.Tag+1;
  837.   If FFilterTimer.Tag>FFilterSteps Then
  838.   Begin
  839.     StopAnimate;
  840.     Exit;
  841.   End;
  842.   ReDrawLED;
  843.   Invalidate;
  844. end;
  845.  
  846. {==============================================================================
  847. }
  848. procedure TSCLED.SetOnCustomDraw(const Value: TNotifyEvent);
  849. begin
  850.   FOnCustomDraw := Value;
  851.   ReDrawText;
  852.   ReDrawLED;
  853.   Invalidate;
  854. end;
  855.  
  856. {==============================================================================
  857. }
  858. function TSCLED.GetLEDCountX: Integer;
  859. begin
  860.   Result:=Width Div (FLEDSize+FLEDDistance);
  861. end;
  862.  
  863. {==============================================================================
  864. }
  865. function TSCLED.GetLEDCountY: Integer;
  866. begin
  867.   Result:=Height Div (FLEDSize+FLEDDistance);
  868. end;
  869.  
  870. {==============================================================================
  871. }
  872. procedure TSCLED.SetLEDCountX(const Value: Integer);
  873. begin
  874.   If (Value<>GetLEDCountX) And (Value>0) Then
  875.   Begin
  876.     If FAutoSize Then
  877.     Begin
  878.       Width:=Value*(FLEDSize+FLEDDistance)+FLEDDistance;
  879.       ReDrawText;
  880.       ReDrawLED;
  881.       Invalidate;
  882.     End;
  883.   End;
  884. End;
  885.  
  886. {==============================================================================
  887. }
  888. procedure TSCLED.SetLEDCountY(const Value: Integer);
  889. begin
  890.   If (Value<>GetLEDCountY) And (Value>0) Then
  891.   Begin
  892.     If FAutoSize Then
  893.     Begin
  894.       Height:=Value*(FLEDSize+FLEDDistance)+FLEDDistance;
  895.       ReDrawText;
  896.       ReDrawLED;
  897.       Invalidate;
  898.     End;
  899.   End;
  900. end;
  901.  
  902. {==============================================================================
  903. }
  904. procedure TSCLED.SetAutosize(const Value: Boolean);
  905. begin
  906.   If Value<>FAutosize Then
  907.   Begin
  908.     FAutosize := Value;
  909.     If FAutoSize Then
  910.     Begin
  911.       Width:=GetLEDCountX*(FLEDSize+FLEDDistance)+FLEDDistance;
  912.       Height:=GetLEDCountY*(FLEDSize+FLEDDistance)+FLEDDistance;
  913.     End;
  914.   End;
  915. End;
  916.  
  917. {==============================================================================
  918. }
  919. end.
  920.