1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
unit Main;
{$mode objfpc}{$H+}
interface
uses
Classes, ComCtrls, ExtCtrls, StdCtrls, SysUtils, FileUtil, Forms, Controls,
Graphics, Dialogs, TAGraph, TAGUIConnectorBGRA, TASeries, TASources,
TAAnimatedSource, TACustomSource, BGRASliceScaling;
type
{ TForm1 }
TForm1 = class(TForm)
btnStartStop: TButton;
cbAntialiasing: TCheckBox;
cbPie: TCheckBox;
ChartGUIConnectorBGRA1: TChartGUIConnectorBGRA;
cbUseConnector: TCheckBox;
chSimple: TChart;
chSimpleAreaSeries1: TAreaSeries;
chSimpleBarSeries1: TBarSeries;
chSimpleLineSeries1: TLineSeries;
chSimplePieSeries1: TPieSeries;
chBarEffects: TChart;
chBarEffectsBarSeries1: TBarSeries;
Image1: TImage;
ListChartSource1: TListChartSource;
PageControl1: TPageControl;
PaintBox1: TPaintBox;
Panel1: TPanel;
Panel2: TPanel;
RandomChartSource1: TRandomChartSource;
rgAnimation: TRadioGroup;
rgStyle: TRadioGroup;
Splitter1: TSplitter;
tsSimple: TTabSheet;
tsBarEffects: TTabSheet;
procedure btnStartStopClick(Sender: TObject);
procedure cbAntialiasingChange(Sender: TObject);
procedure cbPieChange(Sender: TObject);
procedure cbUseConnectorChange(Sender: TObject);
procedure chSimpleAfterPaint(ASender: TChart);
procedure chBarEffectsBarSeries1BeforeDrawBar(ASender: TBarSeries;
ACanvas: TCanvas; const ARect: TRect; APointIndex, AStackIndex: Integer;
var ADoDefaultDrawing: Boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure rgAnimationClick(Sender: TObject);
procedure rgStyleClick(Sender: TObject);
private
FAnimatedSource: TCustomAnimatedChartSource;
FSliceScaling: TBGRASliceScaling;
procedure OnGetItem(
ASource: TCustomAnimatedChartSource;
AIndex: Integer; var AItem: TChartDataItem);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
Math, BGRABitmap, BGRABitmapTypes, BGRAGradients,
TABGRAUtils, TAChartUtils, TADrawerBGRA, TADrawerCanvas, TADrawUtils,
TAGeometry;
{ TForm1 }
procedure TForm1.btnStartStopClick(Sender: TObject);
begin
if FAnimatedSource.IsAnimating then
FAnimatedSource.Stop
else
FAnimatedSource.Start;
end;
procedure TForm1.cbAntialiasingChange(Sender: TObject);
begin
if cbAntialiasing.Checked then
chSimple.AntialiasingMode := amOn
else
chSimple.AntialiasingMode := amOff;
end;
procedure TForm1.cbPieChange(Sender: TObject);
begin
chSimplePieSeries1.Active := cbPie.Checked;
end;
procedure TForm1.cbUseConnectorChange(Sender: TObject);
begin
if cbUseConnector.Checked then
chSimple.GUIConnector := ChartGUIConnectorBGRA1
else
chSimple.GUIConnector := nil;
end;
procedure TForm1.chSimpleAfterPaint(ASender: TChart);
begin
Unused(ASender);
PaintBox1.Invalidate;
end;
procedure TForm1.chBarEffectsBarSeries1BeforeDrawBar(ASender: TBarSeries;
ACanvas: TCanvas; const ARect: TRect; APointIndex, AStackIndex: Integer;
var ADoDefaultDrawing: Boolean);
var
temp, stretched: TBGRABitmap;
sz: TPoint;
lightPos: TPoint;
begin
Unused(ASender);
Unused(APointIndex, AStackIndex);
ADoDefaultDrawing := false;
sz := ARect.BottomRight - ARect.TopLeft;
case rgStyle.ItemIndex of
0: begin
temp := TBGRABitmap.Create(
FSliceScaling.BitmapWidth,
Round(FSliceScaling.BitmapWidth * sz.Y / sz.X));
stretched := nil;
try
FSliceScaling.Draw(temp, 0, 0, temp.Width, temp.Height);
temp.ResampleFilter := rfLinear;
stretched := temp.Resample(sz.x, sz.Y, rmFineResample) as TBGRABitmap;
stretched.Draw(ACanvas, ARect, False);
finally
temp.Free;
stretched.Free;
end;
end;
1: DrawChocolateBar(ASender, ACanvas, ARect, APointIndex, false);
2: DrawPhong3DBar(ASender, ACanvas, ARect, APointIndex);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FAnimatedSource := TCustomAnimatedChartSource.Create(Self);
FAnimatedSource.Origin := ListChartSource1;
FAnimatedSource.AnimationInterval := 30;
FAnimatedSource.AnimationTime := 1000;
FAnimatedSource.OnGetItem := @OnGetItem;
chBarEffectsBarSeries1.Source := FAnimatedSource;
chBarEffects.BackColor:= BGRAToColor(CSSDarkSlateBlue);
chSimple.BackColor:= BGRAToColor(CSSYellowGreen);
chSimple.Color:= BGRAToColor(CSSYellowGreen);
chSimple.BackColor := BGRAToColor(CSSBeige);
FSliceScaling := TBGRASliceScaling.Create(Image1.Picture.Bitmap, 70, 0, 35, 0);
FSliceScaling.AutodetectRepeat;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FSliceScaling.Free;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
bmp: TBGRABitmap;
id: IChartDrawer;
rp: TChartRenderingParams;
begin
bmp := TBGRABitmap.Create(PaintBox1.Width, PaintBox1.Height);
chSimple.DisableRedrawing;
try
chSimple.Title.Text.Text := 'BGRABitmap';
id := TBGRABitmapDrawer.Create(bmp);
id.DoGetFontOrientation := @CanvasGetFontOrientationFunc;
rp := chSimple.RenderingParams;
chSimple.Draw(id, Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
chSimple.RenderingParams := rp;
bmp.Draw(PaintBox1.Canvas, 0, 0);
chSimple.Title.Text.Text := 'Standard';
finally
chSimple.EnableRedrawing;
bmp.Free;
end;
end;
procedure TForm1.OnGetItem(
ASource: TCustomAnimatedChartSource;
AIndex: Integer; var AItem: TChartDataItem);
begin
case rgAnimation.ItemIndex of
0: AItem.Y *= ASource.Progress;
1:
if ASource.Count * ASource.Progress < AIndex then
AItem.Y := 0;
2:
case Sign(Trunc(ASource.Count * ASource.Progress) - AIndex) of
0: AItem.Y *= Frac(ASource.Count * ASource.Progress);
-1: AItem.Y := 0;
end;
end;
end;
procedure TForm1.rgAnimationClick(Sender: TObject);
begin
FAnimatedSource.Start;
end;
procedure TForm1.rgStyleClick(Sender: TObject);
var
d: Integer;
begin
d := IfThen(rgStyle.ItemIndex = 2, 10, 0);
chBarEffects.Depth := d;
chBarEffectsBarSeries1.Depth := d;
chBarEffectsBarSeries1.ZPosition := d;
chBarEffects.BottomAxis.ZPosition := d;
FAnimatedSource.Start;
end;
end.
|