← Back to team overview

kicad-developers team mailing list archive

Patch to add centering cursor on zoom to GAL

 

This patch fixes the following bug:
https://bugs.launchpad.net/kicad/+bug/1454025

Tested by myself and nickoe.

Jon Neal
diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp
index 061f882..faa4cbf 100644
--- a/common/view/wx_view_controls.cpp
+++ b/common/view/wx_view_controls.cpp
@@ -30,6 +30,9 @@
 #include <view/wx_view_controls.h>
 #include <gal/graphics_abstraction_layer.h>
 #include <tool/tool_dispatcher.h>
+#include <class_draw_panel_gal.h>
+#include <class_drawpanel.h>
+#include <draw_frame.h>
 
 using namespace KIGFX;
 
@@ -151,8 +154,21 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
             zoomScale = ( rotation > 0 ) ? 1.05 : 0.95;
         }
 
-        VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
-        m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
+        // warp cursor to center of drawing area or not during zoom
+        EDA_DRAW_PANEL_GAL* galpanel = static_cast<EDA_DRAW_PANEL_GAL*>( m_parentPanel );
+        EDA_DRAW_FRAME* drawframe = static_cast<EDA_DRAW_FRAME*>( galpanel->GetParent() );
+        if( drawframe->GetCanvas()->GetEnableZoomNoCenter() )
+        {
+            VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
+            m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
+        }
+        else
+        {
+            m_view->SetCenter( GetCursorPosition() );
+            m_view->SetScale( m_view->GetScale() * zoomScale );
+            m_parentPanel->WarpPointer( m_view->GetGAL()->GetScreenPixelSize().x/2, 
+                                        m_view->GetGAL()->GetScreenPixelSize().y/2 );
+        }
     }
 
     aEvent.Skip();
diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp
index 926a38d..c146e54 100644
--- a/pcbnew/tools/pcbnew_control.cpp
+++ b/pcbnew/tools/pcbnew_control.cpp
@@ -38,6 +38,7 @@
 #include <class_pcb_screen.h>
 #include <confirm.h>
 #include <hotkeys_basic.h>
+#include <class_drawpanel.h>
 
 #include <tool/tool_manager.h>
 #include <gal/graphics_abstraction_layer.h>
@@ -84,8 +85,15 @@ int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
     else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) )
         zoomScale = 0.7;
 
-    view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() );
-
+    if( m_frame->GetCanvas()->GetEnableZoomNoCenter() )
+        view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() );
+    else
+    {
+        view->SetCenter( getViewControls()->GetCursorPosition() );
+        view->SetScale( view->GetScale() * zoomScale );
+        m_frame->GetGalCanvas()->WarpPointer( view->GetGAL()->GetScreenPixelSize().x/2, 
+                                              view->GetGAL()->GetScreenPixelSize().y/2 );
+    }
     return 0;
 }
 

Follow ups