TAChart: Add event OnCustomDrawBar to TBarSeries, deprecate old OnBeforeDrawBar. Rename TPieSeries.OnDrawPie to .OnCustomDrawPie.

git-svn-id: trunk@60755 -
This commit is contained in:
wp 2019-03-23 23:19:53 +00:00
parent 4c1be2535c
commit 47bccc778c
6 changed files with 115 additions and 58 deletions

View File

@ -9,7 +9,7 @@ object Form1: TForm1
OnCreate = FormCreate
OnDestroy = FormDestroy
Position = poScreenCenter
LCLVersion = '1.1'
LCLVersion = '2.1.0.0'
object Splitter1: TSplitter
Left = 0
Height = 481
@ -27,12 +27,12 @@ object Form1: TForm1
TabOrder = 1
object tsSimple: TTabSheet
Caption = 'Simple'
ClientHeight = 455
ClientHeight = 453
ClientWidth = 708
object Panel1: TPanel
Left = 0
Height = 34
Top = 421
Top = 419
Width = 708
Align = alBottom
ClientHeight = 34
@ -40,27 +40,27 @@ object Form1: TForm1
TabOrder = 0
object cbAntialiasing: TCheckBox
Left = 8
Height = 17
Height = 19
Top = 8
Width = 74
Width = 82
Caption = 'Antialiasing'
OnChange = cbAntialiasingChange
TabOrder = 0
end
object cbPie: TCheckBox
Left = 104
Height = 17
Height = 19
Top = 8
Width = 34
Width = 36
Caption = 'Pie'
OnChange = cbPieChange
TabOrder = 1
end
object cbUseConnector: TCheckBox
Left = 164
Height = 17
Height = 19
Top = 8
Width = 172
Width = 185
Caption = 'Use BGRA for standard drawing'
OnChange = cbUseConnectorChange
TabOrder = 2
@ -68,7 +68,7 @@ object Form1: TForm1
end
object chSimple: TChart
Left = 0
Height = 421
Height = 419
Top = 0
Width = 354
AntialiasingMode = amOff
@ -76,13 +76,17 @@ object Form1: TForm1
item
Marks.LabelFont.Height = 13
Marks.LabelFont.Orientation = 400
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.LabelFont.Height = 13
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end>
BackColor = clMoneyGreen
Foot.Brush.Color = clBtnFace
@ -99,7 +103,6 @@ object Form1: TForm1
Align = alLeft
Color = clGreen
DoubleBuffered = True
ParentColor = False
object chSimpleLineSeries1: TLineSeries
ZPosition = 10
LinePen.Color = clMaroon
@ -126,7 +129,7 @@ object Form1: TForm1
end
object PaintBox1: TPaintBox
Left = 354
Height = 421
Height = 419
Top = 0
Width = 354
Align = alClient
@ -162,7 +165,7 @@ object Form1: TForm1
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 67
ClientHeight = 65
ClientWidth = 116
ItemIndex = 0
Items.Strings = (
@ -310,7 +313,7 @@ object Form1: TForm1
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 67
ClientHeight = 65
ClientWidth = 116
ItemIndex = 0
Items.Strings = (
@ -329,13 +332,17 @@ object Form1: TForm1
Width = 586
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.LabelBrush.Style = bsClear
end
item
Grid.Visible = False
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelBrush.Style = bsClear
end>
BackColor = clBlack
Foot.Brush.Color = clBtnFace
@ -351,12 +358,11 @@ object Form1: TForm1
)
Align = alClient
DoubleBuffered = True
ParentColor = False
object chBarEffectsBarSeries1: TBarSeries
BarBrush.Color = 2183646
BarBrush.Style = bsClear
BarPen.Style = psClear
OnBeforeDrawBar = chBarEffectsBarSeries1BeforeDrawBar
OnCustomDrawBar = chBarEffectsBarSeries1CustomDrawBar
end
end
end

View File

@ -7,7 +7,7 @@ interface
uses
Classes, ComCtrls, ExtCtrls, StdCtrls, SysUtils, FileUtil, Forms, Controls,
Graphics, Dialogs, TAGraph, TAGUIConnectorBGRA, TASeries, TASources,
TAAnimatedSource, TACustomSource, BGRASliceScaling;
TAAnimatedSource, TACustomSource, BGRASliceScaling, Types, TADrawUtils;
type
@ -42,6 +42,9 @@ type
procedure cbAntialiasingChange(Sender: TObject);
procedure cbPieChange(Sender: TObject);
procedure cbUseConnectorChange(Sender: TObject);
procedure chBarEffectsBarSeries1CustomDrawBar(ASeries: TBarSeries;
ADrawer: IChartDrawer; const ARect: TREct; APointIndex,
AStackIndex: Integer);
procedure chSimpleAfterPaint(ASender: TChart);
procedure chBarEffectsBarSeries1BeforeDrawBar(ASender: TBarSeries;
ACanvas: TCanvas; const ARect: TRect; APointIndex, AStackIndex: Integer;
@ -68,7 +71,7 @@ implementation
uses
Math, BGRABitmap, BGRABitmapTypes, BGRAGradients,
TABGRAUtils, TAChartUtils, TADrawerBGRA, TADrawerCanvas, TADrawUtils,
TABGRAUtils, TAChartUtils, TADrawerBGRA, TADrawerCanvas,
TAGeometry;
{ TForm1 }
@ -141,6 +144,41 @@ begin
end;
end;
procedure TForm1.chBarEffectsBarSeries1CustomDrawBar(ASeries: TBarSeries;
ADrawer: IChartDrawer; const ARect: TRect; APointIndex, AStackIndex: Integer);
var
temp, stretched: TBGRABitmap;
sz: TPoint;
ic: IChartTCanvasDrawer;
begin
Unused(ASeries);
Unused(APointIndex, AStackIndex);
if not Supports(ADrawer, IChartTCanvasDrawer, ic) then
raise Exception.Create('This program require a canvas drawer.');
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(ic.Canvas, ARect, False);
finally
temp.Free;
stretched.Free;
end;
end;
1: DrawChocolateBar(ASeries, ic.Canvas, ARect, APointIndex, false);
2: DrawPhong3DBar(ASeries, ic.Canvas, ARect, APointIndex);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FAnimatedSource := TCustomAnimatedChartSource.Create(Self);

View File

@ -1,32 +1,27 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<ProjectOptions BuildModesCount="1">
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<BuildModes>
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default"/>
</Modes>
</RunParams>
<RequiredPackages Count="5">
<Item1>
@ -51,7 +46,6 @@
<Unit0>
<Filename Value="bgrademo.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="bgrademo"/>
</Unit0>
<Unit1>
<Filename Value="Main.pas"/>
@ -59,7 +53,6 @@
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Main"/>
</Unit1>
</Units>
</ProjectOptions>
@ -85,12 +78,6 @@
</Win32>
</Options>
</Linking>
<Other>
<CompilerMessages>
<UseMsgFile Value="True"/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">

View File

@ -64,6 +64,13 @@
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">

View File

@ -66,7 +66,7 @@ type
TSliceArray = array of TPieSlice;
TPieOrientation = (poNormal, poHorizontal, poVertical);
TSlicePart = (spTop, spOuterArcSide, spInnerArcSide, spStartSide, spEndSide);
TDrawPieEvent = procedure(ASeries: TCustomPieSeries; ADrawer: IChartDrawer;
TCustomDrawPieEvent = procedure(ASeries: TCustomPieSeries; ADrawer: IChartDrawer;
ASlice: TPieSlice; APart: TSlicePart; const APoints: TPointArray) of object;
TCustomPieSeries = class(TChartSeries)
@ -81,12 +81,11 @@ type
FInnerRadiusPercent: Integer;
FSlices: array of TPieSlice;
FStartAngle: Integer;
FOnDrawPie: TDrawPieEvent;
private
FEdgePen: TPen;
FExploded: Boolean;
FFixedRadius: TChartDistance;
FRotateLabels: Boolean;
FOnCustomDrawPie: TCustomDrawPieEvent;
function FixAspectRatio(P: TPoint): TPoint;
function GetViewAngle: Integer;
procedure Measure(ADrawer: IChartDrawer);
@ -97,7 +96,7 @@ type
procedure SetMarkDistancePercent(AValue: Boolean);
procedure SetMarkPositionCentered(AValue: Boolean);
procedure SetMarkPositions(AValue: TPieMarkPositions);
procedure SetOnDrawPie(AValue: TDrawPieEvent);
procedure SetOnCustomDrawPie(AValue: TCustomDrawPieEvent);
procedure SetOrientation(AValue: TPieOrientation);
procedure SetRotateLabels(AValue: Boolean);
procedure SetStartAngle(AValue: Integer);
@ -118,8 +117,8 @@ type
read FStartAngle write SetStartAngle default 0;
property ViewAngle: Integer
read GetViewAngle write SetViewAngle default 60;
property OnDrawPie: TDrawPieEvent
read FOnDrawPie write SetOnDrawPie;
property OnCustomDrawPie: TCustomDrawPieEvent
read FOnCustomDrawPie write SetOnCustomDrawPie;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -562,10 +561,10 @@ var
clr := GetDepthColor(SliceColor(ASlice.FOrigIndex));
ADrawer.SetBrushParams(bsSolid, clr);
ADrawer.SetPenParams(psSolid, clr);
if Assigned(FOnDrawPie) then
if Assigned(FOnCustomDrawPie) then
case AInside of
false: FOnDrawPie(Self, ADrawer, ASlice, spOuterArcSide, p);
true: FOnDrawPie(self, ADrawer, ASlice, spInnerArcSide, p);
false: FOnCustomDrawPie(Self, ADrawer, ASlice, spOuterArcSide, p);
true: FOnCustomDrawPie(self, ADrawer, ASlice, spInnerArcSide, p);
end
else
ADrawer.Polygon(p, 0, Length(p));
@ -589,13 +588,13 @@ var
P1 := ASlice.FBase + FixAspectRatio(RotatePointX(innerRadius, -Angle));
P2 := ASlice.FBase + FixAspectRatio(RotatePointX(FRadius, -Angle));
ofs := Displacement;
if Assigned(FOnDrawPie) then begin
if Assigned(FOnCustomDrawPie) then begin
SetLength(p, 4);
p[0] := P1;
p[1] := P1 + ofs;
p[2] := P2 + ofs;
P[3] := P2;
FOnDrawPie(Self, ADrawer, ASlice, APart, p)
FOnCustomDrawPie(Self, ADrawer, ASlice, APart, p)
end else
ADrawer.Polygon([P1, P1 + ofs, P2 + ofs, P2], 0, 4);
end;
@ -619,8 +618,8 @@ var
p: TPointArray;
begin
CalcSlicePoints(ASlice, p);
if Assigned(FOnDrawPie) then
FOnDrawPie(Self, ADrawer, ASlice, spTop, p)
if Assigned(FOnCustomDrawPie) then
FOnCustomDrawPie(Self, ADrawer, ASlice, spTop, p)
else
ADrawer.Polygon(p, 0, Length(p));
end;
@ -865,10 +864,10 @@ begin
UpdateParentChart;
end;
procedure TCustomPieSeries.SetOnDrawPie(AValue: TDrawPieEvent);
procedure TCustomPieSeries.SetOnCustomDrawPie(AValue: TCustomDrawPieEvent);
begin
if TMethod(FOnDrawPie) = TMethod(AValue) then exit;
FOnDrawPie := AValue;
if TMethod(FOnCustomDrawPie) = TMethod(AValue) then exit;
FOnCustomDrawPie := AValue;
UpdateParentChart;
end;

View File

@ -39,7 +39,11 @@ type
TBeforeDrawBarEvent = procedure (
ASender: TBarSeries; ACanvas: TCanvas; const ARect: TRect;
APointIndex, AStackIndex: Integer; var ADoDefaultDrawing: Boolean
) of object;
) of object; deprecated;
TCustomDrawBarEvent = procedure (
ASeries: TBarSeries; ADrawer: IChartDrawer; const ARect: TRect;
APointIndex, AStackIndex: Integer) of object;
{ TBarSeries }
@ -51,6 +55,7 @@ type
FBarWidthPercent: Integer;
FBarWidthStyle: TBarWidthStyle;
FOnBeforeDrawBar: TBeforeDrawBarEvent;
FOnCustomDrawBar: TCustomDrawBarEvent;
FUseZeroLevel: Boolean;
FZeroLevel: Double;
@ -61,6 +66,7 @@ type
procedure SetBarWidthPercent(Value: Integer);
procedure SetBarWidthStyle(AValue: TBarWidthStyle);
procedure SetOnBeforeDrawBar(AValue: TBeforeDrawBarEvent);
procedure SetOnCustomDrawBar(AValue: TCustomDrawBarEvent);
procedure SetSeriesColor(AValue: TColor);
procedure SetUseZeroLevel(AValue: Boolean);
procedure SetZeroLevel(AValue: Double);
@ -113,7 +119,9 @@ type
read FZeroLevel write SetZeroLevel stored IsZeroLevelStored;
published
property OnBeforeDrawBar: TBeforeDrawBarEvent
read FOnBeforeDrawBar write SetOnBeforeDrawBar;
read FOnBeforeDrawBar write SetOnBeforeDrawBar; deprecated 'Use OnCustomDrawBar instead';
property OnCustomDrawBar: TCustomDrawBarEvent
read FOnCustomDrawBar write SetOnCustomDrawBar;
end;
@ -138,7 +146,7 @@ type
property StartAngle;
property Source;
property ViewAngle;
property OnDrawPie;
property OnCustomDrawPie;
end;
TConnectType = (ctLine, ctStepXY, ctStepYX);
@ -1154,6 +1162,11 @@ var
ADrawer.SetPenParams(psSolid, ADrawer.BrushColor);
end;
if Assigned(FOnCustomDrawBar) then begin
FOnCustomDrawBar(Self, ADrawer, AR, pointIndex, stackIndex);
exit;
end;
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(OnBeforeDrawBar) then
OnBeforeDrawBar(Self, ic.Canvas, AR, pointIndex, stackIndex, defaultDrawing);
if not defaultDrawing then exit;
@ -1445,6 +1458,13 @@ begin
UpdateParentChart;
end;
procedure TBarSeries.SetOnCustomDrawBar(AValue: TCustomDrawBarEvent);
begin
if TMethod(FOnCustomDrawBar) = TMethod(AValue) then exit;
FOnCustomDrawBar := AValue;
UpdateParentChart;
end;
procedure TBarSeries.SetSeriesColor(AValue: TColor);
begin
FBarBrush.Color := AValue;