diff --git a/3d-viewer/3d_canvas.cpp b/3d-viewer/3d_canvas.cpp index f59e631224..7980897a9e 100644 --- a/3d-viewer/3d_canvas.cpp +++ b/3d-viewer/3d_canvas.cpp @@ -66,6 +66,9 @@ BEGIN_EVENT_TABLE( EDA_3D_CANVAS, wxGLCanvas ) // mouse events EVT_RIGHT_DOWN( EDA_3D_CANVAS::OnRightClick ) EVT_MOUSEWHEEL( EDA_3D_CANVAS::OnMouseWheel ) +#ifdef USE_OSX_MAGNIFY_EVENT + EVT_MAGNIFY( EDA_3D_CANVAS::OnMagnify ) +#endif EVT_MOTION( EDA_3D_CANVAS::OnMouseMove ) // other events @@ -281,6 +284,21 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event ) GetPrm3DVisu().m_Beginy = event.GetY(); } +#ifdef USE_OSX_MAGNIFY_EVENT +void EDA_3D_CANVAS::OnMagnify( wxMouseEvent& event ) +{ + double magnification = (event.GetMagnification() + 1.0f); + + GetPrm3DVisu().m_Zoom /= magnification; + + if( GetPrm3DVisu().m_Zoom <= 0.01 ) { + GetPrm3DVisu().m_Zoom = 0.01; + } + + DisplayStatus(); + Refresh( false ); +} +#endif void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event ) { diff --git a/3d-viewer/3d_canvas.h b/3d-viewer/3d_canvas.h index bb338409c7..6e03a0e8a4 100644 --- a/3d-viewer/3d_canvas.h +++ b/3d-viewer/3d_canvas.h @@ -115,6 +115,9 @@ public: void OnEraseBackground( wxEraseEvent& event ); void OnChar( wxKeyEvent& event ); void OnMouseWheel( wxMouseEvent& event ); +#ifdef USE_OSX_MAGNIFY_EVENT + void OnMagnify( wxMouseEvent& event ); +#endif void OnMouseMove( wxMouseEvent& event ); void OnRightClick( wxMouseEvent& event ); void OnPopUpMenu( wxCommandEvent& event ); diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dda778525..28ce819099 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,6 +268,10 @@ if( USE_WX_GRAPHICS_CONTEXT ) add_definitions( -DUSE_WX_GRAPHICS_CONTEXT ) endif() +if( USE_OSX_MAGNIFY_EVENT ) + add_definitions( -DUSE_OSX_MAGNIFY_EVENT ) +endif() + # Allow user to override the default settings for adding images to menu items. By default # images in menu items are enabled on all platforms except OSX. This can be over ridden by diff --git a/common/draw_panel.cpp b/common/draw_panel.cpp index 919fdb1dc7..1ff9ec6a2d 100644 --- a/common/draw_panel.cpp +++ b/common/draw_panel.cpp @@ -70,6 +70,9 @@ static const int CURSOR_SIZE = 12; ///< Cursor size in pixels BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow ) EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving ) EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel ) +#ifdef USE_OSX_MAGNIFY_EVENT + EVT_MAGNIFY( EDA_DRAW_PANEL::OnMagnify ) +#endif EVT_MOUSE_EVENTS( EDA_DRAW_PANEL::OnMouseEvent ) EVT_CHAR( EDA_DRAW_PANEL::OnKeyEvent ) EVT_CHAR_HOOK( EDA_DRAW_PANEL::OnCharHook ) @@ -96,7 +99,11 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id, wxASSERT( parent ); #if wxCHECK_VERSION( 2, 9, 5 ) +#ifndef USE_OSX_MAGNIFY_EVENT ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS ); +#else + ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER ); +#endif DisableKeyboardScrolling(); #endif @@ -971,6 +978,32 @@ void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event ) event.Skip(); } +#ifdef USE_OSX_MAGNIFY_EVENT +void EDA_DRAW_PANEL::OnMagnify( wxMouseEvent& event ) +{ + // Scale the panel around our cursor position. + bool warpCursor = false; + + wxPoint cursorPosition = GetParent()->GetCursorPosition(false); + wxPoint centerPosition = GetParent()->GetScrollCenterPosition(); + wxPoint vector = centerPosition - cursorPosition; + + double magnification = (event.GetMagnification() + 1.0f); + double scaleFactor = GetZoom() / magnification; + + // Scale the vector between the cursor and center point + vector.x /= magnification; + vector.y /= magnification; + + SetZoom(scaleFactor); + + // Recenter the window along our scaled vector such that the + // cursor becomes our scale axis, remaining fixed on screen + GetParent()->RedrawScreen(cursorPosition + vector, warpCursor); + + event.Skip(); +} +#endif void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) { diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index f0be4b0316..3755bacedf 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -78,7 +78,11 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK, wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK, wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK, - wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE + wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, +#ifdef USE_OSX_MAGNIFY_EVENT + wxEVT_MAGNIFY, +#endif + KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE }; BOOST_FOREACH( wxEventType eventType, events ) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 569cacf23d..92be70dd2b 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -85,6 +85,9 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); +#ifdef USE_OSX_MAGNIFY_EVENT + Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); +#endif #if defined _WIN32 || defined _WIN64 Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); #endif diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 7166f6596d..3d46b33c21 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -247,6 +247,9 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) // Mouse handling if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL || +#ifdef USE_OSX_MAGNIFY_EVENT + type == wxEVT_MAGNIFY || +#endif type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP || diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 848814e460..3490ff7b78 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -39,6 +39,10 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) : { m_parentPanel->Connect( wxEVT_MOTION, wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this ); +#ifdef USE_OSX_MAGNIFY_EVENT + m_parentPanel->Connect( wxEVT_MAGNIFY, + wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), NULL, this ); +#endif m_parentPanel->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this ); m_parentPanel->Connect( wxEVT_MIDDLE_UP, @@ -175,6 +179,16 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) aEvent.Skip(); } +#ifdef USE_OSX_MAGNIFY_EVENT +void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent ) +{ + // Scale based on the magnification from our underlying magnification event. + VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) ); + setScale( m_view->GetScale() * (aEvent.GetMagnification() + 1.0f), anchor ); + + aEvent.Skip(); +} +#endif void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent ) { diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index d3e69371b3..bc3362ddbf 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -256,6 +256,9 @@ public: *

*/ void OnMouseWheel( wxMouseEvent& event ); +#ifdef USE_OSX_MAGNIFY_EVENT + void OnMagnify( wxMouseEvent& event ); +#endif void OnMouseEvent( wxMouseEvent& event ); void OnMouseLeaving( wxMouseEvent& event ); void OnKeyEvent( wxKeyEvent& event ); diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index d8722d5b78..f5d9f4248b 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -54,6 +54,9 @@ public: /// Handler functions void onWheel( wxMouseEvent& aEvent ); void onMotion( wxMouseEvent& aEvent ); +#ifdef USE_OSX_MAGNIFY_EVENT + void onMagnify( wxMouseEvent& aEvent ); +#endif void onButton( wxMouseEvent& aEvent ); void onEnter( wxMouseEvent& WXUNUSED( aEvent ) ); void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );