Convert mouse coordinates to native pixesl in the 3D viewer

All operations in the camera are done using the native pixel sizes,
so we need to ensure the mouse coordinates are converted to native
pixels to make the mouse operations line up with the view.

Fixes https://gitlab.com/kicad/code/kicad/issues/2561
Fixes https://gitlab.com/kicad/code/kicad/issues/8410
This commit is contained in:
Ian McInerney 2021-10-10 17:49:58 +01:00
parent 52bbfb9109
commit 961c127ebe
4 changed files with 31 additions and 9 deletions

View File

@ -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 ) )

View File

@ -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 );
}

View File

@ -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;

View File

@ -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.
*/