mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-02 20:38:15 +02:00
cody: lvlgraph: imageindex
git-svn-id: trunk@40485 -
This commit is contained in:
parent
d87e924896
commit
219da40eb9
@ -32,7 +32,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
types, math, typinfo, contnrs, Classes, SysUtils, FPCanvas, FPimage,
|
types, math, typinfo, contnrs, Classes, SysUtils, FPCanvas, FPimage,
|
||||||
LazLogger, AvgLvlTree, ComCtrls, Controls, Graphics, LCLType, Forms, LCLIntf,
|
LazLogger, AvgLvlTree, ComCtrls, Controls, Graphics, LCLType, Forms, LCLIntf,
|
||||||
LMessages;
|
LMessages, ImgList, GraphType;
|
||||||
|
|
||||||
type
|
type
|
||||||
TCodyCtrlPalette = array of TFPColor;
|
TCodyCtrlPalette = array of TFPColor;
|
||||||
@ -245,6 +245,8 @@ type
|
|||||||
FCaption: string;
|
FCaption: string;
|
||||||
FColor: TFPColor;
|
FColor: TFPColor;
|
||||||
FGraph: TLvlGraph;
|
FGraph: TLvlGraph;
|
||||||
|
FImageEffect: TGraphicsDrawEffect;
|
||||||
|
FImageIndex: integer;
|
||||||
FInEdges: TFPList; // list of TLvlGraphEdge
|
FInEdges: TFPList; // list of TLvlGraphEdge
|
||||||
FDrawSize: integer;
|
FDrawSize: integer;
|
||||||
FInWeight: single;
|
FInWeight: single;
|
||||||
@ -253,6 +255,7 @@ type
|
|||||||
FOutEdges: TFPList; // list of TLvlGraphEdge
|
FOutEdges: TFPList; // list of TLvlGraphEdge
|
||||||
FDrawPosition: integer;
|
FDrawPosition: integer;
|
||||||
FOutWeight: single;
|
FOutWeight: single;
|
||||||
|
FOverlayIndex: integer;
|
||||||
FPrevSelected: TLvlGraphNode;
|
FPrevSelected: TLvlGraphNode;
|
||||||
FSelected: boolean;
|
FSelected: boolean;
|
||||||
FVisible: boolean;
|
FVisible: boolean;
|
||||||
@ -263,8 +266,11 @@ type
|
|||||||
procedure SetColor(AValue: TFPColor);
|
procedure SetColor(AValue: TFPColor);
|
||||||
procedure OnLevelDestroy;
|
procedure OnLevelDestroy;
|
||||||
procedure SetDrawSize(AValue: integer);
|
procedure SetDrawSize(AValue: integer);
|
||||||
|
procedure SetImageEffect(AValue: TGraphicsDrawEffect);
|
||||||
|
procedure SetImageIndex(AValue: integer);
|
||||||
procedure SetIndexInLevel(AValue: integer);
|
procedure SetIndexInLevel(AValue: integer);
|
||||||
procedure SetLevel(AValue: TLvlGraphLevel);
|
procedure SetLevel(AValue: TLvlGraphLevel);
|
||||||
|
procedure SetOverlayIndex(AValue: integer);
|
||||||
procedure SetSelected(AValue: boolean);
|
procedure SetSelected(AValue: boolean);
|
||||||
procedure SetVisible(AValue: boolean);
|
procedure SetVisible(AValue: boolean);
|
||||||
procedure UnbindLevel;
|
procedure UnbindLevel;
|
||||||
@ -278,6 +284,9 @@ type
|
|||||||
property Color: TFPColor read FColor write SetColor;
|
property Color: TFPColor read FColor write SetColor;
|
||||||
property Caption: string read FCaption write SetCaption;
|
property Caption: string read FCaption write SetCaption;
|
||||||
property Visible: boolean read FVisible write SetVisible;
|
property Visible: boolean read FVisible write SetVisible;
|
||||||
|
property ImageIndex: integer read FImageIndex write SetImageIndex;
|
||||||
|
property OverlayIndex: integer read FOverlayIndex write SetOverlayIndex; // requires ImageIndex>=0
|
||||||
|
property ImageEffect: TGraphicsDrawEffect read FImageEffect write SetImageEffect;
|
||||||
property Graph: TLvlGraph read FGraph;
|
property Graph: TLvlGraph read FGraph;
|
||||||
function IndexOfInEdge(Source: TLvlGraphNode): integer;
|
function IndexOfInEdge(Source: TLvlGraphNode): integer;
|
||||||
function FindInEdge(Source: TLvlGraphNode): TLvlGraphEdge;
|
function FindInEdge(Source: TLvlGraphNode): TLvlGraphEdge;
|
||||||
@ -455,6 +464,7 @@ type
|
|||||||
TLvlGraphNodeCaptionPositions = set of TLvlGraphNodeCaptionPosition;
|
TLvlGraphNodeCaptionPositions = set of TLvlGraphNodeCaptionPosition;
|
||||||
|
|
||||||
TLvlGraphNodeShape = (
|
TLvlGraphNodeShape = (
|
||||||
|
lgnsNone,
|
||||||
lgnsRectangle,
|
lgnsRectangle,
|
||||||
lgnsEllipse
|
lgnsEllipse
|
||||||
);
|
);
|
||||||
@ -491,6 +501,7 @@ type
|
|||||||
FCaptionPosition: TLvlGraphNodeCaptionPosition;
|
FCaptionPosition: TLvlGraphNodeCaptionPosition;
|
||||||
FCaptionScale: single;
|
FCaptionScale: single;
|
||||||
FControl: TCustomLvlGraphControl;
|
FControl: TCustomLvlGraphControl;
|
||||||
|
FDefaultImageIndex: integer;
|
||||||
FGapBottom: integer;
|
FGapBottom: integer;
|
||||||
FGapLeft: integer;
|
FGapLeft: integer;
|
||||||
FGapRight: integer;
|
FGapRight: integer;
|
||||||
@ -499,6 +510,7 @@ type
|
|||||||
FWidth: integer;
|
FWidth: integer;
|
||||||
procedure SetCaptionPosition(AValue: TLvlGraphNodeCaptionPosition);
|
procedure SetCaptionPosition(AValue: TLvlGraphNodeCaptionPosition);
|
||||||
procedure SetCaptionScale(AValue: single);
|
procedure SetCaptionScale(AValue: single);
|
||||||
|
procedure SetDefaultImageIndex(AValue: integer);
|
||||||
procedure SetGapBottom(AValue: integer);
|
procedure SetGapBottom(AValue: integer);
|
||||||
procedure SetGapLeft(AValue: integer);
|
procedure SetGapLeft(AValue: integer);
|
||||||
procedure SetGapRight(AValue: integer);
|
procedure SetGapRight(AValue: integer);
|
||||||
@ -521,6 +533,7 @@ type
|
|||||||
property GapRight: integer read FGapRight write SetGapRight default DefaultLvlGraphNodeGapRight; // used by AutoLayout
|
property GapRight: integer read FGapRight write SetGapRight default DefaultLvlGraphNodeGapRight; // used by AutoLayout
|
||||||
property GapBottom: integer read FGapBottom write SetGapBottom default DefaultLvlGraphNodeGapBottom; // used by AutoLayout
|
property GapBottom: integer read FGapBottom write SetGapBottom default DefaultLvlGraphNodeGapBottom; // used by AutoLayout
|
||||||
property Width: integer read FWidth write SetWidth default DefaultLvlGraphNodeWith;
|
property Width: integer read FWidth write SetWidth default DefaultLvlGraphNodeWith;
|
||||||
|
property DefaultImageIndex: integer read FDefaultImageIndex write SetDefaultImageIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCustomLvlGraphControl }
|
{ TCustomLvlGraphControl }
|
||||||
@ -529,6 +542,8 @@ type
|
|||||||
private
|
private
|
||||||
FEdgeSplitMode: TLvlGraphEdgeSplitMode;
|
FEdgeSplitMode: TLvlGraphEdgeSplitMode;
|
||||||
FGraph: TLvlGraph;
|
FGraph: TLvlGraph;
|
||||||
|
FImageChangeLink: TChangeLink;
|
||||||
|
FImages: TCustomImageList;
|
||||||
FNodeStyle: TLvlGraphNodeStyle;
|
FNodeStyle: TLvlGraphNodeStyle;
|
||||||
FNodeUnderMouse: TLvlGraphNode;
|
FNodeUnderMouse: TLvlGraphNode;
|
||||||
FOnMinimizeCrossings: TNotifyEvent;
|
FOnMinimizeCrossings: TNotifyEvent;
|
||||||
@ -543,6 +558,7 @@ type
|
|||||||
procedure DrawCaptions(const TxtH: integer);
|
procedure DrawCaptions(const TxtH: integer);
|
||||||
procedure DrawEdges(Highlighted: boolean);
|
procedure DrawEdges(Highlighted: boolean);
|
||||||
procedure DrawNodes;
|
procedure DrawNodes;
|
||||||
|
procedure SetImages(AValue: TCustomImageList);
|
||||||
procedure SetNodeStyle(AValue: TLvlGraphNodeStyle);
|
procedure SetNodeStyle(AValue: TLvlGraphNodeStyle);
|
||||||
procedure SetNodeUnderMouse(AValue: TLvlGraphNode);
|
procedure SetNodeUnderMouse(AValue: TLvlGraphNode);
|
||||||
procedure SetOptions(AValue: TLvlGraphCtrlOptions);
|
procedure SetOptions(AValue: TLvlGraphCtrlOptions);
|
||||||
@ -552,6 +568,7 @@ type
|
|||||||
procedure WMHScroll(var Msg: TLMScroll); message LM_HSCROLL;
|
procedure WMHScroll(var Msg: TLMScroll); message LM_HSCROLL;
|
||||||
procedure WMVScroll(var Msg: TLMScroll); message LM_VSCROLL;
|
procedure WMVScroll(var Msg: TLMScroll); message LM_VSCROLL;
|
||||||
procedure WMMouseWheel(var Message: TLMMouseEvent); message LM_MOUSEWHEEL;
|
procedure WMMouseWheel(var Message: TLMMouseEvent); message LM_MOUSEWHEEL;
|
||||||
|
procedure ImageListChange(Sender: TObject);
|
||||||
protected
|
protected
|
||||||
procedure AutoLayoutLevels(TxtH: LongInt); virtual;
|
procedure AutoLayoutLevels(TxtH: LongInt); virtual;
|
||||||
procedure GraphInvalidate(Sender: TObject); virtual;
|
procedure GraphInvalidate(Sender: TObject); virtual;
|
||||||
@ -588,6 +605,7 @@ type
|
|||||||
property ScrollLeft: integer read FScrollLeft write SetScrollLeft;
|
property ScrollLeft: integer read FScrollLeft write SetScrollLeft;
|
||||||
property ScrollLeftMax: integer read FScrollLeftMax;
|
property ScrollLeftMax: integer read FScrollLeftMax;
|
||||||
property OnMinimizeCrossings: TNotifyEvent read FOnMinimizeCrossings write FOnMinimizeCrossings;// provide an alternative minimize crossing algorithm
|
property OnMinimizeCrossings: TNotifyEvent read FOnMinimizeCrossings write FOnMinimizeCrossings;// provide an alternative minimize crossing algorithm
|
||||||
|
property Images: TCustomImageList read FImages write SetImages;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TLvlGraphControl }
|
{ TLvlGraphControl }
|
||||||
@ -1598,6 +1616,13 @@ begin
|
|||||||
Control.InvalidateAutoLayout;
|
Control.InvalidateAutoLayout;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLvlGraphNodeStyle.SetDefaultImageIndex(AValue: integer);
|
||||||
|
begin
|
||||||
|
if FDefaultImageIndex=AValue then Exit;
|
||||||
|
FDefaultImageIndex:=AValue;
|
||||||
|
Control.Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TLvlGraphNodeStyle.SetGapBottom(AValue: integer);
|
procedure TLvlGraphNodeStyle.SetGapBottom(AValue: integer);
|
||||||
begin
|
begin
|
||||||
if FGapBottom=AValue then Exit;
|
if FGapBottom=AValue then Exit;
|
||||||
@ -1651,6 +1676,7 @@ begin
|
|||||||
FCaptionScale:=DefaultLvlGraphNodeCaptionScale;
|
FCaptionScale:=DefaultLvlGraphNodeCaptionScale;
|
||||||
FCaptionPosition:=DefaultLvlGraphNodeCaptionPosition;
|
FCaptionPosition:=DefaultLvlGraphNodeCaptionPosition;
|
||||||
FShape:=DefaultLvlGraphNodeShape;
|
FShape:=DefaultLvlGraphNodeShape;
|
||||||
|
FDefaultImageIndex:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TLvlGraphNodeStyle.Destroy;
|
destructor TLvlGraphNodeStyle.Destroy;
|
||||||
@ -1672,6 +1698,8 @@ begin
|
|||||||
GapBottom:=Src.GapBottom;
|
GapBottom:=Src.GapBottom;
|
||||||
CaptionScale:=Src.CaptionScale;
|
CaptionScale:=Src.CaptionScale;
|
||||||
CaptionPosition:=Src.CaptionPosition;
|
CaptionPosition:=Src.CaptionPosition;
|
||||||
|
Shape:=Src.Shape;
|
||||||
|
DefaultImageIndex:=Src.DefaultImageIndex;
|
||||||
end else
|
end else
|
||||||
inherited Assign(Source);
|
inherited Assign(Source);
|
||||||
end;
|
end;
|
||||||
@ -1690,7 +1718,9 @@ begin
|
|||||||
and (GapTop=Src.GapTop)
|
and (GapTop=Src.GapTop)
|
||||||
and (GapBottom=Src.GapBottom)
|
and (GapBottom=Src.GapBottom)
|
||||||
and (CaptionScale=Src.CaptionScale)
|
and (CaptionScale=Src.CaptionScale)
|
||||||
and (CaptionPosition=Src.CaptionPosition);
|
and (CaptionPosition=Src.CaptionPosition)
|
||||||
|
and (Shape=Src.Shape)
|
||||||
|
and (DefaultImageIndex=Src.DefaultImageIndex);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1895,6 +1925,11 @@ begin
|
|||||||
OnSelectionChanged(Self);
|
OnSelectionChanged(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomLvlGraphControl.ImageListChange(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomLvlGraphControl.DrawCaptions(const TxtH: integer);
|
procedure TCustomLvlGraphControl.DrawCaptions(const TxtH: integer);
|
||||||
var
|
var
|
||||||
Node: TLvlGraphNode;
|
Node: TLvlGraphNode;
|
||||||
@ -1942,6 +1977,7 @@ var
|
|||||||
Node: TLvlGraphNode;
|
Node: TLvlGraphNode;
|
||||||
x: Integer;
|
x: Integer;
|
||||||
y: Integer;
|
y: Integer;
|
||||||
|
ImgIndex: Integer;
|
||||||
begin
|
begin
|
||||||
Canvas.Brush.Style:=bsSolid;
|
Canvas.Brush.Style:=bsSolid;
|
||||||
for i:=0 to Graph.LevelCount-1 do begin
|
for i:=0 to Graph.LevelCount-1 do begin
|
||||||
@ -1950,6 +1986,8 @@ begin
|
|||||||
Node:=Level.Nodes[j];
|
Node:=Level.Nodes[j];
|
||||||
if not Node.Visible then continue;
|
if not Node.Visible then continue;
|
||||||
//debugln(['TCustomLvlGraphControl.Paint ',Node.Caption,' ',dbgs(FPColorToTColor(Node.Color)),' Level.DrawPosition=',Level.DrawPosition,' Node.DrawPosition=',Node.DrawPosition,' ',Node.DrawPositionEnd]);
|
//debugln(['TCustomLvlGraphControl.Paint ',Node.Caption,' ',dbgs(FPColorToTColor(Node.Color)),' Level.DrawPosition=',Level.DrawPosition,' Node.DrawPosition=',Node.DrawPosition,' ',Node.DrawPositionEnd]);
|
||||||
|
|
||||||
|
// draw shape
|
||||||
Canvas.Brush.Color:=FPColorToTColor(Node.Color);
|
Canvas.Brush.Color:=FPColorToTColor(Node.Color);
|
||||||
Canvas.Pen.Color:=Darker(Canvas.Brush.Color);
|
Canvas.Pen.Color:=Darker(Canvas.Brush.Color);
|
||||||
x:=Level.DrawPosition-ScrollLeft;
|
x:=Level.DrawPosition-ScrollLeft;
|
||||||
@ -1960,10 +1998,37 @@ begin
|
|||||||
lgnsEllipse:
|
lgnsEllipse:
|
||||||
Canvas.Ellipse(x, y, x+NodeStyle.Width, y+Node.DrawSize);
|
Canvas.Ellipse(x, y, x+NodeStyle.Width, y+Node.DrawSize);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// draw image and overlay
|
||||||
|
if (Images<>nil) then begin
|
||||||
|
x:=Level.DrawPosition+((NodeStyle.Width-Images.Width) div 2)-ScrollLeft;
|
||||||
|
y:=Node.DrawCenter-(Images.Height div 2)-ScrollTop;
|
||||||
|
ImgIndex:=Node.ImageIndex;
|
||||||
|
if (ImgIndex<0) or (ImgIndex>=Images.Count) then
|
||||||
|
ImgIndex:=NodeStyle.DefaultImageIndex;
|
||||||
|
if (ImgIndex>=0) and (ImgIndex<Images.Count) then begin
|
||||||
|
Images.Draw(Canvas, x, y, ImgIndex, Node.FImageEffect);
|
||||||
|
if (Node.OverlayIndex>=0) and (Node.OverlayIndex<Images.Count) then
|
||||||
|
Images.DrawOverlay(Canvas, x, y, ImgIndex, Node.OverlayIndex, Node.FImageEffect);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomLvlGraphControl.SetImages(AValue: TCustomImageList);
|
||||||
|
begin
|
||||||
|
if FImages=AValue then Exit;
|
||||||
|
if Images <> nil then
|
||||||
|
Images.UnRegisterChanges(FImageChangeLink);
|
||||||
|
FImages:=AValue;
|
||||||
|
if Images <> nil then begin
|
||||||
|
Images.RegisterChanges(FImageChangeLink);
|
||||||
|
Images.FreeNotification(Self);
|
||||||
|
end;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomLvlGraphControl.SetNodeStyle(AValue: TLvlGraphNodeStyle);
|
procedure TCustomLvlGraphControl.SetNodeStyle(AValue: TLvlGraphNodeStyle);
|
||||||
begin
|
begin
|
||||||
if FNodeStyle=AValue then Exit;
|
if FNodeStyle=AValue then Exit;
|
||||||
@ -2219,10 +2284,13 @@ begin
|
|||||||
FGraph.OnSelectionChanged:=@GraphSelectionChanged;
|
FGraph.OnSelectionChanged:=@GraphSelectionChanged;
|
||||||
FGraph.OnStructureChanged:=@GraphStructureChanged;
|
FGraph.OnStructureChanged:=@GraphStructureChanged;
|
||||||
FNodeStyle:=TLvlGraphNodeStyle.Create(Self);
|
FNodeStyle:=TLvlGraphNodeStyle.Create(Self);
|
||||||
|
FImageChangeLink := TChangeLink.Create;
|
||||||
|
FImageChangeLink.OnChange:=@ImageListChange;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCustomLvlGraphControl.Destroy;
|
destructor TCustomLvlGraphControl.Destroy;
|
||||||
begin
|
begin
|
||||||
|
FreeAndNil(FImageChangeLink);
|
||||||
FreeAndNil(FGraph);
|
FreeAndNil(FGraph);
|
||||||
FreeAndNil(FNodeStyle);
|
FreeAndNil(FNodeStyle);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
@ -3151,6 +3219,20 @@ begin
|
|||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLvlGraphNode.SetImageEffect(AValue: TGraphicsDrawEffect);
|
||||||
|
begin
|
||||||
|
if FImageEffect=AValue then Exit;
|
||||||
|
FImageEffect:=AValue;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLvlGraphNode.SetImageIndex(AValue: integer);
|
||||||
|
begin
|
||||||
|
if FImageIndex=AValue then Exit;
|
||||||
|
FImageIndex:=AValue;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TLvlGraphNode.SetIndexInLevel(AValue: integer);
|
procedure TLvlGraphNode.SetIndexInLevel(AValue: integer);
|
||||||
begin
|
begin
|
||||||
Level.MoveNode(Self,AValue);
|
Level.MoveNode(Self,AValue);
|
||||||
@ -3169,6 +3251,13 @@ begin
|
|||||||
FLevel.fNodes.Add(Self);
|
FLevel.fNodes.Add(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLvlGraphNode.SetOverlayIndex(AValue: integer);
|
||||||
|
begin
|
||||||
|
if FOverlayIndex=AValue then Exit;
|
||||||
|
FOverlayIndex:=AValue;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TLvlGraphNode.SetSelected(AValue: boolean);
|
procedure TLvlGraphNode.SetSelected(AValue: boolean);
|
||||||
|
|
||||||
procedure Unselect;
|
procedure Unselect;
|
||||||
@ -3251,6 +3340,8 @@ begin
|
|||||||
FOutEdges:=TFPList.Create;
|
FOutEdges:=TFPList.Create;
|
||||||
FDrawSize:=1;
|
FDrawSize:=1;
|
||||||
FVisible:=true;
|
FVisible:=true;
|
||||||
|
FImageIndex:=-1;
|
||||||
|
FOverlayIndex:=-1;
|
||||||
Level:=TheLevel;
|
Level:=TheLevel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user