SimpleGraph: Center Nodes

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

SimpleGraph: Center Nodes

Postby sergisan » March 2nd, 2006, 10:29 pm

Hi all,

I need to center the screen on a given node say GraphMain.Objects[0] to simplify.

I am doing this
NodeRect := GraphMain.Objects[0].BoundsRect;

ancho := NodeRect.Right -NodeRect.Left ;
alto := NodeRect.Bottom -NodeRect.Top ;
NodeRect.Left := NodeRect.Left - (GraphMain.Width div 2) + (ancho div 2);
NodeRect.Top := NodeRect.Top - (GraphMain.Height div 2)+ (alto div 2);
NodeRect.Right := NodeRect.Right + (GraphMain.Width div 2) - (ancho div 2);
NodeRect.Bottom := NodeRect.Bottom + (GraphMain.Height div 2) - (alto div 2);

It is working well, but it does not work well with zoom , I suppose I have to convert the nodrect with ClientToGraph or GraphToClient but I don't find the solution, any help would be appreciated.

An other thing I must do is to center the screen where the mouse is when the user presses a key (it is something like the previous case but without an object). For example if the mouse is at the bottom right and the user press 'C' then the point where the mouse is should be now the center of the graph (and I must move the mouse position do) it is something very usual in cad programs.


Thanks

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

Postby Kambiz » March 3rd, 2006, 8:17 am

  1. The VisibleBounds property gives you the grpah rectangle that is visible on the control, and it is in graph coordinates.
  2. Range of scrollbars range is defined by the size of the graph. So you cannot scroll freely. However, there's one workaround. Insert two GraphLinks (one point only and not selectable) on top left and bottom right of the graph to manually change the graph bounds.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby sergisan » March 5th, 2006, 8:31 am

Hi Kambiz,

I dont understand what you say :(

may be my question was not clear, I will say it moore clearly.

If i have no zoom and I do
NodeRect.Left := NodeRect.Left - (GraphMain.Width div 2) + (NodeRect.Right -NodeRect.Left div 2);
NodeRect.Top := NodeRect.Top - (GraphMain.Height div 2)+ (NodeRect.Bottom -NodeRect.Topdiv 2);
NodeRect.Right := NodeRect.Right + (GraphMain.Width div 2) - (NodeRect.Right -NodeRect.Left div 2);
NodeRect.Bottom := NodeRect.Bottom + (GraphMain.Height div 2) - (NodeRect.Bottom -NodeRect.Top div 2);
GraphMain.ScrollInView(NodeRect);

I get the node perfectly centered in the Graph ( that is what I want).

If I have a zoom, set the same action does not center the graph on the screen. And I dont know how to solve it.

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

Postby Kambiz » March 5th, 2006, 11:25 am

I said, instead of using Width and Height of SimpleGraph, use VisibleBounds property.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 5 guests

cron