Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Zoom on Scroll of a Mouse for Diagram View (Read 3048 times)
SandeepGowda
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Jan 6th, 2009
Zoom on Scroll of a Mouse for Diagram View
Feb 26th, 2009 at 7:09am
Print Post  
hi,
i tried with below java code, but its not working,can you please help if i am wrong,

public void mouseWheelMoved(MouseWheelEvent evt) {

// evt.
Point2D boxDevPos = new Point(evt.getX(), evt.getY());

// Point2D.Float boxDocPos = m_mainJDiagramView.deviceToDoc(boxDevPos);
Point boxDocPos = m_mainJDiagramView.docToDevice(boxDevPos);

m_mainJDiagramView.setZoomFactor(m_mainJDiagramView.getZoomFactor()
+ evt.getWheelRotation() / 2);

Point2D afterZoom = m_mainJDiagramView.deviceToDoc(boxDocPos);

m_mainJDiagramView.setScrollX((float) (m_mainJDiagramView.getScrollX()
- boxDevPos.getX() + afterZoom.getX()));
m_mainJDiagramView.setScrollY((float) (m_mainJDiagramView.getScrollY()
- boxDevPos.getY() + afterZoom.getY()));

}

regards 
sandeep
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Zoom on Scroll of a Mouse for Diagram View
Reply #1 - Feb 26th, 2009 at 12:51pm
Print Post  
Hi,

To preserve the point below the mouse pointer after zoom as in that sample:

Code
Select All
diagramView.addMouseWheelListener(new MouseWheelListener() {

	public void mouseWheelMoved(MouseWheelEvent e)
	{
		Point2D scrollPos = new Point2D.Float(
			diagramView.getScrollX(),
			diagramView.getScrollY());
		Point scrollPosDev = diagramView.docToDevice(scrollPos);
		Point mousePosDev = e.getPoint();
		Point2D mouseDocPos = diagramView.deviceToDoc(mousePosDev);

		Point mouseOffset = new Point(
			mousePosDev.x - scrollPosDev.x,
			mousePosDev.y - scrollPosDev.y);

		float oldZoom = diagramView.getZoomFactor();
		float newZoom = oldZoom + (float)e.getWheelRotation() / 2;
		diagramView.setZoomFactor(newZoom);

		Point2D mouseOffsetDoc = diagramView.deviceToDoc(mouseOffset);
		float sx = (float)(mouseDocPos.getX() - mouseOffsetDoc.getX());
		float sy = (float)(mouseDocPos.getY() - mouseOffsetDoc.getY());
		diagramView.scrollTo(sx, sy);
	}});
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
SandeepGowda
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Jan 6th, 2009
Re: Zoom on Scroll of a Mouse for Diagram View
Reply #2 - Feb 26th, 2009 at 12:55pm
Print Post  
Thank you very much Stoyan ,its working fine

regards
Sandeep
  
Back to top
 
IP Logged
 
SandeepGowda
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Jan 6th, 2009
Re: Zoom on Scroll of a Mouse for Diagram View
Reply #3 - Mar 11th, 2009 at 10:54am
Print Post  
hi,
Above code is working fine, but can we increase the speed of zooming for scroll of mouse. ie.. small amount of scroll,larger the zooming.

regards
sandeep
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Zoom on Scroll of a Mouse for Diagram View
Reply #4 - Mar 11th, 2009 at 11:01am
Print Post  
Hi,

Remove the division by 2 from this line, or even multiply by some value:

float newZoom = oldZoom + (float)e.getWheelRotation() / 2

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint