cody: lvl graph: InSize, OutSize

git-svn-id: trunk@40157 -
This commit is contained in:
mattias 2013-02-03 12:34:38 +00:00
parent 7f3323cd39
commit aadf9847f2

View File

@ -239,11 +239,12 @@ type
FColor: TFPColor; FColor: TFPColor;
FGraph: TLvlGraph; FGraph: TLvlGraph;
FInEdges: TFPList; // list of TLvlGraphEdge FInEdges: TFPList; // list of TLvlGraphEdge
FInSize: integer; FDrawSize: integer;
FInSize: single;
FLevel: TLvlGraphLevel; FLevel: TLvlGraphLevel;
FOutEdges: TFPList; // list of TLvlGraphEdge FOutEdges: TFPList; // list of TLvlGraphEdge
FOutSize: integer; FDrawPosition: integer;
FPosition: integer; FOutSize: single;
function GetInEdges(Index: integer): TLvlGraphEdge; function GetInEdges(Index: integer): TLvlGraphEdge;
function GetOutEdges(Index: integer): TLvlGraphEdge; function GetOutEdges(Index: integer): TLvlGraphEdge;
procedure SetCaption(AValue: string); procedure SetCaption(AValue: string);
@ -268,12 +269,13 @@ type
function FindOutEdge(Target: TLvlGraphNode): TLvlGraphEdge; function FindOutEdge(Target: TLvlGraphNode): TLvlGraphEdge;
function OutEdgeCount: integer; function OutEdgeCount: integer;
property OutEdges[Index: integer]: TLvlGraphEdge read GetOutEdges; property OutEdges[Index: integer]: TLvlGraphEdge read GetOutEdges;
property Position: integer read FPosition write FPosition; // position in a level property DrawPosition: integer read FDrawPosition write FDrawPosition; // position in a level
function Center: integer; function DrawCenter: integer;
function PositionEnd: integer;// = Position+Max(InSize,OutSize) function DrawPositionEnd: integer;// = DrawPosition+Max(InSize,OutSize)
property InSize: integer read FInSize default 1; property DrawSize: integer read FDrawSize default 1;
property OutSize: integer read FOutSize default 1;
property Level: TLvlGraphLevel read FLevel write SetLevel; property Level: TLvlGraphLevel read FLevel write SetLevel;
property InSize: single read FInSize; // total weight of InEdges
property OutSize: single read FOutSize; // total weight of OutEdges
end; end;
{ TLvlGraphEdge } { TLvlGraphEdge }
@ -303,15 +305,19 @@ type
FGraph: TLvlGraph; FGraph: TLvlGraph;
FIndex: integer; FIndex: integer;
fNodes: TFPList; fNodes: TFPList;
FDrawPosition: integer;
function GetNodes(Index: integer): TLvlGraphNode; function GetNodes(Index: integer): TLvlGraphNode;
procedure SetDrawPosition(AValue: integer);
public public
constructor Create(TheGraph: TLvlGraph; TheIndex: integer); constructor Create(TheGraph: TLvlGraph; TheIndex: integer);
destructor Destroy; override; destructor Destroy; override;
procedure Invalidate;
property Nodes[Index: integer]: TLvlGraphNode read GetNodes; default; property Nodes[Index: integer]: TLvlGraphNode read GetNodes; default;
function IndexOf(Node: TLvlGraphNode): integer; function IndexOf(Node: TLvlGraphNode): integer;
function Count: integer; function Count: integer;
property Index: integer read FIndex; property Index: integer read FIndex;
property Graph: TLvlGraph read FGraph; property Graph: TLvlGraph read FGraph;
property DrawPosition: integer read FDrawPosition write SetDrawPosition;
end; end;
{ TLvlGraph } { TLvlGraph }
@ -493,8 +499,8 @@ var
p1: Integer; p1: Integer;
p2: Integer; p2: Integer;
begin begin
p1:=LNode1.Center; p1:=LNode1.DrawCenter;
p2:=LNode2.Center; p2:=LNode2.DrawCenter;
if p1<p2 then if p1<p2 then
Result:=1 Result:=1
else if p1>p2 then else if p1>p2 then
@ -510,6 +516,13 @@ begin
Result:=TLvlGraphNode(fNodes[Index]); Result:=TLvlGraphNode(fNodes[Index]);
end; end;
procedure TLvlGraphLevel.SetDrawPosition(AValue: integer);
begin
if FDrawPosition=AValue then Exit;
FDrawPosition:=AValue;
Invalidate;
end;
constructor TLvlGraphLevel.Create(TheGraph: TLvlGraph; TheIndex: integer); constructor TLvlGraphLevel.Create(TheGraph: TLvlGraph; TheIndex: integer);
begin begin
FGraph:=TheGraph; FGraph:=TheGraph;
@ -529,6 +542,12 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TLvlGraphLevel.Invalidate;
begin
if Graph<>nil then
Graph.Invalidate;
end;
function TLvlGraphLevel.IndexOf(Node: TLvlGraphNode): integer; function TLvlGraphLevel.IndexOf(Node: TLvlGraphNode): integer;
begin begin
for Result:=0 to Count-1 do for Result:=0 to Count-1 do
@ -915,7 +934,7 @@ begin
Node:=TLvlGraphNode(AVLNode.Data); Node:=TLvlGraphNode(AVLNode.Data);
Last:=Node; Last:=Node;
if (Last<>nil) then if (Last<>nil) then
Node.Position:=Max(Node.Position,Last.PositionEnd+Gap); Node.DrawPosition:=Max(Node.DrawPosition,Last.DrawPositionEnd+Gap);
AVLNode:=Tree.FindSuccessor(AVLNode); AVLNode:=Tree.FindSuccessor(AVLNode);
end; end;
finally finally
@ -1004,8 +1023,13 @@ end;
{ TLvlGraphEdge } { TLvlGraphEdge }
procedure TLvlGraphEdge.SetWeight(AValue: single); procedure TLvlGraphEdge.SetWeight(AValue: single);
var
Diff: single;
begin begin
if FWeight=AValue then Exit; if FWeight=AValue then Exit;
Diff:=AValue-FWeight;
Source.FOutSize+=Diff;
Target.FInSize+=Diff;
FWeight:=AValue; FWeight:=AValue;
Source.Invalidate; Source.Invalidate;
end; end;
@ -1101,8 +1125,7 @@ begin
FCaption:=TheCaption; FCaption:=TheCaption;
FInEdges:=TFPList.Create; FInEdges:=TFPList.Create;
FOutEdges:=TFPList.Create; FOutEdges:=TFPList.Create;
FInSize:=1; FDrawSize:=1;
FOutSize:=1;
Level:=TheLevel; Level:=TheLevel;
end; end;
@ -1167,14 +1190,14 @@ begin
Result:=FOutEdges.Count; Result:=FOutEdges.Count;
end; end;
function TLvlGraphNode.Center: integer; function TLvlGraphNode.DrawCenter: integer;
begin begin
Result:=Position+(Max(InSize,OutSize) div 2); Result:=DrawPosition+(DrawSize div 2);
end; end;
function TLvlGraphNode.PositionEnd: integer; function TLvlGraphNode.DrawPositionEnd: integer;
begin begin
Result:=Position+Max(InSize,OutSize); Result:=DrawPosition+DrawSize;
end; end;
{ TCodyTreeView } { TCodyTreeView }