mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 04:59:08 +02:00
TAChart: Add initial support for shadows
git-svn-id: trunk@40050 -
This commit is contained in:
parent
fe0143e2cd
commit
d91a1f1adc
@ -66,6 +66,7 @@ type
|
|||||||
function GetShowInLegend: Boolean; override;
|
function GetShowInLegend: Boolean; override;
|
||||||
procedure SetActive(AValue: Boolean); override;
|
procedure SetActive(AValue: Boolean); override;
|
||||||
procedure SetDepth(AValue: TChartDistance); override;
|
procedure SetDepth(AValue: TChartDistance); override;
|
||||||
|
procedure SetShadow(AValue: TChartShadow); override;
|
||||||
procedure SetShowInLegend(AValue: Boolean); override;
|
procedure SetShowInLegend(AValue: Boolean); override;
|
||||||
procedure SetTitle(AValue: String); virtual;
|
procedure SetTitle(AValue: String); virtual;
|
||||||
procedure SetTransparency(AValue: TChartTransparency); override;
|
procedure SetTransparency(AValue: TChartTransparency); override;
|
||||||
@ -118,10 +119,11 @@ type
|
|||||||
|
|
||||||
published
|
published
|
||||||
property Legend: TChartSeriesLegend read FLegend write SetLegend;
|
property Legend: TChartSeriesLegend read FLegend write SetLegend;
|
||||||
property Transparency;
|
property Shadow;
|
||||||
property ShowInLegend: Boolean
|
property ShowInLegend: Boolean
|
||||||
read GetShowInLegend write SetShowInLegend stored false default true;
|
read GetShowInLegend write SetShowInLegend stored false default true;
|
||||||
deprecated;
|
deprecated;
|
||||||
|
property Transparency;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TChartGetMarkEvent = procedure (
|
TChartGetMarkEvent = procedure (
|
||||||
@ -323,12 +325,14 @@ begin
|
|||||||
FAxisIndexX := DEF_AXIS_INDEX;
|
FAxisIndexX := DEF_AXIS_INDEX;
|
||||||
FAxisIndexY := DEF_AXIS_INDEX;
|
FAxisIndexY := DEF_AXIS_INDEX;
|
||||||
FLegend := TChartSeriesLegend.Create(FChart);
|
FLegend := TChartSeriesLegend.Create(FChart);
|
||||||
|
FShadow := TChartShadow.Create(FChart);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCustomChartSeries.Destroy;
|
destructor TCustomChartSeries.Destroy;
|
||||||
begin
|
begin
|
||||||
FreeAndNil(FLegend);
|
FreeAndNil(FLegend);
|
||||||
inherited Destroy;
|
FreeAndNil(FShadow);
|
||||||
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomChartSeries.GetAxisX: TChartAxis;
|
function TCustomChartSeries.GetAxisX: TChartAxis;
|
||||||
@ -520,6 +524,13 @@ begin
|
|||||||
(AParent as TChart).AddSeries(Self);
|
(AParent as TChart).AddSeries(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomChartSeries.SetShadow(AValue: TChartShadow);
|
||||||
|
begin
|
||||||
|
if FShadow = AValue then exit;
|
||||||
|
FShadow.Assign(AValue);
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomChartSeries.SetShowInLegend(AValue: Boolean);
|
procedure TCustomChartSeries.SetShowInLegend(AValue: Boolean);
|
||||||
begin
|
begin
|
||||||
Legend.Visible := AValue;
|
Legend.Visible := AValue;
|
||||||
|
@ -48,6 +48,7 @@ type
|
|||||||
FActive: Boolean;
|
FActive: Boolean;
|
||||||
FChart: TChart;
|
FChart: TChart;
|
||||||
FDepth: TChartDistance;
|
FDepth: TChartDistance;
|
||||||
|
FShadow: TChartShadow;
|
||||||
FTransparency: TChartTransparency;
|
FTransparency: TChartTransparency;
|
||||||
FZPosition: TChartDistance;
|
FZPosition: TChartDistance;
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ type
|
|||||||
function GetShowInLegend: Boolean; virtual; abstract;
|
function GetShowInLegend: Boolean; virtual; abstract;
|
||||||
procedure SetActive(AValue: Boolean); virtual; abstract;
|
procedure SetActive(AValue: Boolean); virtual; abstract;
|
||||||
procedure SetDepth(AValue: TChartDistance); virtual; abstract;
|
procedure SetDepth(AValue: TChartDistance); virtual; abstract;
|
||||||
|
procedure SetShadow(AValue: TChartShadow); virtual; abstract;
|
||||||
procedure SetShowInLegend(AValue: Boolean); virtual; abstract;
|
procedure SetShowInLegend(AValue: Boolean); virtual; abstract;
|
||||||
procedure SetTransparency(AValue: TChartTransparency); virtual; abstract;
|
procedure SetTransparency(AValue: TChartTransparency); virtual; abstract;
|
||||||
procedure SetZPosition(AValue: TChartDistance); virtual; abstract;
|
procedure SetZPosition(AValue: TChartDistance); virtual; abstract;
|
||||||
@ -85,6 +87,7 @@ type
|
|||||||
property Active: Boolean read FActive write SetActive default true;
|
property Active: Boolean read FActive write SetActive default true;
|
||||||
property Depth: TChartDistance read FDepth write SetDepth default 0;
|
property Depth: TChartDistance read FDepth write SetDepth default 0;
|
||||||
property ParentChart: TChart read FChart;
|
property ParentChart: TChart read FChart;
|
||||||
|
property Shadow: TChartShadow read FShadow write SetShadow;
|
||||||
property Transparency: TChartTransparency
|
property Transparency: TChartTransparency
|
||||||
read FTransparency write SetTransparency default 0;
|
read FTransparency write SetTransparency default 0;
|
||||||
property ZPosition: TChartDistance read FZPosition write SetZPosition default 0;
|
property ZPosition: TChartDistance read FZPosition write SetZPosition default 0;
|
||||||
@ -674,15 +677,32 @@ end;
|
|||||||
|
|
||||||
procedure TChart.DisplaySeries(ADrawer: IChartDrawer);
|
procedure TChart.DisplaySeries(ADrawer: IChartDrawer);
|
||||||
|
|
||||||
procedure OffsetDrawArea(AZPos, ADepth: Integer);
|
procedure OffsetDrawArea(ADX, ADY: Integer); inline;
|
||||||
begin
|
begin
|
||||||
FOffset.X -= AZPos;
|
FOffset.X += ADX;
|
||||||
FOffset.Y += AZPos;
|
FOffset.Y += ADY;
|
||||||
OffsetRect(FClipRect, -AZPos, AZPos);
|
OffsetRect(FClipRect, ADX, ADY);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure OffsetWithDepth(AZPos, ADepth: Integer);
|
||||||
|
begin
|
||||||
|
OffsetDrawArea(-AZPos, AZPos);
|
||||||
FClipRect.Right += ADepth;
|
FClipRect.Right += ADepth;
|
||||||
FClipRect.Top -= ADepth;
|
FClipRect.Top -= ADepth;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure DrawOrDeactivate(
|
||||||
|
ASeries: TBasicChartSeries; ATransparency: TChartTransparency);
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
ADrawer.SetTransparency(ATransparency);
|
||||||
|
ASeries.Draw(ADrawer);
|
||||||
|
except
|
||||||
|
ASeries.Active := false;
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
axisIndex: Integer;
|
axisIndex: Integer;
|
||||||
seriesInZOrder: TChartSeriesList;
|
seriesInZOrder: TChartSeriesList;
|
||||||
@ -700,18 +720,24 @@ begin
|
|||||||
// Interleave axises with series according to ZPosition.
|
// Interleave axises with series according to ZPosition.
|
||||||
if AxisVisible then
|
if AxisVisible then
|
||||||
AxisList.Draw(s.ZPosition, axisIndex);
|
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));
|
ADrawer.ClippingStart(ClipRectWithoutFrame(s.ZPosition));
|
||||||
|
|
||||||
try
|
try
|
||||||
|
with s.Shadow do
|
||||||
|
if Visible then begin
|
||||||
|
OffsetDrawArea(OffsetX, OffsetY);
|
||||||
|
ADrawer.SetMonochromeColor(Color);
|
||||||
try
|
try
|
||||||
ADrawer.SetTransparency(s.Transparency);
|
DrawOrDeactivate(s, Transparency);
|
||||||
s.Draw(ADrawer);
|
|
||||||
except
|
|
||||||
s.Active := false;
|
|
||||||
raise;
|
|
||||||
end;
|
|
||||||
finally
|
finally
|
||||||
OffsetDrawArea(-Min(s.ZPosition, Depth), -Min(s.Depth, Depth));
|
ADrawer.SetMonochromeColor(clTAColor);
|
||||||
|
OffsetDrawArea(-OffsetX, -OffsetY);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
DrawOrDeactivate(s, s.Transparency);
|
||||||
|
finally
|
||||||
|
OffsetWithDepth(-Min(s.ZPosition, Depth), -Min(s.Depth, Depth));
|
||||||
ADrawer.ClippingStop;
|
ADrawer.ClippingStop;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -38,6 +38,8 @@ const
|
|||||||
MARKS_YINDEX_ALL = -1;
|
MARKS_YINDEX_ALL = -1;
|
||||||
DEF_ARROW_LENGTH = 10;
|
DEF_ARROW_LENGTH = 10;
|
||||||
DEF_ARROW_WIDTH = 5;
|
DEF_ARROW_WIDTH = 5;
|
||||||
|
DEF_SHADOW_OFFSET = 8;
|
||||||
|
DEF_SHADOW_TRANSPARENCY = 128;
|
||||||
|
|
||||||
type
|
type
|
||||||
TCustomChart = class(TCustomControl)
|
TCustomChart = class(TCustomControl)
|
||||||
@ -235,6 +237,28 @@ type
|
|||||||
read FWidth write SetWidth default DEF_ARROW_WIDTH;
|
read FWidth write SetWidth default DEF_ARROW_WIDTH;
|
||||||
end;
|
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
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -666,5 +690,54 @@ begin
|
|||||||
StyleChanged(Self);
|
StyleChanged(Self);
|
||||||
end;
|
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.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user