diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index 36803243ca..da11e45571 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -638,7 +638,7 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event ) } // Update the cursor current mouse position on the camera - m_camera.SetCurMousePosition( event.GetPosition() ); + m_camera.SetCurMousePosition( GetNativePosition( event.GetPosition() ) ); } @@ -670,14 +670,17 @@ void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event ) if( m_camera_is_moving ) return; - m_camera.SetCurWindowSize( GetNativePixelSize() ); + const wxSize& nativeWinSize = GetNativePixelSize(); + const wxPoint& nativePosition = GetNativePosition( event.GetPosition() ); + + m_camera.SetCurWindowSize( nativeWinSize ); if( event.Dragging() ) { if( event.LeftIsDown() ) // Drag - m_camera.Drag( event.GetPosition() ); + m_camera.Drag( nativePosition ); else if( event.MiddleIsDown() ) // Pan - m_camera.Pan( event.GetPosition() ); + m_camera.Pan( nativePosition ); m_mouse_is_moving = true; m_mouse_was_moved = true; @@ -687,8 +690,7 @@ void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event ) Request_refresh(); } - const wxPoint eventPosition = event.GetPosition(); - m_camera.SetCurMousePosition( eventPosition ); + m_camera.SetCurMousePosition( nativePosition ); if( !event.Dragging() && ( m_boardAdapter.GetRenderEngine() == RENDER_ENGINE::OPENGL_LEGACY ) ) diff --git a/3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp b/3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp index f40780d923..9e8af5e2a3 100644 --- a/3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp +++ b/3d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp @@ -401,18 +401,21 @@ void EDA_3D_MODEL_VIEWER::OnMagnify( wxMouseEvent& event ) void EDA_3D_MODEL_VIEWER::OnMouseMove( wxMouseEvent& event ) { - m_trackBallCamera.SetCurWindowSize( GetNativePixelSize() ); + const wxSize& nativeWinSize = GetNativePixelSize(); + const wxPoint& nativePosition = GetNativePosition( event.GetPosition() ); + + m_trackBallCamera.SetCurWindowSize( nativeWinSize ); if( event.Dragging() ) { if( event.LeftIsDown() ) // Drag - m_trackBallCamera.Drag( event.GetPosition() ); + m_trackBallCamera.Drag( nativePosition ); // orientation has changed, redraw mesh Refresh( false ); } - m_trackBallCamera.SetCurMousePosition( event.GetPosition() ); + m_trackBallCamera.SetCurMousePosition( nativePosition ); } diff --git a/common/gal/hidpi_gl_canvas.cpp b/common/gal/hidpi_gl_canvas.cpp index 0585d9e7ce..e20c9eb62a 100644 --- a/common/gal/hidpi_gl_canvas.cpp +++ b/common/gal/hidpi_gl_canvas.cpp @@ -50,6 +50,18 @@ wxSize HIDPI_GL_CANVAS::GetNativePixelSize() const } +wxPoint HIDPI_GL_CANVAS::GetNativePosition( const wxPoint& aPoint ) const +{ + wxPoint nativePoint = aPoint; + + const double scaleFactor = GetScaleFactor(); + nativePoint.x *= scaleFactor; + nativePoint.y *= scaleFactor; + + return nativePoint; +} + + void HIDPI_GL_CANVAS::SetScaleFactor( double aNewScaleFactor ) { m_scale_factor = aNewScaleFactor; diff --git a/include/gal/hidpi_gl_canvas.h b/include/gal/hidpi_gl_canvas.h index 70419e3f9d..0913f9cf1a 100644 --- a/include/gal/hidpi_gl_canvas.h +++ b/include/gal/hidpi_gl_canvas.h @@ -46,6 +46,11 @@ public: virtual wxSize GetNativePixelSize() const; + /** + * Convert the given point from client coordinates to native pixel coordinates. + */ + wxPoint GetNativePosition( const wxPoint& aPoint ) const; + /** * Set the canvas scale factor, probably for a hi-DPI display. */