Fixed zooming with Apple pointing devices (GAL).

This commit is contained in:
Maciej Suminski 2015-05-18 13:48:12 +02:00
parent 7c59d0dcc4
commit cbb86c3b9c
1 changed files with 22 additions and 4 deletions

View File

@ -116,19 +116,37 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
// Zooming // Zooming
wxLongLong timeStamp = wxGetLocalTimeMillis(); wxLongLong timeStamp = wxGetLocalTimeMillis();
double timeDiff = timeStamp.ToDouble() - m_timeStamp.ToDouble(); double timeDiff = timeStamp.ToDouble() - m_timeStamp.ToDouble();
int rotation = aEvent.GetWheelRotation();
double zoomScale;
#ifdef __APPLE__
// The following is to support Apple pointer devices (MagicMouse &
// Macbook touchpad), which send events more frequently, but with smaller
// wheel rotation.
//
// It should not break other platforms, but I prefer to be safe than
// sorry. If you find a device that behaves in the same way on another
// platform, feel free to remove #ifdef directives.
if( timeDiff > 0 && timeDiff < 100 && std::abs( rotation ) < 20 )
{
aEvent.Skip();
return;
}
#endif
m_timeStamp = timeStamp; m_timeStamp = timeStamp;
double zoomScale;
// Set scaling speed depending on scroll wheel event interval // Set scaling speed depending on scroll wheel event interval
if( timeDiff < 500 && timeDiff > 0 ) if( timeDiff < 500 && timeDiff > 0 )
{ {
zoomScale = ( aEvent.GetWheelRotation() > 0 ) ? 2.05 - timeDiff / 500 : zoomScale = 2.05 - timeDiff / 500;
1.0 / ( 2.05 - timeDiff / 500 );
if( rotation < 0 )
zoomScale = 1.0 / zoomScale;
} }
else else
{ {
zoomScale = ( aEvent.GetWheelRotation() > 0 ) ? 1.05 : 0.95; zoomScale = ( rotation > 0 ) ? 1.05 : 0.95;
} }
VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) ); VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );