Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Need Zooming from Viewport Center (Read 6586 times)
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Need Zooming from Viewport Center
Nov 26th, 2009 at 6:52am
Print Post  
Hi Stoyan,

To perform zooming from the center of the diagram, we have used following code.

Code
Select All
public void SetZoom(double percentage)

  {


try


{


    diagram.ZoomToFit();


    if (percentage > 200)


    {



  percentage = 200;


    }


    else if (percentage < 10)


    {



  percentage = 10;


    }



    ScrollViewer scrollViewer = diagram.Parent as ScrollViewer;


    Point oldCenter = diagram.ClientToDoc(new Point(scrollViewer.ViewportWidth / 2, scrollViewer.ViewportHeight / 2));



    double newScrollX = diagram.ScrollX;


    double newScrollY = diagram.ScrollY;


    diagram.ZoomFactor = percentage;



    Rect newBounds = diagram.ClientToDoc(new Rect(0, 0, scrollViewer.ViewportWidth, scrollViewer.ViewportHeight));


    Point newCenter = diagram.ClientToDoc(new Point(scrollViewer.ViewportWidth / 2, scrollViewer.ViewportHeight / 2));



    double diffx = (oldCenter.X - newCenter.X);


    double diffy = (oldCenter.Y - newCenter.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));


    }


catch (Exception ex)


{


    Debug.WriteLine("Exception in SetZoom : " + ex.Message);


}

  } 




Problem:

After zoom when we try to drag the node at extreme right of the diagram, horizontal bar position get change. Now if we zoom again it performs zooming from the diagram center, so in this case we get a different view during zooming from the view on which we were doing some work.

Requirement:

We want zooming should perform from the center of the visible client area. Client area which is viewable should have zooming center.


Please suggest how can we achieve this? ???

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Need Zooming from Viewport Center
Reply #1 - Nov 27th, 2009 at 9:53am
Print Post  
After the diagram.ZoomToFit() call the whole diagram fits within the ScrollViewer, so the scroll viewer center coincides with the diagram's one. Since you are using code to preserve the center point position, it naturally zooms around the diagram's center. So why are you calling this method if you are setting ZoomFactor later anyway?
  
Back to top
 
IP Logged
 
priyanka
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 56
Joined: Sep 2nd, 2009
Re: Need Zooming from Viewport Center
Reply #2 - Dec 1st, 2009 at 12:40pm
Print Post  
Hi,

My requirment is:
I get the content bounds using GetContentBounds().
Need to fill the entire diagram with the content rectangle and  need to make the view port center coincide with the center of the rect obtained from GetContentBounds().

How could this be done.!?

Regards,
« Last Edit: Dec 1st, 2009 at 2:27pm by priyanka »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Need Zooming from Viewport Center
Reply #3 - Dec 2nd, 2009 at 2:10pm
Print Post  
This seems to do what you'e described:

Code
Select All
private void OnDiagramFillView(object sender, RoutedEventArgs e)
{
	diagram.ZoomToFit();
	Rect newBounds = diagram.GetContentBounds(false, false);
	Size newSize = diagram.ClientToDoc(new Rect(
		0, 0, scrollViewer.ActualWidth, scrollViewer.ActualHeight)).Size;
	newBounds.Inflate(
		(newSize.Width - newBounds.Width) / 2,
		(newSize.Height - newBounds.Height) / 2);
	diagram.Bounds = newBounds;
}
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Need Zooming from Viewport Center
Reply #4 - Dec 3rd, 2009 at 2:27pm
Print Post  
Hi Stoyan,

We have tried given code in our application. Now nodes are coming at the center but when we go for zooming they are shifting in up direction. Sometimes diagram gets fluctuate for a while when we performzoom using mouse wheel.

We want zoom should always perform from the content's area center.

Please suggest what we need to do this?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Need Zooming from Viewport Center
Reply #5 - Dec 16th, 2009 at 10:30am
Print Post  
Hi, Stoyan.
I have the rather like question. I want to do the following: when user selects some objects I want to zoom and put these selected objects into the center of visible area of the ruller. What I have to do for this?
I processes the next event:
Code
Select All
	  private void OnDiagram_SelectionChanged(object sender, EventArgs e)
	  {
		if (sender.GetType() == typeof(Diagram))
		{
		    Selection select = m_Diagram.Selection;
		    Rect rectangle = new Rect(select.Bounds.Size);
		    m_Diagram.ZoomToRect(rectangle);
		    m_Diagram.ScrollTo(rectangle.TopLeft);
		}
	  }
 


But how to put this rect into the center of the visible area?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Need Zooming from Viewport Center
Reply #6 - Dec 16th, 2009 at 12:56pm
Print Post  
Hi,

Try this:

Code
Select All
private void OnSelectionChanged(object sender, EventArgs e)
{
	diagram.ZoomToRect(diagram.Selection.Bounds);
	diagram.BringIntoView(diagram.Selection, true);
}
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Need Zooming from Viewport Center
Reply #7 - Dec 16th, 2009 at 3:17pm
Print Post  
Thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint