mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2026-01-26 20:56:45 +01:00
TAChart: Convert diagram decorators from class to interface
git-svn-id: trunk@41889 -
This commit is contained in:
parent
66ae83fa4d
commit
6cf88ec6b4
@ -15,10 +15,10 @@ interface
|
||||
|
||||
uses
|
||||
Types,
|
||||
TAChartUtils, TATypes;
|
||||
TAChartUtils;
|
||||
|
||||
type
|
||||
TDiaObject = class(TObject)
|
||||
TDiaObject = class(TInterfacedObject)
|
||||
public
|
||||
procedure Notify(ASender: TDiaObject); virtual; abstract;
|
||||
procedure Changed(ASender: TDiaObject); virtual; abstract;
|
||||
@ -53,7 +53,10 @@ type
|
||||
|
||||
TDiaDecoratorList = class;
|
||||
|
||||
TDiaDecorator = class(TDiaObject)
|
||||
IDiaDecorator = interface
|
||||
end;
|
||||
|
||||
TDiaDecorator = class(TDiaObject, IDiaDecorator)
|
||||
private
|
||||
FOwner: TDiaObject;
|
||||
public
|
||||
@ -65,12 +68,11 @@ type
|
||||
|
||||
TDiaDecoratorList = class(TDiaObject)
|
||||
private
|
||||
FDecorators: array of TDiaDecorator;
|
||||
FDecorators: array of IDiaDecorator;
|
||||
FOwner: TDiaObject;
|
||||
procedure Add(ADecorator: TDiaDecorator);
|
||||
procedure Add(ADecorator: IDiaDecorator);
|
||||
public
|
||||
constructor Create(AOwner: TDiaObject);
|
||||
destructor Destroy; override;
|
||||
property Owner: TDiaObject read FOwner;
|
||||
function GetEnumerator: TDiaDecoratorEnumerator;
|
||||
end;
|
||||
@ -80,9 +82,9 @@ type
|
||||
FPosition: Integer;
|
||||
public
|
||||
constructor Create(AList: TDiaDecoratorList);
|
||||
function GetCurrent: TDiaDecorator;
|
||||
function GetCurrent: IDiaDecorator;
|
||||
function MoveNext: Boolean;
|
||||
property Current: TDiaDecorator read GetCurrent;
|
||||
property Current: IDiaDecorator read GetCurrent;
|
||||
end;
|
||||
|
||||
TDiagram = class(TDiaObject)
|
||||
@ -362,7 +364,7 @@ begin
|
||||
FPosition := -1;
|
||||
end;
|
||||
|
||||
function TDiaDecoratorEnumerator.GetCurrent: TDiaDecorator;
|
||||
function TDiaDecoratorEnumerator.GetCurrent: IDiaDecorator;
|
||||
begin
|
||||
Result := FList.FDecorators[FPosition];
|
||||
end;
|
||||
@ -375,7 +377,7 @@ end;
|
||||
|
||||
{ TDiaDecoratorList }
|
||||
|
||||
procedure TDiaDecoratorList.Add(ADecorator: TDiaDecorator);
|
||||
procedure TDiaDecoratorList.Add(ADecorator: IDiaDecorator);
|
||||
begin
|
||||
SetLength(FDecorators, Length(FDecorators) + 1);
|
||||
FDecorators[High(FDecorators)] := ADecorator;
|
||||
@ -387,15 +389,6 @@ 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);
|
||||
@ -488,7 +481,7 @@ end;
|
||||
|
||||
procedure TDiaConnector.Changed(ASender: TDiaObject);
|
||||
begin
|
||||
//
|
||||
Unused(ASender);
|
||||
end;
|
||||
|
||||
constructor TDiaConnector.Create;
|
||||
@ -499,7 +492,7 @@ end;
|
||||
procedure TDiaConnector.Notify(ASender: TDiaObject);
|
||||
begin
|
||||
if Element <> nil then
|
||||
Element.Notify(Self);
|
||||
Element.Notify(ASender);
|
||||
end;
|
||||
|
||||
procedure TDiaConnector.SetElement(AValue: TDiaElement);
|
||||
|
||||
@ -14,7 +14,7 @@ unit TADiagramDrawing;
|
||||
interface
|
||||
|
||||
uses
|
||||
FPCanvas,
|
||||
Classes, FPCanvas,
|
||||
TADrawUtils, TADiagram;
|
||||
|
||||
type
|
||||
@ -25,12 +25,19 @@ type
|
||||
property Drawer: IChartDrawer read FDrawer write FDrawer;
|
||||
end;
|
||||
|
||||
TDiaPenDecorator = class(TDiaDecorator)
|
||||
IDiaDrawerDecorator = interface
|
||||
['{A2AB054F-D725-401D-A249-18BF03CFF6FA}']
|
||||
procedure Apply(ADrawer: IChartDrawer);
|
||||
end;
|
||||
|
||||
TDiaPenDecorator = class(TDiaDecorator, IDiaDrawerDecorator)
|
||||
private
|
||||
FPen: TFPCustomPen;
|
||||
public
|
||||
|
||||
constructor Create(AOwner: TDiaDecoratorList);
|
||||
destructor Destroy; override;
|
||||
procedure Apply(ADrawer: IChartDrawer);
|
||||
property Pen: TFPCustomPen read FPen;
|
||||
end;
|
||||
|
||||
@ -42,7 +49,7 @@ uses
|
||||
|
||||
function ToImage(const AP: TDiaPoint): TPoint; inline;
|
||||
begin
|
||||
Result := Point(Round(AP.X[duPixels]), Round(AP.Y[duPixels]));
|
||||
Result := RoundPoint(AP.AsUnits(duPixels));
|
||||
end;
|
||||
|
||||
procedure DrawDiaBox(ASelf: TDiaBox);
|
||||
@ -84,16 +91,16 @@ end;
|
||||
procedure DrawDiaLink(ASelf: TDiaLink);
|
||||
var
|
||||
id: IChartDrawer;
|
||||
var
|
||||
drawDecor: IDiaDrawerDecorator;
|
||||
startPos, endPos, p: TPoint;
|
||||
d: TDiaDecorator;
|
||||
d: IDiaDecorator;
|
||||
begin
|
||||
if (ASelf.Start.Connector = nil) or (ASelf.Finish.Connector = nil) then exit;
|
||||
id := (ASelf.Owner.Context as TDiaContextDrawer).Drawer;
|
||||
id.PrepareSimplePen($000000);
|
||||
for d in ASelf.Decorators do
|
||||
if d is TDiaPenDecorator then
|
||||
id.Pen := (d as TDiaPenDecorator).Pen;
|
||||
if d is IDiaDrawerDecorator then
|
||||
(d as IDiaDrawerDecorator).Apply(id);
|
||||
startPos := ToImage(ASelf.Start.Connector.ActualPos);
|
||||
endPos := ToImage(ASelf.Finish.Connector.ActualPos);
|
||||
case ASelf.Routing of
|
||||
@ -120,6 +127,11 @@ end;
|
||||
|
||||
{ TDiaPenDecorator }
|
||||
|
||||
procedure TDiaPenDecorator.Apply(ADrawer: IChartDrawer);
|
||||
begin
|
||||
ADrawer.Pen := Pen;
|
||||
end;
|
||||
|
||||
constructor TDiaPenDecorator.Create(AOwner: TDiaDecoratorList);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user