DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   Watched TopicsWatched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TSimpleGraph inserting with a click

 
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
sergisan
Member


Joined: 19 Oct 2005
Posts: 20

PostPosted: 12/11/05 19:30    Post subject: TSimpleGraph inserting with a click Reply with quote

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
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 12/11/05 21:24    Post subject: Reply with quote

Use ClientToGraph method.

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

_________________
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sergisan
Member


Joined: 19 Oct 2005
Posts: 20

PostPosted: 12/11/05 22:04    Post subject: Reply with quote

Thanks

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


Serg...
Back to top
View user's profile Send private message
lbc
Member


Joined: 04 Feb 2004
Posts: 48
Location: Italy

PostPosted: 13/11/05 16:24    Post subject: Reply with quote

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
View user's profile Send private message
sergisan
Member


Joined: 19 Oct 2005
Posts: 20

PostPosted: 14/11/05 22:00    Post subject: Reply with quote

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
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 15/11/05 08:49    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
lbc
Member


Joined: 04 Feb 2004
Posts: 48
Location: Italy

PostPosted: 15/11/05 10:33    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Page 1 of 1

Add to favorites

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group