| View previous topic :: View next topic |
| Author |
Message |
sergisan Member
Joined: 19 Oct 2005 Posts: 20
|
Posted: 12/11/05 19:30 Post subject: TSimpleGraph inserting with a click |
|
|
Hi everybody,
I am doing a app that needs the user to insert nodes with a simple clik.
I've modified the mousup event this way:
Original:
cmInsertNode:
begin
try
if (Button = mbLeft) and not (ssDouble in Shift) and not IsRectEmpty(SelectionRect) then InsertNode(@SelectionRect);
Modified:
cmInsertNode:
begin
try
if (Button = mbLeft) and not (ssDouble in Shift) then
begin
if IsRectEmpty(SelectionRect)then SelectionRect := MakeRect(Point(x,y), Point(x+10,y+10));
InsertNode(@SelectionRect)
end;
It's working very well. But when the graph zoom is not 100% the node is not inserted in the point I clik, it seems that x and y need to be calculated ?
Any help ?.
Thanks.
Serg...
|
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1044 Location: Tehran, Iran
|
Posted: 12/11/05 21:24 Post subject: |
|
|
Use ClientToGraph method.
I do suggest to have a look at readme.htm file.
_________________ Kambiz |
|
| Back to top |
|
 |
sergisan Member
Joined: 19 Oct 2005 Posts: 20
|
Posted: 12/11/05 22:04 Post subject: |
|
|
Thanks
and I'll take a closer look to the doc.
Serg...
|
|
| Back to top |
|
 |
lbc Member
Joined: 04 Feb 2004 Posts: 48 Location: Italy
|
Posted: 13/11/05 16:24 Post subject: |
|
|
Hi Sergisan
now that Kambiz has kindly added the new Onclick event i think it's better to use it, this way you don't have to touch the mouseup event
ex.
| Code: |
procedure TForm1.SGClick(Sender: TObject);
var
R: TRect;
begin
SG.DefaultNodeClass := TRectangularNode;
R := MakeRect(Point(10,10),Point(100,100));
SG.InsertNode(@R);
end;
|
hope that helps
|
|
| Back to top |
|
 |
sergisan Member
Joined: 19 Oct 2005 Posts: 20
|
Posted: 14/11/05 22:00 Post subject: |
|
|
lbc,
the problem is that you don't insert the node where the user clicked
| Code: | procedure TForm1.SGClick(Sender: TObject);
var
R: TRect;
begin
SG.DefaultNodeClass := TRectangularNode;
R := MakeRect(Point(10,10),Point(100,100));
SG.InsertNode(@R);
end; |
it is always 10,10
Serg...
|
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1044 Location: Tehran, Iran
|
Posted: 15/11/05 08:49 Post subject: |
|
|
The following code inserts a node at the click position:
| Code: | procedure TMainForm.SimpleGraphClick(Sender: TObject);
const
NewNodeWidth = 10;
NewNodeHeight = 10;
var
Pt: TPoint;
NodeRect: TRect;
begin
Pt := SimpleGraph.ScreenToClient(Mouse.CursorPos);
NodeRect.TopLeft := SimpleGraph.ClientToGraph(Pt.X, Pt.Y);
NodeRect.Right := NodeRect.Left + NewNodeWidth;
NodeRect.Bottom := NodeRect.Top + NewNodeHeight;
SimpleGraph.InsertNode(@NodeRect, TRectangularNode);
end; |
_________________ Kambiz |
|
| Back to top |
|
 |
lbc Member
Joined: 04 Feb 2004 Posts: 48 Location: Italy
|
Posted: 15/11/05 10:33 Post subject: |
|
|
| sergisan wrote: | lbc,
the problem is that you don't insert the node where the user clicked
it is always 10,10
Serg... |
Hi Serg
of course, it was just a sample to show the use of the new Onclick event and a suggestion to not touch the mouseup code
with the complete code that Kambiz has kindly posted you can insert the node at the mouse current position
|
|
| Back to top |
|
 |
|