unit Main; interface uses WebDOM, WebCore, WebUI, WebForms, WebCtrls, WebCtnrs, WebLabels, WebIcons, WebBtns, WebPages, WebEdits, WebLists, WebCals, WebProgs, WebComps, WebGrids, WebBrwsr, WebSlide, WebPaint, WebSizer, WebMenus, WebTlbrs, WebMedia, WebMaps, WebData; const MAX_NUM_PARTICLES = 100; MAX_POINT_HISTORY = 45; type external TMath emit Math = class public class function random: Double; end; TParticle = class(TObject) private FPaint: TPaint; FPosition: TCanvasPoint; FDistance: TCanvasPoint; FHistoryCount: Integer; FHistory: TCanvasPoints; FSize: Double; FColor: TColor; function CalculateDistance(APos: Double; ADistance: Double): Double; procedure UpdatePosition; procedure UpdateHistory; public constructor Create(APaintControl: TPaint); virtual; destructor Destroy; override; property Position: TCanvasPoint read FPosition; property Distance: TCanvasPoint read FDistance; property Size: Double read FSize; property Color: TColor read FColor; procedure Draw(AMousePoint: TPoint); end; TMainForm = class(TForm) HeaderPanel1: THeaderPanel; Label51: TLabel; Icon1: TIcon; MainPanel: TBasicPanel; PagePanel1: TPagePanel; StandardPage: TPage; GraphicsPage: TPage; LabelsGroupPanel: TGroupPanel; AlertLabel1: TAlertLabel; Label1: TLabel; BalloonLabel1: TBalloonLabel; ButtonsIndicatorsGroupPanel: TGroupPanel; Button1: TButton; DialogButton1: TDialogButton; Label2: TLabel; IconButton1: TIconButton; InputGroupPanel: TGroupPanel; Edit1: TEdit; PasswordEdit1: TPasswordEdit; Label3: TLabel; MultiLineEdit1: TMultiLineEdit; EditComboBox1: TEditComboBox; CheckBox1: TCheckBox; RadioButton1: TRadioButton; RadioButton2: TRadioButton; DateEditComboBox1: TDateEditComboBox; ListBox1: TListBox; Label4: TLabel; Calendar1: TCalendar; ButtonComboBox1: TButtonComboBox; Label5: TLabel; Label6: TLabel; FileComboBox1: TFileComboBox; GridPage: TPage; Label7: TLabel; Label8: TLabel; ProgressBarTimer: TTimer; Grid1: TGrid; ImagesIconsGroupPanel: TGroupPanel; Image1: TImage; Label10: TLabel; CanvasGroupPanel: TGroupPanel; BasicPanel1: TBasicPanel; SlideShow1: TSlideShow; Label12: TLabel; BasicPanel2: TBasicPanel; Label13: TLabel; Paint1: TPaint; Label14: TLabel; PaintTimer: TTimer; Label15: TLabel; Link1: TLink; ContainersDialogsPage: TPage; HeaderPanel2: THeaderPanel; Label16: TLabel; BasicPanel3: TBasicPanel; Label18: TLabel; GroupPanel1: TGroupPanel; Panel1: TPanel; PagePanel2: TPagePanel; Page1: TPage; Page2: TPage; Page3: TPage; Page4: TPage; Label19: TLabel; BasicPanel4: TBasicPanel; ScrollPanel1: TScrollPanel; Label17: TLabel; Icon3: TIcon; MenuToolbarsPage: TPage; SideMenu: TMenu; ToolBar1: TToolBar; ToolBarButton1: TToolBarButton; ToolBarButton2: TToolBarButton; ToolBarButton3: TToolBarButton; ToolBarButton4: TToolBarButton; ToolBarButton5: TToolBarButton; ToolBarButton6: TToolBarButton; ToolBarButton7: TToolBarButton; ToolBarButton8: TToolBarButton; ToolBarButton9: TToolBarButton; HTMLPage: TPage; MultimediaPage: TPage; ShowMessageDialogButton: TButton; ShowProgressDialogButton: TButton; ProgressDialogTimer: TTimer; MenuItem1: TMenuItem; MenuItem2: TMenuItem; MenuItem3: TMenuItem; MenuSeparatorItem1: TMenuSeparatorItem; MenuSeparatorItem2: TMenuSeparatorItem; MenuItem4: TMenuItem; MenuItem5: TMenuItem; MenuItem6: TMenuItem; MenuItem7: TMenuItem; MenuItem8: TMenuItem; MenuItem9: TMenuItem; MenuSeparatorItem3: TMenuSeparatorItem; Label20: TLabel; Label21: TLabel; Label22: TLabel; Audio1: TAudio; Label23: TLabel; TracksPlayerPanel: TBasicPanel; PlayButton: TIconButton; PauseButton: TIconButton; NowPlayingPanel: TBasicPanel; NowPlayingTrackLabel: TLabel; NowPlayingCategoryLabel: TLabel; VolumeDownButton: TIconButton; VolumeBar: TProgressBar; VolumeUpButton: TIconButton; Label24: TLabel; BasicPanel5: TBasicPanel; Video1: TVideo; PluginPage: TPage; MapPage: TPage; Link3: TLink; Label26: TLabel; BasicPanel6: TBasicPanel; Browser1: TBrowser; Label27: TLabel; Plugin1: TPlugin; Label28: TLabel; Label29: TLabel; Map1: TMap; Country: TDataSet; GridColumn1: TGridColumn; GridColumn2: TGridColumn; GridColumn3: TGridColumn; GridColumn4: TGridColumn; GridColumn7: TGridColumn; DataSetToolBar1: TDataSetToolBar; Button2: TButton; Label30: TLabel; Link4: TLink; Label25: TLabel; Link2: TLink; Label9: TLabel; ProgressBar1: TProgressBar; Label32: TLabel; Label33: TLabel; Label34: TLabel; MenuBar1: TMenuBar; MenuBarItem1: TMenuBarItem; MenuBarItem2: TMenuBarItem; MenuBarItem3: TMenuBarItem; MenuBarItem8: TMenuBarItem; FileMenu: TMenu; MenuItem10: TMenuItem; MenuItem11: TMenuItem; MenuItem12: TMenuItem; MenuSeparatorItem4: TMenuSeparatorItem; MenuItem13: TMenuItem; MenuSeparatorItem5: TMenuSeparatorItem; NewSubMenu: TMenu; MenuItem14: TMenuItem; MenuItem15: TMenuItem; MenuItem16: TMenuItem; EditMenu: TMenu; MenuItem17: TMenuItem; MenuItem18: TMenuItem; MenuItem19: TMenuItem; MenuItem20: TMenuItem; ViewMenu: TMenu; Navigator: TMenuItem; MenuItem22: TMenuItem; MenuSeparatorItem6: TMenuSeparatorItem; HelpMenu: TMenu; Navigator1: TMenuItem; MenuSeparatorItem7: TMenuSeparatorItem; MenuItem21: TMenuItem; Label35: TLabel; HTMLLabel1: THTMLLabel; Label11: TLabel; Icon2: TIcon; function AlertLabel1CloseQuery(Sender: TObject): Boolean; procedure MainFormCreate(Sender: TObject); procedure ProgressBarTimerTimer(Sender: TObject); procedure GraphicsPageShow(Sender: TObject); procedure Paint1MouseMove(Sender: TObject; ShiftKey, CtrlKey, AltKey: Boolean; X, Y: Integer); procedure PaintTimerTimer(Sender: TObject); procedure GraphicsPageHide(Sender: TObject); procedure StandardPageShow(Sender: TObject); procedure StandardPageHide(Sender: TObject); procedure MainFormShow(Sender: TObject); function Panel1CloseQuery(Sender: TObject): Boolean; procedure ShowMessageDialogButtonClick(Sender: TObject); procedure ShowProgressDialogButtonClick(Sender: TObject); procedure ProgressDialogTimerTimer(Sender: TObject); function Page3CloseQuery(Sender: TObject): Boolean; procedure MultimediaPageShow(Sender: TObject); procedure VolumeDownButtonClick(Sender: TObject); procedure Audio1Play(Sender: TObject); procedure Audio1Pause(Sender: TObject); procedure Audio1VolumeChange(Sender: TObject); procedure Audio1Ended(Sender: TObject); procedure PauseButtonClick(Sender: TObject); procedure PlayButtonClick(Sender: TObject); procedure VolumeUpButtonClick(Sender: TObject); procedure MultimediaPageHide(Sender: TObject); procedure HTMLPageShow(Sender: TObject); procedure PluginPageShow(Sender: TObject); procedure Map1APILoad(Sender: TObject); procedure CountryAfterLoad(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure DialogButton1Click(Sender: TObject); private Particles: array of TParticle; MousePoint: TPoint; TrackActive: Boolean; procedure CreateParticles; procedure UpdatePlayerButton(Playing, Paused: Boolean); public procedure StartParticlesAnimation; procedure StopParticlesAnimation; end; var MainForm: TMainForm; implementation uses WebHTTP; constructor TParticle.Create(APaintControl: TPaint); begin inherited Create; FPaint:=APaintControl; FPosition:=TCanvasPoint.Create; with FPosition do begin X:=(TMath.Random*FPaint.ClientWidth); Y:=(TMath.Random*FPaint.ClientHeight); end; FDistance:=TCanvasPoint.Create; with FDistance do begin X:=((TMath.Random*2)-1); Y:=((TMath.Random*2)-1); end; SetLength(FHistory,FHistoryCount); FSize:=(4+TMath.Random*6); if (TMath.Random > 0.5) then FColor:=clElevateLightBlue else if (TMath.Random > 0.5) then FColor:=clElevateLightGreen else FColor:=clElevateLightBlack; end; destructor TParticle.Destroy; var I: Integer; begin FPosition.Free; FPosition:=nil; FDistance.Free; FDistance:=nil; try for I:=0 to FHistoryCount-1 do begin FHistory[I].Free; FHistory:=nil; end; finally FHistoryCount:=0; end; inherited Destroy; end; function TParticle.CalculateDistance(APos: Double; ADistance: Double): Double; begin if (APos > FPaint.ClientWidth) then Result:=(-1-TMath.Random) else if (APos < 0) then Result:=(1+TMath.Random) else Result:=(ADistance*(1+(TMath.Random*0.005))); end; procedure TParticle.UpdatePosition; begin FPosition.X:=(FPosition.X+FDistance.X); FPosition.Y:=(FPosition.Y+FDistance.Y); FDistance.X:=CalculateDistance(FPosition.X,FDistance.X); FDistance.Y:=CalculateDistance(FPosition.Y,FDistance.Y); end; procedure TParticle.UpdateHistory; var TempHistory: TCanvasPoint; begin if (FHistoryCount=MAX_POINT_HISTORY) then begin TempHistory:=FHistory[0]; Delete(FHistory,0,1); TempHistory.Free; Dec(FHistoryCount); end; Inc(FHistoryCount); SetLength(FHistory,FHistoryCount); TempHistory:=TCanvasPoint.Create; FHistory[FHistoryCount-1]:=TempHistory; with TempHistory do begin X:=FPosition.X; Y:=FPosition.Y; end; end; procedure TParticle.Draw(AMousePoint: TPoint); var I: Integer; TempPoint: TCanvasPoint; TempDistanceFactor: Double; begin UpdatePosition; with FPaint.Canvas do begin StrokeColor:=FColor; BeginPath; for I:=0 to FHistoryCount-1 do LineTo(FHistory[I].X,FHistory[I].Y); Stroke; UpdateHistory; TempPoint:=TCanvasPoint.Create((FPosition.X-AMousePoint.X), (FPosition.Y-AMousePoint.Y)); try TempDistanceFactor:=Sqrt((TempPoint.X*TempPoint.X)+(TempPoint.Y*TempPoint.Y)); TempDistanceFactor:=Max(Min(10-(TempDistanceFactor/5),5),1); finally TempPoint.Free; TempPoint:=nil; end; FillColor:=FColor; BeginPath; Arc(FPosition.X,FPosition.Y,(FSize*TempDistanceFactor),0,(PI*2),True); ClosePath; Fill; end; end; function TMainForm.AlertLabel1CloseQuery(Sender: TObject): Boolean; begin Result:=False; end; procedure TMainForm.MainFormCreate(Sender: TObject); begin MousePoint:=TPoint.Create; Application.ViewPort.OverflowY:=otAuto; with Application.Surface do begin Constraints.Min.Height:=(Self.Height+40); Background.Fill.Color:=clElevateFillGray; end; end; procedure TMainForm.ProgressBarTimerTimer(Sender: TObject); begin if (ProgressBar1.Position=100) then ProgressBar1.Position:=0 else ProgressBar1.Position:=(ProgressBar1.Position+10); end; procedure TMainForm.GraphicsPageShow(Sender: TObject); begin SlideShow1.Start; StartParticlesAnimation; end; procedure TMainForm.CreateParticles; var I: Integer; begin SetLength(Particles,MAX_NUM_PARTICLES); for I:=0 to MAX_NUM_PARTICLES-1 do Particles[I]:=TParticle.Create(Paint1); end; procedure TMainForm.StartParticlesAnimation; begin CreateParticles; with Paint1.Canvas do begin BeginPath; ClearRect(0,0,Width,Height); end; PaintTimer.Enabled:=True; end; procedure TMainForm.StopParticlesAnimation; begin PaintTimer.Enabled:=False; end; procedure TMainForm.PaintTimerTimer(Sender: TObject); var I: Integer; begin with Paint1.Canvas do ClearRect(0,0,Width,Height); for I:=0 to MAX_NUM_PARTICLES-1 do Particles[I].Draw(MousePoint); end; procedure TMainForm.Paint1MouseMove(Sender: TObject; ShiftKey, CtrlKey, AltKey: Boolean; X, Y: Integer); begin MousePoint.X:=X; MousePoint.Y:=Y; end; procedure TMainForm.GraphicsPageHide(Sender: TObject); begin SlideShow1.Stop; StopParticlesAnimation; end; procedure TMainForm.StandardPageShow(Sender: TObject); begin ProgressBarTimer.Enabled:=True; end; procedure TMainForm.StandardPageHide(Sender: TObject); begin ProgressBarTimer.Enabled:=False; end; procedure TMainForm.MainFormShow(Sender: TObject); begin Database.AutoTransactions:=False; Database.DatabaseName:='ExampleData'; Database.LoadRows(Country); ProgressBarTimer.Enabled:=True; end; function TMainForm.Panel1CloseQuery(Sender: TObject): Boolean; begin Result:=False; end; procedure TMainForm.ShowMessageDialogButtonClick(Sender: TObject); begin MessageDlg('This is a message dialog','TDialog',mtInformation,[mbOk,mbCancel],mbOk,nil,True); end; procedure TMainForm.ShowProgressDialogButtonClick(Sender: TObject); begin ShowProgress('TProgressDialog'); ProgressDialogTimer.Enabled:=True; end; procedure TMainForm.ProgressDialogTimerTimer(Sender: TObject); begin ProgressDialogTimer.Enabled:=False; HideProgress; end; function TMainForm.Page3CloseQuery(Sender: TObject): Boolean; begin Result:=False; end; procedure TMainForm.MultimediaPageShow(Sender: TObject); begin VolumeBar.Position:=Audio1.Volume; Audio1.Pause; Audio1.SourceURL:='audio1.mp3'; NowPlayingTrackLabel.Caption:='Amelia Earhart - The Future of Women in Flying'; NowPlayingCategoryLabel.Caption:='Famous Public Domain Speeches'; Video1.SourceURL:='video1.mp4'; Video1.Play; end; procedure TMainForm.UpdatePlayerButton(Playing, Paused: Boolean); begin TracksPlayerPanel.BeginUpdate; try if Playing then begin PlayButton.Visible:=False; PauseButton.Visible:=True; NowPlayingPanel.Visible:=True; end else begin PlayButton.Visible:=True; PauseButton.Visible:=False; if (not Paused) then NowPlayingPanel.Visible:=False; end; finally TracksPlayerPanel.EndUpdate; end; end; procedure TMainForm.Audio1Play(Sender: TObject); begin UpdatePlayerButton(True,False); end; procedure TMainForm.Audio1Pause(Sender: TObject); begin UpdatePlayerButton(False,True); end; procedure TMainForm.PauseButtonClick(Sender: TObject); begin Audio1.Pause; end; procedure TMainForm.PlayButtonClick(Sender: TObject); begin if Audio1.Ended or (not TrackActive) or Audio1.Paused then Audio1.Play; end; procedure TMainForm.VolumeDownButtonClick(Sender: TObject); begin Audio1.Volume:=Max(0,(Audio1.Volume-10)); end; procedure TMainForm.Audio1VolumeChange(Sender: TObject); begin VolumeBar.Position:=Audio1.Volume; end; procedure TMainForm.Audio1Ended(Sender: TObject); begin UpdatePlayerButton(False,False); end; procedure TMainForm.VolumeUpButtonClick(Sender: TObject); begin Audio1.Volume:=Min(100,(Audio1.Volume+10)); end; procedure TMainForm.MultimediaPageHide(Sender: TObject); begin Video1.Pause; end; procedure TMainForm.HTMLPageShow(Sender: TObject); begin Browser1.URL:='TBrowser1.html'; end; procedure TMainForm.PluginPageShow(Sender: TObject); begin Plugin1.URL:='TPlugin1.pdf'; end; procedure TMainForm.Map1APILoad(Sender: TObject); begin with Map1.Locations.Add do begin Center:=True; Address:='Paris, France'; end; end; procedure TMainForm.CountryAfterLoad(Sender: TObject); begin Country.Columns['Code'].SortDirection:=sdAscending; end; procedure TMainForm.Button2Click(Sender: TObject); begin Browser1.Print; end; procedure TMainForm.Button1Click(Sender: TObject); begin if Button1.Icon.Animating then Button1.Icon.StopAnimation else Button1.Icon.StartAnimation; end; procedure TMainForm.DialogButton1Click(Sender: TObject); begin if (DialogButton1.Icon.IconName='') then begin DialogButton1.BeginUpdate; try DialogButton1.Icon.IconName:='DemoDialogButtonIcon'; DialogButton1.Icon.Height:=18; DialogButton1.Icon.Width:=18; finally DialogButton1.EndUpdate; end; end else DialogButton1.Icon.IconName:=''; end; end.