| 1 | unit Main;
|
|---|
| 2 |
|
|---|
| 3 | {$mode objfpc}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, ExtCtrls, Spin, StdCtrls, SysUtils, FileUtil, Forms, Controls,
|
|---|
| 9 | Graphics, Dialogs, TACustomSource, TAGraph, TASeries, TASources,
|
|---|
| 10 | TAAnimatedSource,
|
|---|
| 11 | BGRABitmap, BGRABitmapTypes, BGRASliceScaling, types;
|
|---|
| 12 |
|
|---|
| 13 | type
|
|---|
| 14 |
|
|---|
| 15 | { TForm1 }
|
|---|
| 16 |
|
|---|
| 17 | TForm1 = class(TForm)
|
|---|
| 18 | btnStartStop: TButton;
|
|---|
| 19 | Chart1: TChart;
|
|---|
| 20 | Chart1BarSeries1: TBarSeries;
|
|---|
| 21 | Image1: TImage;
|
|---|
| 22 | lblSkipped: TLabel;
|
|---|
| 23 | ListChartSource1: TListChartSource;
|
|---|
| 24 | Panel1: TPanel;
|
|---|
| 25 | rgMethod: TRadioGroup;
|
|---|
| 26 | seTime: TSpinEdit;
|
|---|
| 27 | procedure btnStartStopClick(Sender: TObject);
|
|---|
| 28 | procedure Chart1BarSeries1BeforeDrawBar(ASender: TBarSeries;
|
|---|
| 29 | ACanvas: TCanvas; const ARect: TRect; APointIndex, AStackIndex: Integer;
|
|---|
| 30 | var ADoDefaultDrawing: Boolean);
|
|---|
| 31 | procedure FormCreate(Sender: TObject);
|
|---|
| 32 | procedure FormDestroy(Sender: TObject);
|
|---|
| 33 | procedure rgMethodClick(Sender: TObject);
|
|---|
| 34 | procedure seTimeChange(Sender: TObject);
|
|---|
| 35 | private
|
|---|
| 36 | FAnimatedSource: TCustomAnimatedChartSource;
|
|---|
| 37 | procedure OnGetItem(
|
|---|
| 38 | ASource: TCustomAnimatedChartSource;
|
|---|
| 39 | AIndex: Integer; var AItem: TChartDataItem);
|
|---|
| 40 | procedure OnStop(ASource: TCustomAnimatedChartSource);
|
|---|
| 41 | public
|
|---|
| 42 | sliceScaling: TBGRASliceScaling;
|
|---|
| 43 | end;
|
|---|
| 44 |
|
|---|
| 45 | var
|
|---|
| 46 | Form1: TForm1;
|
|---|
| 47 |
|
|---|
| 48 | implementation
|
|---|
| 49 |
|
|---|
| 50 | {$R *.lfm}
|
|---|
| 51 |
|
|---|
| 52 | uses
|
|---|
| 53 | Math;
|
|---|
| 54 |
|
|---|
| 55 | { TForm1 }
|
|---|
| 56 |
|
|---|
| 57 | procedure TForm1.btnStartStopClick(Sender: TObject);
|
|---|
| 58 | begin
|
|---|
| 59 | if FAnimatedSource.IsAnimating then
|
|---|
| 60 | FAnimatedSource.Stop
|
|---|
| 61 | else
|
|---|
| 62 | FAnimatedSource.Start;
|
|---|
| 63 | end;
|
|---|
| 64 |
|
|---|
| 65 | procedure TForm1.Chart1BarSeries1BeforeDrawBar(ASender: TBarSeries;
|
|---|
| 66 | ACanvas: TCanvas; const ARect: TRect; APointIndex, AStackIndex: Integer;
|
|---|
| 67 | var ADoDefaultDrawing: Boolean);
|
|---|
| 68 | var
|
|---|
| 69 | temp: TBGRABitmap;
|
|---|
| 70 | begin
|
|---|
| 71 | temp := TBGRABitmap.Create(ARect.Right - ARect.Left, ARect.Bottom - ARect.Top);
|
|---|
| 72 | sliceScaling.Draw(temp, 0, 0, temp.Width, temp.Height, False);
|
|---|
| 73 | temp.Draw(ACanvas, ARect.Left, ARect.Top, False);
|
|---|
| 74 | temp.Free;
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | procedure TForm1.FormCreate(Sender: TObject);
|
|---|
| 78 | begin
|
|---|
| 79 | FAnimatedSource := TCustomAnimatedChartSource.Create(Self);
|
|---|
| 80 | FAnimatedSource.Origin := ListChartSource1;
|
|---|
| 81 | FAnimatedSource.AnimationInterval := 30;
|
|---|
| 82 | FAnimatedSource.OnGetItem := @OnGetItem;
|
|---|
| 83 | FAnimatedSource.OnStop := @OnStop;
|
|---|
| 84 | seTimeChange(nil);
|
|---|
| 85 | Chart1BarSeries1.Source := FAnimatedSource;
|
|---|
| 86 | FAnimatedSource.Start;
|
|---|
| 87 |
|
|---|
| 88 | sliceScaling := TBGRASliceScaling.Create(Image1.Picture.Bitmap, 70, 0, 35, 0);
|
|---|
| 89 | //sliceScaling.ResampleMode := rmSimpleStretch;
|
|---|
| 90 | sliceScaling.AutodetectRepeat;
|
|---|
| 91 | end;
|
|---|
| 92 |
|
|---|
| 93 | procedure TForm1.FormDestroy(Sender: TObject);
|
|---|
| 94 | begin
|
|---|
| 95 | sliceScaling.Free;
|
|---|
| 96 | end;
|
|---|
| 97 |
|
|---|
| 98 | procedure TForm1.OnGetItem(
|
|---|
| 99 | ASource: TCustomAnimatedChartSource;
|
|---|
| 100 | AIndex: Integer; var AItem: TChartDataItem);
|
|---|
| 101 | begin
|
|---|
| 102 | case rgMethod.ItemIndex of
|
|---|
| 103 | 0: AItem.Y *= ASource.Progress;
|
|---|
| 104 | 1:
|
|---|
| 105 | if ASource.Count * ASource.Progress < AIndex then
|
|---|
| 106 | AItem.Y := 0;
|
|---|
| 107 | 2:
|
|---|
| 108 | case Sign(Trunc(ASource.Count * ASource.Progress) - AIndex) of
|
|---|
| 109 | 0: AItem.Y *= Frac(ASource.Count * ASource.Progress);
|
|---|
| 110 | -1: AItem.Y := 0;
|
|---|
| 111 | end;
|
|---|
| 112 | end;
|
|---|
| 113 | end;
|
|---|
| 114 |
|
|---|
| 115 | procedure TForm1.OnStop(ASource: TCustomAnimatedChartSource);
|
|---|
| 116 | begin
|
|---|
| 117 | lblSkipped.Caption := Format('Skipped frames: %d', [ASource.SkippedFramesCount]);
|
|---|
| 118 | end;
|
|---|
| 119 |
|
|---|
| 120 | procedure TForm1.rgMethodClick(Sender: TObject);
|
|---|
| 121 | begin
|
|---|
| 122 | FAnimatedSource.Start;
|
|---|
| 123 | end;
|
|---|
| 124 |
|
|---|
| 125 | procedure TForm1.seTimeChange(Sender: TObject);
|
|---|
| 126 | begin
|
|---|
| 127 | FAnimatedSource.AnimationTime := seTime.Value;
|
|---|
| 128 | end;
|
|---|
| 129 |
|
|---|
| 130 | end.
|
|---|
| 131 |
|
|---|