mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-15 12:19:13 +02:00
TAChart: Initial implementation of diagram decorators
git-svn-id: trunk@41857 -
This commit is contained in:
parent
149c929321
commit
9121096235
@ -47,6 +47,40 @@ type
|
|||||||
|
|
||||||
TDiaElement = class;
|
TDiaElement = class;
|
||||||
|
|
||||||
|
TDiaDecoratorList = class;
|
||||||
|
|
||||||
|
TDiaDecorator = class(TDiaObject)
|
||||||
|
private
|
||||||
|
FOwner: TDiaObject;
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TDiaDecoratorList);
|
||||||
|
property Owner: TDiaObject read FOwner;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TDiaDecoratorEnumerator = class;
|
||||||
|
|
||||||
|
TDiaDecoratorList = class(TDiaObject)
|
||||||
|
private
|
||||||
|
FDecorators: array of TDiaDecorator;
|
||||||
|
FOwner: TDiaObject;
|
||||||
|
procedure Add(ADecorator: TDiaDecorator);
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TDiaObject);
|
||||||
|
destructor Destroy; override;
|
||||||
|
property Owner: TDiaObject read FOwner;
|
||||||
|
function GetEnumerator: TDiaDecoratorEnumerator;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TDiaDecoratorEnumerator = class
|
||||||
|
FList: TDiaDecoratorList;
|
||||||
|
FPosition: Integer;
|
||||||
|
public
|
||||||
|
constructor Create(AList: TDiaDecoratorList);
|
||||||
|
function GetCurrent: TDiaDecorator;
|
||||||
|
function MoveNext: Boolean;
|
||||||
|
property Current: TDiaDecorator read GetCurrent;
|
||||||
|
end;
|
||||||
|
|
||||||
TDiagram = class(TDiaObject)
|
TDiagram = class(TDiaObject)
|
||||||
strict private
|
strict private
|
||||||
FBounds: array [TDiaBoxSide] of TDiaCoordinate;
|
FBounds: array [TDiaBoxSide] of TDiaCoordinate;
|
||||||
@ -74,13 +108,17 @@ type
|
|||||||
FConnectors: array of TDiaConnector;
|
FConnectors: array of TDiaConnector;
|
||||||
FOwner: TDiagram;
|
FOwner: TDiagram;
|
||||||
private
|
private
|
||||||
|
FDecorators: TDiaDecoratorList;
|
||||||
procedure SetOwner(AValue: TDiagram);
|
procedure SetOwner(AValue: TDiagram);
|
||||||
public
|
public
|
||||||
|
constructor Create;
|
||||||
|
destructor Destroy; override;
|
||||||
procedure Add(AConnector: TDiaConnector);
|
procedure Add(AConnector: TDiaConnector);
|
||||||
procedure Changed(ASender: TDiaObject); override;
|
procedure Changed(ASender: TDiaObject); override;
|
||||||
procedure Draw; virtual;
|
procedure Draw; virtual;
|
||||||
procedure Notify(ASender: TDiaObject); override;
|
procedure Notify(ASender: TDiaObject); override;
|
||||||
property Owner: TDiagram read FOwner;
|
property Owner: TDiagram read FOwner;
|
||||||
|
property Decorators: TDiaDecoratorList read FDecorators;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TDiaPosition = class(TDiaObject)
|
TDiaPosition = class(TDiaObject)
|
||||||
@ -218,6 +256,61 @@ begin
|
|||||||
Result.Y := WeightedAverage(AP1.Y, AP2.Y, ACoeff);
|
Result.Y := WeightedAverage(AP1.Y, AP2.Y, ACoeff);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TDiaDecoratorEnumerator }
|
||||||
|
|
||||||
|
constructor TDiaDecoratorEnumerator.Create(AList: TDiaDecoratorList);
|
||||||
|
begin
|
||||||
|
FList := AList;
|
||||||
|
FPosition := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDiaDecoratorEnumerator.GetCurrent: TDiaDecorator;
|
||||||
|
begin
|
||||||
|
Result := FList.FDecorators[FPosition];
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDiaDecoratorEnumerator.MoveNext: Boolean;
|
||||||
|
begin
|
||||||
|
FPosition += 1;
|
||||||
|
Result := FPosition < Length(FList.FDecorators);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TDiaDecoratorList }
|
||||||
|
|
||||||
|
procedure TDiaDecoratorList.Add(ADecorator: TDiaDecorator);
|
||||||
|
begin
|
||||||
|
SetLength(FDecorators, Length(FDecorators) + 1);
|
||||||
|
FDecorators[High(FDecorators)] := ADecorator;
|
||||||
|
//Notify(ADecorator);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TDiaDecoratorList.Create(AOwner: TDiaObject);
|
||||||
|
begin
|
||||||
|
FOwner := AOwner;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TDiaDecoratorList.Destroy;
|
||||||
|
var
|
||||||
|
d: TDiaDecorator;
|
||||||
|
begin
|
||||||
|
for d in FDecorators do
|
||||||
|
d.Free;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDiaDecoratorList.GetEnumerator: TDiaDecoratorEnumerator;
|
||||||
|
begin
|
||||||
|
Result := TDiaDecoratorEnumerator.Create(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TDiaDecorator }
|
||||||
|
|
||||||
|
constructor TDiaDecorator.Create(AOwner: TDiaDecoratorList);
|
||||||
|
begin
|
||||||
|
if AOwner <> nil then
|
||||||
|
AOwner.Add(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TDiaLink }
|
{ TDiaLink }
|
||||||
|
|
||||||
procedure TDiaLink.Draw;
|
procedure TDiaLink.Draw;
|
||||||
@ -540,6 +633,17 @@ begin
|
|||||||
c.Changed(ASender);
|
c.Changed(ASender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TDiaElement.Create;
|
||||||
|
begin
|
||||||
|
FDecorators := TDiaDecoratorList.Create(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TDiaElement.Destroy;
|
||||||
|
begin
|
||||||
|
FreeAndNil(FDecorators);
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDiaElement.Draw;
|
procedure TDiaElement.Draw;
|
||||||
begin
|
begin
|
||||||
//
|
//
|
||||||
|
@ -25,10 +25,19 @@ type
|
|||||||
property Drawer: IChartDrawer read FDrawer write FDrawer;
|
property Drawer: IChartDrawer read FDrawer write FDrawer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TDiaPenDecorator = class(TDiaDecorator)
|
||||||
|
private
|
||||||
|
FPen: TFPCustomPen;
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TDiaDecoratorList);
|
||||||
|
destructor Destroy; override;
|
||||||
|
property Pen: TFPCustomPen read FPen;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Math, Types,
|
Math, Types, SysUtils,
|
||||||
TAGeometry;
|
TAGeometry;
|
||||||
|
|
||||||
function ToImage(const AP: TDiaPoint): TPoint; inline;
|
function ToImage(const AP: TDiaPoint): TPoint; inline;
|
||||||
@ -62,18 +71,20 @@ var
|
|||||||
Length: Integer = 20;
|
Length: Integer = 20;
|
||||||
startPos, endPos: TPoint;
|
startPos, endPos: TPoint;
|
||||||
AAngle: float;
|
AAngle: float;
|
||||||
|
d: TDiaDecorator;
|
||||||
begin
|
begin
|
||||||
if (ASelf.Start = nil) or (ASelf.Finish = nil) then exit;
|
if (ASelf.Start = nil) or (ASelf.Finish = nil) then exit;
|
||||||
id := (ASelf.Owner.Context as TDiaContextDrawer).Drawer;
|
id := (ASelf.Owner.Context as TDiaContextDrawer).Drawer;
|
||||||
id.PrepareSimplePen($000000);
|
id.PrepareSimplePen($000000);
|
||||||
if ASelf.Dashes then
|
for d in ASelf.Decorators do
|
||||||
id.SetPenParams(psDash, $000000);
|
if d is TDiaPenDecorator then
|
||||||
id.SetBrushColor($FFFFFF);
|
id.Pen := (d as TDiaPenDecorator).Pen;
|
||||||
startPos := ToImage(ASelf.Start.ActualPos);
|
startPos := ToImage(ASelf.Start.ActualPos);
|
||||||
endPos := ToImage(ASelf.Finish.ActualPos);
|
endPos := ToImage(ASelf.Finish.ActualPos);
|
||||||
id.Line(startPos, endPos);
|
id.Line(startPos, endPos);
|
||||||
if not ASelf.Arrow then exit;
|
if not ASelf.Arrow then exit;
|
||||||
id.SetPenParams(psSolid, $000000);
|
id.SetPenParams(psSolid, $000000);
|
||||||
|
id.SetBrushColor($FFFFFF);
|
||||||
da := ArcTan2(Width, Length);
|
da := ArcTan2(Width, Length);
|
||||||
|
|
||||||
endPos := ToImage(ASelf.Finish.ActualPos);
|
endPos := ToImage(ASelf.Finish.ActualPos);
|
||||||
@ -84,6 +95,21 @@ begin
|
|||||||
id.Polygon([pt1, endPos, pt2], 0, 3);
|
id.Polygon([pt1, endPos, pt2], 0, 3);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TDiaPenDecorator }
|
||||||
|
|
||||||
|
constructor TDiaPenDecorator.Create(AOwner: TDiaDecoratorList);
|
||||||
|
begin
|
||||||
|
inherited Create(AOwner);
|
||||||
|
FPen := TFPCustomPen.Create;
|
||||||
|
FPen.Mode := pmCopy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TDiaPenDecorator.Destroy;
|
||||||
|
begin
|
||||||
|
FreeAndNil(FPen);
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
TDiaBox.FInternalDraw := @DrawDiaBox;
|
TDiaBox.FInternalDraw := @DrawDiaBox;
|
||||||
TDiaLink.FInternalDraw := @DrawDiaLink;
|
TDiaLink.FInternalDraw := @DrawDiaLink;
|
||||||
|
Loading…
Reference in New Issue
Block a user