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

  1. unit SCLEDDemo_MainUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, ExtCtrls, ShellAPI, SCLED;
  8.  
  9. Const
  10.  
  11.   CRLF=#13#10;
  12.   PAR=#13#10#13#10;
  13.  
  14. type
  15.   TDemoForm = class(TForm)
  16.     PageControl1: TPageControl;
  17.     TabSheet1: TTabSheet;
  18.     TabSheet2: TTabSheet;
  19.     TabSheet3: TTabSheet;
  20.     LED2: TSCLED;
  21.     CycleAnimation: TButton;
  22.     StopCycleButton: TButton;
  23.     LED3: TSCLED;
  24.     ScrollButton: TButton;
  25.     LED1: TSCLED;
  26.     ForePanel: TPanel;
  27.     BackPanel: TPanel;
  28.     ColorPanel: TPanel;
  29.     ColorDialog: TColorDialog;
  30.     LinesMemo: TMemo;
  31.     Label1: TLabel;
  32.     FontButton: TButton;
  33.     FontDialog: TFontDialog;
  34.     GroupBox1: TGroupBox;
  35.     Style1Radio: TRadioButton;
  36.     Style2Radio: TRadioButton;
  37.     GroupBox2: TGroupBox;
  38.     Clip1Radio: TRadioButton;
  39.     Clip2Radio: TRadioButton;
  40.     AfterDrawCheck: TCheckBox;
  41.     RichEdit1: TRichEdit;
  42.     AnimsCombo: TComboBox;
  43.     LED4: TSCLED;
  44.     NumberBox: TEdit;
  45.     RichEdit2: TRichEdit;
  46.     RichEdit3: TRichEdit;
  47.     GroupBox3: TGroupBox;
  48.     Label4: TLabel;
  49.     SizeCombo: TComboBox;
  50.     DistCombo: TComboBox;
  51.     Label5: TLabel;
  52.     GroupBox4: TGroupBox;
  53.     Label2: TLabel;
  54.     HAlignCombo: TComboBox;
  55.     Label3: TLabel;
  56.     VAlignCombo: TComboBox;
  57.     GroupBox5: TGroupBox;
  58.     Label6: TLabel;
  59.     OffsetXBox: TEdit;
  60.     OffsetXTrack: TTrackBar;
  61.     Label7: TLabel;
  62.     OffsetYBox: TEdit;
  63.     OffsetYTrack: TTrackBar;
  64.     Label8: TLabel;
  65.     RichEdit4: TRichEdit;
  66.     Button1: TButton;
  67.     TabSheet4: TTabSheet;
  68.     Label10: TLabel;
  69.     Label11: TLabel;
  70.     Label12: TLabel;
  71.     Label13: TLabel;
  72.     LED5: TSCLED;
  73.     RichEdit5: TRichEdit;
  74.     procedure CycleAnimationClick(Sender: TObject);
  75.     procedure StopCycleButtonClick(Sender: TObject);
  76.     procedure LED2Stop(Sender: TObject);
  77.     procedure LED2AfterDrawText(Sender: TObject);
  78.     procedure NumberBoxChange(Sender: TObject);
  79.     procedure ScrollButtonClick(Sender: TObject);
  80.     procedure ForePanelClick(Sender: TObject);
  81.     procedure BackPanelClick(Sender: TObject);
  82.     procedure ColorPanelClick(Sender: TObject);
  83.     procedure FormShow(Sender: TObject);
  84.     procedure LinesMemoChange(Sender: TObject);
  85.     procedure HAlignComboChange(Sender: TObject);
  86.     procedure VAlignComboChange(Sender: TObject);
  87.     procedure FontButtonClick(Sender: TObject);
  88.     procedure SizeComboChange(Sender: TObject);
  89.     procedure DistComboChange(Sender: TObject);
  90.     procedure StyleRadioClick(Sender: TObject);
  91.     procedure LED1AfterDrawText(Sender: TObject);
  92.     procedure AfterDrawCheckClick(Sender: TObject);
  93.     procedure ClipModeRadioClick(Sender: TObject);
  94.     procedure OffsetXTrackChange(Sender: TObject);
  95.     procedure OffsetYTrackChange(Sender: TObject);
  96.     procedure OffsetXBoxChange(Sender: TObject);
  97.     procedure OffsetYBoxChange(Sender: TObject);
  98.     procedure AnimsComboChange(Sender: TObject);
  99.     procedure PageControl1Change(Sender: TObject);
  100.     procedure Button1Click(Sender: TObject);
  101.     procedure Label10Click(Sender: TObject);
  102.   private
  103.     { Private declarations }
  104.   public
  105.     { Public declarations }
  106.   end;
  107.  
  108. var
  109.   DemoForm: TDemoForm;
  110.  
  111. implementation
  112.  
  113. {$R *.DFM}
  114.  
  115. {==============================================================================
  116. }
  117. procedure TDemoForm.CycleAnimationClick(Sender: TObject);
  118. begin
  119.   LED2.OnStop:=LED2Stop;
  120.   LED2.Animate(1,1,1,0,0,0);
  121. end;
  122.  
  123. {==============================================================================
  124. }
  125. procedure TDemoForm.StopCycleButtonClick(Sender: TObject);
  126. begin
  127.   LED2.OnStop:=NIL;
  128.   LED2.StopAnimate;
  129. end;
  130.  
  131. {==============================================================================
  132. }
  133. procedure TDemoForm.LED2Stop(Sender: TObject);
  134. begin
  135.   AnimsCombo.ItemIndex:=(AnimsCombo.ItemIndex+1) Mod 13;
  136.   AnimsComboChange(AnimsCombo)
  137. end;
  138.  
  139. {==============================================================================
  140. }
  141. procedure TDemoForm.LED2AfterDrawText(Sender: TObject);
  142. begin
  143.   LED2.Bitmap.Canvas.Brush.Color:=clWhite;
  144.   LED2.Bitmap.Canvas.FrameRect(LED2.Bitmap.Canvas.ClipRect);
  145. end;
  146.  
  147. {==============================================================================
  148. }
  149. Procedure TDemoForm.NumberBoxChange(Sender: TObject);
  150. Var
  151.   i,m,n : integer;
  152. Begin
  153.   Try n:=StrToInt(NumberBox.Text); Except On Exception Do n:=0; End;
  154.   m:=1;
  155.   With LED4.Bitmap.Canvas Do
  156.      For i:=0 To 31 Do
  157.      Begin
  158.        If (n And m)<>0 Then Pixels[31-i,0]:=clWhite
  159.        Else Pixels[31-i,0]:=clBlack;
  160.        m:=m SHL 1;
  161.      End;
  162.   LED4.BitmapChanged;
  163. End;
  164.  
  165. {==============================================================================
  166. }
  167. procedure TDemoForm.ScrollButtonClick(Sender: TObject);
  168. begin
  169.   LED3.Animate(10,20,LED3.Bitmap.Width+50,1,LED3.Bitmap.Width+50,0);
  170. end;
  171.  
  172. {==============================================================================
  173. }
  174. procedure TDemoForm.ForePanelClick(Sender: TObject);
  175. begin
  176.   ColorDialog.Color:=(Sender As TPanel).Color;
  177.   If ColorDialog.Execute Then
  178.   Begin
  179.     LED1.ForeColor:=ColorDialog.Color;
  180.     (Sender As TPanel).Color:=ColorDialog.Color;
  181.     (Sender As TPanel).Font.Color:=ColorDialog.Color XOR clWhite;
  182.   End;
  183. end;
  184.  
  185. {==============================================================================
  186. }
  187. procedure TDemoForm.BackPanelClick(Sender: TObject);
  188. begin
  189.   ColorDialog.Color:=(Sender As TPanel).Color;
  190.   If ColorDialog.Execute Then
  191.   Begin
  192.     LED1.BackColor:=ColorDialog.Color;
  193.     (Sender As TPanel).Color:=ColorDialog.Color;
  194.     (Sender As TPanel).Font.Color:=ColorDialog.Color XOR clWhite;
  195.   End;
  196. end;
  197.  
  198. {==============================================================================
  199. }
  200. procedure TDemoForm.ColorPanelClick(Sender: TObject);
  201. begin
  202.   ColorDialog.Color:=(Sender As TPanel).Color;
  203.   If ColorDialog.Execute Then
  204.   Begin
  205.     LED1.Color:=ColorDialog.Color;
  206.     (Sender As TPanel).Color:=ColorDialog.Color;
  207.     (Sender As TPanel).Font.Color:=ColorDialog.Color XOR clWhite;
  208.   End;
  209. End;
  210.  
  211. {==============================================================================
  212. }
  213. procedure TDemoForm.FormShow(Sender: TObject);
  214. begin
  215.   ForePanel.Color:=LED1.ForeColor;
  216.   BackPanel.Color:=LED1.BackColor;
  217.   ColorPanel.Color:=LED1.Color;
  218.   ForePanel.Font.Color:=LED1.ForeColor XOR clWhite;
  219.   BackPanel.Font.Color:=LED1.BackColor XOR clWhite;
  220.   ColorPanel.Font.Color:=LED1.Color XOR clWhite;
  221.   LinesMemo.Lines.Text:=LED1.Lines.Text;
  222.   HAlignCombo.ItemIndex:=Ord(LED1.AlignmentH);
  223.   VAlignCombo.ItemIndex:=Ord(LED1.AlignmentV);
  224.   SizeCombo.ItemIndex:=SizeCombo.Items.IndexOf(IntToStr(LED1.LEDSize));
  225.   DistCombo.ItemIndex:=DistCombo.Items.IndexOf(IntToStr(LED1.LEDDistance));
  226.   Style1Radio.Checked:=LED1.LEDStyle=sclsSquare;
  227.   Style2Radio.Checked:=LED1.LEDStyle=sclsRound;
  228.   AfterDrawCheck.Checked:=Assigned(LED1.OnAfterDrawText);
  229.   Clip1Radio.Checked:=LED1.ClipMode=sccmText;
  230.   Clip2Radio.Checked:=LED1.ClipMode=sccmDisplay;
  231.  
  232.   RichEdit1.Lines.Add(
  233.   'TSCLED 1.0'+CRLF+'Safak Cinar, Dec 29 2001'+PAR+
  234.   'http://members.shaw.ca/safak/'+PAR+
  235.   'safak@shaw.ca'+PAR+
  236.   '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+
  237.   '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+
  238.   'TSCLED displays a monochrome bitmap (accessible through BITMAP property) with adjustable pixel size and inter pixel spacing.'+
  239.     ' 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+
  240.   'Most of the features are quite straightforward, with a couple of exceptions:'+PAR+
  241.   '* For LEDSTYLE, sclsSQUARE and sclsROUND yield identical looking displays unless LEDSIZE is larger than 2 pixels.'+PAR+
  242.   '* 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+
  243.   '* 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'+
  244.     ' WIDTH and HEIGHT become derived properties. Otherwise, LEDCOUNTX and LEDCOUNTY are derived from the other properties. Mainly a design time convenience.'+PAR+
  245.   '* 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. '+
  246.     '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. '+
  247.     'As a rule of thumb, use sccmTEXT unless you are doing custom drawing.'+PAR+
  248.   '* ALIGNMENTH doesn not use Delphi''s TALIGNMENT values but a custom enumerated type. This is in anticipation of a later feature.'
  249.   );
  250.  
  251.   RichEdit3.Lines.Add(
  252.     'The ANIMATE method takes 6 arguments:'+PAR+
  253.     'Procedure Animate(Style,Interval,Steps:Integer;P1,P2,P3:Integer);'+PAR+
  254.     'Style    : 1..13, the various animation styles.'+CRLF+
  255.     'Interval : (Minimum) duration, in milliseconds, of each animation step'+CRLF+
  256.     'Steps    : The  total number of animation steps'+CRLF+
  257.     'P1,P2,P3 : Parameters. These are specific to each animation style.'+PAR+
  258.     'Animation Styles:'+PAR+
  259.     '1 : Blink Foreground'+CRLF+
  260.     '    (no parameters)'+PAR+
  261.     '2 : Blink Background'+CRLF+
  262.     '    (no parameters)'+PAR+
  263.     '3 : Blink background and foreground (ie. Toggle)'+CRLF+
  264.     '    (no parameters)'+PAR+
  265.     '4 : Stretch X'+CRLF+
  266.     '    P1 = Angle (*1) increment (in degrees).'+CRLF+
  267.     '    P2 = X coordinate of the vertical center line (*2)'+CRLF+
  268.     '5 : Stretch Y'+CRLF+
  269.     '    P1 = Angle (*1) increment (in degrees).'+CRLF+
  270.     '    P2 = Y coordinate of the horizontal center line (*2)'+CRLF+
  271.     '6 : Flip X'+CRLF+
  272.     '    P1 = Angle increment (in degrees).'+CRLF+
  273.     '    P2 = X coordinate of the vertical center line (*2)'+CRLF+
  274.     '7 : Flip Y'+CRLF+
  275.     '    P1 = Angle increment (in degrees).'+CRLF+
  276.     '    P2 = Y coordinate of the horizontal center line (*2)'+CRLF+
  277.     '8 : Pulasate '+CRLF+
  278.     '    P1 = Angle (*3) increment (in degrees).'+CRLF+
  279.     '    P2 = X coordinate of the center point (*2)'+CRLF+
  280.     '    P3 = Y coordinate of the center point (*2)'+PAR+
  281.     '9 : Rotate'+CRLF+
  282.     '    P1 = Angle increment (in degrees).'+CRLF+
  283.     '         For full cycle rotation Steps*P1 has to be a multiple of 360.'+CRLF+
  284.     '    P2 = X coordinate of the center point (*2)'+CRLF+
  285.     '    P3 = Y coordinate of the center point (*2)'+PAR+
  286.     '10: Scroll X'+CRLF+
  287.     '    P1 = Pixel increment (can be negative).'+CRLF+
  288.     '    P2 = Wraparound value. After this many pixels, "what goes around comes'+CRLF+
  289.     '         around". For nice cyclic animation, make sure that'+CRLF+
  290.     '           a. Steps is larger than or equal to Bitmap.Width '+CRLF+
  291.     '              or GetLEDCountX (depending on ClipMode).'+CRLF+
  292.     '           b. Wraparound value is a multiple of pixel increment and steps.'+PAR+
  293.     '11: Scroll Y'+CRLF+
  294.     '    P1 = Pixel increment (can be negative).'+CRLF+
  295.     '    P2 = Wraparound value. Same considerations for "Scroll X" apply.'+PAR+
  296.     '12: Wipe X'+CRLF+
  297.     '    P1 = Pixel increment (can NOT be negative).'+PAR+
  298.     '13: Wipe Y'+CRLF+
  299.     '    P1 = Pixel increment (can NOT be negative).'+PAR+
  300.  
  301.     'Notes:'+CRLF+
  302.     '  (1) Stretching uses cosecant in the transformation filter, hence the angle.'+CRLF+
  303.     '  (2) Center of display is "SCLED.LEDCountX Div 2, SCLED.LEDCountY Div 2"'+CRLF+
  304.     '      Center of text is "SCLED.Bitmap.Width Div 2, SCLED.Bitmap.Height Div 2"'+CRLF+
  305.     '      In the demo animations display center has been used.'+CRLF+
  306.     '  (3) Pulsating uses cosine in the transformation filter, hence the angle.'+CRLF+
  307.     ''
  308.   );
  309. End;
  310.  
  311. {==============================================================================
  312. }
  313. procedure TDemoForm.LinesMemoChange(Sender: TObject);
  314. begin
  315.   LED1.Lines.Text:=LinesMemo.Lines.Text;
  316. end;
  317.  
  318. {==============================================================================
  319. }
  320. procedure TDemoForm.HAlignComboChange(Sender: TObject);
  321. begin
  322.   Case HAlignCombo.ItemIndex Of
  323.     0 : LED1.AlignmentH:=schaLeft;
  324.     1 : LED1.AlignmentH:=schaCenter;
  325.     2 : LED1.AlignmentH:=schaRight;
  326.   End;
  327. end;
  328.  
  329. {==============================================================================
  330. }
  331. procedure TDemoForm.VAlignComboChange(Sender: TObject);
  332. begin
  333.   Case VAlignCombo.ItemIndex Of
  334.     0 : LED1.AlignmentV:=scvaTop;
  335.     1 : LED1.AlignmentV:=scvaCenter;
  336.     2 : LED1.AlignmentV:=scvaBottom;
  337.   End;
  338. end;
  339.  
  340. {==============================================================================
  341. }
  342. procedure TDemoForm.FontButtonClick(Sender: TObject);
  343. begin
  344.   FontDialog.Font:=LED1.Font;
  345.   If FontDialog.Execute Then LED1.Font:=FontDialog.Font;
  346. end;
  347.  
  348. {==============================================================================
  349. }
  350. procedure TDemoForm.SizeComboChange(Sender: TObject);
  351. begin
  352.   LED1.LEDSize:=StrToInt(SizeCombo.Text);
  353. end;
  354.  
  355. {==============================================================================
  356. }
  357. procedure TDemoForm.DistComboChange(Sender: TObject);
  358. begin
  359.   LED1.LEDDistance:=StrToInt(DistCombo.Text);
  360. end;
  361.  
  362. {==============================================================================
  363. }
  364. procedure TDemoForm.StyleRadioClick(Sender: TObject);
  365. begin
  366.   If Style1Radio.Checked Then
  367.     LED1.LEDStyle:=sclsSquare
  368.   Else
  369.     LED1.LEDStyle:=sclsRound;
  370. end;
  371.  
  372. {==============================================================================
  373. }
  374. procedure TDemoForm.LED1AfterDrawText(Sender: TObject);
  375. begin
  376.   LED1.Bitmap.Canvas.Brush.Color:=clWhite;
  377.   LED1.Bitmap.Canvas.FrameRect(LED1.Bitmap.Canvas.ClipRect);
  378. end;
  379.  
  380. {==============================================================================
  381. }
  382. procedure TDemoForm.AfterDrawCheckClick(Sender: TObject);
  383. begin
  384.   If AfterDrawCheck.Checked Then
  385.     LED1.OnAfterDrawText:=LED1AfterDrawText
  386.   Else
  387.     LED1.OnAfterDrawText:=NIL;
  388. end;
  389.  
  390. {==============================================================================
  391. }
  392. procedure TDemoForm.ClipModeRadioClick(Sender: TObject);
  393. begin
  394.   If Clip1Radio.Checked Then
  395.     LED1.ClipMode:=sccmText
  396.   Else
  397.     LED1.ClipMode:=sccmDisplay;
  398. end;
  399.  
  400. {==============================================================================
  401. }
  402. procedure TDemoForm.OffsetXTrackChange(Sender: TObject);
  403. begin
  404.   LED1.OffsetX:=OffsetXTrack.Position;
  405.   OffsetXBox.Text:=IntToStr(OffsetXTrack.Position);
  406. end;
  407.  
  408. {==============================================================================
  409. }
  410. procedure TDemoForm.OffsetYTrackChange(Sender: TObject);
  411. begin
  412.   LED1.OffsetY:=OffsetYTrack.Position;
  413.   OffsetYBox.Text:=IntToStr(OffsetYTrack.Position);
  414. end;
  415.  
  416. {==============================================================================
  417. }
  418. procedure TDemoForm.OffsetXBoxChange(Sender: TObject);
  419. Var
  420.   N : Integer;
  421. begin
  422.   Try
  423.     N:=StrToInt(OffsetXBox.Text);
  424.     If Abs(N)>20 Then Raise Exception.Create('');
  425.   Except
  426.     On Exception Do
  427.     Begin
  428.       N:=0;
  429.       OffsetXBox.Text:='';
  430.     End;
  431.   End;
  432.   LED1.OffsetX:=N;
  433.   OffsetXTrack.Position:=N;
  434. end;
  435.  
  436. {==============================================================================
  437. }
  438. procedure TDemoForm.OffsetYBoxChange(Sender: TObject);
  439. Var
  440.   N : Integer;
  441. begin
  442.   Try
  443.     N:=StrToInt(OffsetYBox.Text);
  444.     If Abs(N)>20 Then Raise Exception.Create('');
  445.   Except
  446.     On Exception Do
  447.     Begin
  448.       N:=0;
  449.       OffsetYBox.Text:='';
  450.     End;
  451.   End;
  452.   LED1.OffsetY:=N;
  453.   OffsetYTrack.Position:=N;
  454. end;
  455.  
  456. {==============================================================================
  457. }
  458. procedure TDemoForm.AnimsComboChange(Sender: TObject);
  459. begin
  460.   Case AnimsCombo.ItemIndex+1 Of
  461.     1 : LED2.Animate(1,200,10,0,0,0);
  462.     2 : LED2.Animate(2,200,10,0,0,0);
  463.     3 : LED2.Animate(3,200,10,0,0,0);
  464.     4 : LED2.Animate(4,1,36,10,LED2.Bitmap.Width Div 2,0);
  465.     5 : LED2.Animate(5,1,36,10,LED2.Bitmap.Height Div 2,0);
  466.     6 : LED2.Animate(6,1,36,10,LED2.Bitmap.Width Div 2,0);
  467.     7 : LED2.Animate(7,1,36,10,LED2.Bitmap.Height Div 2,0);
  468.     8 : LED2.Animate(8,1,144,5,LED2.Bitmap.Width Div 2,LED2.Bitmap.Height Div 2);
  469.     9 : LED2.Animate(9,1,72,5,LED2.Bitmap.Width Div 2,LED2.Bitmap.Height Div 2);
  470.    10 : LED2.Animate(10,1,LED2.LEDCountX,2,LED2.LEDCountX*2,0);
  471.    11 : LED2.Animate(11,1,LED2.LEDCountY,2,LED2.LEDCountY*2,0);
  472.    12 : LED2.Animate(12,1,LED2.LEDCountX,4,0,0);
  473.    13 : LED2.Animate(13,1,LED2.LEDCountY,4,0,0);
  474.   End;
  475. End;
  476.  
  477. {==============================================================================
  478. }
  479. procedure TDemoForm.PageControl1Change(Sender: TObject);
  480. begin
  481.   StopCycleButtonClick(NIL);
  482.   If PageControl1.ActivePageIndex=0 Then
  483.     Case Random(2) Of
  484.       0 : LED5.Animate(1,500,999,0,0,0);
  485.       1 : LED5.Animate(10,50,10000,1,LED5.LEDCountX,0);
  486.     End
  487.   Else
  488.     LED5.StopAnimate;
  489. end;
  490.  
  491. {==============================================================================
  492. }
  493. procedure TDemoForm.Button1Click(Sender: TObject);
  494. Var
  495.   i : Integer;
  496. begin
  497.   For i:=0 To 1024 Do
  498.   Begin
  499.     NumberBox.Text:=IntToStr(i);
  500.     NumberBoxChange(NIL);
  501.     Application.ProcessMessages;
  502.   End;
  503. end;
  504.  
  505. {==============================================================================
  506. }
  507. procedure TDemoForm.Label10Click(Sender: TObject);
  508. begin
  509.   ShellExecute(GetDesktopWindow(), 'Open', PChar((Sender As TLabel).Caption), nil, nil, SW_SHOWNORMAL);
  510. end;
  511.  
  512. {==============================================================================
  513. }
  514. end.
  515.