TSimpleGraph inserting with a click

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

TSimpleGraph inserting with a click

Postby sergisan » November 12th, 2005, 7:30 pm

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...
sergisan
Active Member
Active Member
 
Posts: 20
Joined: October 19th, 2005, 8:30 pm

Postby Kambiz » November 12th, 2005, 9:24 pm

Use ClientToGraph method.

I do suggest to have a look at readme.htm file.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2405
Joined: March 7th, 2003, 7:10 pm

Postby sergisan » November 12th, 2005, 10:04 pm

Thanks

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


Serg...
sergisan
Active Member
Active Member
 
Posts: 20
Joined: October 19th, 2005, 8:30 pm

Postby lbc » November 13th, 2005, 4:24 pm

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
lbc
Junior Member
Junior Member
 
Posts: 48
Joined: February 4th, 2004, 7:50 am
Location: Italy

Postby sergisan » November 14th, 2005, 10:00 pm

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...
sergisan
Active Member
Active Member
 
Posts: 20
Joined: October 19th, 2005, 8:30 pm

Postby Kambiz » November 15th, 2005, 8:49 am

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;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2405
Joined: March 7th, 2003, 7:10 pm

Postby lbc » November 15th, 2005, 10:33 am

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
lbc
Junior Member
Junior Member
 
Posts: 48
Joined: February 4th, 2004, 7:50 am
Location: Italy


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests

cron