Eeschema: simulator plot: allow standard mac pan and pinch to zoom

This commit is contained in:
Jonatan Liljedahl 2019-11-19 15:58:32 +01:00 committed by Wayne Stambaugh
parent 2cd60cdfaf
commit 7c7d9c3e3f
3 changed files with 77 additions and 21 deletions

View File

@ -61,7 +61,7 @@
#define mpSCROLL_NUM_PIXELS_PER_LINE 10 #define mpSCROLL_NUM_PIXELS_PER_LINE 10
// See doxygen comments. // See doxygen comments.
double mpWindow::zoomIncrementalFactor = 1.5; double mpWindow::zoomIncrementalFactor = 1.1;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// mpLayer // mpLayer
@ -1716,6 +1716,9 @@ EVT_SCROLLWIN_BOTTOM( mpWindow::OnScrollBottom )
EVT_MIDDLE_DOWN( mpWindow::OnMouseMiddleDown ) // JLB EVT_MIDDLE_DOWN( mpWindow::OnMouseMiddleDown ) // JLB
EVT_RIGHT_UP( mpWindow::OnShowPopupMenu ) EVT_RIGHT_UP( mpWindow::OnShowPopupMenu )
EVT_MOUSEWHEEL( mpWindow::OnMouseWheel ) // JLB EVT_MOUSEWHEEL( mpWindow::OnMouseWheel ) // JLB
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
EVT_MAGNIFY( mpWindow::OnMagnify )
#endif
EVT_MOTION( mpWindow::OnMouseMove ) // JLB EVT_MOTION( mpWindow::OnMouseMove ) // JLB
EVT_LEFT_DOWN( mpWindow::OnMouseLeftDown ) EVT_LEFT_DOWN( mpWindow::OnMouseLeftDown )
EVT_LEFT_UP( mpWindow::OnMouseLeftRelease ) EVT_LEFT_UP( mpWindow::OnMouseLeftRelease )
@ -1797,6 +1800,23 @@ void mpWindow::OnMouseMiddleDown( wxMouseEvent& event )
m_mouseMClick.y = event.GetY(); m_mouseMClick.y = event.GetY();
} }
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
void mpWindow::OnMagnify( wxMouseEvent& event )
{
if( !m_enableMouseNavigation )
{
event.Skip();
return;
}
float zoom = event.GetMagnification() + 1.0f;
wxPoint pos( event.GetX(), event.GetY() );
if( zoom > 1.0f )
ZoomIn( pos, zoom );
else if( zoom < 1.0f )
ZoomOut( pos, 1.0f / zoom );
}
#endif
// Process mouse wheel events // Process mouse wheel events
// JLB // JLB
@ -1808,22 +1828,35 @@ void mpWindow::OnMouseWheel( wxMouseEvent& event )
return; return;
} }
// Scroll vertically or horizontally (this is SHIFT is hold down). int change = event.GetWheelRotation();
int change = -event.GetWheelRotation(); // Opposite direction (More intuitive)! const int axis = event.GetWheelAxis();
double changeUnitsX = change / m_scaleX; double changeUnitsX = change / m_scaleX;
double changeUnitsY = change / m_scaleY; double changeUnitsY = change / m_scaleY;
if( event.m_controlDown ) if( ( !m_enableMouseWheelPan && ( event.ControlDown() || event.ShiftDown() ) )
|| ( m_enableMouseWheelPan && !event.ControlDown() ) )
{ {
// horizontal scroll // Scrolling
SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX, if( m_enableMouseWheelPan )
m_desiredXmin + changeUnitsX ); {
} if( axis == wxMOUSE_WHEEL_HORIZONTAL || event.ShiftDown() )
else if( event.m_shiftDown ) SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
{ m_desiredXmin + changeUnitsX );
// vertical scroll else
SetYView( m_posY - changeUnitsY, m_desiredYmax - changeUnitsY, SetYView( m_posY + changeUnitsY, m_desiredYmax + changeUnitsY,
m_desiredYmin - changeUnitsY ); m_desiredYmin + changeUnitsY );
}
else
{
if( event.ControlDown() )
SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
m_desiredXmin + changeUnitsX );
else
SetYView( m_posY + changeUnitsY, m_desiredYmax + changeUnitsY,
m_desiredYmin + changeUnitsY );
}
UpdateAll();
} }
else else
{ {
@ -1834,9 +1867,9 @@ void mpWindow::OnMouseWheel( wxMouseEvent& event )
ZoomIn( clickPt ); ZoomIn( clickPt );
else else
ZoomOut( clickPt ); ZoomOut( clickPt );
}
UpdateAll(); return;
}
} }
@ -2241,6 +2274,12 @@ bool mpWindow::SetYView( double pos, double desiredMax, double desiredMin )
void mpWindow::ZoomIn( const wxPoint& centerPoint ) void mpWindow::ZoomIn( const wxPoint& centerPoint )
{
ZoomIn( centerPoint, zoomIncrementalFactor );
}
void mpWindow::ZoomIn( const wxPoint& centerPoint, double zoomFactor )
{ {
wxPoint c( centerPoint ); wxPoint c( centerPoint );
@ -2264,8 +2303,8 @@ void mpWindow::ZoomIn( const wxPoint& centerPoint )
// Zoom in: // Zoom in:
const double MAX_SCALE = 1e6; const double MAX_SCALE = 1e6;
double newScaleX = m_scaleX * zoomIncrementalFactor; double newScaleX = m_scaleX * zoomFactor;
double newScaleY = m_scaleY * zoomIncrementalFactor; double newScaleY = m_scaleY * zoomFactor;
// Baaaaad things happen when you zoom in too much.. // Baaaaad things happen when you zoom in too much..
if( newScaleX <= MAX_SCALE && newScaleY <= MAX_SCALE ) if( newScaleX <= MAX_SCALE && newScaleY <= MAX_SCALE )
@ -2298,6 +2337,12 @@ void mpWindow::ZoomIn( const wxPoint& centerPoint )
void mpWindow::ZoomOut( const wxPoint& centerPoint ) void mpWindow::ZoomOut( const wxPoint& centerPoint )
{
ZoomOut( centerPoint, zoomIncrementalFactor );
}
void mpWindow::ZoomOut( const wxPoint& centerPoint, double zoomFactor )
{ {
wxPoint c( centerPoint ); wxPoint c( centerPoint );
@ -2313,8 +2358,8 @@ void mpWindow::ZoomOut( const wxPoint& centerPoint )
double prior_layer_y = p2y( c.y ); double prior_layer_y = p2y( c.y );
// Zoom out: // Zoom out:
m_scaleX = m_scaleX / zoomIncrementalFactor; m_scaleX = m_scaleX / zoomFactor;
m_scaleY = m_scaleY / zoomIncrementalFactor; m_scaleY = m_scaleY / zoomFactor;
// Adjust the new m_posx/y: // Adjust the new m_posx/y:
m_posX = prior_layer_x - c.x / m_scaleX; m_posX = prior_layer_x - c.x / m_scaleX;

View File

@ -395,6 +395,9 @@ SIM_PLOT_PANEL* SIM_PLOT_FRAME::NewPlotPanel( SIM_TYPE aSimType )
{ {
SIM_PLOT_PANEL* plotPanel = new SIM_PLOT_PANEL( aSimType, m_plotNotebook, wxID_ANY ); SIM_PLOT_PANEL* plotPanel = new SIM_PLOT_PANEL( aSimType, m_plotNotebook, wxID_ANY );
plotPanel->EnableMouseWheelPan(
m_schematicFrame->GetCanvas()->GetViewControls()->IsMousewheelPanEnabled() );
if( m_welcomePanel ) if( m_welcomePanel )
{ {
m_plotNotebook->DeletePage( 0 ); m_plotNotebook->DeletePage( 0 );

View File

@ -1208,6 +1208,10 @@ public:
*/ */
void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; } void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; }
/** Enable/disable trackpad friendly panning (2-axis scroll wheel)
*/
void EnableMouseWheelPan( bool enabled ) { m_enableMouseWheelPan = enabled; }
/** Enable or disable X/Y scale aspect locking for the view. /** Enable or disable X/Y scale aspect locking for the view.
* @note Explicit calls to mpWindow::SetScaleX and mpWindow::SetScaleY will set * @note Explicit calls to mpWindow::SetScaleX and mpWindow::SetScaleY will set
* an unlocked aspect, but any other action changing the view scale will * an unlocked aspect, but any other action changing the view scale will
@ -1241,12 +1245,14 @@ public:
* position on the screen after the zoom (by default, the center of the mpWindow). * position on the screen after the zoom (by default, the center of the mpWindow).
*/ */
void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition ); void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition );
void ZoomIn( const wxPoint& centerPoint, double zoomFactor );
/** Zoom out current view and refresh display /** Zoom out current view and refresh display
* @param centerPoint The point (pixel coordinates) that will stay in the same * @param centerPoint The point (pixel coordinates) that will stay in the same
* position on the screen after the zoom (by default, the center of the mpWindow). * position on the screen after the zoom (by default, the center of the mpWindow).
*/ */
void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition ); void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition );
void ZoomOut( const wxPoint& centerPoint, double zoomFactor );
/** Zoom in current view along X and refresh display */ /** Zoom in current view along X and refresh display */
void ZoomInX(); void ZoomInX();
@ -1433,6 +1439,7 @@ protected:
void OnZoomOut( wxCommandEvent& event ); // !< Context menu handler void OnZoomOut( wxCommandEvent& event ); // !< Context menu handler
void OnLockAspect( wxCommandEvent& event ); // !< Context menu handler void OnLockAspect( wxCommandEvent& event ); // !< Context menu handler
void OnMouseWheel( wxMouseEvent& event ); // !< Mouse handler for the wheel void OnMouseWheel( wxMouseEvent& event ); // !< Mouse handler for the wheel
void OnMagnify( wxMouseEvent& event ); // !< Pinch zoom handler
void OnMouseMove( wxMouseEvent& event ); // !< Mouse handler for mouse motion (for pan) void OnMouseMove( wxMouseEvent& event ); // !< Mouse handler for mouse motion (for pan)
void OnMouseLeftDown( wxMouseEvent& event ); // !< Mouse left click (for rect zoom) void OnMouseLeftDown( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
void OnMouseLeftRelease( wxMouseEvent& event ); // !< Mouse left click (for rect zoom) void OnMouseLeftRelease( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
@ -1516,6 +1523,7 @@ protected:
wxBitmap* m_buff_bmp; // !< For double buffering wxBitmap* m_buff_bmp; // !< For double buffering
bool m_enableDoubleBuffer; // !< For double buffering bool m_enableDoubleBuffer; // !< For double buffering
bool m_enableMouseNavigation; // !< For pan/zoom with the mouse. bool m_enableMouseNavigation; // !< For pan/zoom with the mouse.
bool m_enableMouseWheelPan; // !< Trackpad pan/zoom
bool m_enableLimitedView; bool m_enableLimitedView;
wxPoint m_mouseMClick; // !< For the middle button "drag" feature wxPoint m_mouseMClick; // !< For the middle button "drag" feature
wxPoint m_mouseLClick; // !< Starting coords for rectangular zoom selection wxPoint m_mouseLClick; // !< Starting coords for rectangular zoom selection