mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-21 11:20:44 +01:00
cody:lvlgraph: mouse selects
git-svn-id: trunk@40317 -
This commit is contained in:
parent
3d1bfbe763
commit
6662a11ade
@ -246,9 +246,12 @@ type
|
|||||||
FDrawSize: integer;
|
FDrawSize: integer;
|
||||||
FInWeight: single;
|
FInWeight: single;
|
||||||
FLevel: TLvlGraphLevel;
|
FLevel: TLvlGraphLevel;
|
||||||
|
FNextSelected: TLvlGraphNode;
|
||||||
FOutEdges: TFPList; // list of TLvlGraphEdge
|
FOutEdges: TFPList; // list of TLvlGraphEdge
|
||||||
FDrawPosition: integer;
|
FDrawPosition: integer;
|
||||||
FOutWeight: single;
|
FOutWeight: single;
|
||||||
|
FPrevSelected: TLvlGraphNode;
|
||||||
|
FSelected: boolean;
|
||||||
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);
|
||||||
@ -256,6 +259,7 @@ type
|
|||||||
procedure OnLevelDestroy;
|
procedure OnLevelDestroy;
|
||||||
procedure SetDrawSize(AValue: integer);
|
procedure SetDrawSize(AValue: integer);
|
||||||
procedure SetLevel(AValue: TLvlGraphLevel);
|
procedure SetLevel(AValue: TLvlGraphLevel);
|
||||||
|
procedure SetSelected(AValue: boolean);
|
||||||
procedure UnbindLevel;
|
procedure UnbindLevel;
|
||||||
public
|
public
|
||||||
Data: Pointer; // free for user data
|
Data: Pointer; // free for user data
|
||||||
@ -274,11 +278,14 @@ 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 Level: TLvlGraphLevel read FLevel write SetLevel;
|
||||||
|
property Selected: boolean read FSelected write SetSelected;
|
||||||
|
property NextSelected: TLvlGraphNode read FNextSelected;
|
||||||
|
property PrevSelected: TLvlGraphNode read FPrevSelected;
|
||||||
property DrawPosition: integer read FDrawPosition write FDrawPosition; // position in a level
|
property DrawPosition: integer read FDrawPosition write FDrawPosition; // position in a level
|
||||||
|
property DrawSize: integer read FDrawSize write SetDrawSize default 1;
|
||||||
function DrawCenter: integer;
|
function DrawCenter: integer;
|
||||||
function DrawPositionEnd: integer;// = DrawPosition+Max(InSize,OutSize)
|
function DrawPositionEnd: integer;// = DrawPosition+Max(InSize,OutSize)
|
||||||
property DrawSize: integer read FDrawSize write SetDrawSize default 1;
|
|
||||||
property Level: TLvlGraphLevel read FLevel write SetLevel;
|
|
||||||
property InWeight: single read FInWeight; // total weight of InEdges
|
property InWeight: single read FInWeight; // total weight of InEdges
|
||||||
property OutWeight: single read FOutWeight; // total weight of OutEdges
|
property OutWeight: single read FOutWeight; // total weight of OutEdges
|
||||||
end;
|
end;
|
||||||
@ -338,6 +345,8 @@ type
|
|||||||
TLvlGraph = class(TPersistent)
|
TLvlGraph = class(TPersistent)
|
||||||
private
|
private
|
||||||
FEdgeClass: TLvlGraphEdgeClass;
|
FEdgeClass: TLvlGraphEdgeClass;
|
||||||
|
FFirstSelected: TLvlGraphNode;
|
||||||
|
FLastSelected: TLvlGraphNode;
|
||||||
FLevelClass: TLvlGraphLevelClass;
|
FLevelClass: TLvlGraphLevelClass;
|
||||||
FNodeClass: TLvlGraphNodeClass;
|
FNodeClass: TLvlGraphNodeClass;
|
||||||
FOnInvalidate: TNotifyEvent;
|
FOnInvalidate: TNotifyEvent;
|
||||||
@ -367,6 +376,9 @@ type
|
|||||||
property Nodes[Index: integer]: TLvlGraphNode read GetNodes;
|
property Nodes[Index: integer]: TLvlGraphNode read GetNodes;
|
||||||
function GetNode(aCaption: string; CreateIfNotExists: boolean): TLvlGraphNode;
|
function GetNode(aCaption: string; CreateIfNotExists: boolean): TLvlGraphNode;
|
||||||
property NodeClass: TLvlGraphNodeClass read FNodeClass;
|
property NodeClass: TLvlGraphNodeClass read FNodeClass;
|
||||||
|
property FirstSelected: TLvlGraphNode read FFirstSelected;
|
||||||
|
property LastSelected: TLvlGraphNode read FLastSelected;
|
||||||
|
procedure ClearSelection;
|
||||||
|
|
||||||
// edges
|
// edges
|
||||||
function GetEdge(SourceCaption, TargetCaption: string;
|
function GetEdge(SourceCaption, TargetCaption: string;
|
||||||
@ -398,7 +410,8 @@ type
|
|||||||
type
|
type
|
||||||
TLvlGraphCtrlOption = (
|
TLvlGraphCtrlOption = (
|
||||||
lgoAutoLayout, // automatic graph layout after graph was changed
|
lgoAutoLayout, // automatic graph layout after graph was changed
|
||||||
lgoHighlightNodeUnderMouse // when mouse over node highlight node and its edges
|
lgoHighlightNodeUnderMouse, // when mouse over node highlight node and its edges
|
||||||
|
lgoMouseSelects
|
||||||
);
|
);
|
||||||
TLvlGraphCtrlOptions = set of TLvlGraphCtrlOption;
|
TLvlGraphCtrlOptions = set of TLvlGraphCtrlOption;
|
||||||
|
|
||||||
@ -409,7 +422,7 @@ type
|
|||||||
lgncBottom);
|
lgncBottom);
|
||||||
|
|
||||||
const
|
const
|
||||||
DefaultLvlGraphCtrlOptions = [lgoAutoLayout,lgoHighlightNodeUnderMouse];
|
DefaultLvlGraphCtrlOptions = [lgoAutoLayout,lgoHighlightNodeUnderMouse,lgoMouseSelects];
|
||||||
DefaultLvlGraphNodeWith = 10;
|
DefaultLvlGraphNodeWith = 10;
|
||||||
DefaultLvlGraphNodeCaptionScale = 0.7;
|
DefaultLvlGraphNodeCaptionScale = 0.7;
|
||||||
DefaultLvlGraphNodeCaptionPosition = lgncTop;
|
DefaultLvlGraphNodeCaptionPosition = lgncTop;
|
||||||
@ -487,6 +500,8 @@ type
|
|||||||
procedure DoSetBounds(ALeft, ATop, AWidth, AHeight: integer); override;
|
procedure DoSetBounds(ALeft, ATop, AWidth, AHeight: integer); override;
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
||||||
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer
|
||||||
|
); override;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -995,7 +1010,6 @@ var
|
|||||||
TxtW: Integer;
|
TxtW: Integer;
|
||||||
p: TPoint;
|
p: TPoint;
|
||||||
begin
|
begin
|
||||||
Canvas.Brush.Style:=bsClear;
|
|
||||||
Canvas.Font.Height:=round(single(TxtH)*NodeStyle.CaptionScale+0.5);
|
Canvas.Font.Height:=round(single(TxtH)*NodeStyle.CaptionScale+0.5);
|
||||||
for i:=0 to Graph.LevelCount-1 do begin
|
for i:=0 to Graph.LevelCount-1 do begin
|
||||||
Level:=Graph.Levels[i];
|
Level:=Graph.Levels[i];
|
||||||
@ -1013,7 +1027,14 @@ begin
|
|||||||
lgncRight: p.x:=Level.DrawPosition+NodeStyle.Width+NodeStyle.GapRight;
|
lgncRight: p.x:=Level.DrawPosition+NodeStyle.Width+NodeStyle.GapRight;
|
||||||
lgncTop,lgncBottom: p.x:=Level.DrawPosition+((NodeStyle.Width-TxtW) div 2);
|
lgncTop,lgncBottom: p.x:=Level.DrawPosition+((NodeStyle.Width-TxtW) div 2);
|
||||||
end;
|
end;
|
||||||
//debugln(['TCustomLvlGraphControl.Paint ',Node.Caption,' DrawPosition=',Node.DrawPosition,' DrawSize=',Node.DrawSize,' TxtH=',TxtH,' TxtW=',TxtW,' p=',dbgs(p)]);
|
//debugln(['TCustomLvlGraphControl.Paint ',Node.Caption,' DrawPosition=',Node.DrawPosition,' DrawSize=',Node.DrawSize,' TxtH=',TxtH,' TxtW=',TxtW,' p=',dbgs(p),' Selected=',Node.Selected]);
|
||||||
|
if Node.Selected then begin
|
||||||
|
Canvas.Brush.Style:=bsSolid;
|
||||||
|
Canvas.Brush.Color:=clHighlight;
|
||||||
|
end else begin
|
||||||
|
Canvas.Brush.Style:=bsClear;
|
||||||
|
Canvas.Brush.Color:=clNone;
|
||||||
|
end;
|
||||||
Canvas.TextOut(p.x,p.y,Node.Caption);
|
Canvas.TextOut(p.x,p.y,Node.Caption);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1144,6 +1165,34 @@ begin
|
|||||||
NodeUnderMouse:=GetNodeAt(X,Y);
|
NodeUnderMouse:=GetNodeAt(X,Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomLvlGraphControl.MouseDown(Button: TMouseButton;
|
||||||
|
Shift: TShiftState; X, Y: Integer);
|
||||||
|
var
|
||||||
|
Node: TLvlGraphNode;
|
||||||
|
begin
|
||||||
|
BeginUpdate;
|
||||||
|
try
|
||||||
|
inherited MouseDown(Button, Shift, X, Y);
|
||||||
|
Node:=GetNodeAt(X,Y);
|
||||||
|
if Node<>nil then begin
|
||||||
|
if Button=mbLeft then begin
|
||||||
|
if lgoMouseSelects in Options then begin
|
||||||
|
if ssCtrl in Shift then begin
|
||||||
|
// toggle selection
|
||||||
|
Node.Selected:=not Node.Selected;
|
||||||
|
end else begin
|
||||||
|
// single selection
|
||||||
|
Graph.ClearSelection;
|
||||||
|
Node.Selected:=true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
EndUpdate;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TCustomLvlGraphControl.Create(AOwner: TComponent);
|
constructor TCustomLvlGraphControl.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
@ -1402,6 +1451,12 @@ begin
|
|||||||
Result:=nil;
|
Result:=nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLvlGraph.ClearSelection;
|
||||||
|
begin
|
||||||
|
while FirstSelected<>nil do
|
||||||
|
FirstSelected.Selected:=false;
|
||||||
|
end;
|
||||||
|
|
||||||
function TLvlGraph.GetEdge(SourceCaption, TargetCaption: string;
|
function TLvlGraph.GetEdge(SourceCaption, TargetCaption: string;
|
||||||
CreateIfNotExists: boolean): TLvlGraphEdge;
|
CreateIfNotExists: boolean): TLvlGraphEdge;
|
||||||
var
|
var
|
||||||
@ -1925,6 +1980,34 @@ begin
|
|||||||
FLevel.fNodes.Add(Self);
|
FLevel.fNodes.Add(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLvlGraphNode.SetSelected(AValue: boolean);
|
||||||
|
begin
|
||||||
|
if FSelected=AValue then Exit;
|
||||||
|
FSelected:=AValue;
|
||||||
|
if Graph<>nil then begin
|
||||||
|
if Selected then begin
|
||||||
|
FPrevSelected:=Graph.LastSelected;
|
||||||
|
if FPrevSelected<>nil then
|
||||||
|
FPrevSelected.FNextSelected:=Self
|
||||||
|
else
|
||||||
|
Graph.FFirstSelected:=Self;
|
||||||
|
Graph.FLastSelected:=Self;
|
||||||
|
end else begin
|
||||||
|
if FPrevSelected<>nil then
|
||||||
|
FPrevSelected.FNextSelected:=FNextSelected
|
||||||
|
else
|
||||||
|
Graph.FFirstSelected:=FNextSelected;
|
||||||
|
if FNextSelected<>nil then
|
||||||
|
FNextSelected.FPrevSelected:=FPrevSelected
|
||||||
|
else
|
||||||
|
Graph.FLastSelected:=FPrevSelected;
|
||||||
|
FNextSelected:=nil;
|
||||||
|
FPrevSelected:=nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TLvlGraphNode.UnbindLevel;
|
procedure TLvlGraphNode.UnbindLevel;
|
||||||
begin
|
begin
|
||||||
if FLevel<>nil then
|
if FLevel<>nil then
|
||||||
@ -1950,6 +2033,7 @@ end;
|
|||||||
|
|
||||||
destructor TLvlGraphNode.Destroy;
|
destructor TLvlGraphNode.Destroy;
|
||||||
begin
|
begin
|
||||||
|
Selected:=false;
|
||||||
Clear;
|
Clear;
|
||||||
UnbindLevel;
|
UnbindLevel;
|
||||||
if Graph<>nil then
|
if Graph<>nil then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user