Page 1 of 1

TSimpleGraph inserting with a click

PostPosted: November 12th, 2005, 7:30 pm
by sergisan
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...

PostPosted: November 12th, 2005, 9:24 pm
by Kambiz
Use ClientToGraph method.

I do suggest to have a look at readme.htm file.

PostPosted: November 12th, 2005, 10:04 pm
by sergisan
Thanks

and I'll take a closer look to the doc.


Serg...

PostPosted: November 13th, 2005, 4:24 pm
by lbc
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: Select all
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

PostPosted: November 14th, 2005, 10:00 pm
by sergisan
lbc,

the problem is that you don't insert the node where the user clicked

Code: Select all
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...

PostPosted: November 15th, 2005, 8:49 am
by Kambiz
The following code inserts a node at the click position:

Code: Select all
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;

PostPosted: November 15th, 2005, 10:33 am
by lbc
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