TAChart: Add initial support for shadows

git-svn-id: trunk@40050 -
This commit is contained in:
ask 2013-01-30 06:51:15 +00:00
parent fe0143e2cd
commit d91a1f1adc
3 changed files with 125 additions and 15 deletions

View File

@ -66,6 +66,7 @@ type
function GetShowInLegend: Boolean; override;
procedure SetActive(AValue: Boolean); override;
procedure SetDepth(AValue: TChartDistance); override;
procedure SetShadow(AValue: TChartShadow); override;
procedure SetShowInLegend(AValue: Boolean); override;
procedure SetTitle(AValue: String); virtual;
procedure SetTransparency(AValue: TChartTransparency); override;
@ -118,10 +119,11 @@ type
published
property Legend: TChartSeriesLegend read FLegend write SetLegend;
property Transparency;
property Shadow;
property ShowInLegend: Boolean
read GetShowInLegend write SetShowInLegend stored false default true;
deprecated;
property Transparency;
end;
TChartGetMarkEvent = procedure (
@ -323,12 +325,14 @@ begin
FAxisIndexX := DEF_AXIS_INDEX;
FAxisIndexY := DEF_AXIS_INDEX;
FLegend := TChartSeriesLegend.Create(FChart);
FShadow := TChartShadow.Create(FChart);
end;
destructor TCustomChartSeries.Destroy;
begin
FreeAndNil(FLegend);
inherited Destroy;
FreeAndNil(FShadow);
inherited;
end;
function TCustomChartSeries.GetAxisX: TChartAxis;
@ -520,6 +524,13 @@ begin
(AParent as TChart).AddSeries(Self);
end;
procedure TCustomChartSeries.SetShadow(AValue: TChartShadow);
begin
if FShadow = AValue then exit;
FShadow.Assign(AValue);
UpdateParentChart;
end;
procedure TCustomChartSeries.SetShowInLegend(AValue: Boolean);
begin
Legend.Visible := AValue;

View File

@ -48,6 +48,7 @@ type
FActive: Boolean;
FChart: TChart;
FDepth: TChartDistance;
FShadow: TChartShadow;
FTransparency: TChartTransparency;
FZPosition: TChartDistance;
@ -58,6 +59,7 @@ type
function GetShowInLegend: Boolean; virtual; abstract;
procedure SetActive(AValue: Boolean); virtual; abstract;
procedure SetDepth(AValue: TChartDistance); virtual; abstract;
procedure SetShadow(AValue: TChartShadow); virtual; abstract;
procedure SetShowInLegend(AValue: Boolean); virtual; abstract;
procedure SetTransparency(AValue: TChartTransparency); virtual; abstract;
procedure SetZPosition(AValue: TChartDistance); virtual; abstract;
@ -85,6 +87,7 @@ type
property Active: Boolean read FActive write SetActive default true;
property Depth: TChartDistance read FDepth write SetDepth default 0;
property ParentChart: TChart read FChart;
property Shadow: TChartShadow read FShadow write SetShadow;
property Transparency: TChartTransparency
read FTransparency write SetTransparency default 0;
property ZPosition: TChartDistance read FZPosition write SetZPosition default 0;
@ -674,15 +677,32 @@ end;
procedure TChart.DisplaySeries(ADrawer: IChartDrawer);
procedure OffsetDrawArea(AZPos, ADepth: Integer);
procedure OffsetDrawArea(ADX, ADY: Integer); inline;
begin
FOffset.X -= AZPos;
FOffset.Y += AZPos;
OffsetRect(FClipRect, -AZPos, AZPos);
FOffset.X += ADX;
FOffset.Y += ADY;
OffsetRect(FClipRect, ADX, ADY);
end;
procedure OffsetWithDepth(AZPos, ADepth: Integer);
begin
OffsetDrawArea(-AZPos, AZPos);
FClipRect.Right += ADepth;
FClipRect.Top -= ADepth;
end;
procedure DrawOrDeactivate(
ASeries: TBasicChartSeries; ATransparency: TChartTransparency);
begin
try
ADrawer.SetTransparency(ATransparency);
ASeries.Draw(ADrawer);
except
ASeries.Active := false;
raise;
end;
end;
var
axisIndex: Integer;
seriesInZOrder: TChartSeriesList;
@ -700,18 +720,24 @@ begin
// Interleave axises with series according to ZPosition.
if AxisVisible then
AxisList.Draw(s.ZPosition, axisIndex);
OffsetDrawArea(Min(s.ZPosition, Depth), Min(s.Depth, Depth));
OffsetWithDepth(Min(s.ZPosition, Depth), Min(s.Depth, Depth));
ADrawer.ClippingStart(ClipRectWithoutFrame(s.ZPosition));
try
try
ADrawer.SetTransparency(s.Transparency);
s.Draw(ADrawer);
except
s.Active := false;
raise;
end;
with s.Shadow do
if Visible then begin
OffsetDrawArea(OffsetX, OffsetY);
ADrawer.SetMonochromeColor(Color);
try
DrawOrDeactivate(s, Transparency);
finally
ADrawer.SetMonochromeColor(clTAColor);
OffsetDrawArea(-OffsetX, -OffsetY);
end;
end;
DrawOrDeactivate(s, s.Transparency);
finally
OffsetDrawArea(-Min(s.ZPosition, Depth), -Min(s.Depth, Depth));
OffsetWithDepth(-Min(s.ZPosition, Depth), -Min(s.Depth, Depth));
ADrawer.ClippingStop;
end;
end;

View File

@ -38,6 +38,8 @@ const
MARKS_YINDEX_ALL = -1;
DEF_ARROW_LENGTH = 10;
DEF_ARROW_WIDTH = 5;
DEF_SHADOW_OFFSET = 8;
DEF_SHADOW_TRANSPARENCY = 128;
type
TCustomChart = class(TCustomControl)
@ -235,6 +237,28 @@ type
read FWidth write SetWidth default DEF_ARROW_WIDTH;
end;
TChartShadow = class(TChartElement)
strict private
FColor: TColor;
FOffset: TPoint;
FTransparency: TChartTransparency;
procedure SetColor(AValue: TColor);
procedure SetOffsetX(AValue: Integer);
procedure SetOffsetY(AValue: Integer);
procedure SetTransparency(AValue: TChartTransparency);
public
constructor Create(AOwner: TCustomChart);
public
procedure Assign(ASource: TPersistent); override;
published
property Color: TColor read FColor write SetColor default clBlack;
property OffsetX: Integer read FOffset.X write SetOffsetX default DEF_SHADOW_OFFSET;
property OffsetY: Integer read FOffset.Y write SetOffsetY default DEF_SHADOW_OFFSET;
property Transparency: TChartTransparency
read FTransparency write SetTransparency default DEF_SHADOW_TRANSPARENCY;
property Visible default false;
end;
implementation
uses
@ -666,5 +690,54 @@ begin
StyleChanged(Self);
end;
{ TChartShadow }
procedure TChartShadow.Assign(ASource: TPersistent);
begin
if ASource is TChartShadow then
with TChartShadow(ASource) do begin
Self.FColor := Color;
Self.FOffset := FOffset;
Self.FTransparency := Transparency;
end;
inherited Assign(ASource);
end;
constructor TChartShadow.Create(AOwner: TCustomChart);
begin
inherited Create(AOwner);
FColor := clBlack;
FOffset := Point(DEF_SHADOW_OFFSET, DEF_SHADOW_OFFSET);
FTransparency := DEF_SHADOW_TRANSPARENCY;
end;
procedure TChartShadow.SetColor(AValue: TColor);
begin
if FColor = AValue then exit;
FColor := AValue;
StyleChanged(Self);
end;
procedure TChartShadow.SetOffsetX(AValue: Integer);
begin
if FOffset.X = AValue then exit;
FOffset.X := AValue;
StyleChanged(Self);
end;
procedure TChartShadow.SetOffsetY(AValue: Integer);
begin
if FOffset.Y = AValue then exit;
FOffset.Y := AValue;
StyleChanged(Self);
end;
procedure TChartShadow.SetTransparency(AValue: TChartTransparency);
begin
if FTransparency = AValue then exit;
FTransparency := AValue;
StyleChanged(Self);
end;
end.