source: trunk/Packages/bgracontrols/tachartslicescaling/Main.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 3.4 KB
Line 
1unit Main;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, ExtCtrls, Spin, StdCtrls, SysUtils, FileUtil, Forms, Controls,
9 Graphics, Dialogs, TACustomSource, TAGraph, TASeries, TASources,
10 TAAnimatedSource,
11 BGRABitmap, BGRABitmapTypes, BGRASliceScaling, types;
12
13type
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
45var
46 Form1: TForm1;
47
48implementation
49
50{$R *.lfm}
51
52uses
53 Math;
54
55{ TForm1 }
56
57procedure TForm1.btnStartStopClick(Sender: TObject);
58begin
59 if FAnimatedSource.IsAnimating then
60 FAnimatedSource.Stop
61 else
62 FAnimatedSource.Start;
63end;
64
65procedure TForm1.Chart1BarSeries1BeforeDrawBar(ASender: TBarSeries;
66 ACanvas: TCanvas; const ARect: TRect; APointIndex, AStackIndex: Integer;
67 var ADoDefaultDrawing: Boolean);
68var
69 temp: TBGRABitmap;
70begin
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;
75end;
76
77procedure TForm1.FormCreate(Sender: TObject);
78begin
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;
91end;
92
93procedure TForm1.FormDestroy(Sender: TObject);
94begin
95 sliceScaling.Free;
96end;
97
98procedure TForm1.OnGetItem(
99 ASource: TCustomAnimatedChartSource;
100 AIndex: Integer; var AItem: TChartDataItem);
101begin
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;
113end;
114
115procedure TForm1.OnStop(ASource: TCustomAnimatedChartSource);
116begin
117 lblSkipped.Caption := Format('Skipped frames: %d', [ASource.SkippedFramesCount]);
118end;
119
120procedure TForm1.rgMethodClick(Sender: TObject);
121begin
122 FAnimatedSource.Start;
123end;
124
125procedure TForm1.seTimeChange(Sender: TObject);
126begin
127 FAnimatedSource.AnimationTime := seTime.Value;
128end;
129
130end.
131
Note: See TracBrowser for help on using the repository browser.