home *** CD-ROM | disk | FTP | other *** search
Wrap
unit SCLEDDemo_MainUnit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls, ShellAPI, SCLED; Const CRLF=#13#10; PAR=#13#10#13#10; type TDemoForm = class(TForm) PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; TabSheet3: TTabSheet; LED2: TSCLED; CycleAnimation: TButton; StopCycleButton: TButton; LED3: TSCLED; ScrollButton: TButton; LED1: TSCLED; ForePanel: TPanel; BackPanel: TPanel; ColorPanel: TPanel; ColorDialog: TColorDialog; LinesMemo: TMemo; Label1: TLabel; FontButton: TButton; FontDialog: TFontDialog; GroupBox1: TGroupBox; Style1Radio: TRadioButton; Style2Radio: TRadioButton; GroupBox2: TGroupBox; Clip1Radio: TRadioButton; Clip2Radio: TRadioButton; AfterDrawCheck: TCheckBox; RichEdit1: TRichEdit; AnimsCombo: TComboBox; LED4: TSCLED; NumberBox: TEdit; RichEdit2: TRichEdit; RichEdit3: TRichEdit; GroupBox3: TGroupBox; Label4: TLabel; SizeCombo: TComboBox; DistCombo: TComboBox; Label5: TLabel; GroupBox4: TGroupBox; Label2: TLabel; HAlignCombo: TComboBox; Label3: TLabel; VAlignCombo: TComboBox; GroupBox5: TGroupBox; Label6: TLabel; OffsetXBox: TEdit; OffsetXTrack: TTrackBar; Label7: TLabel; OffsetYBox: TEdit; OffsetYTrack: TTrackBar; Label8: TLabel; RichEdit4: TRichEdit; Button1: TButton; TabSheet4: TTabSheet; Label10: TLabel; Label11: TLabel; Label12: TLabel; Label13: TLabel; LED5: TSCLED; RichEdit5: TRichEdit; procedure CycleAnimationClick(Sender: TObject); procedure StopCycleButtonClick(Sender: TObject); procedure LED2Stop(Sender: TObject); procedure LED2AfterDrawText(Sender: TObject); procedure NumberBoxChange(Sender: TObject); procedure ScrollButtonClick(Sender: TObject); procedure ForePanelClick(Sender: TObject); procedure BackPanelClick(Sender: TObject); procedure ColorPanelClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure LinesMemoChange(Sender: TObject); procedure HAlignComboChange(Sender: TObject); procedure VAlignComboChange(Sender: TObject); procedure FontButtonClick(Sender: TObject); procedure SizeComboChange(Sender: TObject); procedure DistComboChange(Sender: TObject); procedure StyleRadioClick(Sender: TObject); procedure LED1AfterDrawText(Sender: TObject); procedure AfterDrawCheckClick(Sender: TObject); procedure ClipModeRadioClick(Sender: TObject); procedure OffsetXTrackChange(Sender: TObject); procedure OffsetYTrackChange(Sender: TObject); procedure OffsetXBoxChange(Sender: TObject); procedure OffsetYBoxChange(Sender: TObject); procedure AnimsComboChange(Sender: TObject); procedure PageControl1Change(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Label10Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var DemoForm: TDemoForm; implementation {$R *.DFM} {============================================================================== } procedure TDemoForm.CycleAnimationClick(Sender: TObject); begin LED2.OnStop:=LED2Stop; LED2.Animate(1,1,1,0,0,0); end; {============================================================================== } procedure TDemoForm.StopCycleButtonClick(Sender: TObject); begin LED2.OnStop:=NIL; LED2.StopAnimate; end; {============================================================================== } procedure TDemoForm.LED2Stop(Sender: TObject); begin AnimsCombo.ItemIndex:=(AnimsCombo.ItemIndex+1) Mod 13; AnimsComboChange(AnimsCombo) end; {============================================================================== } procedure TDemoForm.LED2AfterDrawText(Sender: TObject); begin LED2.Bitmap.Canvas.Brush.Color:=clWhite; LED2.Bitmap.Canvas.FrameRect(LED2.Bitmap.Canvas.ClipRect); end; {============================================================================== } Procedure TDemoForm.NumberBoxChange(Sender: TObject); Var i,m,n : integer; Begin Try n:=StrToInt(NumberBox.Text); Except On Exception Do n:=0; End; m:=1; With LED4.Bitmap.Canvas Do For i:=0 To 31 Do Begin If (n And m)<>0 Then Pixels[31-i,0]:=clWhite Else Pixels[31-i,0]:=clBlack; m:=m SHL 1; End; LED4.BitmapChanged; End; {============================================================================== } procedure TDemoForm.ScrollButtonClick(Sender: TObject); begin LED3.Animate(10,20,LED3.Bitmap.Width+50,1,LED3.Bitmap.Width+50,0); end; {============================================================================== } procedure TDemoForm.ForePanelClick(Sender: TObject); begin ColorDialog.Color:=(Sender As TPanel).Color; If ColorDialog.Execute Then Begin LED1.ForeColor:=ColorDialog.Color; (Sender As TPanel).Color:=ColorDialog.Color; (Sender As TPanel).Font.Color:=ColorDialog.Color XOR clWhite; End; end; {============================================================================== } procedure TDemoForm.BackPanelClick(Sender: TObject); begin ColorDialog.Color:=(Sender As TPanel).Color; If ColorDialog.Execute Then Begin LED1.BackColor:=ColorDialog.Color; (Sender As TPanel).Color:=ColorDialog.Color; (Sender As TPanel).Font.Color:=ColorDialog.Color XOR clWhite; End; end; {============================================================================== } procedure TDemoForm.ColorPanelClick(Sender: TObject); begin ColorDialog.Color:=(Sender As TPanel).Color; If ColorDialog.Execute Then Begin LED1.Color:=ColorDialog.Color; (Sender As TPanel).Color:=ColorDialog.Color; (Sender As TPanel).Font.Color:=ColorDialog.Color XOR clWhite; End; End; {============================================================================== } procedure TDemoForm.FormShow(Sender: TObject); begin ForePanel.Color:=LED1.ForeColor; BackPanel.Color:=LED1.BackColor; ColorPanel.Color:=LED1.Color; ForePanel.Font.Color:=LED1.ForeColor XOR clWhite; BackPanel.Font.Color:=LED1.BackColor XOR clWhite; ColorPanel.Font.Color:=LED1.Color XOR clWhite; LinesMemo.Lines.Text:=LED1.Lines.Text; HAlignCombo.ItemIndex:=Ord(LED1.AlignmentH); VAlignCombo.ItemIndex:=Ord(LED1.AlignmentV); SizeCombo.ItemIndex:=SizeCombo.Items.IndexOf(IntToStr(LED1.LEDSize)); DistCombo.ItemIndex:=DistCombo.Items.IndexOf(IntToStr(LED1.LEDDistance)); Style1Radio.Checked:=LED1.LEDStyle=sclsSquare; Style2Radio.Checked:=LED1.LEDStyle=sclsRound; AfterDrawCheck.Checked:=Assigned(LED1.OnAfterDrawText); Clip1Radio.Checked:=LED1.ClipMode=sccmText; Clip2Radio.Checked:=LED1.ClipMode=sccmDisplay; RichEdit1.Lines.Add( 'TSCLED 1.0'+CRLF+'Safak Cinar, Dec 29 2001'+PAR+ 'http://members.shaw.ca/safak/'+PAR+ 'safak@shaw.ca'+PAR+ 'TSCLED is a multiline dot matrix LED display emulator that uses a monochrome offscreen bitmap to draw on. Text can be displayed using any installed font and it has a dozen or so built in animation sequences and custom draw functionality.'+PAR+ 'TSCLED is based on the component TDynaLED 1.0 by Samson Fu. You can download his component from http://www.torry.net/leds.htm.'+PAR+ 'TSCLED displays a monochrome bitmap (accessible through BITMAP property) with adjustable pixel size and inter pixel spacing.'+ ' Although this BITMAP is exposed, you need not use it directly when simply displaying text, which you do by assigning strings to either the CAPTION or LINES properties.'+PAR+ 'Most of the features are quite straightforward, with a couple of exceptions:'+PAR+ '* For LEDSTYLE, sclsSQUARE and sclsROUND yield identical looking displays unless LEDSIZE is larger than 2 pixels.'+PAR+ '* TSCLED has both a LINES and a CAPTION property. If LINES is empty, CAPTION is used,otherwise LINES is used. It is a little easier using LINES at design time when entering multi-line text.'+PAR+ '* The AUTOSIZE property may not be what you expect. If it is set to true, any change in LEDSIZE, LEDDISTANCE or LEDCOUNTX or LEDCOUNTY will change the component size, in other words, component'+ ' WIDTH and HEIGHT become derived properties. Otherwise, LEDCOUNTX and LEDCOUNTY are derived from the other properties. Mainly a design time convenience.'+PAR+ '* CLIPMODE can either be set to sccmTEXT or sccmDISPLAY. If set to sccmTEXT, the monochrome BITMAP will be the minimum size to accomodate the text drawn on it. '+ 'Otherwise, the BITMAP will be the same size as display (ie LEDCOUNTX by LEDCOUNTY pixels). To better visualize this, enable ONAFTERDRAW on the this demo page, which will draw a frame around the BITMAP. '+ 'As a rule of thumb, use sccmTEXT unless you are doing custom drawing.'+PAR+ '* ALIGNMENTH doesn not use Delphi''s TALIGNMENT values but a custom enumerated type. This is in anticipation of a later feature.' ); RichEdit3.Lines.Add( 'The ANIMATE method takes 6 arguments:'+PAR+ 'Procedure Animate(Style,Interval,Steps:Integer;P1,P2,P3:Integer);'+PAR+ 'Style : 1..13, the various animation styles.'+CRLF+ 'Interval : (Minimum) duration, in milliseconds, of each animation step'+CRLF+ 'Steps : The total number of animation steps'+CRLF+ 'P1,P2,P3 : Parameters. These are specific to each animation style.'+PAR+ 'Animation Styles:'+PAR+ '1 : Blink Foreground'+CRLF+ ' (no parameters)'+PAR+ '2 : Blink Background'+CRLF+ ' (no parameters)'+PAR+ '3 : Blink background and foreground (ie. Toggle)'+CRLF+ ' (no parameters)'+PAR+ '4 : Stretch X'+CRLF+ ' P1 = Angle (*1) increment (in degrees).'+CRLF+ ' P2 = X coordinate of the vertical center line (*2)'+CRLF+ '5 : Stretch Y'+CRLF+ ' P1 = Angle (*1) increment (in degrees).'+CRLF+ ' P2 = Y coordinate of the horizontal center line (*2)'+CRLF+ '6 : Flip X'+CRLF+ ' P1 = Angle increment (in degrees).'+CRLF+ ' P2 = X coordinate of the vertical center line (*2)'+CRLF+ '7 : Flip Y'+CRLF+ ' P1 = Angle increment (in degrees).'+CRLF+ ' P2 = Y coordinate of the horizontal center line (*2)'+CRLF+ '8 : Pulasate '+CRLF+ ' P1 = Angle (*3) increment (in degrees).'+CRLF+ ' P2 = X coordinate of the center point (*2)'+CRLF+ ' P3 = Y coordinate of the center point (*2)'+PAR+ '9 : Rotate'+CRLF+ ' P1 = Angle increment (in degrees).'+CRLF+ ' For full cycle rotation Steps*P1 has to be a multiple of 360.'+CRLF+ ' P2 = X coordinate of the center point (*2)'+CRLF+ ' P3 = Y coordinate of the center point (*2)'+PAR+ '10: Scroll X'+CRLF+ ' P1 = Pixel increment (can be negative).'+CRLF+ ' P2 = Wraparound value. After this many pixels, "what goes around comes'+CRLF+ ' around". For nice cyclic animation, make sure that'+CRLF+ ' a. Steps is larger than or equal to Bitmap.Width '+CRLF+ ' or GetLEDCountX (depending on ClipMode).'+CRLF+ ' b. Wraparound value is a multiple of pixel increment and steps.'+PAR+ '11: Scroll Y'+CRLF+ ' P1 = Pixel increment (can be negative).'+CRLF+ ' P2 = Wraparound value. Same considerations for "Scroll X" apply.'+PAR+ '12: Wipe X'+CRLF+ ' P1 = Pixel increment (can NOT be negative).'+PAR+ '13: Wipe Y'+CRLF+ ' P1 = Pixel increment (can NOT be negative).'+PAR+ 'Notes:'+CRLF+ ' (1) Stretching uses cosecant in the transformation filter, hence the angle.'+CRLF+ ' (2) Center of display is "SCLED.LEDCountX Div 2, SCLED.LEDCountY Div 2"'+CRLF+ ' Center of text is "SCLED.Bitmap.Width Div 2, SCLED.Bitmap.Height Div 2"'+CRLF+ ' In the demo animations display center has been used.'+CRLF+ ' (3) Pulsating uses cosine in the transformation filter, hence the angle.'+CRLF+ '' ); End; {============================================================================== } procedure TDemoForm.LinesMemoChange(Sender: TObject); begin LED1.Lines.Text:=LinesMemo.Lines.Text; end; {============================================================================== } procedure TDemoForm.HAlignComboChange(Sender: TObject); begin Case HAlignCombo.ItemIndex Of 0 : LED1.AlignmentH:=schaLeft; 1 : LED1.AlignmentH:=schaCenter; 2 : LED1.AlignmentH:=schaRight; End; end; {============================================================================== } procedure TDemoForm.VAlignComboChange(Sender: TObject); begin Case VAlignCombo.ItemIndex Of 0 : LED1.AlignmentV:=scvaTop; 1 : LED1.AlignmentV:=scvaCenter; 2 : LED1.AlignmentV:=scvaBottom; End; end; {============================================================================== } procedure TDemoForm.FontButtonClick(Sender: TObject); begin FontDialog.Font:=LED1.Font; If FontDialog.Execute Then LED1.Font:=FontDialog.Font; end; {============================================================================== } procedure TDemoForm.SizeComboChange(Sender: TObject); begin LED1.LEDSize:=StrToInt(SizeCombo.Text); end; {============================================================================== } procedure TDemoForm.DistComboChange(Sender: TObject); begin LED1.LEDDistance:=StrToInt(DistCombo.Text); end; {============================================================================== } procedure TDemoForm.StyleRadioClick(Sender: TObject); begin If Style1Radio.Checked Then LED1.LEDStyle:=sclsSquare Else LED1.LEDStyle:=sclsRound; end; {============================================================================== } procedure TDemoForm.LED1AfterDrawText(Sender: TObject); begin LED1.Bitmap.Canvas.Brush.Color:=clWhite; LED1.Bitmap.Canvas.FrameRect(LED1.Bitmap.Canvas.ClipRect); end; {============================================================================== } procedure TDemoForm.AfterDrawCheckClick(Sender: TObject); begin If AfterDrawCheck.Checked Then LED1.OnAfterDrawText:=LED1AfterDrawText Else LED1.OnAfterDrawText:=NIL; end; {============================================================================== } procedure TDemoForm.ClipModeRadioClick(Sender: TObject); begin If Clip1Radio.Checked Then LED1.ClipMode:=sccmText Else LED1.ClipMode:=sccmDisplay; end; {============================================================================== } procedure TDemoForm.OffsetXTrackChange(Sender: TObject); begin LED1.OffsetX:=OffsetXTrack.Position; OffsetXBox.Text:=IntToStr(OffsetXTrack.Position); end; {============================================================================== } procedure TDemoForm.OffsetYTrackChange(Sender: TObject); begin LED1.OffsetY:=OffsetYTrack.Position; OffsetYBox.Text:=IntToStr(OffsetYTrack.Position); end; {============================================================================== } procedure TDemoForm.OffsetXBoxChange(Sender: TObject); Var N : Integer; begin Try N:=StrToInt(OffsetXBox.Text); If Abs(N)>20 Then Raise Exception.Create(''); Except On Exception Do Begin N:=0; OffsetXBox.Text:=''; End; End; LED1.OffsetX:=N; OffsetXTrack.Position:=N; end; {============================================================================== } procedure TDemoForm.OffsetYBoxChange(Sender: TObject); Var N : Integer; begin Try N:=StrToInt(OffsetYBox.Text); If Abs(N)>20 Then Raise Exception.Create(''); Except On Exception Do Begin N:=0; OffsetYBox.Text:=''; End; End; LED1.OffsetY:=N; OffsetYTrack.Position:=N; end; {============================================================================== } procedure TDemoForm.AnimsComboChange(Sender: TObject); begin Case AnimsCombo.ItemIndex+1 Of 1 : LED2.Animate(1,200,10,0,0,0); 2 : LED2.Animate(2,200,10,0,0,0); 3 : LED2.Animate(3,200,10,0,0,0); 4 : LED2.Animate(4,1,36,10,LED2.Bitmap.Width Div 2,0); 5 : LED2.Animate(5,1,36,10,LED2.Bitmap.Height Div 2,0); 6 : LED2.Animate(6,1,36,10,LED2.Bitmap.Width Div 2,0); 7 : LED2.Animate(7,1,36,10,LED2.Bitmap.Height Div 2,0); 8 : LED2.Animate(8,1,144,5,LED2.Bitmap.Width Div 2,LED2.Bitmap.Height Div 2); 9 : LED2.Animate(9,1,72,5,LED2.Bitmap.Width Div 2,LED2.Bitmap.Height Div 2); 10 : LED2.Animate(10,1,LED2.LEDCountX,2,LED2.LEDCountX*2,0); 11 : LED2.Animate(11,1,LED2.LEDCountY,2,LED2.LEDCountY*2,0); 12 : LED2.Animate(12,1,LED2.LEDCountX,4,0,0); 13 : LED2.Animate(13,1,LED2.LEDCountY,4,0,0); End; End; {============================================================================== } procedure TDemoForm.PageControl1Change(Sender: TObject); begin StopCycleButtonClick(NIL); If PageControl1.ActivePageIndex=0 Then Case Random(2) Of 0 : LED5.Animate(1,500,999,0,0,0); 1 : LED5.Animate(10,50,10000,1,LED5.LEDCountX,0); End Else LED5.StopAnimate; end; {============================================================================== } procedure TDemoForm.Button1Click(Sender: TObject); Var i : Integer; begin For i:=0 To 1024 Do Begin NumberBox.Text:=IntToStr(i); NumberBoxChange(NIL); Application.ProcessMessages; End; end; {============================================================================== } procedure TDemoForm.Label10Click(Sender: TObject); begin ShellExecute(GetDesktopWindow(), 'Open', PChar((Sender As TLabel).Caption), nil, nil, SW_SHOWNORMAL); end; {============================================================================== } end.