Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Need selected area at the center of the diagram (Read 3517 times)
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Need selected area at the center of the diagram
Nov 25th, 2009 at 4:51pm
Print Post  
Hi Stoyan,

We have some nodes in our diagram.
We want to magnify some of the nodes, for that we are selecting that nodes using mouse drag. When we drag the mouse a ned rect is created and we want to magnify that rect portion only. For this purpose we are using following code.

Code
Select All
Point oldCursorPosition = diagram.ClientToDoc(Mouse.GetPosition(diagram.Parent as ScrollViewer));
		    double newScrollX = diagram.ScrollX;
		    double newScrollY = diagram.ScrollY;
		    diagram.ZoomFactor = 200;
		    Rect newBounds = diagram.ClientToDoc(new Rect(0, 0, scrollViewer.ActualWidth, scrollViewer.ActualHeight));
		    Point newCursorPosition = new Point(newBounds.X + newBounds.Width / 2, newBounds.Y + newBounds.Height / 2);
		    double diffx = (oldCursorPosition.X - newCursorPosition.X);
		    double diffy = (oldCursorPosition.Y - newCursorPosition.Y);
		    newScrollX += diffx;
		    newScrollY += diffy;
		    newBounds.X = newScrollX;
		    newBounds.Y = newScrollY;
		    newBounds.Union(diagram.GetContentBounds(false, false));
		    newBounds.Inflate(200, 200);
		    diagram.Bounds = newBounds;
		    diagram.ScrollTo(new Point(newScrollX, newScrollY)); 




It is working very fine. We want after magnification, this rect will come at the center of the diagram so that when we perform zooming, we always get this rect as center, how can we do this?


Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Need selected area at the center of the diagra
Reply #1 - Nov 27th, 2009 at 3:33pm
Print Post  
Can't you just call the diagram.ZoomToRect() method?
  
Back to top
 
IP Logged
 
priyanka
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 56
Joined: Sep 2nd, 2009
Re: Need selected area at the center of the diagra
Reply #2 - Nov 30th, 2009 at 11:04am
Print Post  
Hi,

diagram.ZoomToRect() will zoom the content of the rect to fit the diagram completely.

But the requirment is the zooming should get performed taking that selected rectangle as center to zoom,
ie. when we zoom in/out the zooming should get performed with respect to the specified rectangle only and not from the center of diagram.

Regards,
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Need selected area at the center of the diagra
Reply #3 - Nov 30th, 2009 at 12:48pm
Print Post  
Hi,

Isn't that the same as zooming around a given point, where the point is the center of the rectangle in this case? Some time ago I sent you the code for a mouse-wheel handler that does this.

Regards,
Stoyan
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Need selected area at the center of the diagram
Reply #4 - May 13th, 2021 at 6:45pm
Print Post  
I am having the same issue.
Whats the solution for it! Can someone please share the sample code here..
Thank you.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Need selected area at the center of the diagram
Reply #5 - May 14th, 2021 at 6:02am
Print Post  
Hi,

If you mean you need to change zoom with viewport's center staying at same position, you should be able to use these methods -

Code
Select All
public void SetZoomFactor (
    double zoomFactor,
    Point pivotPoint
)

public void ZoomToRect (
    Rect rect,
    bool centered
) 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint